Skip to content

Commit 7655200

Browse files
committed
add feedback when moving reservation slot
1 parent d73da51 commit 7655200

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

locale/fr/LC_MESSAGES/djangojs.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ msgstr "La réorganisation des types de produit a échoué avec le code : %d"
255255
msgid "Rooms"
256256
msgstr "Salles"
257257

258+
#: reservation/static/bundled/reservation/slot-reservation-index.ts
259+
msgid "This slot has been successfully moved"
260+
msgstr "Ce créneau a été bougé avec succès"
261+
258262
#: sas/static/bundled/sas/pictures-download-index.ts
259263
msgid "pictures.%(extension)s"
260264
msgstr "photos.%(extension)s"

reservation/static/bundled/reservation/components/room-scheduler-index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,14 @@ export class RoomScheduler extends inheritHtmlElement("div") {
7676
* the start and the duration of a reservation slot
7777
*/
7878
async changeReservation(args: EventDropArg) {
79-
const duration = new Date(args.event.end.getTime() - args.event.start.getTime());
8079
const response = await reservationslotUpdateSlot({
8180
// biome-ignore lint/style/useNamingConvention: api is snake_case
8281
path: { slot_id: Number.parseInt(args.event.id) },
83-
body: {
84-
start_at: args.event.startStr,
85-
end_at: args.event.endStr,
86-
},
82+
// biome-ignore lint/style/useNamingConvention: api is snake_case
83+
body: { start_at: args.event.startStr, end_at: args.event.endStr },
8784
});
8885
if (response.response.ok) {
86+
document.dispatchEvent(new CustomEvent("reservationSlotChanged"));
8987
this.scheduler.refetchEvents();
9088
}
9189
}

reservation/static/bundled/reservation/slot-reservation-index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AlertMessage } from "#core:utils/alert-message";
12
import type { SlotSelectedEventArg } from "#reservation:reservation/types";
23

34
document.addEventListener("alpine:init", () => {
@@ -20,4 +21,19 @@ document.addEventListener("alpine:init", () => {
2021
);
2122
},
2223
}));
24+
25+
/**
26+
* Component that will catch events sent from the scheduler
27+
* to display success messages accordingly.
28+
*/
29+
Alpine.data("scheduleMessages", () => ({
30+
alertMessage: new AlertMessage({ defaultDuration: 2000 }),
31+
init() {
32+
document.addEventListener("reservationSlotChanged", (_event: CustomEvent) => {
33+
this.alertMessage.display(gettext("This slot has been successfully moved"), {
34+
success: true,
35+
});
36+
});
37+
},
38+
}));
2339
});

reservation/templates/reservation/schedule.jinja

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313

1414
{% block content %}
1515
<h2 class="margin-bottom">{% trans %}Room reservation{% endtrans %}</h2>
16+
<p
17+
x-data="scheduleMessages"
18+
class="alert snackbar"
19+
:class="alertMessage.success ? 'alert-green' : 'alert-red'"
20+
x-show="alertMessage.open"
21+
x-transition.duration.500ms
22+
x-text="alertMessage.content"
23+
></p>
1624
<room-scheduler
1725
locale="{{ LANGUAGE_CODE }}"
1826
can_edit_slot="{{ user.has_perm("reservation.change_reservationslot") }}"

0 commit comments

Comments
 (0)