This commit is contained in:
Luke Vella 2022-05-09 08:21:53 +01:00 committed by GitHub
parent 1d7bcddf1b
commit 5c991d7011
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
83 changed files with 2463 additions and 1178 deletions

View file

@ -20,14 +20,14 @@ import {
} from "../components/forms";
import StandardLayout from "../components/standard-layout";
import Steps from "../components/steps";
import { useUserName } from "../components/user-name-context";
import { encodeDateOption } from "../utils/date-time-utils";
import { SessionProps, useSession, withSession } from "./session";
type StepName = "eventDetails" | "options" | "userDetails";
const steps: StepName[] = ["eventDetails", "options", "userDetails"];
const required = <T extends unknown>(v: T | undefined): T => {
const required = <T,>(v: T | undefined): T => {
if (!v) {
throw new Error("Required value is missing");
}
@ -38,16 +38,25 @@ const required = <T extends unknown>(v: T | undefined): T => {
const initialNewEventData: NewEventData = { currentStep: 0 };
const sessionStorageKey = "newEventFormData";
const Page: NextPage<{
export interface CreatePollPageProps extends SessionProps {
title?: string;
location?: string;
description?: string;
view?: "week" | "month";
}> = ({ title, location, description, view }) => {
}
const Page: NextPage<CreatePollPageProps> = ({
title,
location,
description,
view,
}) => {
const { t } = useTranslation("app");
const router = useRouter();
const session = useSession();
const [persistedFormData, setPersistedFormData] =
useSessionStorage<NewEventData>(sessionStorageKey, {
currentStep: 0,
@ -59,6 +68,13 @@ const Page: NextPage<{
options: {
view,
},
userDetails:
session.user?.isGuest === false
? {
name: session.user.name,
contact: session.user.email,
}
: undefined,
});
const [formData, setTransientFormData] = React.useState(persistedFormData);
@ -77,8 +93,6 @@ const Page: NextPage<{
const [isRedirecting, setIsRedirecting] = React.useState(false);
const [, setUserName] = useUserName();
const plausible = usePlausible();
const { mutate: createEventMutation, isLoading: isCreatingPoll } =
@ -101,7 +115,6 @@ const Page: NextPage<{
{
onSuccess: (poll) => {
setIsRedirecting(true);
setUserName(poll.authorName);
plausible("Created poll", {
props: {
numberOfOptions: formData.options?.options?.length,
@ -220,4 +233,4 @@ const Page: NextPage<{
);
};
export default Page;
export default withSession(Page);