-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
BaseOnboardingWork.tsx
121 lines (110 loc) · 5.5 KB
/
BaseOnboardingWork.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React, {useCallback} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import KeyboardAvoidingView from '@components/KeyboardAvoidingView';
import OfflineIndicator from '@components/OfflineIndicator';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import useDisableModalDismissOnEscape from '@hooks/useDisableModalDismissOnEscape';
import useLocalize from '@hooks/useLocalize';
import useOnboardingLayout from '@hooks/useOnboardingLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ValidationUtils from '@libs/ValidationUtils';
import * as Policy from '@userActions/Policy';
import * as Welcome from '@userActions/Welcome';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import INPUT_IDS from '@src/types/form/WorkForm';
import type {BaseOnboardingWorkOnyxProps, BaseOnboardingWorkProps} from './types';
const OPEN_WORK_PAGE_PURPOSES = [CONST.ONBOARDING_CHOICES.MANAGE_TEAM];
function BaseOnboardingWork({shouldUseNativeStyles, onboardingPurposeSelected}: BaseOnboardingWorkProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useOnboardingLayout();
useDisableModalDismissOnEscape();
const completeEngagement = useCallback(
(values: FormOnyxValues<'onboardingWorkForm'>) => {
if (!onboardingPurposeSelected) {
return;
}
const work = values.work.trim();
const {adminsChatReportID} = Policy.createWorkspace(undefined, true, work);
Welcome.setOnboardingAdminsChatReportID(adminsChatReportID);
Navigation.navigate(ROUTES.ONBOARDING_PERSONAL_DETAILS);
},
[onboardingPurposeSelected],
);
const validate = (values: FormOnyxValues<'onboardingWorkForm'>) => {
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.ONBOARDING_PERSONAL_WORK> = {};
const work = values.work.trim();
if (!ValidationUtils.isRequiredFulfilled(work)) {
errors.work = 'workspace.editor.nameIsRequiredError';
} else if ([...work].length > CONST.TITLE_CHARACTER_LIMIT) {
// Uses the spread syntax to count the number of Unicode code points instead of the number of UTF-16
// code units.
ErrorUtils.addErrorMessage(errors, 'work', ['common.error.characterLimitExceedCounter', {length: [...work].length, limit: CONST.TITLE_CHARACTER_LIMIT}]);
}
return errors;
};
const WorkFooterInstance = <OfflineIndicator />;
return (
<View style={[styles.h100, styles.defaultModalContainer, shouldUseNativeStyles && styles.pt8]}>
<HeaderWithBackButton
shouldShowBackButton
progressBarPercentage={OPEN_WORK_PAGE_PURPOSES.includes(onboardingPurposeSelected ?? '') ? 50 : 75}
onBackButtonPress={Navigation.goBack}
/>
<KeyboardAvoidingView
style={[styles.flex1, styles.dFlex]}
behavior="padding"
>
<FormProvider
style={[styles.flexGrow1, shouldUseNarrowLayout && styles.mt5, styles.mb5, shouldUseNarrowLayout ? styles.mh8 : styles.mh5]}
formID={ONYXKEYS.FORMS.ONBOARDING_PERSONAL_WORK}
footerContent={isSmallScreenWidth && WorkFooterInstance}
validate={validate}
onSubmit={completeEngagement}
submitButtonText={translate('common.continue')}
enabledWhenOffline
submitFlexEnabled
shouldValidateOnBlur
shouldValidateOnChange
shouldTrimValues={false}
>
<View style={[shouldUseNarrowLayout ? styles.flexRow : styles.flexColumn, styles.mb5]}>
<Text style={[styles.textHeadlineH1, styles.textXXLarge]}>{translate('onboarding.whereYouWork')}</Text>
</View>
<View style={styles.mb4}>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.WORK}
name="fwork"
label={translate('common.businessName')}
aria-label={translate('common.businessName')}
role={CONST.ROLE.PRESENTATION}
shouldSaveDraft
maxLength={CONST.TITLE_CHARACTER_LIMIT}
spellCheck={false}
autoFocus
/>
</View>
</FormProvider>
</KeyboardAvoidingView>
</View>
);
}
BaseOnboardingWork.displayName = 'BaseOnboardingWork';
export default withOnyx<BaseOnboardingWorkProps, BaseOnboardingWorkOnyxProps>({
onboardingPurposeSelected: {
key: ONYXKEYS.ONBOARDING_PURPOSE_SELECTED,
},
})(BaseOnboardingWork);