Skip to content

Commit f4a70e0

Browse files
committed
add feedback when moving reservation slot
1 parent 2d91526 commit f4a70e0

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

locale/fr/LC_MESSAGES/djangojs.po

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

270+
#: reservation/static/bundled/reservation/slot-reservation-index.ts
271+
msgid "This slot has been successfully moved"
272+
msgstr "Ce créneau a été bougé avec succès"
273+
270274
#: sas/static/bundled/sas/pictures-download-index.ts
271275
msgid "pictures.%(extension)s"
272276
msgstr "photos.%(extension)s"

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import enLocale from "@fullcalendar/core/locales/en-gb";
88
import frLocale from "@fullcalendar/core/locales/fr";
99
import interactionPlugin, { type EventResizeDoneArg } from "@fullcalendar/interaction";
1010
import resourceTimelinePlugin from "@fullcalendar/resource-timeline";
11-
1211
import { paginated } from "#core:utils/api";
1312
import { inheritHtmlElement, registerComponent } from "#core:utils/web-components";
1413
import {
@@ -19,8 +18,6 @@ import {
1918
type SlotSchema,
2019
} from "#openapi";
2120
import type { SlotSelectedEventArg } from "#reservation:reservation/types";
22-
import interactionPlugin from "@fullcalendar/interaction";
23-
import resourceTimelinePlugin from "@fullcalendar/resource-timeline";
2421

2522
@registerComponent("room-scheduler")
2623
export class RoomScheduler extends inheritHtmlElement("div") {
@@ -76,17 +73,15 @@ export class RoomScheduler extends inheritHtmlElement("div") {
7673
* Send a request to the API to change
7774
* the start and the duration of a reservation slot
7875
*/
79-
async changeReservation(args: EventDropArg) {
80-
const duration = new Date(args.event.end.getTime() - args.event.start.getTime());
76+
async changeReservation(args: EventDropArg | EventResizeDoneArg) {
8177
const response = await reservationslotUpdateSlot({
8278
// biome-ignore lint/style/useNamingConvention: api is snake_case
8379
path: { slot_id: Number.parseInt(args.event.id) },
84-
body: {
85-
start_at: args.event.startStr,
86-
end_at: args.event.endStr,
87-
},
80+
// biome-ignore lint/style/useNamingConvention: api is snake_case
81+
body: { start_at: args.event.startStr, end_at: args.event.endStr },
8882
});
8983
if (response.response.ok) {
84+
document.dispatchEvent(new CustomEvent("reservationSlotChanged"));
9085
this.scheduler.refetchEvents();
9186
}
9287
}
@@ -134,6 +129,7 @@ export class RoomScheduler extends inheritHtmlElement("div") {
134129
selectConstraint: { start: new Date() },
135130
nowIndicator: true,
136131
eventDrop: this.changeReservation,
132+
eventResize: this.changeReservation,
137133
});
138134
this.scheduler.render();
139135
}

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)