Files
twenty/front/src/modules/companies/table/components/EditableCompanyAddressCell.tsx
Charles Bochet 557e56492a Various fixes on table, board, tasks (#983)
* Misc fixes

* Misc fixes

* Misc fixes

* Fix login
2023-07-28 15:20:32 -07:00

41 lines
1.1 KiB
TypeScript

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