diff --git a/src/app/shared/store/user.state.ts b/src/app/shared/store/user.state.ts index 3fce964ae1..eeb1d625db 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( @@ -231,7 +231,7 @@ export class UserState { } @Action(OnCreateWorkshopSuccess) - onCreateWorkshopSuccess({patchState, dispatch }: StateContext, { payload }: OnCreateWorkshopSuccess): void { + onCreateWorkshopSuccess({ patchState, dispatch }: StateContext, { payload }: OnCreateWorkshopSuccess): void { patchState({ isLoading: false }) dispatch(new MarkFormDirty(false)); console.log('Workshop is created', payload); @@ -431,7 +431,7 @@ export class UserState { 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) 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..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 @@ -23,7 +23,7 @@ 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({ @@ -31,28 +31,53 @@ 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)]), }); } 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.sameAddressHandler(); this.provider && this.activateEditMode(); } - activateEditMode(): void { + private activateEditMode(): void { + 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 }); + } - 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 the formgroup + */ + private sameAddressHandler(): void { + this.isSameAddressControl.valueChanges.subscribe((isSame: boolean) => { + if (isSame) { + this.ActualAddressFormGroup.reset(); + this.ActualAddressFormGroup.disable(); + this.ActualAddressFormGroup.clearValidators(); + } else { + this.ActualAddressFormGroup.enable(); + this.ActualAddressFormGroup.markAsUntouched(); + this.setValidators(); + this.provider.actualAddress && this.ActualAddressFormGroup.get('id').setValue(this.provider.actualAddress.id); + } + }); + } + /** + * This method add validators to teh form-group when actual address is not teh same as legal address + */ + 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) => { + this.ActualAddressFormGroup.get(formControlTitle).setValidators([addValidator(formControlTitle), Validators.required]); + }); } } 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 34ddf4f2f4..a9be68ed40 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 @@ -87,19 +87,18 @@ export class CreateProviderComponent implements OnInit, AfterViewInit, OnDestroy 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)); }