Skip to content

Commit

Permalink
[FEAT] Delete service done
Browse files Browse the repository at this point in the history
  • Loading branch information
Landris18 committed Feb 29, 2024
1 parent 71678bb commit 6e94a7f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ <h2 class="text-secondary text-3xl"><strong>Aucun service trouvé</strong></h2>
<button mat-icon-button (click)="showDefault = false; isEdit = true; setServiceForm(s)">
<mat-icon>edit</mat-icon>
</button>
<button mat-icon-button>
<button mat-icon-button (click)="openConfirmationDialog(s)">
<mat-icon class="text-red-500">delete</mat-icon>
</button>
</td>
Expand Down
46 changes: 45 additions & 1 deletion src/app/modules/admin/dashboards/project/project.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { User } from 'app/core/user/user.types';
import { FinanceService } from '../finance/finance.service';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { FuseAlertType } from '@fuse/components/alert';
import { FuseConfirmationService } from '@fuse/services/confirmation/confirmation.service';

@Component({
selector: 'project',
Expand Down Expand Up @@ -41,7 +42,7 @@ export class ProjectComponent implements OnInit, OnDestroy {
Manager: "/manager/dashboard"
};
configForm: FormGroup;
isEdit: boolean = false;
isEdit: boolean = false;
service: any;

/**
Expand All @@ -53,6 +54,7 @@ export class ProjectComponent implements OnInit, OnDestroy {
private _financeService: FinanceService,
private _router: Router,
private _formBuilder: FormBuilder,
private _fuseConfirmationService: FuseConfirmationService
) {
}

Expand All @@ -71,6 +73,29 @@ export class ProjectComponent implements OnInit, OnDestroy {
commissionPercentage: ["", [Validators.required]]
});

// Build the config form
this.configForm = this._formBuilder.group({
title: 'Supprimer un service',
message: 'Voulez-vous vraiment supprimer ce service',
icon: this._formBuilder.group({
show: true,
name: 'heroicons_outline:exclamation',
color: 'warn'
}),
actions: this._formBuilder.group({
confirm: this._formBuilder.group({
show: true,
label: 'Supprimer',
color: 'warn'
}),
cancel: this._formBuilder.group({
show: true,
label: 'Annuler'
})
}),
dismissible: true
});

// Subscribe to the user service
this._userService.user$
.pipe((takeUntil(this._unsubscribeAll)))
Expand Down Expand Up @@ -223,6 +248,25 @@ export class ProjectComponent implements OnInit, OnDestroy {
});
}

/**
* Open confirmation dialog
*/
openConfirmationDialog(service: any): void {
// Open the dialog and save the reference of it
const dialogRef = this._fuseConfirmationService.open(this.configForm.value);

// Subscribe to afterClosed from the dialog reference
dialogRef.afterClosed().subscribe((result) => {
console.log(result);
if (result === "confirmed") {
this._projectService.deleteService(service._id).subscribe((res: any) => {
}, () => {
});
this.getAllServices();
}
});
}

// -----------------------------------------------------------------------------------------------------
// @ Public methods
// -----------------------------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/app/modules/admin/dashboards/project/project.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { MatRadioModule } from '@angular/material/radio';
import { MatSelectModule } from '@angular/material/select';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { FuseAlertModule } from '@fuse/components/alert';
import { FuseHighlightModule } from '@fuse/components/highlight';

@NgModule({
declarations: [
Expand Down Expand Up @@ -52,7 +53,8 @@ import { FuseAlertModule } from '@fuse/components/alert';
MatRadioModule,
MatSelectModule,
MatDatepickerModule,
FuseAlertModule
FuseAlertModule,
FuseHighlightModule
]
})
export class ProjectModule
Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/admin/dashboards/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ export class ProjectService {
updateService(id: string, data: any): Observable<any> {
return this._httpClient.put(`${this._baseUrl}/service/${id}`, data);
}

deleteService(id: string): Observable<any> {
return this._httpClient.delete(`${this._baseUrl}/service/${id}`);
}
}

0 comments on commit 6e94a7f

Please sign in to comment.