From 460f2e8ca7ec6a915ec375af835d177546539675 Mon Sep 17 00:00:00 2001 From: Sasha Date: Tue, 26 Oct 2021 20:55:14 +0300 Subject: [PATCH 1/7] first view --- .../create-contacts-form.component.html | 8 +++- .../create-contacts-form.component.scss | 5 ++- .../create-contacts-form.component.ts | 39 ++++++++++++------- .../create-provider.component.ts | 9 ++--- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.html b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.html index dc31ec1d4f..6db8210f96 100644 --- a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.html +++ b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.html @@ -68,12 +68,16 @@

Юридична адреса


-
-

Фактична адреса

+
+

Фактична адреса

Співпадає з юридичною адресою +
+ + diff --git a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.scss b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.scss index 5f5f962c8f..74b66f98df 100644 --- a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.scss +++ b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.scss @@ -1,2 +1,5 @@ @import "src/app/shared/styles/create-form.scss"; -@import "src/app/shared/styles/validation-form.scss"; \ No newline at end of file +@import "src/app/shared/styles/validation-form.scss"; +.disbale{ + opacity: 0.3; +} \ No newline at end of file diff --git a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts index 97f0ad94ca..49c5491af9 100644 --- a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts +++ b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts @@ -23,36 +23,45 @@ export class CreateContactsFormComponent implements OnInit { buildingNumber: new FormControl('', [Validators.required, Validators.pattern(TEXT_WITH_DIGITS_REGEX)]), city: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), district: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), - region: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]) + region: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), }); this.ActualAddressFormGroup = this.formBuilder.group({ - street: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), - buildingNumber: new FormControl('', [Validators.required, Validators.pattern(TEXT_WITH_DIGITS_REGEX)]), - city: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), - district: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), - region: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]) + street: new FormControl(''), + buildingNumber: new FormControl(''), + city: new FormControl(''), + district: new FormControl(''), + region: new FormControl('') }); } ngOnInit(): void { this.passActualAddressFormGroup.emit(this.ActualAddressFormGroup); this.passLegalAddressFormGroup.emit(this.LegalAddressFormGroup); - this.isSameAddressControl.valueChanges.subscribe((isSame: boolean) => { - (isSame) ? this.ActualAddressFormGroup.patchValue(this.LegalAddressFormGroup.value) : this.ActualAddressFormGroup.reset(); - }); + this.onDisableIsSameAddressControlInit(); this.provider && this.activateEditMode(); } activateEditMode(): void { this.LegalAddressFormGroup.patchValue(this.provider.legalAddress, { emitEvent: false }); + this.isSameAddressControl.setValue(!Boolean(this.provider.actualAddress)); + this.provider.actualAddress && this.ActualAddressFormGroup.patchValue(this.provider.actualAddress, { emitEvent: false }); + } - if (this.provider?.actualAddress) { - this.ActualAddressFormGroup.patchValue(this.provider.actualAddress, { emitEvent: false }); - } else { - this.ActualAddressFormGroup.patchValue(this.provider.legalAddress, { emitEvent: false }); - } - + /** + * This method makes input enable if radiobutton value is true and sets the value to teh formgroup + */ + onDisableIsSameAddressControlInit(): void { + this.isSameAddressControl.valueChanges.subscribe((isSame: boolean) => { + this.ActualAddressFormGroup.reset(); + if (isSame) { + this.ActualAddressFormGroup.disable(); + this.ActualAddressFormGroup.clearValidators(); + } else { + this.ActualAddressFormGroup.enable(); + this.ActualAddressFormGroup.setValidators([Validators.required, Validators.pattern(TEXT_REGEX)]); + } + }); } } diff --git a/src/app/shell/personal-cabinet/provider/create-provider/create-provider.component.ts b/src/app/shell/personal-cabinet/provider/create-provider/create-provider.component.ts index 66f9b70e52..4a7ba22801 100644 --- a/src/app/shell/personal-cabinet/provider/create-provider/create-provider.component.ts +++ b/src/app/shell/personal-cabinet/provider/create-provider/create-provider.component.ts @@ -72,19 +72,18 @@ export class CreateProviderComponent implements OnInit, AfterViewInit { this.checkValidation(this.PhotoFormGroup); } else { const user: User = this.store.selectSnapshot(RegistrationState.user); - let legalAddress: Address; let actulaAdress: Address; let provider: Provider; if (this.editMode) { - legalAddress = new Address(this.ActualAddressFormGroup.value, this.provider.legalAddress); - actulaAdress = new Address(this.LegalAddressFormGroup.value, this.provider.actualAddress); + legalAddress = new Address(this.LegalAddressFormGroup.value, this.provider.legalAddress); + actulaAdress = this.ActualAddressFormGroup.disabled ? null : new Address(this.ActualAddressFormGroup.value, this.provider.actualAddress); provider = new Provider(this.InfoFormGroup.value, legalAddress, actulaAdress, this.PhotoFormGroup.value, user, this.provider); this.store.dispatch(new UpdateProvider(provider)); } else { - legalAddress = new Address(this.ActualAddressFormGroup.value); - actulaAdress = new Address(this.LegalAddressFormGroup.value); + legalAddress = new Address(this.LegalAddressFormGroup.value); + actulaAdress = this.ActualAddressFormGroup.disabled ? null : new Address(this.ActualAddressFormGroup.value); provider = new Provider(this.InfoFormGroup.value, legalAddress, actulaAdress, this.PhotoFormGroup.value, user); this.store.dispatch(new CreateProvider(provider)); } From 88e21ff7df74f4bf2fa61c800823d39042a07f0d Mon Sep 17 00:00:00 2001 From: Sasha Date: Wed, 3 Nov 2021 13:52:09 +0200 Subject: [PATCH 2/7] Update create-contacts-form.component.ts --- .../create-contacts-form.component.ts | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts index 49c5491af9..02a19d801a 100644 --- a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts +++ b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts @@ -27,41 +27,54 @@ export class CreateContactsFormComponent implements OnInit { }); this.ActualAddressFormGroup = this.formBuilder.group({ - street: new FormControl(''), - buildingNumber: new FormControl(''), - city: new FormControl(''), - district: new FormControl(''), - region: new FormControl('') + street: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), + buildingNumber: new FormControl('', [Validators.required, Validators.pattern(TEXT_WITH_DIGITS_REGEX)]), + city: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), + district: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), + region: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]), }); } ngOnInit(): void { this.passActualAddressFormGroup.emit(this.ActualAddressFormGroup); this.passLegalAddressFormGroup.emit(this.LegalAddressFormGroup); - this.onDisableIsSameAddressControlInit(); + this.initDisableIsSameAddressControl(); this.provider && this.activateEditMode(); } activateEditMode(): void { - this.LegalAddressFormGroup.patchValue(this.provider.legalAddress, { emitEvent: false }); + this.LegalAddressFormGroup.addControl('id', this.formBuilder.control('')); + this.ActualAddressFormGroup.addControl('id', this.formBuilder.control('')); + this.isSameAddressControl.setValue(!Boolean(this.provider.actualAddress)); + + this.LegalAddressFormGroup.patchValue(this.provider.legalAddress, { emitEvent: false }); this.provider.actualAddress && this.ActualAddressFormGroup.patchValue(this.provider.actualAddress, { emitEvent: false }); } /** * This method makes input enable if radiobutton value is true and sets the value to teh formgroup */ - onDisableIsSameAddressControlInit(): void { + initDisableIsSameAddressControl(): void { this.isSameAddressControl.valueChanges.subscribe((isSame: boolean) => { - this.ActualAddressFormGroup.reset(); if (isSame) { + this.ActualAddressFormGroup.reset(); this.ActualAddressFormGroup.disable(); this.ActualAddressFormGroup.clearValidators(); } else { this.ActualAddressFormGroup.enable(); - this.ActualAddressFormGroup.setValidators([Validators.required, Validators.pattern(TEXT_REGEX)]); + this.ActualAddressFormGroup.markAsUntouched(); + this.setValidators(); } }); } + + setValidators(): void { + const addValidator = (formControlTitle: string) => (formControlTitle !== 'buildingNumber') ? Validators.pattern(TEXT_REGEX) : Validators.pattern(TEXT_WITH_DIGITS_REGEX); + + Object.keys(this.ActualAddressFormGroup.controls).forEach((formControlTitle: string) => { + this.ActualAddressFormGroup.get(formControlTitle).setValidators([addValidator(formControlTitle), Validators.required]); + }); + } } From 59fabea7e12c236c9fcf1a8c4bdb5a2fb00ec9d6 Mon Sep 17 00:00:00 2001 From: Sasha Date: Wed, 3 Nov 2021 13:55:52 +0200 Subject: [PATCH 3/7] Update create-contacts-form.component.ts --- .../create-contacts-form/create-contacts-form.component.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts index 02a19d801a..0f3c82bbe1 100644 --- a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts +++ b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts @@ -54,7 +54,7 @@ export class CreateContactsFormComponent implements OnInit { } /** - * This method makes input enable if radiobutton value is true and sets the value to teh formgroup + * This method makes input enable if radiobutton value is true and sets the value to the formgroup */ initDisableIsSameAddressControl(): void { this.isSameAddressControl.valueChanges.subscribe((isSame: boolean) => { @@ -69,7 +69,9 @@ export class CreateContactsFormComponent implements OnInit { } }); } - + /** + * This method add validators to teh form-group when actual address is not teh same as legal address + */ setValidators(): void { const addValidator = (formControlTitle: string) => (formControlTitle !== 'buildingNumber') ? Validators.pattern(TEXT_REGEX) : Validators.pattern(TEXT_WITH_DIGITS_REGEX); From d775b8dd4d5d70de60d2014392e6f57f080c2150 Mon Sep 17 00:00:00 2001 From: Sasha Date: Wed, 3 Nov 2021 14:12:10 +0200 Subject: [PATCH 4/7] Update create-contacts-form.component.ts --- .../create-contacts-form/create-contacts-form.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts index 0f3c82bbe1..a95935994d 100644 --- a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts +++ b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts @@ -66,6 +66,7 @@ export class CreateContactsFormComponent implements OnInit { this.ActualAddressFormGroup.enable(); this.ActualAddressFormGroup.markAsUntouched(); this.setValidators(); + this.provider.actualAddress && this.ActualAddressFormGroup.get('id').setValue(this.provider.actualAddress.id); } }); } From 369730ce9a06b2f4265029cfcc5e21a43cec4d89 Mon Sep 17 00:00:00 2001 From: Sasha Date: Thu, 11 Nov 2021 14:32:52 +0200 Subject: [PATCH 5/7] dispatch actions --- src/app/shared/models/workshop.model.ts | 2 +- src/app/shared/store/user.actions.ts | 2 +- src/app/shared/store/user.state.ts | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/app/shared/models/workshop.model.ts b/src/app/shared/models/workshop.model.ts index 41081a339e..745a34514d 100644 --- a/src/app/shared/models/workshop.model.ts +++ b/src/app/shared/models/workshop.model.ts @@ -72,7 +72,7 @@ export interface WorkshopCard { minAge: number; photo?: string; price: number; - providerId: number; + providerId: string; providerTitle: string; rating: number; title: string; diff --git a/src/app/shared/store/user.actions.ts b/src/app/shared/store/user.actions.ts index 466f53547c..222f8fea92 100644 --- a/src/app/shared/store/user.actions.ts +++ b/src/app/shared/store/user.actions.ts @@ -60,7 +60,7 @@ export class DeleteWorkshopById { } export class OnDeleteWorkshopSuccess { static readonly type = '[user] delete Workshop success'; - constructor(public payload: string) { } + constructor(public payload: WorkshopCard) { } } export class OnDeleteWorkshopFail { static readonly type = '[user] delete Workshop fail'; diff --git a/src/app/shared/store/user.state.ts b/src/app/shared/store/user.state.ts index 73465139a1..b5d78e6d58 100644 --- a/src/app/shared/store/user.state.ts +++ b/src/app/shared/store/user.state.ts @@ -246,7 +246,7 @@ export class UserState { return this.userWorkshopService .deleteWorkshop(payload.workshopId) .pipe( - tap((res) => dispatch(new OnDeleteWorkshopSuccess(payload.title))), + tap((res) => dispatch(new OnDeleteWorkshopSuccess(payload))), catchError((error: Error) => of(dispatch(new OnDeleteWorkshopFail(error)))) ); } @@ -259,8 +259,10 @@ export class UserState { @Action(OnDeleteWorkshopSuccess) onDeleteWorkshopSuccess({ dispatch }: StateContext, { payload }: OnDeleteWorkshopSuccess): void { - console.log('Workshop is deleted', payload); + console.log('Workshop is deleted', payload.title); dispatch(new ShowMessageBar({ message: `Дякуємо! Гурток "${payload}" видалено!`, type: 'success' })); + dispatch(new GetWorkshopsByProviderId(payload.providerId)); + } @Action(CreateChildren) @@ -424,11 +426,11 @@ export class UserState { } @Action(OnUpdateProviderSuccess) - onUpdateProviderSuccess({ dispatch }: StateContext, { payload }: OnUpdateProviderSuccess): void { + onUpdateProviderSuccess({ dispatch, patchState }: StateContext, { payload }: OnUpdateProviderSuccess): void { dispatch(new MarkFormDirty(false)); console.log('Provider is updated', payload); dispatch(new ShowMessageBar({ message: 'Організація успішно відредагована', type: 'success' })); - this.router.navigate(['/personal-cabinet/provider/info']); + dispatch(new GetProfile()).subscribe(() => this.router.navigate(['/personal-cabinet/provider/info'])); } @Action(UpdateUser) From 94ab65044b329831f2eb30b6e45efb823a7841c7 Mon Sep 17 00:00:00 2001 From: Sasha Date: Thu, 11 Nov 2021 14:36:03 +0200 Subject: [PATCH 6/7] Update user.state.ts --- src/app/shared/store/user.state.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/shared/store/user.state.ts b/src/app/shared/store/user.state.ts index b5d78e6d58..853ceb31b0 100644 --- a/src/app/shared/store/user.state.ts +++ b/src/app/shared/store/user.state.ts @@ -204,7 +204,7 @@ export class UserState { } @Action(GetAllUsersChildren) - getAllUsersChildren({ patchState, getState }: StateContext, { }: GetAllUsersChildren): Observable { + getAllUsersChildren({ patchState }: StateContext, { }: GetAllUsersChildren): Observable { return this.childrenService .getAllUsersChildren() .pipe( @@ -426,7 +426,7 @@ export class UserState { } @Action(OnUpdateProviderSuccess) - onUpdateProviderSuccess({ dispatch, patchState }: StateContext, { payload }: OnUpdateProviderSuccess): void { + onUpdateProviderSuccess({ dispatch }: StateContext, { payload }: OnUpdateProviderSuccess): void { dispatch(new MarkFormDirty(false)); console.log('Provider is updated', payload); dispatch(new ShowMessageBar({ message: 'Організація успішно відредагована', type: 'success' })); From 135cd19fba1d0ccd873134ec02827a6553392ed1 Mon Sep 17 00:00:00 2001 From: Sasha Date: Thu, 11 Nov 2021 14:47:56 +0200 Subject: [PATCH 7/7] Update create-contacts-form.component.ts --- .../create-contacts-form.component.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts index a95935994d..b947db2b0e 100644 --- a/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts +++ b/src/app/shell/personal-cabinet/provider/create-provider/create-contacts-form/create-contacts-form.component.ts @@ -38,12 +38,12 @@ export class CreateContactsFormComponent implements OnInit { ngOnInit(): void { this.passActualAddressFormGroup.emit(this.ActualAddressFormGroup); this.passLegalAddressFormGroup.emit(this.LegalAddressFormGroup); - this.initDisableIsSameAddressControl(); + this.sameAddressHandler(); this.provider && this.activateEditMode(); } - activateEditMode(): void { + private activateEditMode(): void { this.LegalAddressFormGroup.addControl('id', this.formBuilder.control('')); this.ActualAddressFormGroup.addControl('id', this.formBuilder.control('')); @@ -56,7 +56,7 @@ export class CreateContactsFormComponent implements OnInit { /** * This method makes input enable if radiobutton value is true and sets the value to the formgroup */ - initDisableIsSameAddressControl(): void { + private sameAddressHandler(): void { this.isSameAddressControl.valueChanges.subscribe((isSame: boolean) => { if (isSame) { this.ActualAddressFormGroup.reset(); @@ -73,7 +73,7 @@ export class CreateContactsFormComponent implements OnInit { /** * This method add validators to teh form-group when actual address is not teh same as legal address */ - setValidators(): void { + private setValidators(): void { const addValidator = (formControlTitle: string) => (formControlTitle !== 'buildingNumber') ? Validators.pattern(TEXT_REGEX) : Validators.pattern(TEXT_WITH_DIGITS_REGEX); Object.keys(this.ActualAddressFormGroup.controls).forEach((formControlTitle: string) => {