Files
twenty/front/src/modules/companies/components/CompanyEditableNameCell.tsx
Emilien Chauvet 6446692f25 Refacto/remaining inplace input cells (#531)
* Add inplace date input component

* Add inplace phone input component

* Add inplace double text input component

* Add inplace chip input component

* Remove useless styled component

* Reduce code through props destructuring
2023-07-07 15:00:01 -07:00

60 lines
1.6 KiB
TypeScript

import { CellCommentChip } from '@/comments/components/CellCommentChip';
import { useOpenCommentRightDrawer } from '@/comments/hooks/useOpenCommentRightDrawer';
import { EditableChipCell } from '@/ui/components/editable-cell/types/EditableChipCell';
import { getLogoUrlFromDomainName } from '@/utils/utils';
import {
CommentableType,
GetCompaniesQuery,
useUpdateCompanyMutation,
} from '~/generated/graphql';
import CompanyChip from './CompanyChip';
type OwnProps = {
company: Pick<
GetCompaniesQuery['companies'][0],
'id' | 'name' | 'domainName' | '_commentCount' | 'accountOwner'
>;
};
export function CompanyEditableNameChipCell({ company }: OwnProps) {
const openCommentRightDrawer = useOpenCommentRightDrawer();
const [updateCompany] = useUpdateCompanyMutation();
function handleCommentClick(event: React.MouseEvent<HTMLDivElement>) {
event.preventDefault();
event.stopPropagation();
openCommentRightDrawer([
{
type: CommentableType.Company,
id: company.id,
},
]);
}
return (
<EditableChipCell
value={company.name || ''}
placeholder="Name"
picture={getLogoUrlFromDomainName(company.domainName)}
changeHandler={(value: string) => {
updateCompany({
variables: {
...company,
name: value,
accountOwnerId: company.accountOwner?.id,
},
});
}}
ChipComponent={CompanyChip}
rightEndContents={[
<CellCommentChip
count={company._commentCount ?? 0}
onClick={handleCommentClick}
/>,
]}
/>
);
}