Skip to content

Commit fcdc46a

Browse files
authored
fix: TT-477 customer change status (#787)
* fix: TT-477 customer change status * refactor: TT-477 change of name of variable * refactor: TT-477 based on scastillo-jp comments Includes fix of a typo
1 parent 95d9b90 commit fcdc46a

File tree

7 files changed

+28
-9
lines changed

7 files changed

+28
-9
lines changed

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
<td class="col-4 text-break">{{ customer.id }}</td>
2121
<td class="col-4 text-break">{{ customer.name }}</td>
2222
<td class="col-2 text-center">
23-
<button
24-
data-toggle="modal"
25-
(click)="editCustomer(customer.id)"
23+
<button
24+
data-toggle="modal"
25+
(click)="editCustomer(customer.id)"
2626
type="button" data-target="#editModal"
2727
class="btn btn-sm btn-primary">
2828
<i class="fa fa-pen fa-xs"></i>
@@ -48,7 +48,7 @@
4848
aria-hidden="true"
4949
[title]="'Disable Customer'"
5050
[body]="message"
51-
(closeModalEvent)="deleteCustomer()"
51+
(closeModalEvent)="changeStatus()"
5252
>
5353
</app-dialog>
5454

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ describe('CustomerTableListComponent', () => {
277277
expect(component.showModal).toBeFalse();
278278
});
279279

280+
281+
it('changeStatus should set inactive when active', () => {
282+
component.changeStatus();
283+
expect(component.statusToEdit === 'inactive');
284+
});
285+
286+
280287
afterEach(() => {
281288
component.dtTrigger.unsubscribe();
282289
component.changeCustomerSubscription.unsubscribe();

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
4040
showModal = false;
4141
idToDelete: string;
4242
idToEdit: string;
43+
statusToEdit: string;
4344
currentCustomerIdToEdit: string;
4445
message: string;
4546
isLoading$: Observable<boolean>;
@@ -170,20 +171,30 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
170171

171172
openModal(item: Customer) {
172173
this.idToDelete = item.id;
174+
this.statusToEdit = item.status;
173175
this.message = `Are you sure you want to disable ${item.name}?`;
174176
this.showModal = true;
175177
}
176178

177179
switchStatus(item: CustomerUI): void {
180+
178181
if (item.key !== 'inactive') {
179182
this.openModal(item);
180183
} else {
181184
this.showModal = false;
182-
this.store.dispatch(new UnarchiveCustomer(item.id));
185+
this.store.dispatch(new UnarchiveCustomer(item.id, this.changeOppositeStatus(item.key)));
183186
}
184187
}
185188

186189
setActive(status: any): string {
187190
return status === 'inactive' ? 'inactive' : 'active';
188191
}
192+
changeOppositeStatus(status: string): string {
193+
return status === 'inactive' ? 'active' : 'inactive';
194+
}
195+
196+
changeStatus(): void {
197+
this.store.dispatch(new UnarchiveCustomer(this.idToDelete, this.changeOppositeStatus(this.statusToEdit)));
198+
}
199+
189200
}

src/app/modules/customer-management/store/customer-management.actions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('CustomerManagmentActions', () => {
7979
});
8080

8181
it('UnarchiveCustomer type is CustomerManagementActionTypes.UNARCHIVE_CUSTOMER', () => {
82-
const unArchiveCustomer = new actions.UnarchiveCustomer('id_test');
82+
const unArchiveCustomer = new actions.UnarchiveCustomer('id_test', 'active');
8383
expect(unArchiveCustomer.type).toEqual(actions.CustomerManagementActionTypes.UNARCHIVE_CUSTOMER);
8484
});
8585

src/app/modules/customer-management/store/customer-management.actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class ResetCustomerToEdit implements Action {
103103
export class UnarchiveCustomer implements Action {
104104
public readonly type = CustomerManagementActionTypes.UNARCHIVE_CUSTOMER;
105105

106-
constructor(public payload: string) {}
106+
constructor(public payload: string, public status: string) {}
107107
}
108108

109109
export class UnarchiveCustomerSuccess implements Action {

src/app/modules/customer-management/store/customer-management.effects.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ export class CustomerEffects {
9393
unarchiveCustomer$: Observable<Action> = this.actions$.pipe(
9494
ofType(actions.CustomerManagementActionTypes.UNARCHIVE_CUSTOMER),
9595
map((action: actions.UnarchiveCustomer) => ({
96+
9697
id: action.payload,
97-
status: 'active',
98+
status: action.status,
9899
})),
99100
mergeMap((customer: Status) =>
100101
this.customerService.updateCustomer(customer).pipe(

src/app/modules/customer-management/store/customer-management.reducers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('customerManagementReducer', () => {
135135
});
136136

137137
it('on UnarchiveCustomer, isLoading is true', () => {
138-
const action = new actions.UnarchiveCustomer('1');
138+
const action = new actions.UnarchiveCustomer('1', 'inactive');
139139
const state = customerManagementReducer(initialState, action);
140140

141141
expect(state.isLoading).toEqual(true);

0 commit comments

Comments
 (0)