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 77 additions and 10 deletions
Showing only changes of commit bd3e8df4aa - Show all commits

View File

@ -118,6 +118,23 @@ export class AccommodationsReservationsApi {
return new AccommodationsReservationsList(data); return new AccommodationsReservationsList(data);
} }
/**
* Update a reservation
*/
static async Update(
family: Family,
r: UpdateAccommodationReservation
): Promise<void> {
await APIClient.exec({
method: "PATCH",
uri: `/family/${family.family_id}/accommodations/reservation/${r.reservation_id}`,
jsonData: {
start: r.start,
end: r.end,
},
});
}
/** /**
* Delete a reservation * Delete a reservation
*/ */

View File

@ -5,6 +5,7 @@ import interactionPlugin from "@fullcalendar/interaction";
import listPlugin from "@fullcalendar/list"; import listPlugin from "@fullcalendar/list";
import FullCalendar from "@fullcalendar/react"; import FullCalendar from "@fullcalendar/react";
import DeleteIcon from "@mui/icons-material/Delete"; import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit";
import { import {
Alert, Alert,
Avatar, Avatar,
@ -172,6 +173,44 @@ export function AccommodationsReservationsRoute(): React.ReactElement {
}); });
}; };
const changeReservation = async (r: AccommodationReservation) => {
try {
const ac = accommodations.accommodations.get(r.accommodation_id);
if (
ac?.need_validation &&
!(await confirm(
"Voulez-vous vraiment changer cette réservation ? Celle-ci devra être de nouveau validée !"
))
)
return;
const newResa = await updateReservation(
{
reservation_id: r.id,
accommodation_id: r.accommodation_id,
start: r.reservation_start,
end: r.reservation_end,
},
false
);
if (!newResa) return;
setActiveEvent(undefined);
loadingMessage.show("Mise à jour de la réservation en cours...");
await AccommodationsReservationsApi.Update(family.family, newResa);
reload();
snackbar("La réservation a été mise à jour avec succès !");
} catch (e) {
console.error("Failed to update a reservation!", e);
alert("Échec de la mise à jour de la réservation!");
} finally {
loadingMessage.hide();
}
};
const deleteReservation = async (r: AccommodationReservation) => { const deleteReservation = async (r: AccommodationReservation) => {
try { try {
if ( if (
@ -428,6 +467,16 @@ export function AccommodationsReservationsRoute(): React.ReactElement {
</CardContent> </CardContent>
<CardActions disableSpacing> <CardActions disableSpacing>
{user.user.id === activeEvent?.reservation.user_id && ( {user.user.id === activeEvent?.reservation.user_id && (
<>
<Tooltip title="Modifer les dates de réservation" arrow>
<IconButton
onClick={() =>
changeReservation(activeEvent?.reservation)
}
>
<EditIcon />
</IconButton>
</Tooltip>
<Tooltip title="Supprimer la réservation" arrow> <Tooltip title="Supprimer la réservation" arrow>
<IconButton <IconButton
color="error" color="error"
@ -438,6 +487,7 @@ export function AccommodationsReservationsRoute(): React.ReactElement {
<DeleteIcon /> <DeleteIcon />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
</>
)} )}
</CardActions> </CardActions>
</Card> </Card>