Skip to content

Commit 6e87570

Browse files
committed
fixed search filters and added naf params in url
1 parent e95ca0e commit 6e87570

File tree

6 files changed

+46
-10
lines changed

6 files changed

+46
-10
lines changed

front/src/app/components/forms/autocomplete/AppellationAutocomplete.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ export const AppellationAutocomplete = ({
4545
const [options, setOptions] = useState<AppellationMatchDto[]>([]);
4646
const [isSearching, setIsSearching] = useState(false);
4747
const debounceSearchTerm = useDebounce(searchTerm);
48-
useEffect(() => {
49-
if (initialOption && selectedOption === null) {
50-
setSelectedOption(initialOption);
51-
}
52-
}, [initialOption, selectedOption]);
48+
if (initialOption && selectedOption === null) {
49+
setSelectedOption(initialOption);
50+
}
5351
useEffect(() => {
5452
(async () => {
5553
const sanitizedTerm = debounceSearchTerm.trim();
@@ -104,6 +102,12 @@ export const AppellationAutocomplete = ({
104102
inputId: props.selectProps?.inputId ?? "im-select__input--appellation",
105103
loadingMessage: () => <>Recherche de métier en cours... 🔎</>,
106104
inputValue: searchTerm,
105+
defaultValue: initialValue
106+
? {
107+
label: initialValue.appellationLabel,
108+
value: initialValue,
109+
}
110+
: undefined,
107111
noOptionsMessage: () =>
108112
noOptionText({ isSearching, debounceSearchTerm, searchTerm }),
109113
placeholder:

front/src/app/components/forms/autocomplete/NafAutocomplete.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import { nafSlice } from "src/core-logic/domain/naf/naf.slice";
1212
export type NafAutocompleteProps = RSAutocompleteComponentProps<
1313
"naf",
1414
NafSectionSuggestion
15-
>;
15+
> & {
16+
initialValue?: NafSectionSuggestion;
17+
};
1618

1719
export const NafAutocomplete = ({
1820
onNafSelected,
1921
onNafClear,
22+
initialValue,
2023
...props
2124
}: NafAutocompleteProps) => {
2225
const dispatch = useDispatch();
@@ -45,6 +48,12 @@ export const NafAutocomplete = ({
4548
dispatch(nafSlice.actions.queryWasEmptied());
4649
}
4750
},
51+
defaultValue: initialValue
52+
? {
53+
label: initialValue.label,
54+
value: initialValue,
55+
}
56+
: undefined,
4857
options: options.map((option) => ({
4958
label: option.label,
5059
value: option,

front/src/app/pages/search/SearchPage.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export const SearchPage = ({
9999
longitude: undefined,
100100
fitForDisabledWorkers: undefined,
101101
currentPage: 1,
102+
nafCodes: undefined,
103+
nafLabel: undefined,
102104
...acquisitionParams,
103105
};
104106
const [tempValue, setTempValue] = useState<SearchPageParams>(initialValues);
@@ -419,14 +421,22 @@ export const SearchPage = ({
419421
onNafClear={() => {
420422
setTempValue({
421423
...tempValue,
422-
nafCodes: undefined,
424+
nafCodes: initialValues.nafCodes,
425+
nafLabel: initialValues.nafLabel,
423426
});
424427
}}
425428
selectProps={{
426429
inputId: domElementIds.search.nafAutocomplete,
427430
}}
428431
className={fr.cx("fr-mt-2w")}
429-
initialInputValue={formValues.nafLabel}
432+
initialValue={
433+
formValues.nafLabel && formValues.nafCodes
434+
? {
435+
label: formValues.nafLabel,
436+
nafCodes: formValues.nafCodes,
437+
}
438+
: undefined
439+
}
430440
/>
431441
</>
432442
),

front/src/app/routes/routeParams/convention.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ImmersionObjective,
1111
InternshipKind,
1212
LevelOfEducation,
13+
NafCode,
1314
ScheduleDto,
1415
addressDtoToString,
1516
addressStringToDto,
@@ -265,6 +266,11 @@ export const appellationStringSerializer: ValueSerializer<AppellationCode> = {
265266
stringify: (appellation) => appellation,
266267
};
267268

269+
export const nafCodeSerializer: ValueSerializer<NafCode[]> = {
270+
parse: (raw) => parseStringToJsonOrThrow(raw, "nafCodes"),
271+
stringify: (nafCode) => JSON.stringify(nafCode),
272+
};
273+
268274
export type ConventionFormKeysInUrl = keyof ConventionQueryParams;
269275
type ConventionQueryParams = typeof conventionValuesFromUrl;
270276

front/src/app/routes/routes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
appellationAndRomeDtoArraySerializer,
1313
appellationStringSerializer,
1414
conventionValuesFromUrl,
15+
nafCodeSerializer,
1516
} from "./routeParams/convention";
1617
import { formEstablishmentParamsInUrl } from "./routeParams/formEstablishment";
1718
import { standardPagesSerializer } from "./routeParams/standardPage";
@@ -75,6 +76,8 @@ export const searchParams = {
7576
place: param.query.optional.string,
7677
fitForDisabledWorkers: param.query.optional.boolean,
7778
currentPage: param.query.optional.number,
79+
nafCodes: param.query.optional.ofType(nafCodeSerializer),
80+
nafLabel: param.query.optional.string,
7881
...acquisitionParams,
7982
};
8083

libs/react-design-system/src/immersionFacile/components/search-filter/SearchFilter.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ export const SearchFilter = ({
5151
isOpened &&
5252
wrapperElement.current &&
5353
wrapperElement.current.querySelectorAll(`.${prefix}__control--is-focused`)
54-
.length === 0
54+
.length === 0 &&
55+
wrapperElement.current.querySelector("input")
5556
) {
56-
wrapperElement.current.querySelector("input")?.focus();
57+
const input = wrapperElement.current.querySelector("input");
58+
if (input && input.value === "") {
59+
input.focus();
60+
}
5761
}
5862
document.body.addEventListener("click", handleClickOutside);
5963
});

0 commit comments

Comments
 (0)