From 0e61f84fb849e925d13e7ff15acbb1b95bccf946 Mon Sep 17 00:00:00 2001 From: aetchego Date: Thu, 19 Dec 2024 12:36:03 +0100 Subject: [PATCH] continue --- .../Dashboard/PatientList/index.tsx | 1 - .../SavedFiltersSection/EditSavedFilter.tsx | 9 +-- .../SavedFiltersSection/SaveFilterAction.tsx | 59 +++++++++++++------ .../SavedFiltersSection/index.tsx | 10 +++- .../SearchSection/FilterAction.tsx | 9 ++- .../SearchSection/OccurrenceSearch.tsx | 54 ++++++++++------- src/components/PatientsBoard/index.tsx | 2 +- .../PatientsBoard/usePatientsBoard.ts | 2 +- src/components/ui/Searchbar/SearchInput.tsx | 6 +- 9 files changed, 93 insertions(+), 59 deletions(-) diff --git a/src/components/Dashboard/PatientList/index.tsx b/src/components/Dashboard/PatientList/index.tsx index 83abc9403..570616a96 100644 --- a/src/components/Dashboard/PatientList/index.tsx +++ b/src/components/Dashboard/PatientList/index.tsx @@ -47,7 +47,6 @@ import { useSearchParams } from 'react-router-dom' import { checkIfPageAvailable, handlePageError, cleanSearchParams } from 'utils/paginationUtils' import List from 'components/ui/List' import { v4 as uuidv4 } from 'uuid' -import { useForm } from 'hooks/useForm' import CheckboxGroup from 'components/ui/Inputs/CheckboxGroup' import DurationRange from 'components/ui/Inputs/DurationRange' import Text from 'components/ui/Inputs/Text' diff --git a/src/components/PatientsBoard/SavedFiltersSection/EditSavedFilter.tsx b/src/components/PatientsBoard/SavedFiltersSection/EditSavedFilter.tsx index 99d6657b2..00db8c905 100644 --- a/src/components/PatientsBoard/SavedFiltersSection/EditSavedFilter.tsx +++ b/src/components/PatientsBoard/SavedFiltersSection/EditSavedFilter.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react' +import React, { useEffect } from 'react' import { Grid } from '@mui/material' import CheckboxGroup from 'components/ui/Inputs/CheckboxGroup' import Modal from 'components/ui/Modal' @@ -11,7 +11,6 @@ import { SearchByTypes } from 'types/searchCriterias' import { SelectedFilter } from 'hooks/filters/useSavedFilters' -/*import { useForm } from 'hooks/useForm'*/ import Select from 'components/ui/Searchbar/Select' import DurationRange from 'components/ui/Inputs/DurationRange' import { Controller, useForm } from 'react-hook-form' @@ -27,7 +26,7 @@ type EditSavedFilterProps = { } type DynamicFilters = { - [key: string]: string[] // ou tout autre type selon vos données + [key: string]: string[] } export type DynamicSelectedFilter = SelectedFilter @@ -40,7 +39,6 @@ const EditSavedFilter = ({ onEdit, onClose }: EditSavedFilterProps) => { - const { control, handleSubmit, @@ -51,7 +49,7 @@ const EditSavedFilter = ({ mode: 'onChange', reValidateMode: 'onChange' }) - + useEffect(() => { reset(criteria) }, [criteria, reset]) @@ -70,7 +68,6 @@ const EditSavedFilter = ({ void } -const SaveFilterAction = ({ disabled = false, onSubmit }: SaveFilterActionProps) => { +const SaveFilterAction = ({ disabled = false, error, onSubmit }: SaveFilterActionProps) => { const [toggleModal, setToggleModal] = useState(false) const { - getValues, - register, + control, handleSubmit, - formState: { errors, isDirty, isValid } - } = useForm<{name: string}>() + reset, + formState: { errors, isValid, isDirty } + } = useForm<{ name: string }>({ + mode: 'onChange', + reValidateMode: 'onChange' + }) + + useEffect(() => { + reset({ name: '' }) + }, [toggleModal]) + + useEffect(() => { + console.log('test save name', errors.name, isValid, errors) + }, [isValid]) return ( <> @@ -41,26 +53,37 @@ const SaveFilterAction = ({ disabled = false, onSubmit }: SaveFilterActionProps) title="Sauvegarder le filtre" color="secondary" open={toggleModal} - readonly={false} - //readonly={disabled || !isDirty} + readonly={disabled} onClose={() => setToggleModal(false)} - onSubmit={handleSubmit((data) => console.log(data))} - //isError={!isValid} + onSubmit={handleSubmit((data) => { + onSubmit(data.name) + setToggleModal(false) + reset() + })} + isError={!isValid} > - ( + + )} /> diff --git a/src/components/PatientsBoard/SavedFiltersSection/index.tsx b/src/components/PatientsBoard/SavedFiltersSection/index.tsx index 04eaf4365..5e3e738b1 100644 --- a/src/components/PatientsBoard/SavedFiltersSection/index.tsx +++ b/src/components/PatientsBoard/SavedFiltersSection/index.tsx @@ -1,5 +1,5 @@ import React, { useMemo } from 'react' -import { Grid } from '@mui/material' +import { Alert, Grid, Snackbar } from '@mui/material' import SaveFilterAction from './SaveFilterAction' import { Filters, PatientsFilters, SearchCriterias } from 'types/searchCriterias' import { ResourceType } from 'types/requestCriterias' @@ -38,6 +38,14 @@ const SavedFiltersSection = ({ deidentified, criterias, canSave, onSelect }: Sav /> )} + resetSavedFilterError()} + anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} + autoHideDuration={6000} + > + {savedFiltersErrors.errorMessage} + {asListItems.length > 0 && ( { - const { + /*const { inputs, inputs: { genders, vitalStatuses, birthdatesRanges }, changeFormError, changeInput, hasErrors - } = useForm(filters) + } = useForm(filters)*/ const [toggleModal, setToggleModal] = useState(false) return ( @@ -34,7 +33,7 @@ const FilterAction = ({ filters, deidentified, onSubmit }: FilterActionProps) => > Filtrer - onChange={(value) => changeInput(FilterKeys.BIRTHDATES, value)} onError={changeFormError} /> - + */} ) } diff --git a/src/components/PatientsBoard/SearchSection/OccurrenceSearch.tsx b/src/components/PatientsBoard/SearchSection/OccurrenceSearch.tsx index a9dd4e8fc..82acd16e8 100644 --- a/src/components/PatientsBoard/SearchSection/OccurrenceSearch.tsx +++ b/src/components/PatientsBoard/SearchSection/OccurrenceSearch.tsx @@ -4,7 +4,7 @@ import DisplayLocked from 'components/ui/Display/DisplayLocked' import { SearchByTypes, searchByListPatients } from 'types/searchCriterias' import Select from 'components/ui/Searchbar/Select' import SearchInput from 'components/ui/Searchbar/SearchInput' -import { useForm } from 'hooks/useForm' +import { Controller, useForm, useWatch } from 'react-hook-form' type SearchType = { searchBy: SearchByTypes @@ -18,32 +18,42 @@ type OccurrencesSearchProps = { } const OccurrencesSearch = ({ search, deidentified, onChange }: OccurrencesSearchProps) => { - const { - inputs, - inputs: { searchBy, searchInput }, - changeInput - } = useForm(search) + const { control } = useForm({ defaultValues: search }) - useEffect(() => onChange(inputs), [inputs]) + const watchedFields = useWatch({ + control + }) + + useEffect(() => onChange(watchedFields as SearchType), [watchedFields]) return ( <> {!deidentified && ( - <> -