diff --git a/packages/twenty-front/src/effect-components/PageChangeEffect.tsx b/packages/twenty-front/src/effect-components/PageChangeEffect.tsx index 1e88b5bce643..bf083a157e5a 100644 --- a/packages/twenty-front/src/effect-components/PageChangeEffect.tsx +++ b/packages/twenty-front/src/effect-components/PageChangeEffect.tsx @@ -155,7 +155,7 @@ export const PageChangeEffect = () => { Icon: IconCheckbox, onCommandClick: () => openCreateActivity({ - targetableObjects: [{ id: '', targetObjectNameSingular: '' }], + targetableObjects: [], }), }, ]); diff --git a/packages/twenty-front/src/modules/activities/hooks/useOpenCreateActivityDrawer.ts b/packages/twenty-front/src/modules/activities/hooks/useOpenCreateActivityDrawer.ts index 74781c52cecd..400c1f398a95 100644 --- a/packages/twenty-front/src/modules/activities/hooks/useOpenCreateActivityDrawer.ts +++ b/packages/twenty-front/src/modules/activities/hooks/useOpenCreateActivityDrawer.ts @@ -68,24 +68,40 @@ export const useOpenCreateActivityDrawer = ({ assigneeId: customAssignee?.id, }); - const targetableObjectRelationIdName = `${targetableObjects[0].targetObjectNameSingular}Id`; - - await createOneActivityTarget({ - taskId: - activityObjectNameSingular === CoreObjectNameSingular.Task - ? activity.id - : undefined, - noteId: - activityObjectNameSingular === CoreObjectNameSingular.Note - ? activity.id - : undefined, - [targetableObjectRelationIdName]: targetableObjects[0].id, - }); + if (targetableObjects.length > 0) { + const targetableObjectRelationIdName = `${targetableObjects[0].targetObjectNameSingular}Id`; + + await createOneActivityTarget({ + taskId: + activityObjectNameSingular === CoreObjectNameSingular.Task + ? activity.id + : undefined, + noteId: + activityObjectNameSingular === CoreObjectNameSingular.Note + ? activity.id + : undefined, + [targetableObjectRelationIdName]: targetableObjects[0].id, + }); + + setActivityTargetableEntityArray(targetableObjects); + } else { + await createOneActivityTarget({ + taskId: + activityObjectNameSingular === CoreObjectNameSingular.Task + ? activity.id + : undefined, + noteId: + activityObjectNameSingular === CoreObjectNameSingular.Note + ? activity.id + : undefined, + }); + + setActivityTargetableEntityArray([]); + } setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false }); setViewableRecordId(activity.id); setViewableRecordNameSingular(activityObjectNameSingular); - setActivityTargetableEntityArray(targetableObjects ?? []); openRightDrawer(RightDrawerPages.ViewRecord); setIsUpsertingActivityInDB(false);