personal min and max future booking days

master
alex 2024-02-03 09:25:36 +01:00
parent 3bce0e214a
commit d2bd8296e4
2 changed files with 53 additions and 43 deletions

View File

@ -110,12 +110,12 @@ export function MyPasswordFormInput({
); );
} }
export function MyCalendarMaxFutureBookingDaysFormInput() { export function MyCalendarMaxFutureBookingDaysFormInput({ formItemName }) {
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
<MyFormInput <MyFormInput
formItemName="calendarMaxFutureBookingDays" formItemName={formItemName}
minLength={Constants.GLOBALS.MIN_CALENDAR_FUTURE_BOOKING_DAYS} minLength={Constants.GLOBALS.MIN_CALENDAR_FUTURE_BOOKING_DAYS}
maxLength={Constants.GLOBALS.MAX_CALENDAR_FUTURE_BOOKING_DAYS} maxLength={Constants.GLOBALS.MAX_CALENDAR_FUTURE_BOOKING_DAYS}
label={t("common.calendarMaxFutureBookingDays")} label={t("common.calendarMaxFutureBookingDays")}
@ -131,12 +131,12 @@ export function MyCalendarMaxFutureBookingDaysFormInput() {
); );
} }
export function MyCalendarMinEarliestBookingTimeFormInput() { export function MyCalendarMinEarliestBookingTimeFormInput({ formItem }) {
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
<MyFormInput <MyFormInput
formItemName="calendarMinEarliestBookingTime" formItemName={formItem}
minLength={Constants.GLOBALS.MIN_CALENDAR_EARLIEST_BOOKING_TIME} minLength={Constants.GLOBALS.MIN_CALENDAR_EARLIEST_BOOKING_TIME}
maxLength={Constants.GLOBALS.MAX_CALENDAR_EARLIEST_BOOKING_TIME} maxLength={Constants.GLOBALS.MAX_CALENDAR_EARLIEST_BOOKING_TIME}
label={t("common.calendarMinEarliestBookingTime")} label={t("common.calendarMinEarliestBookingTime")}

View File

@ -78,12 +78,8 @@ export default function StoreCalendar() {
notificationApi: notificationApi, notificationApi: notificationApi,
t: t, t: t,
}) })
.then((res) => { .then((res) => setCalendarSettings(res))
setCalendarSettings(res); .catch(() => {});
})
.catch((err) => {
console.log(err);
});
}, 2000); }, 2000);
} }
@ -251,22 +247,35 @@ function CardPersonalCalendarSettings({ settings }) {
"calendarUsingPrimaryCalendar", "calendarUsingPrimaryCalendar",
form form
); );
const maxFutureBookingDays = Form.useWatch(
"personalCalendarMaxFutureBookingDays",
form
);
const minEarliestBookingTime = Form.useWatch(
"personalCalendarMinEarliestBookingTime",
form
);
const handleModalClose = () => { const handleModalClose = () => setIsModalOpen(false);
setIsModalOpen(false);
};
useEffect(() => { useEffect(() => {
if (!settings) return; if (!settings) return;
form.setFieldValue( form.setFieldsValue({
"calendarUsingPrimaryCalendar", calendarUsingPrimaryCalendar: settings.calendar_using_primary_calendar,
settings.calendar_using_primary_calendar personalCalendarMaxFutureBookingDays:
); settings.calendar_max_future_booking_days,
personalCalendarMinEarliestBookingTime:
settings.calendar_min_earliest_booking_time,
});
}, []); }, []);
useEffect(() => { useEffect(() => {
if (usingPrimaryCalendar === undefined) return; if (
usingPrimaryCalendar === undefined ||
maxFutureBookingDays === undefined ||
minEarliestBookingTime === undefined
)
return;
if (RequestState.INIT === requestState) { if (RequestState.INIT === requestState) {
setRequestState(RequestState.NOTHING); setRequestState(RequestState.NOTHING);
@ -285,17 +294,16 @@ function CardPersonalCalendarSettings({ settings }) {
method: "POST", method: "POST",
body: { body: {
calendarUsingPrimaryCalendar: usingPrimaryCalendar, calendarUsingPrimaryCalendar: usingPrimaryCalendar,
calendarMaxFutureBookingDays: maxFutureBookingDays,
calendarMinEarliestBookingTime: minEarliestBookingTime,
}, },
notificationApi: notificationApi, notificationApi: notificationApi,
t: t, t: t,
}) })
.then(() => setRequestState(RequestState.SUCCESS)) .then(() => setRequestState(RequestState.SUCCESS))
.catch((errStatus) => { .catch((errStatus) => setRequestState(RequestState.FAILED));
console.log(errStatus);
setRequestState(RequestState.FAILED);
});
}, 500); }, 500);
}, [usingPrimaryCalendar]); }, [usingPrimaryCalendar, maxFutureBookingDays, minEarliestBookingTime]);
useEffect(() => { useEffect(() => {
if (!isModalOpen) return; if (!isModalOpen) return;
@ -374,6 +382,10 @@ function CardPersonalCalendarSettings({ settings }) {
> >
<Switch /> <Switch />
</Form.Item> </Form.Item>
<MyCalendarMaxFutureBookingDaysFormInput formItemName="personalCalendarMaxFutureBookingDays" />
<MyCalendarMinEarliestBookingTimeFormInput formItem="personalCalendarMinEarliestBookingTime" />
</Form> </Form>
</Card> </Card>
@ -439,13 +451,13 @@ function CardStoreCalendarSettings({ settings }) {
const [requestState, setRequestState] = useState(RequestState.INIT); const [requestState, setRequestState] = useState(RequestState.INIT);
const delayTimeout = useRef(); const delayTimeout = useRef();
const calendarMaxFutureBookingDays = Form.useWatch( const storeCalendarMaxFutureBookingDays = Form.useWatch(
"calendarMaxFutureBookingDays", "storeCalendarMaxFutureBookingDays",
form form
); );
const calendarMinEarliestBookingTime = Form.useWatch( const storeCalendarMinEarliestBookingTime = Form.useWatch(
"calendarMinEarliestBookingTime", "storeCalendarMinEarliestBookingTime",
form form
); );
@ -453,8 +465,9 @@ function CardStoreCalendarSettings({ settings }) {
if (!settings) return; if (!settings) return;
form.setFieldsValue({ form.setFieldsValue({
calendarMaxFutureBookingDays: settings.calendar_max_future_booking_days, storeCalendarMaxFutureBookingDays:
calendarMinEarliestBookingTime: settings.calendar_max_future_booking_days,
storeCalendarMinEarliestBookingTime:
settings.calendar_min_earliest_booking_time, settings.calendar_min_earliest_booking_time,
}); });
}, []); }, []);
@ -463,10 +476,10 @@ function CardStoreCalendarSettings({ settings }) {
// undefined on first render // undefined on first render
// null when input is empty // null when input is empty
if ( if (
calendarMaxFutureBookingDays === undefined || storeCalendarMaxFutureBookingDays === undefined ||
calendarMinEarliestBookingTime === undefined || storeCalendarMinEarliestBookingTime === undefined ||
calendarMaxFutureBookingDays === null || storeCalendarMaxFutureBookingDays === null ||
calendarMinEarliestBookingTime === null storeCalendarMinEarliestBookingTime === null
) )
return; return;
@ -486,19 +499,16 @@ function CardStoreCalendarSettings({ settings }) {
url: "/calendar/settings/store", url: "/calendar/settings/store",
method: "POST", method: "POST",
body: { body: {
calendarMaxFutureBookingDays, calendarMaxFutureBookingDays: storeCalendarMaxFutureBookingDays,
calendarMinEarliestBookingTime, calendarMinEarliestBookingTime: storeCalendarMinEarliestBookingTime,
}, },
notificationApi: notificationApi, notificationApi: notificationApi,
t: t, t: t,
}) })
.then(() => setRequestState(RequestState.SUCCESS)) .then(() => setRequestState(RequestState.SUCCESS))
.catch((errStatus) => { .catch(() => setRequestState(RequestState.FAILED));
console.log(errStatus);
setRequestState(RequestState.FAILED);
});
}, 500); }, 500);
}, [calendarMaxFutureBookingDays, calendarMinEarliestBookingTime]); }, [storeCalendarMaxFutureBookingDays, storeCalendarMinEarliestBookingTime]);
return ( return (
<> <>
@ -515,9 +525,9 @@ function CardStoreCalendarSettings({ settings }) {
> >
<Form form={form} requiredMark={false}> <Form form={form} requiredMark={false}>
<> <>
<MyCalendarMaxFutureBookingDaysFormInput /> <MyCalendarMaxFutureBookingDaysFormInput formItemName="storeCalendarMaxFutureBookingDays" />
<MyCalendarMinEarliestBookingTimeFormInput /> <MyCalendarMinEarliestBookingTimeFormInput formItem="storeCalendarMinEarliestBookingTime" />
</> </>
</Form> </Form>
</Card> </Card>