Persist table cell values on cell close (#655)

* Persist table cell values on cell close

* Apply to all cells
This commit is contained in:
Charles Bochet
2023-07-13 21:20:08 -07:00
committed by GitHub
parent ca1723f2e6
commit 551c3b5e60
20 changed files with 260 additions and 133 deletions

View File

@ -1,3 +1,4 @@
import { useEffect, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { peopleCityFamilyState } from '@/people/states/peopleCityFamilyState';
@ -12,19 +13,25 @@ export function EditablePeopleCityCell() {
const city = useRecoilValue(peopleCityFamilyState(currentRowEntityId ?? ''));
const [internalValue, setInternalValue] = useState(city ?? '');
useEffect(() => {
setInternalValue(city ?? '');
}, [city]);
return (
<EditableCellPhone
value={city ?? ''}
onChange={async (newCity: string) => {
if (!currentRowEntityId) return;
await updatePerson({
value={internalValue}
onChange={setInternalValue}
onSubmit={() =>
updatePerson({
variables: {
id: currentRowEntityId,
city: newCity,
city: internalValue,
},
});
}}
})
}
onCancel={() => setInternalValue(city ?? '')}
/>
);
}