From d839531d08aa6763b113dbf72a844f558f75e31b Mon Sep 17 00:00:00 2001 From: Raviraj Bahirsheth <111955585+rbahirsheth@users.noreply.github.com> Date: Fri, 25 Aug 2023 18:43:14 +0530 Subject: [PATCH] =?UTF-8?q?[APPS-2134]=20Remove=20moment.js=20dependency?= =?UTF-8?q?=20from=20start-task-cloud.compone=E2=80=A6=20(#8845)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [APPS-2134] Remove moment.js dependency from start-task-cloud.component.ts * Removed the console log * Update variable name --- .../components/start-task-cloud.component.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.ts b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.ts index dab14a92e5..70c1c965ac 100644 --- a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.ts @@ -17,11 +17,10 @@ import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation, OnDestroy, ViewChild } from '@angular/core'; import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core'; -import moment, { Moment } from 'moment'; import { Observable, Subject } from 'rxjs'; import { UntypedFormBuilder, Validators, UntypedFormGroup, UntypedFormControl } from '@angular/forms'; import { - MOMENT_DATE_FORMATS, MomentDateAdapter, + DateFnsUtils, LogService, UserPreferencesService, UserPreferenceValues @@ -34,17 +33,19 @@ import { takeUntil } from 'rxjs/operators'; import { TaskPriorityOption } from '../../models/task.model'; import { IdentityUserService } from '../../../people/services/identity-user.service'; import { IdentityUserModel } from '../../../people/models/identity-user.model'; +import { DateFnsAdapter, MAT_DATE_FNS_FORMATS } from '@angular/material-date-fns-adapter'; +import { isValid, parse } from 'date-fns'; const MAX_NAME_LENGTH = 255; -const DATE_FORMAT: string = 'DD/MM/YYYY'; +const DATE_FORMAT: string = 'dd/MM/yyyy'; @Component({ selector: 'adf-cloud-start-task', templateUrl: './start-task-cloud.component.html', styleUrls: ['./start-task-cloud.component.scss'], providers: [ - { provide: DateAdapter, useClass: MomentDateAdapter }, - { provide: MAT_DATE_FORMATS, useValue: MOMENT_DATE_FORMATS }], + { provide: DateAdapter, useClass: DateFnsAdapter }, + { provide: MAT_DATE_FORMATS, useValue: MAT_DATE_FNS_FORMATS }], encapsulation: ViewEncapsulation.None }) export class StartTaskCloudComponent implements OnInit, OnDestroy { @@ -105,7 +106,7 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy { private onDestroy$ = new Subject(); constructor(private taskService: TaskCloudService, - private dateAdapter: DateAdapter, + private dateAdapter: DateAdapter, private userPreferencesService: UserPreferencesService, private formBuilder: UntypedFormBuilder, private identityUserService: IdentityUserService, @@ -116,7 +117,7 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy { this.userPreferencesService .select(UserPreferenceValues.Locale) .pipe(takeUntil(this.onDestroy$)) - .subscribe(locale => this.dateAdapter.setLocale(locale)); + .subscribe(locale => this.dateAdapter.setLocale(DateFnsUtils.getLocaleFromString(locale))); this.loadCurrentUser(); this.buildForm(); this.loadDefaultPriorities(); @@ -182,8 +183,9 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy { this.dateError = false; if (newDateValue) { - const momentDate = moment(newDateValue, DATE_FORMAT, true); - if (!momentDate.isValid()) { + const date = parse(newDateValue, DATE_FORMAT, new Date()); + + if (!isValid(date)) { this.dateError = true; } } @@ -219,8 +221,8 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy { public whitespaceValidator(control: UntypedFormControl) { const isWhitespace = (control.value || '').trim().length === 0; - const isValid = control.value.length === 0 || !isWhitespace; - return isValid ? null : { whitespace: true }; + const isControlValid = control.value.length === 0 || !isWhitespace; + return isControlValid ? null : { whitespace: true }; } get nameController(): UntypedFormControl {