Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
Fix issue with SSR state mismatch on booking page
Browse files Browse the repository at this point in the history
  • Loading branch information
Macludde committed May 25, 2023
1 parent 7ef9dc4 commit 7a8cc77
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 41 deletions.
22 changes: 0 additions & 22 deletions frontend/components/BookingFilter/index.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions frontend/components/Calendar/EventEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,11 @@ export default function EditEvent({ onSubmit, eventQuery }: BookingFormProps) {
value={startDateTime}
onChange={setStartDateTime}
label={t('booking:startTime')}
InputProps={{ fullWidth: true }}
/>
<DateTimePicker
value={endDateTime}
onChange={setEndDateTime}
label={t('booking:endTime')}
InputProps={{ fullWidth: true }}
/>
</Stack>

Expand Down
11 changes: 6 additions & 5 deletions frontend/components/DateTimePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ export default function DateTimePicker(props: DateTimePickerProps) {
return (
<LocalizationProvider dateAdapter={AdapterLuxon} locale={i18n.language}>
<MuiDateTimePicker
renderInput={(p) => <TextField fullWidth {...p} />}
renderInput={(p) => (
<TextField
fullWidth
{...p}
/>
)}
{...props}
InputProps={{
fullWidth: true,
error: false,
}}
/>
</LocalizationProvider>
);
Expand Down
33 changes: 21 additions & 12 deletions frontend/pages/booking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,40 @@ import { DateTime } from 'luxon';
import { useTranslation } from 'next-i18next';
import Link from 'next/link';
import { useRouter } from 'next/router';
import React, { useContext, useEffect } from 'react';
import BookingFilter from '~/components/BookingFilter';
import React, { useContext } from 'react';
import BookingForm from '~/components/BookingForm';
import BookingList from '~/components/BookingTable';
import DateTimePicker from '~/components/DateTimePicker';
import MarkdownPage from '~/components/MarkdownPage';
import genGetProps from '~/functions/genGetServerSideProps';
import { BookingStatus, useGetBookingsQuery } from '~/generated/graphql';
import { hasAccess, useApiAccess } from '~/providers/ApiAccessProvider';
import { useSetPageName } from '~/providers/PageNameProvider';
import UserContext from '~/providers/UserProvider';
import routes from '../../routes';
import { useSetPageName } from '~/providers/PageNameProvider';

const YESTERDAY = DateTime.now().minus({ days: 1 });
const NEXT_MONTH = DateTime.now().plus({ month: 1 });

export default function BookingPage() {
const router = useRouter();
const { t } = useTranslation(['common', 'booking']);
useSetPageName(t('booking:bookings'));
const { user } = useContext(UserContext);
const [from, setFrom] = React.useState(YESTERDAY);
const [to, setTo] = React.useState(NEXT_MONTH);
const [from, setFrom] = React.useState(null);
const [to, setTo] = React.useState(null);
const apiContext = useApiAccess();
const [status] = React.useState<BookingStatus>(undefined);

useEffect(() => {
React.useEffect(() => {
const initialEndDate = router.query.endDate
? DateTime.fromMillis(parseInt(Array.isArray(router.query.endDate)
? router.query.endDate[0]
: router.query.endDate, 10))
: undefined;
if (initialEndDate && initialEndDate.isValid) {
setTo(initialEndDate);
}
setFrom(YESTERDAY);
setTo((initialEndDate && initialEndDate.isValid)
? initialEndDate : NEXT_MONTH);
}, [router.query.endDate]);

const { data, loading, refetch } = useGetBookingsQuery({
Expand All @@ -63,7 +64,7 @@ export default function BookingPage() {
)}
</Box>
<MarkdownPage name="booking" />
<Accordion>
<Accordion defaultExpanded>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
Expand All @@ -74,10 +75,18 @@ export default function BookingPage() {
<AccordionDetails>
<Stack direction="row" gap={2} flexWrap="wrap">
<Box sx={{ flex: 1, flexBasis: 0, minWidth: 240 }}>
<BookingFilter isStart value={from} onChange={setFrom} />
<DateTimePicker
value={from}
onChange={setFrom}
label={t('booking:startTime')}
/>
</Box>
<Box sx={{ flex: 1, flexBasis: 0, minWidth: 240 }}>
<BookingFilter value={to} onChange={setTo} />
<DateTimePicker
value={to}
onChange={setTo}
label={t('booking:endTime')}
/>
</Box>
</Stack>
</AccordionDetails>
Expand Down

0 comments on commit 7a8cc77

Please sign in to comment.