Proper handling of reservation validation errors
This commit is contained in:
parent
f6d8d6b3d1
commit
136ed8121e
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 !");
|
||||
|
Loading…
Reference in New Issue
Block a user