|
| 1 | +import React from 'react'; |
| 2 | +import {View} from 'react-native'; |
| 3 | +import {useOnyx} from 'react-native-onyx'; |
| 4 | +import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; |
| 5 | +import FormProvider from '@components/Form/FormProvider'; |
| 6 | +import InputWrapper from '@components/Form/InputWrapper'; |
| 7 | +import type {FormOnyxValues} from '@components/Form/types'; |
| 8 | +import HeaderWithBackButton from '@components/HeaderWithBackButton'; |
| 9 | +import ScreenWrapper from '@components/ScreenWrapper'; |
| 10 | +import TextInput from '@components/TextInput'; |
| 11 | +import useAutoFocusInput from '@hooks/useAutoFocusInput'; |
| 12 | +import useLocalize from '@hooks/useLocalize'; |
| 13 | +import useThemeStyles from '@hooks/useThemeStyles'; |
| 14 | +import {updateAdvancedFilters} from '@libs/actions/Search'; |
| 15 | +import Navigation from '@libs/Navigation/Navigation'; |
| 16 | +import CONST from '@src/CONST'; |
| 17 | +import ONYXKEYS from '@src/ONYXKEYS'; |
| 18 | +import ROUTES from '@src/ROUTES'; |
| 19 | +import INPUT_IDS from '@src/types/form/SearchAdvancedFiltersForm'; |
| 20 | + |
| 21 | +function SearchFiltersDescriptionPage() { |
| 22 | + const styles = useThemeStyles(); |
| 23 | + const {translate} = useLocalize(); |
| 24 | + |
| 25 | + const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); |
| 26 | + const description = searchAdvancedFiltersForm?.[INPUT_IDS.DESCRIPTION]; |
| 27 | + const {inputCallbackRef} = useAutoFocusInput(); |
| 28 | + |
| 29 | + const updateDescriptionFilter = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM>) => { |
| 30 | + updateAdvancedFilters(values); |
| 31 | + Navigation.goBack(ROUTES.SEARCH_ADVANCED_FILTERS); |
| 32 | + }; |
| 33 | + |
| 34 | + return ( |
| 35 | + <ScreenWrapper |
| 36 | + testID={SearchFiltersDescriptionPage.displayName} |
| 37 | + shouldShowOfflineIndicatorInWideScreen |
| 38 | + offlineIndicatorStyle={styles.mtAuto} |
| 39 | + > |
| 40 | + <FullPageNotFoundView shouldShow={false}> |
| 41 | + <HeaderWithBackButton |
| 42 | + title={translate('common.description')} |
| 43 | + onBackButtonPress={() => { |
| 44 | + Navigation.goBack(ROUTES.SEARCH_ADVANCED_FILTERS); |
| 45 | + }} |
| 46 | + /> |
| 47 | + <FormProvider |
| 48 | + style={[styles.flex1, styles.ph5]} |
| 49 | + formID={ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM} |
| 50 | + onSubmit={updateDescriptionFilter} |
| 51 | + submitButtonText={translate('common.save')} |
| 52 | + enabledWhenOffline |
| 53 | + > |
| 54 | + <View style={styles.mb4}> |
| 55 | + <InputWrapper |
| 56 | + InputComponent={TextInput} |
| 57 | + inputID={INPUT_IDS.DESCRIPTION} |
| 58 | + name={INPUT_IDS.DESCRIPTION} |
| 59 | + defaultValue={description} |
| 60 | + maxLength={CONST.DESCRIPTION_LIMIT} |
| 61 | + label={translate('common.description')} |
| 62 | + accessibilityLabel={translate('common.description')} |
| 63 | + role={CONST.ROLE.PRESENTATION} |
| 64 | + ref={inputCallbackRef} |
| 65 | + /> |
| 66 | + </View> |
| 67 | + </FormProvider> |
| 68 | + </FullPageNotFoundView> |
| 69 | + </ScreenWrapper> |
| 70 | + ); |
| 71 | +} |
| 72 | + |
| 73 | +SearchFiltersDescriptionPage.displayName = 'SearchFiltersDescriptionPage'; |
| 74 | + |
| 75 | +export default SearchFiltersDescriptionPage; |
0 commit comments