mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-21 12:56:21 +02:00
Sessions (#162)
This commit is contained in:
parent
1d7bcddf1b
commit
5c991d7011
83 changed files with 2463 additions and 1178 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue