Skip to content

Commit dc10fcf

Browse files
feat: TT-208 remove delete button & assign openmodal to switch
1 parent 6c1c06f commit dc10fcf

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

src/app/modules/activities-management/components/activity-list/activity-list.component.html

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,15 @@
1717
<button type="button" class="btn btn-sm btn-primary" (click)="updateActivity(activity.id)">
1818
<i class="fa fa-pencil fa-xs"></i>
1919
</button>
20-
<button
21-
type="button"
22-
class="btn btn-sm btn-danger ml-2"
23-
data-toggle="modal"
24-
data-target="#deleteModal"
25-
(click)="openModal(activity)"
26-
>
27-
<i class="fas fa-trash-alt fa-xs"></i>
28-
</button>
2920
</td>
3021
<td class="col-2 text-center">
3122
<ui-switch
3223
size="small"
33-
(change)="switchStatus('active')"
24+
data-toggle="modal"
25+
data-target="#deleteModal"
3426
[checked]="activity.status === 'active'"
27+
(valueChange)="switchStatus($event, activity)"
28+
[beforeChange]="OnSwitch(activity)"
3529
></ui-switch>
3630
</td>
3731
</tr>
@@ -46,7 +40,7 @@
4640
tabindex="-1"
4741
role="dialog"
4842
aria-hidden="true"
49-
[title]="'Delete Activity'"
43+
[title]="'Archive Activity'"
5044
[body]="message"
5145
(closeModalEvent)="deleteActivity()"
5246
>
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
import { Component, OnInit } from '@angular/core';
22
import { select, Store } from '@ngrx/store';
3-
import { Observable } from 'rxjs';
3+
import { Observable, of } from 'rxjs';
44
import { delay } from 'rxjs/operators';
55
import { getIsLoading } from 'src/app/modules/activities-management/store/activity-management.selectors';
66
import { Activity } from '../../../shared/models';
77
import { allActivities } from '../../store';
88
import { DeleteActivity, LoadActivities, SetActivityToEdit } from './../../store/activity-management.actions';
99
import { ActivityState } from './../../store/activity-management.reducers';
1010

11-
1211
@Component({
1312
selector: 'app-activity-list',
1413
templateUrl: './activity-list.component.html',
1514
styleUrls: ['./activity-list.component.scss'],
1615
})
1716
export class ActivityListComponent implements OnInit {
17+
constructor(private store: Store<ActivityState>) {
18+
this.isLoading$ = store.pipe(delay(0), select(getIsLoading));
19+
}
1820
activities: Activity[] = [];
1921
showModal = false;
2022
activityToDelete: Activity;
2123
message: string;
2224
idToDelete: string;
2325
isLoading$: Observable<boolean>;
24-
constructor(private store: Store<ActivityState>) {
25-
this.isLoading$ = store.pipe(delay(0), select(getIsLoading));
26-
}
2726

2827
ngOnInit() {
2928
this.store.dispatch(new LoadActivities());
@@ -35,8 +34,9 @@ export class ActivityListComponent implements OnInit {
3534
}
3635

3736
deleteActivity() {
38-
this.store.dispatch(new DeleteActivity(this.idToDelete));
39-
this.showModal = true;
37+
// this.store.dispatch(new DeleteActivity(this.idToDelete));
38+
console.log('despachado el evento');
39+
this.showModal = false;
4040
}
4141

4242
updateActivity(activityId: string) {
@@ -45,15 +45,26 @@ export class ActivityListComponent implements OnInit {
4545

4646
openModal(item: Activity) {
4747
this.idToDelete = item.id;
48-
this.message = `Are you sure you want to delete ${item.name}?`;
48+
this.message = `Are you sure you want to archive activity ${item.name}?`;
4949
this.showModal = true;
50+
console.log(`Despliegue del modal para id: ${item.id}`);
51+
}
52+
53+
switchStatus(evt: boolean, item: Activity): void {
54+
if (!evt) {
55+
// FIXME: Si el usuario selecciona cancelar, se produce la animación de cambio
56+
// del switch
57+
this.openModal(item);
58+
} else {
59+
this.showModal = false;
60+
// TODO: dispatch para actualizar la operacion
61+
// this.store.dispatch(new SetToTrueActivity());
62+
}
5063
}
5164

52-
switchStatus(state: string): void {
53-
// this.store.dispatch(
54-
// user.groups.includes(groupName)
55-
// ? new RemoveUserFromGroup(user.id, groupName)
56-
// : new AddUserToGroup(user.id, groupName)
57-
// );
65+
OnSwitch(item: Activity): Observable<boolean> {
66+
// FIXME: OnBeforeChange debería ser un evento que traiga el estado del switch
67+
// para poder realizar una acción antes de que el estado cambie.
68+
return of(true);
5869
}
5970
}

0 commit comments

Comments
 (0)