|
1 | | -import { minLength, useTranslate } from "react-admin"; |
| 1 | +import { FilterLiveForm, minLength, useTranslate } from "react-admin"; |
2 | 2 |
|
3 | | -import { useForm, FormProvider } from "react-hook-form"; |
4 | 3 | import { Box, Button, InputAdornment } from "@mui/material"; |
5 | 4 | import SearchIcon from "@mui/icons-material/Search"; |
6 | | -import { TextInput, useListContext } from "react-admin"; |
7 | | -import { useEffect } from "react"; |
| 5 | +import { TextInput } from "react-admin"; |
8 | 6 | import JobTypeRaFilter from "./JobRaTypeFilter"; |
9 | | - |
10 | | -type JobRaListFilterValues = { |
11 | | - job_type?: string[]; |
12 | | - search_query?: string; |
13 | | -}; |
| 7 | +import { LocationRaTypeFilter } from "../location"; |
14 | 8 |
|
15 | 9 | const JobRaListFilters = () => { |
16 | 10 | const translate = useTranslate(); |
17 | | - const { filterValues, setFilters } = useListContext(); |
18 | | - const form = useForm({ defaultValues: filterValues }); |
19 | | - |
20 | | - const submit = form.handleSubmit((formValues: JobRaListFilterValues) => { |
21 | | - if (Object.keys(formValues).length > 0) { |
22 | | - setFilters(formValues); |
23 | | - } |
24 | | - }); |
25 | | - |
26 | | - // fill up filters just after opening the page |
27 | | - useEffect(() => { |
28 | | - submit(); |
29 | | - }, []); |
30 | 11 |
|
31 | 12 | return ( |
32 | | - <FormProvider {...form}> |
33 | | - <form onSubmit={submit}> |
34 | | - <Box display="flex" alignItems="flex-end"> |
35 | | - <Box component="span" mr={2}> |
36 | | - <JobTypeRaFilter /> |
37 | | - </Box> |
| 13 | + <FilterLiveForm> |
| 14 | + <Box display="flex" alignItems="flex-end"> |
| 15 | + <Box component="span" mr={2} sx={{ flex: "0.2" }}> |
| 16 | + <LocationRaTypeFilter /> |
| 17 | + </Box> |
38 | 18 |
|
39 | | - <Box component="span" mr={2} sx={{ flex: "0.3 1 1" }}> |
40 | | - {/* Not using SearchInput here because it doesn't match styles with other filters */} |
41 | | - <TextInput |
42 | | - source="search_query" |
43 | | - InputProps={{ |
44 | | - endAdornment: ( |
45 | | - <InputAdornment position="end"> |
46 | | - <SearchIcon color="disabled" /> |
47 | | - </InputAdornment> |
48 | | - ), |
49 | | - }} |
50 | | - validate={minLength(3)} |
51 | | - label="resources.jobs.filters.search_query.label" |
52 | | - helperText="resources.jobs.filters.search_query.helperText" |
53 | | - /> |
54 | | - </Box> |
| 19 | + <Box component="span" mr={2} sx={{ flex: "0.2" }}> |
| 20 | + <JobTypeRaFilter /> |
| 21 | + </Box> |
55 | 22 |
|
56 | | - <Box component="span" mb={4}> |
57 | | - <Button |
58 | | - variant="outlined" |
59 | | - color="primary" |
60 | | - type="submit" |
61 | | - > |
62 | | - {translate("resources.jobs.filters.apply_button")} |
63 | | - </Button> |
64 | | - </Box> |
| 23 | + <Box component="span" mr={2} sx={{ flex: "0.3 1 1" }}> |
| 24 | + {/* Not using SearchInput here because it doesn't match styles with other filters */} |
| 25 | + <TextInput |
| 26 | + source="search_query" |
| 27 | + InputProps={{ |
| 28 | + endAdornment: ( |
| 29 | + <InputAdornment position="end"> |
| 30 | + <SearchIcon color="disabled" /> |
| 31 | + </InputAdornment> |
| 32 | + ), |
| 33 | + }} |
| 34 | + validate={minLength(3)} |
| 35 | + label="resources.jobs.filters.search_query.label" |
| 36 | + helperText="resources.jobs.filters.search_query.helperText" |
| 37 | + /> |
65 | 38 | </Box> |
66 | | - </form> |
67 | | - </FormProvider> |
| 39 | + </Box> |
| 40 | + </FilterLiveForm> |
68 | 41 | ); |
69 | 42 | }; |
70 | 43 |
|
|
0 commit comments