all repos — caroster @ 01900f894c783e01cfa3d75eedf28316abfa310f

[Octree] Group carpool to your event https://caroster.io

feat: :sparkles: Improve event creation flow for unauthenticated user

#572
Tim Izzo tim@octree.ch
Thu, 20 Feb 2025 14:36:29 +0100
commit

01900f894c783e01cfa3d75eedf28316abfa310f

parent

a5cbadb535a4d75beefc3fcf51332a787ef8f4aa

2 files changed, 26 insertions(+), 21 deletions(-)

jump to
M frontend/containers/EventTypeCard/PlusAction.tsxfrontend/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.tsfrontend/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}});