Add an accommodations reservations module #188

Merged
pierre merged 81 commits from accomodation_module into master 2024-06-22 21:30:26 +00:00
2 changed files with 25 additions and 3 deletions
Showing only changes of commit 136ed8121e - Show all commits

View File

@ -2,6 +2,12 @@ import { APIClient } from "../ApiClient";
import { Family } from "../FamilyApi";
import { Accommodation } from "./AccommodationListApi";
export enum ValidateResaResult {
Success,
Error,
Conflict,
}
export interface AccommodationReservation {
id: number;
family_id: number;
@ -151,13 +157,19 @@ export class AccommodationsReservationsApi {
static async Validate(
r: AccommodationReservation,
accept: boolean
): Promise<void> {
await APIClient.exec({
): Promise<ValidateResaResult> {
const res = await APIClient.exec({
method: "POST",
uri: `/family/${r.family_id}/accommodations/reservation/${r.id}/validate`,
jsonData: {
validate: accept,
},
allowFail: true,
});
if (res.status >= 200 && res.status <= 299)
return ValidateResaResult.Success;
if (res.status === 409) return ValidateResaResult.Conflict;
return ValidateResaResult.Error;
}
}

View File

@ -34,6 +34,7 @@ import {
AccommodationReservation,
AccommodationsReservationsApi,
AccommodationsReservationsList,
ValidateResaResult,
} from "../../../api/accommodations/AccommodationsReservationsApi";
import { useAlert } from "../../../hooks/context_providers/AlertDialogProvider";
import { useConfirm } from "../../../hooks/context_providers/ConfirmDialogProvider";
@ -186,9 +187,18 @@ export function AccommodationsReservationsRoute(): React.ReactElement {
try {
loadingMessage.show("Validation de la réservation en cours...");
setValidateResaAnchorEl(null);
setActiveEvent(undefined);
await AccommodationsReservationsApi.Validate(r, validate);
const res = await AccommodationsReservationsApi.Validate(r, validate);
if (res === ValidateResaResult.Conflict) {
throw new Error(
"The reservation is in conflict with other reservations!"
);
} else if (res === ValidateResaResult.Error) {
throw new Error("Failed to validate the reservation!");
}
reload();
snackbar("La réservation a été mise à jour avec succès !");