-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Refactor netsuite connection page to use useSubPage #80711
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
Changes from all commits
5dc3f6b
1e4f7e5
16cae1c
472b19a
7fd4700
ce7b1ab
3eb8acc
3f37288
7a46b72
f481453
f0d1f17
9ca32bb
aca8154
dcda4b9
272be94
d21d480
98faa3b
691a23e
f3bcb25
5eb0be4
5205bf6
1af269c
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 |
|---|---|---|
| @@ -1,56 +1,50 @@ | ||
| import React, {useRef} from 'react'; | ||
| import type {ComponentType, ForwardedRef} from 'react'; | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import ConnectionLayout from '@components/ConnectionLayout'; | ||
| import InteractiveStepSubHeader from '@components/InteractiveStepSubHeader'; | ||
| import type {InteractiveStepSubHeaderHandle} from '@components/InteractiveStepSubHeader'; | ||
| import useSubStep from '@hooks/useSubStep'; | ||
| import InteractiveStepSubPageHeader from '@components/InteractiveStepSubPageHeader'; | ||
| import useSubPage from '@hooks/useSubPage'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {isAuthenticationError} from '@libs/actions/connections'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import type {SubStepWithPolicy} from '@pages/workspace/accounting/netsuite/types'; | ||
| import type {CustomSubPageTokenInputProps} from '@pages/workspace/accounting/netsuite/types'; | ||
| import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; | ||
| import withPolicyConnections from '@pages/workspace/withPolicyConnections'; | ||
| import CONST from '@src/CONST'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
| import NetSuiteTokenInputForm from './substeps/NetSuiteTokenInputForm'; | ||
| import NetSuiteTokenSetupContent from './substeps/NetSuiteTokenSetupContent'; | ||
| import NetSuiteTokenInputForm from './subPages/NetSuiteTokenInputForm'; | ||
| import NetSuiteTokenSetupContent from './subPages/NetSuiteTokenSetupContent'; | ||
|
|
||
| const staticContentSteps = Array<ComponentType<SubStepWithPolicy>>(4).fill(NetSuiteTokenSetupContent); | ||
| const tokenInputSteps: Array<ComponentType<SubStepWithPolicy>> = [...staticContentSteps, NetSuiteTokenInputForm]; | ||
| const pages = [ | ||
| {pageName: CONST.NETSUITE_CONFIG.TOKEN_INPUT.PAGE_NAME.INSTALL, component: NetSuiteTokenSetupContent}, | ||
| {pageName: CONST.NETSUITE_CONFIG.TOKEN_INPUT.PAGE_NAME.AUTHENTICATION, component: NetSuiteTokenSetupContent}, | ||
| {pageName: CONST.NETSUITE_CONFIG.TOKEN_INPUT.PAGE_NAME.SOAP, component: NetSuiteTokenSetupContent}, | ||
| {pageName: CONST.NETSUITE_CONFIG.TOKEN_INPUT.PAGE_NAME.ACCESS_TOKEN, component: NetSuiteTokenSetupContent}, | ||
| {pageName: CONST.NETSUITE_CONFIG.TOKEN_INPUT.PAGE_NAME.CREDENTIALS, component: NetSuiteTokenInputForm}, | ||
| ]; | ||
|
|
||
| function NetSuiteTokenInputPage({policy}: WithPolicyConnectionsProps) { | ||
| function NetSuiteTokenInputPage({policy, route}: WithPolicyConnectionsProps) { | ||
| const policyID = policy?.id; | ||
| const styles = useThemeStyles(); | ||
| const ref: ForwardedRef<InteractiveStepSubHeaderHandle> = useRef(null); | ||
|
|
||
| const hasAuthError = isAuthenticationError(policy, CONST.POLICY.CONNECTIONS.NAME.NETSUITE); | ||
|
|
||
| const submit = () => { | ||
| Navigation.dismissModal(); | ||
| }; | ||
|
|
||
| const { | ||
| componentToRender: SubStep, | ||
| isEditing, | ||
| nextScreen, | ||
| prevScreen, | ||
| screenIndex, | ||
| moveTo, | ||
| } = useSubStep<SubStepWithPolicy>({bodyContent: tokenInputSteps, startFrom: hasAuthError ? 4 : 0, onFinished: submit}); | ||
| const {CurrentPage, nextPage, prevPage, pageIndex, moveTo, currentPageName} = useSubPage<CustomSubPageTokenInputProps>({ | ||
| pages, | ||
| onFinished: submit, | ||
|
bernhardoj marked this conversation as resolved.
|
||
| buildRoute: (pageName) => ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(route.params.policyID, pageName), | ||
|
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. Can we use policy?.id instead of route.params.policyID?
Contributor
Author
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.
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. If so I think we should pass policyID to NetSuiteTokenInputPage instead of the whole route data
Contributor
Author
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. All react-navigation page/screen have
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. Okay I got it. I was mistaken for your other PR. |
||
| }); | ||
|
|
||
| const handleBackButtonPress = () => { | ||
| if (screenIndex === 0) { | ||
| if (pageIndex === 0) { | ||
| Navigation.goBack(); | ||
| return; | ||
| } | ||
| ref.current?.movePrevious(); | ||
| prevScreen(); | ||
| }; | ||
|
|
||
| const handleNextScreen = () => { | ||
| ref.current?.moveNext(); | ||
| nextScreen(); | ||
| prevPage(); | ||
| }; | ||
|
|
||
| const shouldPageBeBlocked = !isEmptyObject(policy?.connections?.[CONST.POLICY.CONNECTIONS.NAME.NETSUITE]) && !hasAuthError; | ||
|
|
@@ -68,20 +62,20 @@ function NetSuiteTokenInputPage({policy}: WithPolicyConnectionsProps) { | |
| onBackButtonPress={handleBackButtonPress} | ||
| shouldLoadForEmptyConnection={isEmptyObject(policy?.connections?.[CONST.POLICY.CONNECTIONS.NAME.NETSUITE])} | ||
| shouldBeBlocked={shouldPageBeBlocked} | ||
| shouldUseScrollView={SubStep !== NetSuiteTokenInputForm} | ||
| shouldUseScrollView={CurrentPage !== NetSuiteTokenInputForm} | ||
| > | ||
| <View style={[styles.ph5, styles.mb3, styles.mt3, {height: CONST.BANK_ACCOUNT.STEPS_HEADER_HEIGHT}]}> | ||
| <InteractiveStepSubHeader | ||
| ref={ref} | ||
| startStepIndex={screenIndex} | ||
| stepNames={CONST.NETSUITE_CONFIG.TOKEN_INPUT_STEP_NAMES} | ||
| <InteractiveStepSubPageHeader | ||
| currentStepIndex={pageIndex} | ||
| stepNames={CONST.NETSUITE_CONFIG.TOKEN_INPUT.STEP_INDEX_LIST} | ||
| onStepSelected={moveTo} | ||
| /> | ||
| </View> | ||
| <SubStep | ||
| isEditing={isEditing} | ||
| onNext={handleNextScreen} | ||
| <CurrentPage | ||
| isEditing={false} | ||
| onNext={nextPage} | ||
| onMove={moveTo} | ||
| screenIndex={screenIndex} | ||
| currentPageName={currentPageName} | ||
| policyID={policyID} | ||
| /> | ||
| </ConnectionLayout> | ||
|
|
||
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.
Removed
isEditingbecause bothNetSuiteTokenSetupContentandNetSuiteTokenInputFormdon't use it.