Skip to content

Commit

Permalink
fix(campaign): open congrats step on mobile and reset to badges step …
Browse files Browse the repository at this point in the history
…after that
  • Loading branch information
robertu7 committed Jul 26, 2024
1 parent b1dd83a commit 2313112
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
11 changes: 9 additions & 2 deletions src/views/User/UserProfile/BadgeGrandDialog/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react'
import { FormattedMessage } from 'react-intl'

import { ReactComponent as IconLeft } from '@/public/static/icons/24px/left.svg'
Expand All @@ -17,7 +18,7 @@ const BadgeGrandDialogContent = ({
closeDialog,
goBack,
}: BadgeGrandDialogContentProps) => {
const { getQuery } = useRoute()
const { getQuery, router } = useRoute()
const userName = getQuery('name')
const userProfilePath = toPath({
page: 'userProfile',
Expand All @@ -27,9 +28,15 @@ const BadgeGrandDialogContent = ({
typeof window !== 'undefined'
? `${window.location.origin}${userProfilePath.href}?${URL_USER_PROFILE.OPEN_GRAND_BADGE_DIALOG.key}=${URL_USER_PROFILE.OPEN_GRAND_BADGE_DIALOG.value}`
: ''
const isCongrats =
const initialCongrats =
getQuery(URL_USER_PROFILE.GRAND_BADGE_DIALOG_STEP.key) ===
URL_USER_PROFILE.GRAND_BADGE_DIALOG_STEP.value
const [isCongrats] = useState(initialCongrats)

// remove `dialog` and `step` query params
useEffect(() => {
router.replace(userProfilePath.href, undefined, { shallow: true })
}, [])

return (
<>
Expand Down
23 changes: 13 additions & 10 deletions src/views/User/UserProfile/BadgesDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { ReactComponent as IconTimes } from '@/public/static/icons/24px/times.sv
import {
OPEN_GRAND_BADGE_DIALOG,
OPEN_NOMAD_BADGE_DIALOG,
URL_USER_PROFILE,
} from '~/common/enums'
import {
Button,
Dialog,
Icon,
useDialogSwitch,
useEventListener,
useRoute,
} from '~/components'

import BadgeGrandContent from '../BadgeGrandDialog/Content'
Expand All @@ -26,7 +28,6 @@ interface BadgesDialogProps extends BadgesOptions {
}: {
openDialog: (step?: Step) => void
}) => React.ReactNode
step?: Step
}

export const BaseBadgesDialog = ({
Expand All @@ -39,24 +40,26 @@ export const BaseBadgesDialog = ({
hasGoldenMotorBadge,
hasArchitectBadge,
isCivicLiker,
step: initStep = 'badges',
}: BadgesDialogProps) => {
const { show, openDialog, closeDialog } = useDialogSwitch(true)
const { getQuery } = useRoute()

const initNomad =
getQuery(URL_USER_PROFILE.OPEN_NOMAD_BADGE_DIALOG.key) ===
URL_USER_PROFILE.OPEN_NOMAD_BADGE_DIALOG.value
const initGrand =
getQuery(URL_USER_PROFILE.OPEN_GRAND_BADGE_DIALOG.key) ===
URL_USER_PROFILE.OPEN_GRAND_BADGE_DIALOG.value
const initStep = initGrand ? 'grand' : initNomad ? 'nomad' : 'badges'
const [step, setStep] = useState<Step>(initStep)

const isInBadgesStep = step === 'badges'
const isInNomadStep = step === 'nomad'
const isInGrandStep = step === 'grand'

const openStepDialog = (step?: Step) => {
if (step) {
setStep(step)
}
openDialog()
}

return (
<>
{children({ openDialog: openStepDialog })}
{children({ openDialog })}

<Dialog isOpen={show} onDismiss={closeDialog}>
{isInBadgesStep && (
Expand Down

0 comments on commit 2313112

Please sign in to comment.