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 { Family } from "../FamilyApi";
|
||||||
import { Accommodation } from "./AccommodationListApi";
|
import { Accommodation } from "./AccommodationListApi";
|
||||||
|
|
||||||
|
export enum ValidateResaResult {
|
||||||
|
Success,
|
||||||
|
Error,
|
||||||
|
Conflict,
|
||||||
|
}
|
||||||
|
|
||||||
export interface AccommodationReservation {
|
export interface AccommodationReservation {
|
||||||
id: number;
|
id: number;
|
||||||
family_id: number;
|
family_id: number;
|
||||||
@ -151,13 +157,19 @@ export class AccommodationsReservationsApi {
|
|||||||
static async Validate(
|
static async Validate(
|
||||||
r: AccommodationReservation,
|
r: AccommodationReservation,
|
||||||
accept: boolean
|
accept: boolean
|
||||||
): Promise<void> {
|
): Promise<ValidateResaResult> {
|
||||||
await APIClient.exec({
|
const res = await APIClient.exec({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
uri: `/family/${r.family_id}/accommodations/reservation/${r.id}/validate`,
|
uri: `/family/${r.family_id}/accommodations/reservation/${r.id}/validate`,
|
||||||
jsonData: {
|
jsonData: {
|
||||||
validate: accept,
|
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,
|
AccommodationReservation,
|
||||||
AccommodationsReservationsApi,
|
AccommodationsReservationsApi,
|
||||||
AccommodationsReservationsList,
|
AccommodationsReservationsList,
|
||||||
|
ValidateResaResult,
|
||||||
} from "../../../api/accommodations/AccommodationsReservationsApi";
|
} from "../../../api/accommodations/AccommodationsReservationsApi";
|
||||||
import { useAlert } from "../../../hooks/context_providers/AlertDialogProvider";
|
import { useAlert } from "../../../hooks/context_providers/AlertDialogProvider";
|
||||||
import { useConfirm } from "../../../hooks/context_providers/ConfirmDialogProvider";
|
import { useConfirm } from "../../../hooks/context_providers/ConfirmDialogProvider";
|
||||||
@ -186,9 +187,18 @@ export function AccommodationsReservationsRoute(): React.ReactElement {
|
|||||||
try {
|
try {
|
||||||
loadingMessage.show("Validation de la réservation en cours...");
|
loadingMessage.show("Validation de la réservation en cours...");
|
||||||
|
|
||||||
|
setValidateResaAnchorEl(null);
|
||||||
setActiveEvent(undefined);
|
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();
|
reload();
|
||||||
snackbar("La réservation a été mise à jour avec succès !");
|
snackbar("La réservation a été mise à jour avec succès !");
|
||||||
|
Loading…
Reference in New Issue
Block a user