feat: :sparkles: Improve event creation flow for unauthenticated user #572
Tim Izzo tim@octree.ch
Thu, 20 Feb 2025 14:36:29 +0100
2 files changed,
26 insertions(+),
21 deletions(-)
M
frontend/containers/EventTypeCard/PlusAction.tsx
→
frontend/containers/EventTypeCard/PlusAction.tsx
@@ -1,6 +1,5 @@
import {Button} from '@mui/material'; import {useSession} from 'next-auth/react'; -import Link from 'next/link'; import {useTranslation} from 'next-i18next'; import useLocale from '../../hooks/useLocale'; import useEventCreationStore from '../../stores/useEventCreationStore';@@ -36,31 +35,34 @@ },
refetchQueries: [ProfileDocument], }); const createdEvent = data.createEvent.data; - addToUserEvents(createdEvent.id); useEventCreationStore.persist.clearStorage(); - setCookie('redirectPath', `/${locale}/e/${createdEvent.attributes.uuid}`); - router.push( - `/${locale}/new/prices?eventId=${createdEvent.attributes.uuid}` - ); + + if (isAuthenticated) { + addToUserEvents(createdEvent.id); + setCookie( + 'redirectPath', + `/${locale}/e/${createdEvent.attributes.uuid}` + ); + router.push( + `/${locale}/new/prices?eventId=${createdEvent.attributes.uuid}` + ); + } else { + setCookie( + 'redirectPath', + `/${locale}/new/prices?eventId=${createdEvent.attributes.uuid}` + ); + router.push('/auth/login'); + } } catch (error) { console.error(error); } }; - if (isAuthenticated) - return ( - <Button - fullWidth - variant="outlined" - onClick={onClick} - >{t`event.creation.plus.button`}</Button> - ); - else - return ( - <Link href={`/auth/login?redirectPath=/new/type/`} passHref> - <Button variant="outlined" fullWidth>{t`signin.title`}</Button> - </Link> - ); + return ( + <Button fullWidth variant="outlined" onClick={onClick}> + {isAuthenticated ? t`event.creation.plus.button` : t`signin.title`} + </Button> + ); }; export default PlusAction;
M
frontend/stores/useEventCreationStore.ts
→
frontend/stores/useEventCreationStore.ts
@@ -12,7 +12,10 @@ const useEventCreationStore = create<State>()(
persist( (set, get) => ({ ready: false, - event: {}, + event: { + name: '', + email: '', + }, setField: (field, value) => { const currentEvent = get().event; set({event: {...currentEvent, [field]: value}});