Reservation creation is effective from web UI
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Pierre HUBERT 2024-06-19 22:25:39 +02:00
parent 9929c5db48
commit e5f36a3d29
3 changed files with 57 additions and 15 deletions

View File

@ -64,6 +64,25 @@ export interface UpdateAccommodationReservation {
} }
export class AccommodationsReservationsApi { export class AccommodationsReservationsApi {
/**
* Create a new reservation
*/
static async Create(
family: Family,
reservation: UpdateAccommodationReservation
): Promise<AccommodationReservation> {
return (
await APIClient.exec({
method: "POST",
uri: `/family/${family.family_id}/accommodations/reservations/accommodation/${reservation.accommodation_id}/create`,
jsonData: {
start: reservation.start,
end: reservation.end,
},
})
).data;
}
/** /**
* Get the entire list of accommodations of a family * Get the entire list of accommodations of a family
*/ */

View File

@ -5,7 +5,6 @@ import {
DialogActions, DialogActions,
DialogContent, DialogContent,
DialogTitle, DialogTitle,
Typography,
} from "@mui/material"; } from "@mui/material";
import React from "react"; import React from "react";
import { import {
@ -14,11 +13,11 @@ import {
UpdateAccommodationReservation, UpdateAccommodationReservation,
} from "../../api/accommodations/AccommodationsReservationsApi"; } from "../../api/accommodations/AccommodationsReservationsApi";
import { useAlert } from "../../hooks/context_providers/AlertDialogProvider"; import { useAlert } from "../../hooks/context_providers/AlertDialogProvider";
import { fmtUnixDate } from "../../utils/time_utils";
import { useFamily } from "../../widgets/BaseFamilyRoute"; import { useFamily } from "../../widgets/BaseFamilyRoute";
import { useAccommodations } from "../../widgets/accommodations/BaseAccommodationsRoute"; import { useAccommodations } from "../../widgets/accommodations/BaseAccommodationsRoute";
import { PropDateInput } from "../../widgets/forms/PropDateInput"; import { PropDateInput } from "../../widgets/forms/PropDateInput";
import { PropSelect } from "../../widgets/forms/PropSelect"; import { PropSelect } from "../../widgets/forms/PropSelect";
import { fmtUnixDate } from "../../utils/time_utils";
export function UpdateReservationDialog(p: { export function UpdateReservationDialog(p: {
open: boolean; open: boolean;
@ -121,7 +120,11 @@ export function UpdateReservationDialog(p: {
return { label: a.name, value: a.id.toString() }; return { label: a.name, value: a.id.toString() };
} }
)} )}
value={reservation?.accommodation_id?.toString()} value={
reservation?.accommodation_id === -1
? ""
: reservation?.accommodation_id?.toString()
}
/> />
<PropDateInput <PropDateInput

View File

@ -17,6 +17,9 @@ import {
AccommodationsReservationsApi, AccommodationsReservationsApi,
AccommodationsReservationsList, AccommodationsReservationsList,
} from "../../../api/accommodations/AccommodationsReservationsApi"; } from "../../../api/accommodations/AccommodationsReservationsApi";
import { useAlert } from "../../../hooks/context_providers/AlertDialogProvider";
import { useLoadingMessage } from "../../../hooks/context_providers/LoadingMessageProvider";
import { useSnackbar } from "../../../hooks/context_providers/SnackbarProvider";
import { useUpdateAccommodationReservation } from "../../../hooks/context_providers/accommodations/UpdateReservationDialogProvider"; import { useUpdateAccommodationReservation } from "../../../hooks/context_providers/accommodations/UpdateReservationDialogProvider";
import { AsyncWidget } from "../../../widgets/AsyncWidget"; import { AsyncWidget } from "../../../widgets/AsyncWidget";
import { useFamily } from "../../../widgets/BaseFamilyRoute"; import { useFamily } from "../../../widgets/BaseFamilyRoute";
@ -24,6 +27,10 @@ import { FamilyPageTitle } from "../../../widgets/FamilyPageTitle";
import { useAccommodations } from "../../../widgets/accommodations/BaseAccommodationsRoute"; import { useAccommodations } from "../../../widgets/accommodations/BaseAccommodationsRoute";
export function AccommodationsReservationsRoute(): React.ReactElement { export function AccommodationsReservationsRoute(): React.ReactElement {
const snackbar = useSnackbar();
const alert = useAlert();
const loadingMessage = useLoadingMessage();
const loadKey = React.useRef(1); const loadKey = React.useRef(1);
const family = useFamily(); const family = useFamily();
@ -58,18 +65,31 @@ export function AccommodationsReservationsRoute(): React.ReactElement {
setUsers(null); setUsers(null);
}; };
const onSelect = (d: DateSelectArg) => { const onSelect = async (d: DateSelectArg) => {
// TODO : render this functional try {
// TODO : handle busy case const resa = await updateReservation(
console.info(d); {
updateReservation( accommodation_id: -1,
{ start: Math.floor(d.start.getTime() / 1000),
accommodation_id: -1, end: Math.floor(d.end.getTime() / 1000),
start: Math.floor(d.start.getTime() / 1000), },
end: Math.floor(d.end.getTime() / 1000), true
}, );
true
); if (!resa) return;
loadingMessage.show("Création de la réservation en cours...");
await AccommodationsReservationsApi.Create(family.family, resa);
reload();
snackbar("La réservation a été créée avec succès !");
} catch (e) {
console.error("Failed to create a reservation!", e);
alert("Échec de la création de la réservation!");
} finally {
loadingMessage.hide();
}
}; };
return ( return (