Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<td class="col-4 text-break">{{ customer.id }}</td>
<td class="col-4 text-break">{{ customer.name }}</td>
<td class="col-2 text-center">
<button
data-toggle="modal"
(click)="editCustomer(customer.id)"
<button
data-toggle="modal"
(click)="editCustomer(customer.id)"
type="button" data-target="#editModal"
class="btn btn-sm btn-primary">
<i class="fa fa-pen fa-xs"></i>
Expand All @@ -48,7 +48,7 @@
aria-hidden="true"
[title]="'Disable Customer'"
[body]="message"
(closeModalEvent)="deleteCustomer()"
(closeModalEvent)="changeStatus()"
>
</app-dialog>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ describe('CustomerTableListComponent', () => {
expect(component.showModal).toBeFalse();
});


it('changeStatus should set inactive whan active', () => {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this white line

component.changeStatus();
expect(component.status === 'inactive');
});


afterEach(() => {
component.dtTrigger.unsubscribe();
component.changeCustomerSubscription.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
showModal = false;
idToDelete: string;
idToEdit: string;
status: string;
currentCustomerIdToEdit: string;
message: string;
isLoading$: Observable<boolean>;
Expand Down Expand Up @@ -170,20 +171,32 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {

openModal(item: Customer) {
this.idToDelete = item.id;
this.status = item.status;
this.message = `Are you sure you want to disable ${item.name}?`;
this.showModal = true;
}

switchStatus(item: CustomerUI): void {

if (item.key !== 'inactive') {
this.openModal(item);
} else {
this.showModal = false;
this.store.dispatch(new UnarchiveCustomer(item.id));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this white line

this.store.dispatch(new UnarchiveCustomer(item.id, this.changeOppositeStatus(item.key)));
}
}

setActive(status: any): string {
return status === 'inactive' ? 'inactive' : 'active';
}
changeOppositeStatus(status: string): string{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a space before {
string {

return status === 'inactive' ? 'active' : 'inactive';

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this white line

}

changeStatus(): void{
this.store.dispatch(new UnarchiveCustomer(this.idToDelete, this.changeOppositeStatus(this.status)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('CustomerManagmentActions', () => {
});

it('UnarchiveCustomer type is CustomerManagementActionTypes.UNARCHIVE_CUSTOMER', () => {
const unArchiveCustomer = new actions.UnarchiveCustomer('id_test');
const unArchiveCustomer = new actions.UnarchiveCustomer('id_test', 'active');
expect(unArchiveCustomer.type).toEqual(actions.CustomerManagementActionTypes.UNARCHIVE_CUSTOMER);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class ResetCustomerToEdit implements Action {
export class UnarchiveCustomer implements Action {
public readonly type = CustomerManagementActionTypes.UNARCHIVE_CUSTOMER;

constructor(public payload: string) {}
constructor(public payload: string, public status: string) {}
}

export class UnarchiveCustomerSuccess implements Action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export class CustomerEffects {
unarchiveCustomer$: Observable<Action> = this.actions$.pipe(
ofType(actions.CustomerManagementActionTypes.UNARCHIVE_CUSTOMER),
map((action: actions.UnarchiveCustomer) => ({

id: action.payload,
status: 'active',
status: action.status,
})),
mergeMap((customer: Status) =>
this.customerService.updateCustomer(customer).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('customerManagementReducer', () => {
});

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

expect(state.isLoading).toEqual(true);
Expand Down