Skip to content

Commit

Permalink
add props spread for not found page
Browse files Browse the repository at this point in the history
  • Loading branch information
BrtqKr committed Apr 29, 2024
1 parent dd27831 commit 8fc1426
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/pages/ErrorPage/NotFoundPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import ScreenWrapper from '@components/ScreenWrapper';

type NotFoundPageProps = {
onBackButtonPress?: () => void;
} & Pick<FullPageNotFoundViewProps, 'subtitleKey' | 'onLinkPress'>;
} & FullPageNotFoundViewProps;

// eslint-disable-next-line rulesdir/no-negated-variables
function NotFoundPage({onBackButtonPress, subtitleKey, onLinkPress}: NotFoundPageProps) {
function NotFoundPage({onBackButtonPress, ...fullPageNotFoundViewProps}: NotFoundPageProps) {
return (
<ScreenWrapper testID={NotFoundPage.displayName}>
<FullPageNotFoundView
shouldShow
onBackButtonPress={onBackButtonPress}
subtitleKey={subtitleKey}
onLinkPress={onLinkPress}
// eslint-disable-next-line react/jsx-props-no-spreading
{...fullPageNotFoundViewProps}
/>
</ScreenWrapper>
);
Expand Down
20 changes: 11 additions & 9 deletions src/pages/workspace/AccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,32 @@ type AccessOrNotFoundWrapperProps = AccessOrNotFoundWrapperOnyxProps & {

/** The current feature name that the user tries to get access to */
featureName?: PolicyFeatureName;

/** Props for customizing fallback pages */
fullPageNotFoundViewProps?: FullPageNotFoundViewProps;
} & Pick<FullPageNotFoundViewProps, 'subtitleKey' | 'onLinkPress'>;

type PageNotFoundFallbackProps = Pick<AccessOrNotFoundWrapperProps, 'policyID' | 'subtitleKey' | 'onLinkPress'> & {shouldShowFullScreenFallback: boolean};
type PageNotFoundFallbackProps = Pick<AccessOrNotFoundWrapperProps, 'policyID' | 'fullPageNotFoundViewProps'> & {shouldShowFullScreenFallback: boolean};

function PageNotFoundFallback({policyID, shouldShowFullScreenFallback, subtitleKey, onLinkPress}: PageNotFoundFallbackProps) {
function PageNotFoundFallback({policyID, shouldShowFullScreenFallback, fullPageNotFoundViewProps}: PageNotFoundFallbackProps) {
return shouldShowFullScreenFallback ? (
<FullPageNotFoundView
shouldShow
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
shouldForceFullScreen
subtitleKey={subtitleKey}
onLinkPress={onLinkPress}
// eslint-disable-next-line react/jsx-props-no-spreading
{...fullPageNotFoundViewProps}
/>
) : (
<NotFoundPage
onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_PROFILE.getRoute(policyID))}
subtitleKey={subtitleKey}
onLinkPress={onLinkPress}
// eslint-disable-next-line react/jsx-props-no-spreading
{...fullPageNotFoundViewProps}
/>
);
}

function AccessOrNotFoundWrapper({accessVariants = [], subtitleKey, onLinkPress, ...props}: AccessOrNotFoundWrapperProps) {
function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps, ...props}: AccessOrNotFoundWrapperProps) {
const {policy, policyID, featureName, isLoadingReportData} = props;

const isPolicyIDInRoute = !!policyID?.length;
Expand Down Expand Up @@ -100,8 +103,7 @@ function AccessOrNotFoundWrapper({accessVariants = [], subtitleKey, onLinkPress,
<PageNotFoundFallback
policyID={policyID}
shouldShowFullScreenFallback={!isFeatureEnabled}
subtitleKey={subtitleKey}
onLinkPress={onLinkPress}
fullPageNotFoundViewProps={fullPageNotFoundViewProps}
/>
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/WorkspaceInviteMessagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ function WorkspaceInviteMessagePage({
<AccessOrNotFoundWrapper
policyID={route.params.policyID}
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
fullPageNotFoundViewProps={{subtitleKey: isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized', onLinkPress: PolicyUtils.goBackFromInvalidPolicy}}
>
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/WorkspaceInvitePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ function WorkspaceInvitePage({route, betas, invitedEmailsToAccountIDsDraft, poli
<AccessOrNotFoundWrapper
policyID={route.params.policyID}
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
fullPageNotFoundViewProps={{subtitleKey: isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized', onLinkPress: PolicyUtils.goBackFromInvalidPolicy}}
>
<ScreenWrapper
shouldEnableMaxHeight
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/WorkspaceProfileCurrencyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ function WorkspaceProfileCurrencyPage({currencyList = {}, policy}: WorkspaceProf
<AccessOrNotFoundWrapper
policyID={policy?.id ?? ''}
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
fullPageNotFoundViewProps={{onLinkPress: PolicyUtils.goBackFromInvalidPolicy, subtitleKey: isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}}
>
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand Down

0 comments on commit 8fc1426

Please sign in to comment.