-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
SavedSearchRenamePage.tsx
73 lines (65 loc) · 2.69 KB
/
SavedSearchRenamePage.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
import React, {useState} from 'react';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import type {SearchQueryJSON} from '@components/Search/types';
import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as SearchActions from '@libs/actions/Search';
import Navigation from '@libs/Navigation/Navigation';
import * as SearchUtils from '@libs/SearchUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import INPUT_IDS from '@src/types/form/SearchSavedSearchRenameForm';
function SavedSearchRenamePage({route}: {route: {params: {q: string; name: string}}}) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {q, name} = route.params;
const [newName, setNewName] = useState(name);
const applyFiltersAndNavigate = () => {
SearchActions.clearAdvancedFilters();
Navigation.navigate(
ROUTES.SEARCH_CENTRAL_PANE.getRoute({
query: q,
}),
);
};
const onSaveSearch = () => {
const queryJSON = SearchUtils.buildSearchQueryJSON(q || SearchUtils.buildCannedSearchQuery()) ?? ({} as SearchQueryJSON);
SearchActions.saveSearch({
queryJSON,
name: newName,
});
applyFiltersAndNavigate();
};
return (
<ScreenWrapper
testID={SavedSearchRenamePage.displayName}
shouldShowOfflineIndicatorInWideScreen
offlineIndicatorStyle={styles.mtAuto}
includeSafeAreaPaddingBottom={false}
>
<HeaderWithBackButton title={translate('common.rename')} />
<FormProvider
formID={ONYXKEYS.FORMS.SEARCH_SAVED_SEARCH_RENAME_FORM}
submitButtonText={translate('common.save')}
onSubmit={onSaveSearch}
style={[styles.mh5, styles.flex1]}
>
<InputWrapper
InputComponent={TextInput}
inputID={INPUT_IDS.NAME}
label={translate('search.searchName')}
accessibilityLabel={translate('search.searchName')}
role={CONST.ROLE.PRESENTATION}
onChangeText={(renamedName) => setNewName(renamedName)}
/>
</FormProvider>
</ScreenWrapper>
);
}
SavedSearchRenamePage.displayName = 'SavedSearchRenamePage';
export default SavedSearchRenamePage;