Remove activityType and Id (#1179)
* Remove activityType and Id * Fix tests * Fix tests
This commit is contained in:
@ -6,20 +6,20 @@ import { GET_PEOPLE } from '@/people/queries';
|
||||
import {
|
||||
Activity,
|
||||
ActivityTarget,
|
||||
CommentableType,
|
||||
useAddActivityTargetsOnActivityMutation,
|
||||
useRemoveActivityTargetsOnActivityMutation,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import { GET_ACTIVITY } from '../queries';
|
||||
import { CommentableEntityForSelect } from '../types/CommentableEntityForSelect';
|
||||
import { ActivityTargetableEntityType } from '../types/ActivityTargetableEntity';
|
||||
import { ActivityTargetableEntityForSelect } from '../types/ActivityTargetableEntityForSelect';
|
||||
|
||||
export function useHandleCheckableActivityTargetChange({
|
||||
activity,
|
||||
}: {
|
||||
activity?: Pick<Activity, 'id'> & {
|
||||
activityTargets?: Array<
|
||||
Pick<ActivityTarget, 'id' | 'commentableId' | 'commentableType'>
|
||||
Pick<ActivityTarget, 'id' | 'personId' | 'companyId'>
|
||||
> | null;
|
||||
};
|
||||
}) {
|
||||
@ -43,14 +43,16 @@ export function useHandleCheckableActivityTargetChange({
|
||||
|
||||
return async function handleCheckItemsChange(
|
||||
entityValues: Record<string, boolean>,
|
||||
entities: CommentableEntityForSelect[],
|
||||
entities: ActivityTargetableEntityForSelect[],
|
||||
) {
|
||||
if (!activity) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentEntityIds = activity.activityTargets
|
||||
? activity.activityTargets.map(({ commentableId }) => commentableId)
|
||||
? activity.activityTargets.map(
|
||||
({ personId, companyId }) => personId ?? companyId,
|
||||
)
|
||||
: [];
|
||||
|
||||
const entitiesToAdd = entities.filter(
|
||||
@ -64,12 +66,14 @@ export function useHandleCheckableActivityTargetChange({
|
||||
activityTargetInputs: entitiesToAdd.map((entity) => ({
|
||||
id: v4(),
|
||||
createdAt: new Date().toISOString(),
|
||||
commentableType: entity.entityType,
|
||||
commentableId: entity.id,
|
||||
companyId:
|
||||
entity.entityType === CommentableType.Company ? entity.id : null,
|
||||
entity.entityType === ActivityTargetableEntityType.Company
|
||||
? entity.id
|
||||
: null,
|
||||
personId:
|
||||
entity.entityType === CommentableType.Person ? entity.id : null,
|
||||
entity.entityType === ActivityTargetableEntityType.Person
|
||||
? entity.id
|
||||
: null,
|
||||
})),
|
||||
},
|
||||
});
|
||||
@ -77,8 +81,9 @@ export function useHandleCheckableActivityTargetChange({
|
||||
const activityTargetIdsToDelete = activity.activityTargets
|
||||
? activity.activityTargets
|
||||
.filter(
|
||||
({ commentableId }) =>
|
||||
commentableId && !entityValues[commentableId],
|
||||
({ personId, companyId }) =>
|
||||
(personId ?? companyId) &&
|
||||
!entityValues[personId ?? companyId ?? ''],
|
||||
)
|
||||
.map(({ id }) => id)
|
||||
: [];
|
||||
|
||||
@ -9,20 +9,19 @@ import { useRightDrawer } from '@/ui/right-drawer/hooks/useRightDrawer';
|
||||
import { RightDrawerHotkeyScope } from '@/ui/right-drawer/types/RightDrawerHotkeyScope';
|
||||
import { RightDrawerPages } from '@/ui/right-drawer/types/RightDrawerPages';
|
||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||
import {
|
||||
ActivityType,
|
||||
CommentableType,
|
||||
useCreateActivityMutation,
|
||||
} from '~/generated/graphql';
|
||||
import { ActivityType, useCreateActivityMutation } from '~/generated/graphql';
|
||||
|
||||
import {
|
||||
GET_ACTIVITIES,
|
||||
GET_ACTIVITIES_BY_TARGETS,
|
||||
GET_ACTIVITY,
|
||||
} from '../queries';
|
||||
import { commentableEntityArrayState } from '../states/commentableEntityArrayState';
|
||||
import { activityTargetableEntityArrayState } from '../states/activityTargetableEntityArrayState';
|
||||
import { viewableActivityIdState } from '../states/viewableActivityIdState';
|
||||
import { CommentableEntity } from '../types/CommentableEntity';
|
||||
import {
|
||||
ActivityTargetableEntity,
|
||||
ActivityTargetableEntityType,
|
||||
} from '../types/ActivityTargetableEntity';
|
||||
|
||||
export function useOpenCreateActivityDrawer() {
|
||||
const { openRightDrawer } = useRightDrawer();
|
||||
@ -30,14 +29,14 @@ export function useOpenCreateActivityDrawer() {
|
||||
const currentUser = useRecoilValue(currentUserState);
|
||||
const setHotkeyScope = useSetHotkeyScope();
|
||||
|
||||
const [, setCommentableEntityArray] = useRecoilState(
|
||||
commentableEntityArrayState,
|
||||
const [, setActivityTargetableEntityArray] = useRecoilState(
|
||||
activityTargetableEntityArrayState,
|
||||
);
|
||||
const [, setViewableActivityId] = useRecoilState(viewableActivityIdState);
|
||||
|
||||
return function openCreateActivityDrawer(
|
||||
type: ActivityType,
|
||||
entities?: CommentableEntity[],
|
||||
entities?: ActivityTargetableEntity[],
|
||||
) {
|
||||
const now = new Date().toISOString();
|
||||
|
||||
@ -54,14 +53,14 @@ export function useOpenCreateActivityDrawer() {
|
||||
createMany: {
|
||||
data: entities
|
||||
? entities.map((entity) => ({
|
||||
commentableId: entity.id,
|
||||
commentableType: entity.type,
|
||||
companyId:
|
||||
entity.type === CommentableType.Company
|
||||
entity.type === ActivityTargetableEntityType.Company
|
||||
? entity.id
|
||||
: null,
|
||||
personId:
|
||||
entity.type === CommentableType.Person ? entity.id : null,
|
||||
entity.type === ActivityTargetableEntityType.Person
|
||||
? entity.id
|
||||
: null,
|
||||
id: v4(),
|
||||
createdAt: now,
|
||||
}))
|
||||
@ -81,7 +80,7 @@ export function useOpenCreateActivityDrawer() {
|
||||
onCompleted(data) {
|
||||
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
|
||||
setViewableActivityId(data.createOneActivity.id);
|
||||
setCommentableEntityArray(entities ?? []);
|
||||
setActivityTargetableEntityArray(entities ?? []);
|
||||
openRightDrawer(RightDrawerPages.CreateActivity);
|
||||
},
|
||||
});
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { selectedRowIdsSelector } from '@/ui/table/states/selectedRowIdsSelector';
|
||||
import { ActivityType, CommentableType } from '~/generated/graphql';
|
||||
import { ActivityType } from '~/generated/graphql';
|
||||
|
||||
import { CommentableEntity } from '../types/CommentableEntity';
|
||||
import {
|
||||
ActivityTargetableEntity,
|
||||
ActivityTargetableEntityType,
|
||||
} from '../types/ActivityTargetableEntity';
|
||||
|
||||
import { useOpenCreateActivityDrawer } from './useOpenCreateActivityDrawer';
|
||||
|
||||
@ -14,14 +17,13 @@ export function useOpenCreateActivityDrawerForSelectedRowIds() {
|
||||
|
||||
return function openCreateCommentDrawerForSelectedRowIds(
|
||||
type: ActivityType,
|
||||
entityType: CommentableType,
|
||||
entityType: ActivityTargetableEntityType,
|
||||
) {
|
||||
const commentableEntityArray: CommentableEntity[] = selectedEntityIds.map(
|
||||
(id) => ({
|
||||
const activityTargetableEntityArray: ActivityTargetableEntity[] =
|
||||
selectedEntityIds.map((id) => ({
|
||||
type: entityType,
|
||||
id,
|
||||
}),
|
||||
);
|
||||
openCreateActivityDrawer(type, commentableEntityArray);
|
||||
}));
|
||||
openCreateActivityDrawer(type, activityTargetableEntityArray);
|
||||
};
|
||||
}
|
||||
|
||||
@ -5,22 +5,22 @@ import { RightDrawerHotkeyScope } from '@/ui/right-drawer/types/RightDrawerHotke
|
||||
import { RightDrawerPages } from '@/ui/right-drawer/types/RightDrawerPages';
|
||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||
|
||||
import { commentableEntityArrayState } from '../states/commentableEntityArrayState';
|
||||
import { CommentableEntity } from '../types/CommentableEntity';
|
||||
import { activityTargetableEntityArrayState } from '../states/activityTargetableEntityArrayState';
|
||||
import { ActivityTargetableEntity } from '../types/ActivityTargetableEntity';
|
||||
|
||||
// TODO: refactor with recoil callback to avoid rerender
|
||||
export function useOpenTimelineRightDrawer() {
|
||||
const { openRightDrawer } = useRightDrawer();
|
||||
const [, setCommentableEntityArray] = useRecoilState(
|
||||
commentableEntityArrayState,
|
||||
const [, setActivityTargetableEntityArray] = useRecoilState(
|
||||
activityTargetableEntityArrayState,
|
||||
);
|
||||
const setHotkeyScope = useSetHotkeyScope();
|
||||
|
||||
return function openTimelineRightDrawer(
|
||||
commentableEntityArray: CommentableEntity[],
|
||||
activityTargetableEntityArray: ActivityTargetableEntity[],
|
||||
) {
|
||||
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
|
||||
setCommentableEntityArray(commentableEntityArray);
|
||||
setActivityTargetableEntityArray(activityTargetableEntityArray);
|
||||
openRightDrawer(RightDrawerPages.Timeline);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user