Skip to content

Commit c1b84a0

Browse files
authored
Merge pull request #192 from os2display/feature/2.5.2-fixes
Calendar Instant booking fixes
2 parents 670e53e + a78485a commit c1b84a0

10 files changed

+52
-112
lines changed

build/calendar-admin.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@
6969
}
7070
]
7171
},
72+
{
73+
"key": "calendar-form-enable-instant-booking",
74+
"input": "checkbox",
75+
"label": "Aktivér straksbooking",
76+
"helpText": "Aktivér mulighed for straksbooking. Dette gælder kun for \"Enkelt lokale med booking\" layoutet og kræver, at resursen er opsat og godkendt af systemadministrator.",
77+
"name": "instantBookingEnabled",
78+
"formGroupClasses": "mb-3"
79+
},
7280
{
7381
"key": "calendar-form-form-14",
7482
"input": "select",
@@ -210,13 +218,5 @@
210218
"name": "headerOrder",
211219
"formGroupClasses": "col-md-6 mb-3",
212220
"helpText": "Dette er kun relevant hvis \"Flere resurser\" er valgt under \"layout\". Standard er \"Hvornår, hvad, hvor.\""
213-
},
214-
{
215-
"key": "calendar-form-enable-instant-booking",
216-
"input": "checkbox",
217-
"label": "Aktivér straksbooking",
218-
"helpText": "Aktivér mulighed for straksbooking. Dette kræver at resursen er opsat og godkendt af systemadministrator.",
219-
"name": "instantBookingEnabled",
220-
"formGroupClasses": "mb-3"
221221
}
222222
]

build/calendar-config-develop.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"id": "01FRJPF4XATRN8PBZ35XN84PS6",
55
"description": "Mulighed for at vise et kalenderfeed.",
66
"resources": {
7-
"component": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar.js?ts=1756988530669",
8-
"admin": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar-admin.json?ts=1756988530669",
9-
"schema": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar-schema.json?ts=1756988530669",
7+
"component": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar.js?ts=1758285165573",
8+
"admin": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar-admin.json?ts=1758285165573",
9+
"schema": "https://raw.githubusercontent.com/os2display/display-templates/develop/build/calendar-schema.json?ts=1758285165573",
1010
"assets": [],
1111
"options": {},
1212
"content": {}

build/calendar-config-main.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"id": "01FRJPF4XATRN8PBZ35XN84PS6",
55
"description": "Mulighed for at vise et kalenderfeed.",
66
"resources": {
7-
"component": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar.js?ts=1756988530669",
8-
"admin": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar-admin.json?ts=1756988530669",
9-
"schema": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar-schema.json?ts=1756988530669",
7+
"component": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar.js?ts=1758285165573",
8+
"admin": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar-admin.json?ts=1758285165573",
9+
"schema": "https://raw.githubusercontent.com/os2display/display-templates/main/build/calendar-schema.json?ts=1758285165573",
1010
"assets": [],
1111
"options": {},
1212
"content": {}

build/calendar.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/calendar/calendar-admin.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@
6969
}
7070
]
7171
},
72+
{
73+
"key": "calendar-form-enable-instant-booking",
74+
"input": "checkbox",
75+
"label": "Aktivér straksbooking",
76+
"helpText": "Aktivér mulighed for straksbooking. Dette gælder kun for \"Enkelt lokale med booking\" layoutet og kræver, at resursen er opsat og godkendt af systemadministrator.",
77+
"name": "instantBookingEnabled",
78+
"formGroupClasses": "mb-3"
79+
},
7280
{
7381
"key": "calendar-form-form-14",
7482
"input": "select",
@@ -210,13 +218,5 @@
210218
"name": "headerOrder",
211219
"formGroupClasses": "col-md-6 mb-3",
212220
"helpText": "Dette er kun relevant hvis \"Flere resurser\" er valgt under \"layout\". Standard er \"Hvornår, hvad, hvor.\""
213-
},
214-
{
215-
"key": "calendar-form-enable-instant-booking",
216-
"input": "checkbox",
217-
"label": "Aktivér straksbooking",
218-
"helpText": "Aktivér mulighed for straksbooking. Dette kræver at resursen er opsat og godkendt af systemadministrator.",
219-
"name": "instantBookingEnabled",
220-
"formGroupClasses": "mb-3"
221221
}
222222
]

