-
Notifications
You must be signed in to change notification settings - Fork 13
Add install PWA step in invites flow android #1534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,13 +4,15 @@ import ErrorAlert from '@/components/Global/ErrorAlert' | |||||||||||||||||||||||||||||||||||||||
| import { Icon } from '@/components/Global/Icons/Icon' | ||||||||||||||||||||||||||||||||||||||||
| import Modal from '@/components/Global/Modal' | ||||||||||||||||||||||||||||||||||||||||
| import QRCodeWrapper from '@/components/Global/QRCodeWrapper' | ||||||||||||||||||||||||||||||||||||||||
| import { type BeforeInstallPromptEvent, type ScreenId } from '@/components/Setup/Setup.types' | ||||||||||||||||||||||||||||||||||||||||
| import { type BeforeInstallPromptEvent, type ISetupStep, type ScreenId } from '@/components/Setup/Setup.types' | ||||||||||||||||||||||||||||||||||||||||
| import { useAuth } from '@/context/authContext' | ||||||||||||||||||||||||||||||||||||||||
| import { useSetupFlow } from '@/hooks/useSetupFlow' | ||||||||||||||||||||||||||||||||||||||||
| import { useRouter } from 'next/navigation' | ||||||||||||||||||||||||||||||||||||||||
| import { useCallback, useEffect, useState } from 'react' | ||||||||||||||||||||||||||||||||||||||||
| import { captureException } from '@sentry/nextjs' | ||||||||||||||||||||||||||||||||||||||||
| import { DeviceType } from '@/hooks/useGetDeviceType' | ||||||||||||||||||||||||||||||||||||||||
| import { useAppDispatch, useSetupStore } from '@/redux/hooks' | ||||||||||||||||||||||||||||||||||||||||
| import { setupActions } from '@/redux/slices/setup-slice' | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const StepTitle = ({ text }: { text: string }) => <h3 className="text-xl font-extrabold leading-6">{text}</h3> | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -34,6 +36,7 @@ const InstallPWA = ({ | |||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||
| const toast = useToast() | ||||||||||||||||||||||||||||||||||||||||
| const { handleNext, isLoading: isSetupFlowLoading } = useSetupFlow() | ||||||||||||||||||||||||||||||||||||||||
| const { inviteCode, steps } = useSetupStore() | ||||||||||||||||||||||||||||||||||||||||
| const [showModal, setShowModal] = useState(false) | ||||||||||||||||||||||||||||||||||||||||
| const [installComplete, setInstallComplete] = useState(false) | ||||||||||||||||||||||||||||||||||||||||
| const [installCancelled, setInstallCancelled] = useState(false) | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -42,6 +45,7 @@ const InstallPWA = ({ | |||||||||||||||||||||||||||||||||||||||
| const [isBrave, setIsBrave] = useState(false) | ||||||||||||||||||||||||||||||||||||||||
| const { user } = useAuth() | ||||||||||||||||||||||||||||||||||||||||
| const { push } = useRouter() | ||||||||||||||||||||||||||||||||||||||||
| const dispatch = useAppDispatch() | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||
| if (installComplete) { | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -215,7 +219,20 @@ const InstallPWA = ({ | |||||||||||||||||||||||||||||||||||||||
| <div className="space-y-2 text-center"> | ||||||||||||||||||||||||||||||||||||||||
| <p className="text-sm text-grey-1">Could not initiate automatic installation.</p> | ||||||||||||||||||||||||||||||||||||||||
| <p className="text-sm text-grey-1">Please try adding to Home Screen manually via your browser menu.</p> | ||||||||||||||||||||||||||||||||||||||||
| <Button onClick={() => handleNext()} className="mt-4 w-full" shadowSize="4" variant="purple"> | ||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||
| onClick={() => { | ||||||||||||||||||||||||||||||||||||||||
| // If user is on android and has an invite code, redirect to signup screen | ||||||||||||||||||||||||||||||||||||||||
| if (inviteCode && deviceType === DeviceType.ANDROID) { | ||||||||||||||||||||||||||||||||||||||||
| const signupScreeenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup') | ||||||||||||||||||||||||||||||||||||||||
| dispatch(setupActions.setStep(signupScreeenIndex + 1)) | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| handleNext() | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+224
to
+230
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typos and add error handling for missing signup step. Issues identified:
Apply this diff to fix the typos and add error handling: - // If user is on android and has an invite code, redirect to signup screen
+ // If user is on android and has an invite code, redirect to signup screen
if (inviteCode && deviceType === DeviceType.ANDROID) {
- const signupScreeenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
- dispatch(setupActions.setStep(signupScreeenIndex + 1))
+ const signupScreenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
+ if (signupScreenIndex !== -1) {
+ dispatch(setupActions.setStep(signupScreenIndex + 1))
+ } else {
+ // Fallback to handleNext if signup step not found
+ handleNext()
+ }
} else {
handleNext()
}Note: If the intent is to navigate TO the signup step (not after it), remove the 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||
| className="mt-4 w-full" | ||||||||||||||||||||||||||||||||||||||||
| shadowSize="4" | ||||||||||||||||||||||||||||||||||||||||
| variant="purple" | ||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||
| Continue | ||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add missing error handling for
findIndexresults.The code uses
findIndexto locate step indices but doesn't check if the step exists (returns -1), unlike the existing logic at lines 140-148 which properly handles this case. If either'android-initial-pwa-install'or'signup'steps are missing from the steps array, this would dispatch invalid step indices.Apply this diff to add consistent error handling:
// If invite code is present, set the step to the signup screen if (determinedSetupInitialStepId && userInviteCode) { // if user is on android and not in a standalone pwa, force them to install the PWA first if (localDeviceType === 'android' && !isStandalonePWA) { const androidInitialPwaInstallScreenIndex = steps.findIndex( (s: ISetupStep) => s.screenId === 'android-initial-pwa-install' ) - dispatch(setupActions.setStep(androidInitialPwaInstallScreenIndex + 1)) + if (androidInitialPwaInstallScreenIndex !== -1) { + dispatch(setupActions.setStep(androidInitialPwaInstallScreenIndex + 1)) + } else { + console.warn('Could not find android-initial-pwa-install step. Defaulting to step 1.') + dispatch(setupActions.setStep(1)) + } } else { const signupScreenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup') - dispatch(setupActions.setStep(signupScreenIndex + 1)) + if (signupScreenIndex !== -1) { + dispatch(setupActions.setStep(signupScreenIndex + 1)) + } else { + console.warn('Could not find signup step. Defaulting to step 1.') + dispatch(setupActions.setStep(1)) + } }📝 Committable suggestion
🤖 Prompt for AI Agents