HIMA-831 cart saving notification workflow adjustments

This commit is contained in:
Mikuta Aleksandras
2020-02-27 12:09:27 +01:00
parent 2d74cc0d03
commit 5545526759
3 changed files with 30 additions and 17 deletions

View File

@@ -79,7 +79,7 @@
</ng-template>
<div class="buttons">
<app-button (action)="saveEmail()" [color]="buttonColor('email.email', 'email')">Speichern</app-button>
<app-button (action)="saveEmail()" [disabled]="buttonDisabled('email.email', 'email')">Speichern</app-button>
</div>
</div>
</ng-container>
@@ -128,7 +128,7 @@
</ng-template>
<div class="buttons">
<app-button (action)="savePhone()" [color]="buttonColor('sms.telephone', 'phone')">Speichern</app-button>
<app-button (action)="savePhone()" [disabled]="buttonDisabled('sms.telephone', 'phone')">Speichern</app-button>
</div>
</div>
</ng-container>

View File

@@ -1,3 +1,13 @@
:host {
::ng-deep {
app-button {
.secondary-disabled {
color: #557596 !important;
}
}
}
}
label {
font-size: 16px;
font-weight: bold;

View File

@@ -2,7 +2,7 @@ import { Component, OnInit, Input, ChangeDetectorRef, ChangeDetectionStrategy, O
import { FormGroup, FormBuilder, Validators, AbstractControl } from '@angular/forms';
import { Actions, ofActionSuccessful, Select, Store } from '@ngxs/store';
import { take, takeUntil } from 'rxjs/operators';
import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { SetUserDetails } from '../../../../core/store/actions/customer.actions';
import { CustomValidators } from '../../../../shared/validation/custom-validation';
import { SharedSelectors } from '../../../../core/store/selectors/shared.selectors';
@@ -82,9 +82,8 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
edit() {
if (this.customer) {
this.editMode = true;
this.notificationForm.enable();
this.notificationInEditMode.emit(true);
this.setEditMode(true);
}
}
@@ -100,11 +99,16 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
updateUserData.notificationSms = sms;
updateUserData.notificationEmail = email || this.isDelivery;
this.store.dispatch(new SetUserDetails(updateUserData, false));
this.actions
.pipe(ofActionSuccessful(SetUserDetails), take(1))
.subscribe(() => {
if (this.customer.error) {
return;
}
this.patchVariable(this.submitted$, { email: false, phone: false });
this.setEditMode(false);
});
}
this.patchVariable(this.submitted$, { email: false, phone: false });
this.editMode = false;
this.notificationInEditMode.emit(false);
}
savePhone() {
@@ -132,8 +136,6 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
return;
}
this.patchVariable(this.submitted$, { phone: false });
this.editMode = this.selected('email') && !this.customer.email;
this.notificationInEditMode.emit(false);
});
} else {
this.patchVariable(this.submitted$, { phone: true });
@@ -165,8 +167,6 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
return;
}
this.patchVariable(this.submitted$, { email: false });
this.editMode = this.selected('sms') && !this.customer.mobile_number;
this.notificationInEditMode.emit(false);
});
} else {
this.patchVariable(this.submitted$, { email: true });
@@ -180,10 +180,8 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
this.patchVariable(this.serverErrors$, { [type]: null });
}
buttonColor(typeField: string, typeServerError: string) {
return !this.notificationForm.get(typeField).valid || (this.serverErrors$.value && this.serverErrors$.value[typeServerError])
? '#557596'
: '#f70400';
buttonDisabled(typeField: string, typeServerError: string) {
return !this.notificationForm.get(typeField).valid || (this.serverErrors$.value && this.serverErrors$.value[typeServerError]);
}
validSms(control: AbstractControl) {
@@ -267,4 +265,9 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
...patch
});
}
private setEditMode(mode: boolean) {
this.editMode = mode;
this.notificationInEditMode.emit(mode);
}
}