-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34157 from allroundexperts/feat-32763
feat: Add report field picker components
- Loading branch information
Showing
12 changed files
with
365 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,82 @@ | ||
import React, {useCallback, useRef} from 'react'; | ||
import {View} from 'react-native'; | ||
import DatePicker from '@components/DatePicker'; | ||
import FormProvider from '@components/Form/FormProvider'; | ||
import InputWrapper from '@components/Form/InputWrapper'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
||
type EditReportFieldDatePageProps = { | ||
/** Value of the policy report field */ | ||
fieldValue: string; | ||
|
||
/** Name of the policy report field */ | ||
fieldName: string; | ||
|
||
/** ID of the policy report field */ | ||
fieldID: string; | ||
|
||
/** Callback to fire when the Save button is pressed */ | ||
onSubmit: () => void; | ||
}; | ||
|
||
function EditReportFieldDatePage({fieldName, onSubmit, fieldValue, fieldID}: EditReportFieldDatePageProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const validate = useCallback( | ||
(value: Record<string, string>) => { | ||
const errors: Record<string, string> = {}; | ||
if (value[fieldID].trim() === '') { | ||
errors[fieldID] = 'common.error.fieldRequired'; | ||
} | ||
return errors; | ||
}, | ||
[fieldID], | ||
); | ||
|
||
return ( | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
shouldEnableMaxHeight | ||
onEntryTransitionEnd={() => inputRef.current?.focus()} | ||
testID={EditReportFieldDatePage.displayName} | ||
> | ||
<HeaderWithBackButton title={fieldName} /> | ||
{/* @ts-expect-error TODO: TS migration */} | ||
<FormProvider | ||
style={[styles.flexGrow1, styles.ph5]} | ||
formID={ONYXKEYS.FORMS.POLICY_REPORT_FIELD_EDIT_FORM} | ||
onSubmit={onSubmit} | ||
validate={validate} | ||
submitButtonText={translate('common.save')} | ||
enabledWhenOffline | ||
> | ||
<View style={styles.mb4}> | ||
<InputWrapper | ||
// @ts-expect-error TODO: TS migration | ||
InputComponent={DatePicker} | ||
inputID={fieldID} | ||
name={fieldID} | ||
defaultValue={fieldValue} | ||
label={fieldName} | ||
accessibilityLabel={fieldName} | ||
role={CONST.ROLE.PRESENTATION} | ||
maxDate={CONST.CALENDAR_PICKER.MAX_DATE} | ||
minDate={CONST.CALENDAR_PICKER.MIN_DATE} | ||
ref={inputRef} | ||
/> | ||
</View> | ||
</FormProvider> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
EditReportFieldDatePage.displayName = 'EditReportFieldDatePage'; | ||
|
||
export default EditReportFieldDatePage; |
This file contains 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,82 @@ | ||
import React, {useMemo, useState} from 'react'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import OptionsSelector from '@components/OptionsSelector'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useStyleUtils from '@hooks/useStyleUtils'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
||
type EditReportFieldDropdownPageProps = { | ||
/** Value of the policy report field */ | ||
fieldValue: string; | ||
|
||
/** Name of the policy report field */ | ||
fieldName: string; | ||
|
||
/** Options of the policy report field */ | ||
fieldOptions: string[]; | ||
|
||
/** Callback to fire when the Save button is pressed */ | ||
onSubmit: () => void; | ||
}; | ||
|
||
function EditReportFieldDropdownPage({fieldName, onSubmit, fieldValue, fieldOptions}: EditReportFieldDropdownPageProps) { | ||
const [searchValue, setSearchValue] = useState(''); | ||
const styles = useThemeStyles(); | ||
const {getSafeAreaMargins} = useStyleUtils(); | ||
const {translate} = useLocalize(); | ||
|
||
const sections = useMemo(() => { | ||
const filteredOptions = fieldOptions.filter((option) => option.toLowerCase().includes(searchValue.toLowerCase())); | ||
return [ | ||
{ | ||
title: translate('common.recents'), | ||
shouldShow: true, | ||
data: [], | ||
}, | ||
{ | ||
title: translate('common.all'), | ||
shouldShow: true, | ||
data: filteredOptions.map((option) => ({ | ||
text: option, | ||
keyForList: option, | ||
searchText: option, | ||
tooltipText: option, | ||
})), | ||
}, | ||
]; | ||
}, [fieldOptions, searchValue, translate]); | ||
|
||
return ( | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
shouldEnableMaxHeight | ||
testID={EditReportFieldDropdownPage.displayName} | ||
> | ||
{({insets}) => ( | ||
<> | ||
<HeaderWithBackButton title={fieldName} /> | ||
<OptionsSelector | ||
// @ts-expect-error TODO: TS migration | ||
contentContainerStyles={[{paddingBottom: getSafeAreaMargins(insets).marginBottom}]} | ||
optionHoveredStyle={styles.hoveredComponentBG} | ||
sectionHeaderStyle={styles.mt5} | ||
selectedOptions={[{name: fieldValue}]} | ||
textInputLabel={translate('common.search')} | ||
boldStyle | ||
sections={sections} | ||
value={searchValue} | ||
onSelectRow={onSubmit} | ||
onChangeText={setSearchValue} | ||
highlightSelectedOptions | ||
isRowMultilineSupported | ||
/> | ||
</> | ||
)} | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
EditReportFieldDropdownPage.displayName = 'EditReportFieldDropdownPage'; | ||
|
||
export default EditReportFieldDropdownPage; |
This file contains 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,103 @@ | ||
import React, {useEffect} from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {PolicyReportFields, Report} from '@src/types/onyx'; | ||
import EditReportFieldDatePage from './EditReportFieldDatePage'; | ||
import EditReportFieldDropdownPage from './EditReportFieldDropdownPage'; | ||
import EditReportFieldTextPage from './EditReportFieldTextPage'; | ||
|
||
type EditReportFieldPageOnyxProps = { | ||
/** The report object for the expense report */ | ||
report: OnyxEntry<Report>; | ||
|
||
/** Policy report fields */ | ||
policyReportFields: OnyxEntry<PolicyReportFields>; | ||
}; | ||
|
||
type EditReportFieldPageProps = EditReportFieldPageOnyxProps & { | ||
/** Route from navigation */ | ||
route: { | ||
/** Params from the route */ | ||
params: { | ||
/** Which field we are editing */ | ||
fieldID: string; | ||
|
||
/** reportID for the expense report */ | ||
reportID: string; | ||
|
||
/** policyID for the expense report */ | ||
policyID: string; | ||
}; | ||
}; | ||
}; | ||
|
||
function EditReportFieldPage({route, report, policyReportFields}: EditReportFieldPageProps) { | ||
const policyReportField = policyReportFields?.[route.params.fieldID]; | ||
const reportFieldValue = report?.reportFields?.[policyReportField?.fieldID ?? '']; | ||
|
||
// Decides whether to allow or disallow editing a money request | ||
useEffect(() => {}, []); | ||
|
||
if (policyReportField) { | ||
if (policyReportField.type === 'text' || policyReportField.type === 'formula') { | ||
return ( | ||
<EditReportFieldTextPage | ||
fieldName={policyReportField.name} | ||
fieldID={policyReportField.fieldID} | ||
fieldValue={reportFieldValue ?? policyReportField.defaultValue} | ||
onSubmit={() => {}} | ||
/> | ||
); | ||
} | ||
|
||
if (policyReportField.type === 'date') { | ||
return ( | ||
<EditReportFieldDatePage | ||
fieldName={policyReportField.name} | ||
fieldID={policyReportField.fieldID} | ||
fieldValue={reportFieldValue ?? policyReportField.defaultValue} | ||
onSubmit={() => {}} | ||
/> | ||
); | ||
} | ||
|
||
if (policyReportField.type === 'dropdown') { | ||
return ( | ||
<EditReportFieldDropdownPage | ||
fieldName={policyReportField.name} | ||
fieldValue={reportFieldValue ?? policyReportField.defaultValue} | ||
fieldOptions={policyReportField.values} | ||
onSubmit={() => {}} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
shouldEnableMaxHeight | ||
testID={EditReportFieldPage.displayName} | ||
> | ||
<FullPageNotFoundView | ||
shouldShow | ||
onBackButtonPress={() => {}} | ||
onLinkPress={() => {}} | ||
/> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
EditReportFieldPage.displayName = 'EditReportFieldPage'; | ||
|
||
export default withOnyx<EditReportFieldPageProps, EditReportFieldPageOnyxProps>({ | ||
report: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`, | ||
}, | ||
policyReportFields: { | ||
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_REPORT_FIELDS}${route.params.policyID}`, | ||
}, | ||
})(EditReportFieldPage); |
Oops, something went wrong.