[HIMA-1195] fixed issue with notifications after update and changing tabs would show the old value before update

This commit is contained in:
Eraldo Hasanaj
2020-03-27 10:11:30 +01:00
parent 227ffd56a1
commit 52aec3e2fe
6 changed files with 99 additions and 49 deletions

View File

@@ -36,6 +36,7 @@ export interface Process {
shelfSearch: ShelfSearch;
onlineCustomerCreationError?: { error: boolean; invalidProperties: any };
userData: ProcessUserData;
customerNotificationFlag?: boolean;
}
export class CustomerFormState {

View File

@@ -43,6 +43,7 @@ export const UPDATE_CURRENT_ROUTE_QUERY_PARAMS = '[PROCESS] Update current route
export const SET_ONLINE_CUSTOMER_CREATION_STATUS = '[PROCESS] Set last online customer creation status';
export const CLEAR_PART_CUSTOMER_CREATION_STATUS = '[PROCESS] Clear part of customer creation status';
export const SET_USER_DATA = '[PROCESS] Set user form data';
export const SET_CUSTOMER_NOTIFICATION_FLAG = '[PROCESS] Set customer notification flag';
export class AddProcess {
static readonly type = ADD_PROCESS;
@@ -227,3 +228,9 @@ export class RemoveSelectedItem {
constructor() {}
}
export class SetCustomerNotificationFlag {
static readonly type = SET_CUSTOMER_NOTIFICATION_FLAG;
constructor(public flag: boolean) {}
}

View File

@@ -42,6 +42,14 @@ export class ProcessSelectors {
}
}
@Selector([AppState, ProcessState])
static getCurrentProcessCustomerNotificationFlag(state: AppStateModel, processState: ProcessStateModel) {
const currentProcess = processState.processes[state.currentProcesssId];
if (currentProcess) {
return currentProcess.customerNotificationFlag;
}
}
@Selector([AppState, ProcessState])
static getScrollPositionForProduct(state: AppStateModel, processState: ProcessStateModel) {
const currentProcess = processState.processes[state.currentProcesssId];

View File

@@ -62,6 +62,7 @@ export class ProcessState {
ordersOpenend: false,
closeDirectlyTab: false,
articleSearchErrorStatus: false,
customerNotificationFlag: false,
productSearchFilters: {
archiveFilters: false,
radioButtonGroup: <RadioButtonGroup>{
@@ -364,6 +365,20 @@ export class ProcessState {
}
}
@Action(actions.SetCustomerNotificationFlag)
setCustomerNotificationFlag(ctx: StateContext<ProcessStateModel>, { flag }: actions.SetCustomerNotificationFlag) {
const state = ctx.getState();
if (!state) {
return;
}
const currentProcesses = state.processes;
const currentProcessId = this.store.selectSnapshot(AppState.getCurrentProcessId);
if (currentProcesses && currentProcessId && currentProcesses[currentProcessId]) {
const process = { ...currentProcesses[currentProcessId], customerNotificationFlag: flag };
ctx.setState(this.updateProcess(process));
}
}
@Action(actions.SetProcessNewStatusToFalse)
setProcessNewStatusToFalse(ctx: StateContext<ProcessStateModel>) {
const state = ctx.getState();
@@ -577,7 +592,8 @@ export class ProcessState {
uniqueIdentifier: oldProcess.uniqueIdentifier,
ordersOpenend: oldProcess.ordersOpenend,
articleSearchErrorStatus: oldProcess.articleSearchErrorStatus,
productSearchFilters: oldProcess.productSearchFilters
productSearchFilters: oldProcess.productSearchFilters,
customerNotificationFlag: false
};
let processes = { ...currentProcesses };
processes[oldProcess.id] = newProcess;

View File

@@ -8,6 +8,8 @@ import { CustomValidators } from '../../../../shared/validation/custom-validatio
import { SharedSelectors } from '../../../../core/store/selectors/shared.selectors';
import { User } from '../../../../core/models/user.model';
import { ViewRef_ } from '@angular/core/src/view';
import { ProcessSelectors } from 'apps/sales/src/app/core/store/selectors/process.selectors';
import { SetCustomerNotificationFlag } from 'apps/sales/src/app/core/store/actions/process.actions';
@Component({
selector: 'app-notification-settings',
@@ -50,28 +52,35 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
ngOnInit() {
if (this.customer) {
const updateUserData = {...this.customer};
updateUserData.notificationSms = false;
updateUserData.notificationEmail = false;
if (this.customer.email) {
this.notificationForm.get('email.selected').setValue(true);
updateUserData.notificationEmail = true;
} else {
this.notificationForm.get('email.selected').setValue(false);
updateUserData.notificationEmail = this.isDelivery;
}
if (this.customer.mobile_number) {
this.notificationForm.get('sms.selected').setValue(true);
updateUserData.notificationSms = true;
} else {
this.notificationForm.get('sms.selected').setValue(false);
const updateUserData = { ...this.customer };
const customerFlag = this.store.selectSnapshot(ProcessSelectors.getCurrentProcessCustomerNotificationFlag);
if (!customerFlag) {
updateUserData.notificationSms = false;
}
if (
this.customer.notificationSms !== updateUserData.notificationSms ||
this.customer.notificationEmail !== updateUserData.notificationEmail
) {
this.store.dispatch(new SetUserDetails(updateUserData, false));
updateUserData.notificationEmail = false;
if (this.customer.email) {
this.notificationForm.get('email.selected').setValue(true);
updateUserData.notificationEmail = true;
} else {
this.notificationForm.get('email.selected').setValue(false);
updateUserData.notificationEmail = this.isDelivery;
}
if (this.customer.mobile_number) {
this.notificationForm.get('sms.selected').setValue(true);
updateUserData.notificationSms = true;
} else {
this.notificationForm.get('sms.selected').setValue(false);
updateUserData.notificationSms = false;
}
if (
this.customer.notificationSms !== updateUserData.notificationSms ||
this.customer.notificationEmail !== updateUserData.notificationEmail
) {
this.store.dispatch(new SetUserDetails(updateUserData, false));
}
this.store.dispatch(new SetCustomerNotificationFlag(true));
} else {
this.notificationForm.get('email.selected').setValue(this.customer.notificationEmail);
this.notificationForm.get('sms.selected').setValue(this.customer.notificationSms);
}
this.detectChanges();
}
@@ -96,16 +105,17 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
const sms = this.selected('sms');
const email = this.selected('email');
if ((this.notificationForm.get('sms.telephone').valid || !sms) && (this.notificationForm.get('email.email').valid || !email)) {
const updateUserData = {...this.customer};
const updateUserData = { ...this.customer };
updateUserData.notificationSms = sms;
updateUserData.notificationEmail = email || this.isDelivery;
this.store.dispatch(new SetUserDetails(updateUserData, false))
this.store
.dispatch(new SetUserDetails(updateUserData, false))
.pipe(take(1))
.subscribe(() => {
if (this.customer.error) {
return;
}
this.patchVariable(this.submitted$, {email: false, phone: false});
this.patchVariable(this.submitted$, { email: false, phone: false });
this.setEditMode(false);
});
}
@@ -123,7 +133,8 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
mobile_number: phoneField.value,
notificationSms: this.selected('sms')
};
this.store.dispatch(new SetUserDetails(c, false))
this.store
.dispatch(new SetUserDetails(c, false))
.pipe(take(1))
.subscribe(() => {
this.patchVariable(this.serverErrors$, {
@@ -134,10 +145,10 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
if (this.customer.error) {
return;
}
this.patchVariable(this.submitted$, {phone: false});
this.patchVariable(this.submitted$, { phone: false });
});
} else {
this.patchVariable(this.submitted$, {phone: true});
this.patchVariable(this.submitted$, { phone: true });
}
}
@@ -153,7 +164,8 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
email: emailField.value,
notificationEmail: this.selected('email') || this.isDelivery
};
this.store.dispatch(new SetUserDetails(c, false))
this.store
.dispatch(new SetUserDetails(c, false))
.pipe(take(1))
.subscribe(() => {
this.patchVariable(this.serverErrors$, {
@@ -164,18 +176,18 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
if (this.customer.error) {
return;
}
this.patchVariable(this.submitted$, {email: false});
this.patchVariable(this.submitted$, { email: false });
});
} else {
this.patchVariable(this.submitted$, {email: true});
this.patchVariable(this.submitted$, { email: true });
}
}
onInputChange(value: string, type: string) {
if (!value) {
this.patchVariable(this.submitted$, {[type]: false});
this.patchVariable(this.submitted$, { [type]: false });
}
this.patchVariable(this.serverErrors$, {[type]: null});
this.patchVariable(this.serverErrors$, { [type]: null });
}
buttonDisabled(typeField: string, typeServerError: string) {
@@ -184,7 +196,7 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
validSms(control: AbstractControl) {
if (control.value && control.value.selected && !control.get('telephone').valid) {
return {invalidSms: true};
return { invalidSms: true };
}
return null;
}
@@ -199,7 +211,7 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
update(val, type: string) {
if (!val) {
this.patchVariable(this.submitted$, {[type === 'email' ? type : 'phone']: false});
this.patchVariable(this.submitted$, { [type === 'email' ? type : 'phone']: false });
}
this.notificationForm.get(type + '.selected').setValue(val);
@@ -208,7 +220,7 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
setEmailNotification() {
if (this.customer) {
// If delivery type, then email is mandatory
const updateUserData = {...this.customer};
const updateUserData = { ...this.customer };
updateUserData.notificationEmail = true;
this.store.dispatch(new SetUserDetails(updateUserData, false));
}
@@ -219,13 +231,13 @@ export class NotificationSettingsComponent implements OnInit, OnDestroy {
sms: fb.group(
{
selected: false,
telephone: fb.control('', {validators: [Validators.required, CustomValidators.validateTelephone]})
telephone: fb.control('', { validators: [Validators.required, CustomValidators.validateTelephone] })
},
{validators: this.validSms}
{ validators: this.validSms }
),
email: fb.group({
selected: this.isDelivery,
email: fb.control('', {validators: [Validators.required, CustomValidators.validateEmail]})
email: fb.control('', { validators: [Validators.required, CustomValidators.validateEmail] })
})
});
}

View File

@@ -3,7 +3,12 @@ import { Subject, Observable, of } from 'rxjs';
import { User, Features } from '../../../../core/models/user.model';
import { Select, Store } from '@ngxs/store';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ChangeCurrentRoute, SetActiveCustomer, UpdateProcessName } from '../../../../core/store/actions/process.actions';
import {
ChangeCurrentRoute,
SetActiveCustomer,
UpdateProcessName,
SetCustomerNotificationFlag
} from '../../../../core/store/actions/process.actions';
import { Router, ActivatedRoute } from '@angular/router';
import { Breadcrumb } from '../../../../core/models/breadcrumb.model';
import {
@@ -12,7 +17,7 @@ import {
AddNewShippingAddress,
AddNewInvoiceAddress,
SetLastCreatedCustomerId,
ClearLastCustomerCreatedId,
ClearLastCustomerCreatedId
} from '../../../../core/store/actions/customer.actions';
import { AddBreadcrumb } from '../../../../core/store/actions/breadcrumb.actions';
import { takeUntil, filter } from 'rxjs/operators';
@@ -31,13 +36,13 @@ import { CustomerFeatures } from 'apps/sales/src/app/core/models/customer-featur
export enum AddressUpdateType {
ShippingAddressUpdate,
InvoiceAddressUpdate,
NoUpdate,
NoUpdate
}
@Component({
selector: 'app-edit-customer-card',
templateUrl: './customer-edit-card.component.html',
styleUrls: ['./customer-edit-card.component.scss'],
styleUrls: ['./customer-edit-card.component.scss']
})
export class CustomerEditCardComponent implements OnInit, OnDestroy {
@Select(SharedSelectors.getCustomerEditData) customerEditData$: Observable<EditCustomerData>;
@@ -278,7 +283,7 @@ export class CustomerEditCardComponent implements OnInit, OnDestroy {
name: companyName,
extraAddress: extraAddress,
department: department,
vatId: vatId,
vatId: vatId
};
} else {
updateCustomer.organisation = undefined;
@@ -289,7 +294,7 @@ export class CustomerEditCardComponent implements OnInit, OnDestroy {
shoppingCart() {
const newBread: Breadcrumb = {
name: 'Warenkorb',
path: '/cart/review',
path: '/cart/review'
};
const userSet = this.setUserInStore();
userSet.ifTrue(() => this.navigate(newBread, 'shoppingCart', true));
@@ -298,7 +303,7 @@ export class CustomerEditCardComponent implements OnInit, OnDestroy {
articleSearch() {
const newBread: Breadcrumb = {
name: 'Artikelsuche',
path: '/product/search',
path: '/product/search'
};
const userSet = this.setUserInStore();
userSet.ifTrue(() => this.navigate(newBread, 'product', true));
@@ -312,6 +317,7 @@ export class CustomerEditCardComponent implements OnInit, OnDestroy {
// this.store.dispatch(new SetUserDetailsById(this.userId));
this.store.dispatch(new SetActiveCustomer(this.customer.id));
this.store.dispatch(new UpdateProcessName(this.customer.last_name));
this.store.dispatch(new SetCustomerNotificationFlag(false));
return true;
}
return false;
@@ -342,7 +348,7 @@ export class CustomerEditCardComponent implements OnInit, OnDestroy {
const newBread: Breadcrumb = {
name: 'Rechnungsadresse',
path: '/customer/edit/' + this.customer.id + '/billing',
queryParams: queryParams,
queryParams: queryParams
};
this.navigate(newBread, 'customer', false, queryParams);
@@ -353,7 +359,7 @@ export class CustomerEditCardComponent implements OnInit, OnDestroy {
const newBread: Breadcrumb = {
name: 'Lieferadresse',
path: '/customer/edit/' + this.customer.id + '/delivery',
queryParams: queryParams,
queryParams: queryParams
};
this.navigate(newBread, 'customer', false, queryParams);
@@ -380,7 +386,7 @@ export class CustomerEditCardComponent implements OnInit, OnDestroy {
company_name: [''],
company_address: [''],
company_department: [''],
company_vatId: [''],
company_vatId: ['']
});
}