-
Notifications
You must be signed in to change notification settings - Fork 0
Story/am 849 toegangscode alleen voor bepaalde schermen zetten #538
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
Draft
WouterAms
wants to merge
11
commits into
main
Choose a base branch
from
story/AM-849-toegangscode-alleen-voor-bepaalde-schermen-zetten
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
feb985b
Add proxy screen and additional function to handle individual screen …
WouterAms ab7121e
Implement access code gate functionality for screen navigation
WouterAms fcd799c
Name change; fix duplicate header; add accessCodeGate to boat chargin…
WouterAms 418d2cd
Add jsDoc example
WouterAms 9989746
Potential fix for pull request finding
WouterAms 8202654
Potential fix for pull request finding
WouterAms dc8eb72
Potential fix for pull request finding
WouterAms 0b47b90
Add additional condition option in config
WouterAms 0c6a5a9
Too much to mention
WouterAms 25489ab
Revert changes
WouterAms 110f308
Init access code flow in login screen
WouterAms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/modules/access-code/components/AccessCodeGateProxyScreen.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import Animated, {FadeIn} from 'react-native-reanimated' | ||
| import type {StackElement} from '@/modules/access-code/types' | ||
| import type {Route} from '@react-navigation/native' | ||
| import type {StackNavigationOptions} from '@react-navigation/stack' | ||
| import type {ComponentType} from 'react' | ||
| import type {ViewProps} from 'react-native' | ||
| import {createStackNavigator} from '@/app/navigation/createStackNavigator' | ||
| import { | ||
| type NavigationProps, | ||
| type RootStackParams, | ||
| type StackNavigationRoutes, | ||
| } from '@/app/navigation/types' | ||
| import {PleaseWait} from '@/components/ui/feedback/PleaseWait' | ||
| import {SomethingWentWrong} from '@/components/ui/feedback/SomethingWentWrong' | ||
| import {Center} from '@/components/ui/layout/Center' | ||
| import {ACCESS_CODE_SCREEN_MAP} from '@/modules/access-code/constants/accessCodeScreenMap' | ||
| import {FORGOT_CODE_SCREEN} from '@/modules/access-code/constants/forgotAccessCodeScreenConfig' | ||
| import { | ||
| AccessCodeGateStateName, | ||
| useAccessCodeGateState, | ||
| } from '@/modules/access-code/hooks/useAccessCodeGateState' | ||
| import {layoutStyles} from '@/styles/layoutStyles' | ||
|
|
||
| type AccessCodeGateProxyScreenProps<RouteName extends keyof RootStackParams> = { | ||
| ForgotCodeScreen: ComponentType | ||
| ProtectedScreenComponent: | ||
| | ComponentType<{ | ||
| navigation: unknown | ||
| route: Route<Extract<RouteName, string>, RootStackParams[RouteName]> | ||
| }> | ||
| | ComponentType | ||
| loginSteps?: StackNavigationRoutes<RootStackParams> | ||
| navigatorScreenOptions?: StackNavigationOptions | ||
| state: ReturnType<typeof useAccessCodeGateState> | ||
| } & NavigationProps<RouteName> & | ||
| StackElement<'Screen'>['props'] | ||
|
|
||
| const AccessCodeGateStack = createStackNavigator<RootStackParams>() | ||
|
|
||
| const AnimatedView = (layoutProps: ViewProps) => ( | ||
| <Animated.View | ||
| entering={FadeIn} | ||
| style={layoutStyles.grow} | ||
| {...layoutProps} | ||
| /> | ||
| ) | ||
|
|
||
| export const AccessCodeGateProxyScreen = < | ||
| RouteName extends keyof RootStackParams, | ||
| >({ | ||
| ProtectedScreenComponent, | ||
| ForgotCodeScreen, | ||
| state, | ||
| loginSteps, | ||
| navigatorScreenOptions, | ||
| ...props | ||
| }: AccessCodeGateProxyScreenProps<RouteName>) => { | ||
| if (state === AccessCodeGateStateName.loading) { | ||
| return ( | ||
| <Center grow> | ||
| <PleaseWait testID="AccessCodeGateProxyScreenPleaseWait" /> | ||
| </Center> | ||
| ) | ||
| } | ||
|
|
||
| if (state === AccessCodeGateStateName.fallback) { | ||
| return ( | ||
| <Center grow> | ||
| <SomethingWentWrong testID="AccessCodeGateProxyScreenSomethingWentWrong" /> | ||
| </Center> | ||
| ) | ||
| } | ||
|
|
||
| if (state === AccessCodeGateStateName.allowed) { | ||
| return ( | ||
| <AnimatedView> | ||
| <ProtectedScreenComponent {...props} /> | ||
| </AnimatedView> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <AccessCodeGateStack.Navigator | ||
| layout={AnimatedView} | ||
| screenOptions={{...navigatorScreenOptions, headerShown: true}}> | ||
| {state === AccessCodeGateStateName.biometricsPermission && ( | ||
| <AccessCodeGateStack.Screen | ||
| {...ACCESS_CODE_SCREEN_MAP.biometricsPermission} | ||
| /> | ||
| )} | ||
|
|
||
| {state === AccessCodeGateStateName.forgotCode && ( | ||
| <AccessCodeGateStack.Screen | ||
| {...FORGOT_CODE_SCREEN} | ||
| component={ForgotCodeScreen} | ||
| /> | ||
| )} | ||
|
|
||
| {state === AccessCodeGateStateName.invalid && ( | ||
| <AccessCodeGateStack.Screen {...ACCESS_CODE_SCREEN_MAP.invalid} /> | ||
| )} | ||
|
|
||
| {state === AccessCodeGateStateName.accessCode && ( | ||
| <AccessCodeGateStack.Screen {...ACCESS_CODE_SCREEN_MAP.accessCode} /> | ||
| )} | ||
|
|
||
| {state === AccessCodeGateStateName.setup && ( | ||
| <AccessCodeGateStack.Group screenOptions={navigatorScreenOptions}> | ||
| {!!loginSteps && | ||
| Object.entries(loginSteps).map(([key, route]) => ( | ||
| <AccessCodeGateStack.Screen | ||
| key={key} | ||
| {...route} | ||
| /> | ||
| ))} | ||
|
|
||
| <AccessCodeGateStack.Screen {...ACCESS_CODE_SCREEN_MAP.setup} /> | ||
| <AccessCodeGateStack.Screen {...ACCESS_CODE_SCREEN_MAP.confirm} /> | ||
| </AccessCodeGateStack.Group> | ||
| )} | ||
| </AccessCodeGateStack.Navigator> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import {TransitionPresets} from '@react-navigation/stack' | ||
| import type {StackFactory} from '@/modules/access-code/types' | ||
| import type {ComponentProps} from 'react' | ||
| import {FORGOT_CODE_SCREEN} from '@/modules/access-code/constants/forgotAccessCodeScreenConfig' | ||
| import {AccessCodeGateStateName} from '@/modules/access-code/hooks/useAccessCodeGateState' | ||
| import {AccessCodeRouteName} from '@/modules/access-code/routes' | ||
| import {AccessCodeScreen} from '@/modules/access-code/screens/AccessCode.screen' | ||
| import {AccessCodeInvalidScreen} from '@/modules/access-code/screens/AccessCodeInvalid.screen' | ||
| import {BiometricsPermissionScreen} from '@/modules/access-code/screens/BiometricsPermission.screen' | ||
| import {ConfirmAccessCodeScreen} from '@/modules/access-code/screens/ConfirmAccessCode.screen' | ||
| import {SetAccessCodeScreen} from '@/modules/access-code/screens/SetAccessCode.screen' | ||
|
|
||
| enum AccessCodeGateRouteName { | ||
| fallback = 'AccessCodeGateFallback', | ||
| loading = 'AccessCodeGateLoading', | ||
| } | ||
|
|
||
| export const ACCESS_CODE_SCREEN_MAP: Record< | ||
| Exclude<AccessCodeGateStateName, 'allowed'>, | ||
| ComponentProps<StackFactory['Screen']> | ||
| > = { | ||
| [AccessCodeGateStateName.biometricsPermission]: { | ||
| component: BiometricsPermissionScreen, | ||
| name: AccessCodeRouteName.biometricsPermission, | ||
| options: { | ||
| headerTitle: 'Sneller toegang', | ||
| }, | ||
| }, | ||
| [AccessCodeGateStateName.forgotCode]: { | ||
| component: FORGOT_CODE_SCREEN.component, | ||
| name: AccessCodeRouteName.forgotAccessCode, | ||
| options: {headerTitle: 'Toegangscode vergeten'}, | ||
| }, | ||
| [AccessCodeGateStateName.invalid]: { | ||
| component: AccessCodeInvalidScreen, | ||
| name: AccessCodeRouteName.accessCodeInvalid, | ||
| }, | ||
| [AccessCodeGateStateName.accessCode]: { | ||
| component: AccessCodeScreen as never, | ||
| name: AccessCodeRouteName.accessCode, | ||
| options: { | ||
| headerTitle: 'Toegangscode invoeren', | ||
| ...TransitionPresets.ModalFadeTransition, | ||
| }, | ||
| }, | ||
| [AccessCodeGateStateName.setup]: { | ||
| component: SetAccessCodeScreen as never, | ||
| name: AccessCodeRouteName.setAccessCode, | ||
| options: { | ||
| headerTitle: 'Toegangscode kiezen', | ||
| }, | ||
| }, | ||
| [AccessCodeGateStateName.confirm]: { | ||
| component: ConfirmAccessCodeScreen as never, | ||
| name: AccessCodeRouteName.confirmAccessCode, | ||
| options: { | ||
| headerTitle: 'Toegangscode herhalen', | ||
| }, | ||
| }, | ||
| [AccessCodeGateStateName.loading]: { | ||
| children: () => null, | ||
| name: AccessCodeGateRouteName.loading, | ||
| options: { | ||
| ...TransitionPresets.ModalFadeTransition, | ||
| }, | ||
| }, | ||
| [AccessCodeGateStateName.fallback]: { | ||
| children: () => null, | ||
| name: AccessCodeGateRouteName.fallback, | ||
| options: { | ||
| ...TransitionPresets.ModalFadeTransition, | ||
| }, | ||
| }, | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/modules/access-code/constants/forgotAccessCodeScreenConfig.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import {AccessCodeRouteName} from '@/modules/access-code/routes' | ||
| import {ForgotAccessCodeScreen} from '@/modules/access-code/screens/ForgotAccessCode.screen' | ||
|
|
||
| export const FORGOT_CODE_SCREEN = { | ||
| component: ForgotAccessCodeScreen, | ||
| name: AccessCodeRouteName.forgotAccessCode, | ||
| options: {headerTitle: 'Toegangscode vergeten'}, | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.