Skip to content

Commit

Permalink
cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
allgandalf committed Dec 27, 2024
1 parent f131cfe commit 8b92ded
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 58 deletions.
95 changes: 42 additions & 53 deletions src/pages/OnboardingWorkEmail/BaseOnboardingWorkEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import INPUT_IDS from '@src/types/form/OnboardingWorkEmailForm';
import type IconAsset from '@src/types/utils/IconAsset';
import type {BaseOnboardingWorkEmailProps} from './types';

type Item = {
icon: IconAsset;
titleTranslationKey: TranslationPaths;
};

function BaseOnboardingWorkEmail({shouldUseNativeStyles}: BaseOnboardingWorkEmailProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
Expand All @@ -39,7 +44,7 @@ function BaseOnboardingWorkEmail({shouldUseNativeStyles}: BaseOnboardingWorkEmai
const isVsb = onboardingValues && 'signupQualifier' in onboardingValues && onboardingValues.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.VSB;
// We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth} = useResponsiveLayout();
const {inputCallbackRef} = useAutoFocusInput();
const [shouldValidateOnChange, setShouldValidateOnChange] = useState(false);
const {isOffline} = useNetwork();
Expand Down Expand Up @@ -88,57 +93,20 @@ function BaseOnboardingWorkEmail({shouldUseNativeStyles}: BaseOnboardingWorkEmai
return errors;
};

type Item = {
icon: IconAsset;
titleTranslationKey: TranslationPaths;
};

type SectionObject = {
titleTranslationKey: TranslationPaths;
subtitleTranslationKey: TranslationPaths;
items: Item[];
};

const section: SectionObject = {
titleTranslationKey: 'onboarding.workEmail.title',
subtitleTranslationKey: 'onboarding.workEmail.subtitle',
items: [
{
icon: Illustrations.EnvelopeReceipt,
titleTranslationKey: 'onboarding.workEmail.explanationModal.descriptionOne',
},
{
icon: Illustrations.Profile,
titleTranslationKey: 'onboarding.workEmail.explanationModal.descriptionTwo',
},
{
icon: Illustrations.Gears,
titleTranslationKey: 'onboarding.workEmail.explanationModal.descriptionThree',
},
],
};

const renderItem = useCallback(
(item: Item) => (
<View
key={item.titleTranslationKey}
style={[styles.mt2, styles.mb3]}
>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]}>
<Icon
src={item.icon}
height={ICON_SIZE}
width={ICON_SIZE}
additionalStyles={[styles.mr3]}
/>
<View style={[styles.flexColumn, styles.flex1]}>
<Text style={[styles.textStrong, styles.lh20]}>{translate(item.titleTranslationKey)}</Text>
</View>
</View>
</View>
),
[styles, translate],
);
const section: Item[] = [
{
icon: Illustrations.EnvelopeReceipt,
titleTranslationKey: 'onboarding.workEmail.explanationModal.descriptionOne',
},
{
icon: Illustrations.Profile,
titleTranslationKey: 'onboarding.workEmail.explanationModal.descriptionTwo',
},
{
icon: Illustrations.Gears,
titleTranslationKey: 'onboarding.workEmail.explanationModal.descriptionThree',
},
];

return (
<ScreenWrapper
Expand Down Expand Up @@ -188,7 +156,28 @@ function BaseOnboardingWorkEmail({shouldUseNativeStyles}: BaseOnboardingWorkEmai
<View style={styles.mb2}>
<Text style={[styles.textNormal, styles.colorMuted]}>{translate('onboarding.workEmail.subtitle')}</Text>
</View>
<View>{section.items.map(renderItem)}</View>
<View>
{section.map((item) => {
return (
<View
key={item.titleTranslationKey}
style={[styles.mt2, styles.mb3]}
>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]}>
<Icon
src={item.icon}
height={ICON_SIZE}
width={ICON_SIZE}
additionalStyles={[styles.mr3]}
/>
<View style={[styles.flexColumn, styles.flex1]}>
<Text style={[styles.textStrong, styles.lh20]}>{translate(item.titleTranslationKey)}</Text>
</View>
</View>
</View>
);
})}
</View>
</View>

<View style={[styles.mb4, styles.pt3]}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useEffect} from 'react';
import React, {useCallback} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
Expand Down Expand Up @@ -32,12 +32,9 @@ function BaseOnboardingWorkEmailValidation({shouldUseNativeStyles, route}: BaseO
const [validateCodeAction] = useOnyx(ONYXKEYS.VALIDATE_ACTION_CODE);
const {shouldUseNarrowLayout, onboardingIsMediumOrLargerScreenWidth} = useResponsiveLayout();

const isValidated = UserUtils.isCurrentUserValidated(loginList);

const isValidateCodeFormSubmitting = AccountUtils.isValidateCodeFormSubmitting(account);

const email = session?.email ?? '';

Check failure on line 37 in src/pages/OnboardingWorkEmailValidation/BaseOnboardingWorkEmailValidation.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'email' is assigned a value but never used

Check failure on line 37 in src/pages/OnboardingWorkEmailValidation/BaseOnboardingWorkEmailValidation.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

'email' is assigned a value but never used
const domain = email.split('@').at(1) ?? '';

const sendValidateCode = useCallback(() => {
if (!credentials?.login) {
Expand Down
1 change: 0 additions & 1 deletion src/types/onyx/Onboarding.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type * as OnyxCommon from './OnyxCommon';

/** Model of onboarding */
type Onboarding = {
Expand Down

0 comments on commit 8b92ded

Please sign in to comment.