[cal-184] add and handle date query params for event types (#359)
parent
61fd300bc8
commit
793351fe96
|
@ -15,12 +15,19 @@ const DatePicker = ({
|
||||||
organizerTimeZone,
|
organizerTimeZone,
|
||||||
inviteeTimeZone,
|
inviteeTimeZone,
|
||||||
eventLength,
|
eventLength,
|
||||||
|
date,
|
||||||
}) => {
|
}) => {
|
||||||
const [calendar, setCalendar] = useState([]);
|
const [calendar, setCalendar] = useState([]);
|
||||||
const [selectedMonth, setSelectedMonth]: number = useState();
|
const [selectedMonth, setSelectedMonth] = useState<number>();
|
||||||
const [selectedDate, setSelectedDate]: Dayjs = useState();
|
const [selectedDate, setSelectedDate] = useState<Dayjs>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (date) {
|
||||||
|
setSelectedDate(dayjs(date).tz(inviteeTimeZone));
|
||||||
|
setSelectedMonth(dayjs(date).tz(inviteeTimeZone).month());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setSelectedMonth(dayjs().tz(inviteeTimeZone).month());
|
setSelectedMonth(dayjs().tz(inviteeTimeZone).month());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { GetServerSideProps } from "next";
|
import { GetServerSideProps, GetServerSidePropsContext } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import { ChevronDownIcon, ClockIcon, GlobeIcon } from "@heroicons/react/solid";
|
import { ChevronDownIcon, ClockIcon, GlobeIcon } from "@heroicons/react/solid";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { Dayjs } from "dayjs";
|
import dayjs, { Dayjs } from "dayjs";
|
||||||
|
|
||||||
import prisma, { whereAndSelect } from "@lib/prisma";
|
import prisma, { whereAndSelect } from "@lib/prisma";
|
||||||
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "../../lib/telemetry";
|
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "../../lib/telemetry";
|
||||||
|
@ -22,7 +22,9 @@ export default function Type(props): Type {
|
||||||
|
|
||||||
const { isReady } = Theme(props.user.theme);
|
const { isReady } = Theme(props.user.theme);
|
||||||
|
|
||||||
const [selectedDate, setSelectedDate] = useState<Dayjs>();
|
const [selectedDate, setSelectedDate] = useState<Dayjs>(() => {
|
||||||
|
return props.date && dayjs(props.date).isValid() ? dayjs(props.date) : null;
|
||||||
|
});
|
||||||
const [isTimeOptionsOpen, setIsTimeOptionsOpen] = useState(false);
|
const [isTimeOptionsOpen, setIsTimeOptionsOpen] = useState(false);
|
||||||
const [timeFormat, setTimeFormat] = useState("h:mma");
|
const [timeFormat, setTimeFormat] = useState("h:mma");
|
||||||
const telemetry = useTelemetry();
|
const telemetry = useTelemetry();
|
||||||
|
@ -37,6 +39,26 @@ export default function Type(props): Type {
|
||||||
setSelectedDate(date);
|
setSelectedDate(date);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!selectedDate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const formattedDate = selectedDate.utc().format("YYYY-MM-DD");
|
||||||
|
|
||||||
|
router.replace(
|
||||||
|
{
|
||||||
|
query: {
|
||||||
|
date: formattedDate,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
shallow: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, [selectedDate]);
|
||||||
|
|
||||||
const handleSelectTimeZone = (selectedTimeZone: string): void => {
|
const handleSelectTimeZone = (selectedTimeZone: string): void => {
|
||||||
if (selectedDate) {
|
if (selectedDate) {
|
||||||
setSelectedDate(selectedDate.tz(selectedTimeZone));
|
setSelectedDate(selectedDate.tz(selectedTimeZone));
|
||||||
|
@ -133,6 +155,7 @@ export default function Type(props): Type {
|
||||||
<p className="dark:text-gray-200 text-gray-600 mt-3 mb-8">{props.eventType.description}</p>
|
<p className="dark:text-gray-200 text-gray-600 mt-3 mb-8">{props.eventType.description}</p>
|
||||||
</div>
|
</div>
|
||||||
<DatePicker
|
<DatePicker
|
||||||
|
date={selectedDate}
|
||||||
weekStart={props.user.weekStart}
|
weekStart={props.user.weekStart}
|
||||||
onDatePicked={changeDate}
|
onDatePicked={changeDate}
|
||||||
workingHours={props.workingHours}
|
workingHours={props.workingHours}
|
||||||
|
@ -160,7 +183,10 @@ export default function Type(props): Type {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||||
|
const dateQuery = context.query?.date ?? null;
|
||||||
|
const date = Array.isArray(dateQuery) && dateQuery.length > 0 ? dateQuery.pop() : dateQuery;
|
||||||
|
|
||||||
const user = await whereAndSelect(
|
const user = await whereAndSelect(
|
||||||
prisma.user.findFirst,
|
prisma.user.findFirst,
|
||||||
{
|
{
|
||||||
|
@ -226,6 +252,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
user,
|
user,
|
||||||
|
date,
|
||||||
eventType,
|
eventType,
|
||||||
workingHours,
|
workingHours,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue