all repos — caroster @ a27343386d2ba1d0fa8ebc6da3e755c906ac6cf5

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

fix: 🐛 Fix onboarding
Tim Izzo tim@octree.ch
Mon, 07 Feb 2022 15:03:27 +0000
commit

a27343386d2ba1d0fa8ebc6da3e755c906ac6cf5

parent

6a629062a8bc34c4d4e65df3f7e8242515460e30

M frontend/containers/Fab/index.tsxfrontend/containers/Fab/index.tsx

@@ -9,12 +9,7 @@ const classes = useStyles({open, variant});

return ( <div className={classes.container}> - <FabMui - className="tour_car_add1" - color="secondary" - variant={variant} - {...props} - > + <FabMui color="secondary" variant={variant} {...props}> <Icon className={classes.icon}>add</Icon> {children} </FabMui>
M frontend/containers/TravelColumns/AddTravel.tsxfrontend/containers/TravelColumns/AddTravel.tsx

@@ -3,6 +3,7 @@ import Button from '@material-ui/core/Button';

import Container from '@material-ui/core/Container'; import {makeStyles} from '@material-ui/core'; import {useTranslation} from 'react-i18next'; +import clsx from 'clsx'; interface Props { toggle: () => void;

@@ -13,7 +14,10 @@ const {toggle} = props;

const classes = useStyles(); const {t} = useTranslation(); return ( - <Container maxWidth="sm" className={classes.container}> + <Container + maxWidth="sm" + className={clsx([classes.container, 'tour_travel_add'])} + > <Button classes={{containedSecondary: classes.button}} fullWidth
M frontend/hooks/useProfile.tsfrontend/hooks/useProfile.ts

@@ -1,27 +1,29 @@

-import {useState, useEffect} from 'react'; +import {useEffect, useState} from 'react'; import useAuthStore from '../stores/useAuthStore'; -import {useProfileLazyQuery, ProfileQuery} from '../generated/graphql'; +import {useProfileLazyQuery} from '../generated/graphql'; const useProfile = () => { const token = useAuthStore(s => s.token); const user = useAuthStore(s => s.user); - const [profile, setProfile] = useState<ProfileQuery['me']['profile']>(undefined); - const [fetchProfile, {data}] = useProfileLazyQuery(); - - useEffect(() => { - if (token) fetchProfile(); - }, [token]); + const [isReady, setIsReady] = useState(false); + const [ + fetchProfile, + {data: {me: {profile = null} = {}} = {}}, + ] = useProfileLazyQuery({ + onCompleted: () => setIsReady(true), + }); useEffect(() => { - if (data) setProfile(data.me?.profile); - else setProfile(null); - }, [data]); + if (profile) setIsReady(true); + else if (token) fetchProfile(); + else setIsReady(true); + }, [token, profile]); return { profile, connected: !!token, user: user, - notReady: typeof profile === 'undefined', + isReady, }; };
M frontend/hooks/useTour.tsfrontend/hooks/useTour.ts

@@ -32,21 +32,20 @@ const setTour = useTourStore(s => s.setTour);

const onboardingUser = useOnboardingStore(s => s.onboardingUser); const onboardingCreator = useOnboardingStore(s => s.onboardingCreator); const setOnboarding = useOnboardingStore(s => s.setOnboarding); - const {profile, notReady} = useProfile(); + const {profile, isReady} = useProfile(); const event = useEventStore(s => s.event); const {eventsToBeAdded} = useAddToEvents(); const [updateProfile] = useUpdateMeMutation(); // Check if user is the event creator useEffect(() => { - if (notReady || !event) return; + if (!isReady || !event) return; + + let isCreator = eventsToBeAdded.includes(event?.id); + if (profile) isCreator = profile.events.map(e => e.id).includes(event?.id); - if (profile) { - setTour({isCreator: profile.events.map(e => e.id).includes(event?.id)}); - } else { - setTour({isCreator: eventsToBeAdded.includes(event?.id)}); - } - }, [notReady, event, eventsToBeAdded, profile]); + setTour({isCreator}); + }, [isReady, event, eventsToBeAdded, profile]); const steps = useMemo(() => { if (isCreator === null) return [];

@@ -56,10 +55,10 @@ {content: t`tour.creator.step1`, target: '.tour_event_infos'},

{content: t`tour.creator.step2`, target: '.tour_event_edit'}, {content: t`tour.creator.step3`, target: '.tour_event_share'}, {content: t`tour.creator.step4`, target: '.tour_waiting_list'}, - {content: t`tour.creator.step5`, target: '.tour_car_add1'}, + {content: t`tour.creator.step5`, target: '.tour_travel_add'}, ].map(step => ({...step, ...STEP_SETTINGS})) : [ - {content: t`tour.user.step1`, target: '.tour_car_add1'}, + {content: t`tour.user.step1`, target: '.tour_travel_add'}, {content: t`tour.user.step2`, target: '.tour_waiting_list'}, {content: t`tour.user.step3`, target: '.tour_event_infos'}, {content: t`tour.user.step4`, target: '.tour_event_share'},

@@ -68,13 +67,14 @@ }, [isCreator]);

// Init tour useEffect(() => { - const hasOnboarded = () => { - if (isCreator) return profile?.onboardingCreator || onboardingCreator; - else return profile?.onboardingUser || onboardingUser; - }; - if (!hasOnboarded() && steps.length > 0) setTour({showWelcome: true}); - else setTour({showWelcome: false}); - }, [steps, isCreator, onboardingCreator, onboardingUser, profile]); + if (!isReady) return; + let hasOnboarded = profile?.onboardingUser || onboardingUser; + if (isCreator) + hasOnboarded = profile?.onboardingCreator || onboardingCreator; + const hasSteps = steps.length > 0; + const showWelcome = hasSteps && !hasOnboarded; + setTour({showWelcome}); + }, [steps, isCreator, onboardingCreator, onboardingUser, profile, isReady]); // On step change : wait for the UI a little and run it useEffect(() => {
M frontend/pages/dashboard.tsxfrontend/pages/dashboard.tsx

@@ -15,7 +15,7 @@ const Dashboard = () => {

const {t} = useTranslation(); const router = useRouter(); const isAuth = useAuthStore(s => !!s.token); - const {profile, notReady} = useProfile(); + const {profile, isReady} = useProfile(); const {events} = profile || {}; const classes = useStyles();

@@ -41,10 +41,9 @@ .sort(sortDesc),

[events] ); - const noDateEvents = useMemo( - () => events?.filter(({date}) => !date), - [events] - ); + const noDateEvents = useMemo(() => events?.filter(({date}) => !date), [ + events, + ]); const menuActions = [ {

@@ -59,7 +58,7 @@ id: 'ProfileTabs',

}, ]; - if (!events || !isAuth || notReady) + if (!events || !isAuth || !isReady) return ( <LayoutDefault menuTitle={t('dashboard.title')}> <Loading />
M frontend/pages/index.tsxfrontend/pages/index.tsx

@@ -9,7 +9,7 @@

const Home = () => { const {t} = useTranslation(); const router = useRouter(); - const {notReady, profile} = useProfile(); + const {isReady, profile} = useProfile(); const noUserMenuActions = [ {

@@ -39,7 +39,7 @@ ];

const menuActions = !!profile ? loggedMenuActions : noUserMenuActions; - if (notReady) return null; + if (!isReady) return null; return ( <Layout