mirror of
https://github.com/lingble/twenty.git
synced 2025-11-27 03:13:52 +00:00
* Removed useless folder * First working version * Refactored MultipleEntitySelect and splitted into 2 components * Added TODO * Removed useless Query * Fixed refetch * Fixed naming * Fix tests --------- Co-authored-by: Charles Bochet <charles@twenty.com>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { v4 } from 'uuid';
|
|
|
|
import {
|
|
useAddCommentThreadTargetOnCommentThreadMutation,
|
|
useRemoveCommentThreadTargetOnCommentThreadMutation,
|
|
} from '~/generated/graphql';
|
|
|
|
import { EntityForSelect } from '../components/MultipleEntitySelect';
|
|
import { CommentThreadForDrawer } from '../types/CommentThreadForDrawer';
|
|
|
|
export function useHandleCheckableCommentThreadTargetChange({
|
|
commentThread,
|
|
}: {
|
|
commentThread: CommentThreadForDrawer;
|
|
}) {
|
|
const [addCommentThreadTargetOnCommentThread] =
|
|
useAddCommentThreadTargetOnCommentThreadMutation({
|
|
refetchQueries: ['GetCompanies', 'GetPeople'],
|
|
});
|
|
|
|
const [removeCommentThreadTargetOnCommentThread] =
|
|
useRemoveCommentThreadTargetOnCommentThreadMutation({
|
|
refetchQueries: ['GetCompanies', 'GetPeople'],
|
|
});
|
|
|
|
return function handleCheckItemChange(
|
|
newCheckedValue: boolean,
|
|
entity: EntityForSelect,
|
|
) {
|
|
if (newCheckedValue) {
|
|
addCommentThreadTargetOnCommentThread({
|
|
variables: {
|
|
commentableEntityId: entity.id,
|
|
commentableEntityType: entity.entityType,
|
|
commentThreadId: commentThread.id,
|
|
commentThreadTargetCreationDate: new Date().toISOString(),
|
|
commentThreadTargetId: v4(),
|
|
},
|
|
});
|
|
} else {
|
|
const foundCorrespondingTarget = commentThread.commentThreadTargets?.find(
|
|
(target) => target.commentableId === entity.id,
|
|
);
|
|
|
|
if (foundCorrespondingTarget) {
|
|
removeCommentThreadTargetOnCommentThread({
|
|
variables: {
|
|
commentThreadId: commentThread.id,
|
|
commentThreadTargetId: foundCorrespondingTarget.id,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
};
|
|
}
|