= this.actions$.pipe(
+ ofType(actions.CustomerManagementActionTypes.UNARCHIVE_CUSTOMER),
+ map((action: actions.UnArchiveCustomer) => ({
+ id: action.payload,
+ status: 'active',
+ })),
+ mergeMap((customer: Status) =>
+ this.customerService.updateCustomer(customer).pipe(
+ map((customerData) => {
+ this.toastrService.success(INFO_SAVED_SUCCESSFULLY);
+ return new actions.UpdateCustomerSuccess(customerData);
+ }),
+ catchError((error) => {
+ this.toastrService.error(error.error.message);
+ return of(new actions.UpdateCustomerFail(error));
+ })
+ )
+ )
+ );
}
diff --git a/src/app/modules/customer-management/store/customer-management.reducers.spec.ts b/src/app/modules/customer-management/store/customer-management.reducers.spec.ts
index f69256259..27cb43765 100644
--- a/src/app/modules/customer-management/store/customer-management.reducers.spec.ts
+++ b/src/app/modules/customer-management/store/customer-management.reducers.spec.ts
@@ -1,10 +1,10 @@
import { CustomerState, customerManagementReducer } from './customer-management.reducers';
-import { Customer } from '../../shared/models/index';
+import { Customer, Status } from '../../shared/models/index';
import * as actions from './customer-management.actions';
describe('customerManagementReducer', () => {
const initialState: CustomerState = { data: [], isLoading: false, message: '', customerIdToEdit: '', customerId: '' };
- const customer: Customer = { name: 'aa', description: 'bb' };
+ const customer: Customer = { name: 'aa', description: 'bb', status: 'inactive' };
it('on LoadCustomer, isLoading is true ', () => {
const action = new actions.LoadCustomers();
@@ -63,11 +63,11 @@ describe('customerManagementReducer', () => {
it('on DeleteCustomerSuccess, message equal to Customer removed successfully!', () => {
const currentState = {
- data: [{ name: 'aa', description: 'bb', tenant_id: 'cc', id: '1' }],
+ data: [{ name: 'aa', description: 'bb', tenant_id: 'cc', id: '1', status: 'inactive' }],
isLoading: false,
message: '',
customerIdToEdit: '',
- customerId: ''
+ customerId: '',
};
const customerToDeleteId = '1';
const action = new actions.DeleteCustomerSuccesss(customerToDeleteId);
@@ -75,7 +75,7 @@ describe('customerManagementReducer', () => {
expect(state.isLoading).toEqual(false);
expect(state.data.length).toEqual(0);
- expect(state.message).toEqual('Customer removed successfully!');
+ expect(state.message).toEqual('Customer archived successfully!');
});
it('on DeleteCustomeryFail, message equal to Something went wrong deleting customer!', () => {
@@ -100,7 +100,7 @@ describe('customerManagementReducer', () => {
isLoading: false,
message: '',
customerIdToEdit: '1',
- customerId: ''
+ customerId: '',
};
const customerEdited = { name: 'xx', description: 'yy', tenant_id: 'cc', id: '1' };
const action = new actions.UpdateCustomerSuccess(customerEdited);
@@ -133,4 +133,37 @@ describe('customerManagementReducer', () => {
expect(state.customerIdToEdit).toEqual('');
});
+
+ it('on UnarchiveCustomer, isLoading is true', () => {
+ const action = new actions.UnArchiveCustomer('1');
+ const state = customerManagementReducer(initialState, action);
+
+ expect(state.isLoading).toEqual(true);
+ });
+
+ it('on UnarchiveCustomerSuccess, status customer is change to "active" in the store', () => {
+ const currentState = {
+ data: [{ name: 'aa', description: 'bb', tenant_id: 'cc', id: '1', status: 'inactive' }],
+ isLoading: false,
+ message: '',
+ customerIdToEdit: '1',
+ customerId: '',
+ };
+ const customerEdited: Status = { id: '1', status: 'active' };
+ const expectedCustomer = { name: 'aa', description: 'bb', tenant_id: 'cc', id: '1', status: 'active' };
+ const action = new actions.UnArchiveCustomerSuccess(customerEdited);
+ const state = customerManagementReducer(currentState, action);
+
+ expect(state.data).toEqual([expectedCustomer]);
+ expect(state.isLoading).toEqual(false);
+ expect(state.message).toEqual('Customer unarchive successfully!');
+ });
+
+ it('on UnarchiveCustomerFail, message equal to Something went wrong unarchiving customer!', () => {
+ const action = new actions.UnArchiveCustomerFail('error');
+ const state = customerManagementReducer(initialState, action);
+
+ expect(state.message).toEqual('Something went wrong unarchiving customer!');
+ expect(state.isLoading).toEqual(false);
+ });
});
diff --git a/src/app/modules/customer-management/store/customer-management.reducers.ts b/src/app/modules/customer-management/store/customer-management.reducers.ts
index 189f9e31c..8238761ba 100644
--- a/src/app/modules/customer-management/store/customer-management.reducers.ts
+++ b/src/app/modules/customer-management/store/customer-management.reducers.ts
@@ -81,7 +81,7 @@ export const customerManagementReducer = (state: CustomerState = initialState, a
...state,
data: customers,
isLoading: false,
- message: 'Customer removed successfully!',
+ message: 'Customer archived successfully!',
};
}
@@ -137,6 +137,33 @@ export const customerManagementReducer = (state: CustomerState = initialState, a
};
}
+ case CustomerManagementActionTypes.UNARCHIVE_CUSTOMER: {
+ return {
+ ...state,
+ isLoading: true,
+ };
+ }
+
+ case CustomerManagementActionTypes.UNARCHIVE_CUSTOMER_SUCCESS: {
+ const index = customersList.findIndex((customer) => customer.id === action.payload.id);
+ customersList[index] = { ...customersList[index], ...action.payload };
+ return {
+ ...state,
+ data: customersList,
+ isLoading: false,
+ message: 'Customer unarchive successfully!',
+ };
+ }
+
+ case CustomerManagementActionTypes.UNARCHIVE_CUSTOMER_FAIL: {
+ return {
+ ...state,
+ data: [],
+ isLoading: false,
+ message: 'Something went wrong unarchiving customer!',
+ };
+ }
+
default:
return state;
}
diff --git a/src/app/modules/shared/models/customer.model.ts b/src/app/modules/shared/models/customer.model.ts
index 67337e5d9..42107c878 100644
--- a/src/app/modules/shared/models/customer.model.ts
+++ b/src/app/modules/shared/models/customer.model.ts
@@ -1,5 +1,20 @@
export interface Customer {
id?: string;
- name: string;
+ name?: string;
description?: string;
+ status?: any;
+}
+export interface CustomerUI {
+ id?: string;
+ name?: string;
+ description?: string;
+ status?: any;
+ key?: string;
+ btnColor?: string;
+ btnIcon?: string;
+ btnName?: string;
+}
+export interface Status {
+ id: string;
+ status: any;
}
From 69a63f95f03db4480443463c15ac266c32bdcf22 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jefferson=20O=C3=B1a?=
<67077796+jeffqev@users.noreply.github.com>
Date: Fri, 23 Apr 2021 14:50:01 -0500
Subject: [PATCH 2/2] fix: TT-223-Consume-end-point-archive-customers
---
.../customer-list/customer-list.component.html | 2 +-
.../customer-list/customer-list.component.spec.ts | 2 +-
.../customer-list/customer-list.component.ts | 4 ++--
.../store/customer-management.actions.spec.ts | 13 ++++++-------
.../store/customer-management.actions.ts | 12 ++++++------
.../store/customer-management.effects.ts | 2 +-
.../store/customer-management.reducers.spec.ts | 6 +++---
7 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html b/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html
index a01782271..acf7e6f99 100644
--- a/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html
+++ b/src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html
@@ -30,7 +30,7 @@
|