Files
twenty_crm/front/src/modules/companies/table/components/EditableCompanyAddressCell.tsx
Charles Bochet 551c3b5e60 Persist table cell values on cell close (#655)
* Persist table cell values on cell close

* Apply to all cells
2023-07-14 06:20:08 +02:00

39 lines
1.1 KiB
TypeScript

import { useEffect, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { companyAddressFamilyState } from '@/companies/states/companyAddressFamilyState';
import { EditableCellText } from '@/ui/components/editable-cell/types/EditableCellText';
import { useCurrentRowEntityId } from '@/ui/tables/hooks/useCurrentEntityId';
import { useUpdateCompanyMutation } from '~/generated/graphql';
export function EditableCompanyAddressCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updateCompany] = useUpdateCompanyMutation();
const address = useRecoilValue(
companyAddressFamilyState(currentRowEntityId ?? ''),
);
const [internalValue, setInternalValue] = useState(address ?? '');
useEffect(() => {
setInternalValue(address ?? '');
}, [address]);
return (
<EditableCellText
value={internalValue}
onChange={setInternalValue}
onSubmit={() =>
updateCompany({
variables: {
id: currentRowEntityId,
address: internalValue,
},
})
}
onCancel={() => setInternalValue(address ?? '')}
/>
);
}