src/calendar/calendar-multiple-days.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dayjs from "dayjs";
44
import localeDa from "dayjs/locale/da";
55
import localizedFormat from "dayjs/plugin/localizedFormat";
66
import styled from "styled-components";
7-
import { renderTimeOfDayFromUnixTimestamp } from "./helper";
7+
import renderTimeOfDayFromUnixTimestamp from "./helper";
88

99
/**
1010
* Multiple days resource calendar.

src/calendar/calendar-single-booking-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import styled from "styled-components";
22
import dayjs from "dayjs";
33
import React from "react";
44
import IconCalendarPlus from "./icon-calendar-plus.svg";
5-
import { renderTimeOfDayFromUnixTimestamp } from "./helper";
5+
import renderTimeOfDayFromUnixTimestamp from "./helper";
66

77
const Wrapper = styled.div`
88
/* Wrapper styling */

src/calendar/calendar-single-booking.js

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import localizedFormat from "dayjs/plugin/localizedFormat";
66
import { FormattedMessage } from "react-intl";
77
import IconCheck from "./icon-check.svg";
88
import IconExclamation from "./icon-exclamation.svg";
9-
import {
10-
renderTimeOfDayFromUnixTimestamp,
11-
timeCountdownString,
12-
} from "./helper";
9+
import renderTimeOfDayFromUnixTimestamp from "./helper";
1310
import {
1411
Button,
1512
Content,
@@ -72,8 +69,7 @@ function CalendarSingleBooking({
7269
const [currentTime, setCurrentTime] = useState(dayjs());
7370
const [bookingResult, setBookingResult] = useState(null);
7471
const [processingBooking, setProcessingBooking] = useState(false);
75-
const [secondsUntilNextEvent, setSecondsUntilNextEvent] = useState(null);
76-
const [bookingError, setBookingError] = useState(false);
72+
const [bookingError, setBookingError] = useState(null);
7773

7874
const fetchBookingIntervals = () => {
7975
if (!instantBookingEnabled) {
@@ -131,30 +127,6 @@ function CalendarSingleBooking({
131127
const intervalChecking = () => {
132128
setCurrentTime(dayjs());
133129

134-
// Find time until next event.
135-
const now = dayjs();
136-
let closestEvent = null;
137-
138-
if (calendarEvents.length === 0) {
139-
setSecondsUntilNextEvent(null);
140-
} else {
141-
calendarEvents.forEach((event) => {
142-
const eventStartTime = dayjs(event.startTime * 1000);
143-
if (eventStartTime >= now) {
144-
if (
145-
closestEvent === null ||
146-
eventStartTime < dayjs(closestEvent.startTime * 1000)
147-
) {
148-
closestEvent = event;
149-
}
150-
}
151-
});
152-
}
153-
154-
if (closestEvent !== null) {
155-
setSecondsUntilNextEvent(closestEvent.startTime - now.unix());
156-
}
157-
158130
const instantBooking = getInstantBookingFromLocalStorage(slide["@id"]);
159131

160132
let newBookingResult = null;
@@ -199,14 +171,30 @@ function CalendarSingleBooking({
199171
},
200172
}),
201173
})
202-
.then((r) => r.json())
174+
.then((r) => {
175+
if (r?.ok === false) {
176+
return {
177+
error: true,
178+
status: r.status,
179+
response: r,
180+
};
181+
}
182+
183+
return r.json();
184+
})
203185
.then((data) => {
204-
setBookingResult(data);
205-
setInstantBookingFromLocalStorage(slide["@id"], data);
186+
if (data?.error) {
187+
const message = `Straksbooking lykkedes ikke. ${
188+
data?.status === 409 ? "Intervallet er optaget." : ""
189+
}`;
190+
setBookingError(message);
191+
} else {
192+
setBookingResult(data);
193+
setInstantBookingFromLocalStorage(slide["@id"], data);
194+
}
206195
})
207196
.catch(() => {
208-
setBookingError(true);
209-
setTimeout(() => setBookingError(false), 10000);
197+
setBookingError("Straksbooking lykkedes ikke.");
210198
})
211199
.finally(() => {
212200
setProcessingBooking(false);
@@ -248,7 +236,7 @@ function CalendarSingleBooking({
248236
const roomInUse = bookingResult !== null || currentEvents.length > 0;
249237

250238
const roomAvailableForInstantBooking =
251-
!roomInUse && fetchingIntervals ? null : bookableIntervals?.length > 0;
239+
!roomInUse && bookableIntervals?.length > 0;
252240

253241
const headerColor = roomInUse
254242
? "var(--color-red-900)"
@@ -363,19 +351,6 @@ function CalendarSingleBooking({
363351
</ButtonWrapper>
364352
</>
365353
)}
366-
{!roomAvailableForInstantBooking && (
367-
<>
368-
<p>
369-
<FormattedMessage
370-
id="instant_booked_not_available"
371-
defaultMessage="Straksbooking ikke tilgængeligt"
372-
/>
373-
</p>
374-
<div style={{ fontSize: ".5em" }}>
375-
{timeCountdownString(secondsUntilNextEvent)}
376-
</div>
377-
</>
378-
)}
379354
</>
380355
)}
381356
{processingBooking && !bookingResult && !bookingError && (
@@ -386,14 +361,7 @@ function CalendarSingleBooking({
386361
/>
387362
</p>
388363
)}
389-
{bookingError && (
390-
<p>
391-
<FormattedMessage
392-
id="instant_booking_error"
393-
defaultMessage="Straksbooking fejlede. Prøv igen lidt senere."
394-
/>
395-
</p>
396-
)}
364+
{bookingError && <p>{bookingError}</p>}
397365
{bookingResult?.status === 201 && (
398366
<p>
399367
<FormattedMessage

src/calendar/calendar-single.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from "prop-types";
33
import dayjs from "dayjs";
44
import localizedFormat from "dayjs/plugin/localizedFormat";
55
import styled from "styled-components";
6-
import { renderTimeOfDayFromUnixTimestamp } from "./helper";
6+
import renderTimeOfDayFromUnixTimestamp from "./helper";
77
import "./calendar.scss";
88

99
/**

src/calendar/helper.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,4 @@ const renderTimeOfDayFromUnixTimestamp = (unixTimestamp) =>
66
.locale(localeDa)
77
.format("HH:mm");
88

9-
const timeCountdownString = (seconds) => {
10-
if (seconds <= 0) return "";
11-
12-
const daysUntil = Math.floor(seconds / (60 * 60 * 24));
13-
const hoursUntil = Math.floor(
14-
(seconds - daysUntil * 60 * 60 * 24) / (60 * 60)
15-
);
16-
const minutesUntil = Math.floor((seconds - hoursUntil * 60 * 60) / 60);
17-
const secondsUntil = seconds % 60;
18-
19-
// TODO: Translate strings.
20-
const textEnd = " til næste begivenhed";
21-
22-
if (daysUntil > 0) {
23-
return `${daysUntil} dag${daysUntil > 1 ? "e" : ""} ${textEnd}`;
24-
}
25-
if (hoursUntil > 0) {
26-
return `${hoursUntil} time${hoursUntil > 1 ? "r" : ""} ${textEnd}`;
27-
}
28-
if (minutesUntil > 0) {
29-
return `${minutesUntil} minut${minutesUntil > 1 ? "ter" : ""} ${textEnd}`;
30-
}
31-
if (secondsUntil > 0) {
32-
return `Mindre end et minut ${textEnd}`;
33-
}
34-
return "";
35-
};
36-
37-
export { renderTimeOfDayFromUnixTimestamp, timeCountdownString };
9+
export default renderTimeOfDayFromUnixTimestamp;

0 commit comments

Comments
 (0)