Add task to action bar (#1153)

- add task to action bar
This commit is contained in:
brendanlaschke
2023-08-10 18:17:58 +02:00
committed by GitHub
parent 0f364cc9e7
commit c91844071a
7 changed files with 92 additions and 104 deletions

View File

@ -37,7 +37,7 @@ export function useOpenCreateActivityDrawer() {
return function openCreateActivityDrawer( return function openCreateActivityDrawer(
type: ActivityType, type: ActivityType,
entity?: CommentableEntity, entities?: CommentableEntity[],
) { ) {
const now = new Date().toISOString(); const now = new Date().toISOString();
@ -52,23 +52,19 @@ export function useOpenCreateActivityDrawer() {
type: type, type: type,
activityTargets: { activityTargets: {
createMany: { createMany: {
data: entity data: entities
? [ ? entities.map((entity) => ({
{ commentableId: entity.id,
commentableId: entity.id, commentableType: entity.type,
commentableType: entity.type, companyId:
companyId: entity.type === CommentableType.Company
entity.type === CommentableType.Company ? entity.id
? entity.id : null,
: null, personId:
personId: entity.type === CommentableType.Person ? entity.id : null,
entity.type === CommentableType.Person id: v4(),
? entity.id createdAt: now,
: null, }))
id: v4(),
createdAt: now,
},
]
: [], : [],
skipDuplicates: true, skipDuplicates: true,
}, },
@ -85,7 +81,7 @@ export function useOpenCreateActivityDrawer() {
onCompleted(data) { onCompleted(data) {
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false }); setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
setViewableActivityId(data.createOneActivity.id); setViewableActivityId(data.createOneActivity.id);
setCommentableEntityArray(entity ? [entity] : []); setCommentableEntityArray(entities ?? []);
openRightDrawer(RightDrawerPages.CreateActivity); openRightDrawer(RightDrawerPages.CreateActivity);
}, },
}); });

View File

@ -1,41 +1,19 @@
import { getOperationName } from '@apollo/client/utilities/graphql/getFromAST'; import { useRecoilValue } from 'recoil';
import { useRecoilState, useRecoilValue } from 'recoil';
import { v4 } from 'uuid';
import { currentUserState } from '@/auth/states/currentUserState';
import { GET_COMPANIES } from '@/companies/queries';
import { GET_PEOPLE } from '@/people/queries';
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 { selectedRowIdsSelector } from '@/ui/table/states/selectedRowIdsSelector'; import { selectedRowIdsSelector } from '@/ui/table/states/selectedRowIdsSelector';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; import { ActivityType, CommentableType } from '~/generated/graphql';
import {
ActivityType,
CommentableType,
useCreateActivityMutation,
} from '~/generated/graphql';
import { GET_ACTIVITIES_BY_TARGETS, GET_ACTIVITY } from '../queries';
import { commentableEntityArrayState } from '../states/commentableEntityArrayState';
import { viewableActivityIdState } from '../states/viewableActivityIdState';
import { CommentableEntity } from '../types/CommentableEntity'; import { CommentableEntity } from '../types/CommentableEntity';
import { useOpenCreateActivityDrawer } from './useOpenCreateActivityDrawer';
export function useOpenCreateActivityDrawerForSelectedRowIds() { export function useOpenCreateActivityDrawerForSelectedRowIds() {
const { openRightDrawer } = useRightDrawer();
const [createActivityMutation] = useCreateActivityMutation();
const currentUser = useRecoilValue(currentUserState);
const [, setViewableActivityId] = useRecoilState(viewableActivityIdState);
const setHotkeyScope = useSetHotkeyScope();
const [, setCommentableEntityArray] = useRecoilState(
commentableEntityArrayState,
);
const selectedEntityIds = useRecoilValue(selectedRowIdsSelector); const selectedEntityIds = useRecoilValue(selectedRowIdsSelector);
const openCreateActivityDrawer = useOpenCreateActivityDrawer();
return function openCreateCommentDrawerForSelectedRowIds( return function openCreateCommentDrawerForSelectedRowIds(
type: ActivityType,
entityType: CommentableType, entityType: CommentableType,
) { ) {
const commentableEntityArray: CommentableEntity[] = selectedEntityIds.map( const commentableEntityArray: CommentableEntity[] = selectedEntityIds.map(
@ -44,45 +22,6 @@ export function useOpenCreateActivityDrawerForSelectedRowIds() {
id, id,
}), }),
); );
const now = new Date().toISOString(); openCreateActivityDrawer(type, commentableEntityArray);
createActivityMutation({
variables: {
data: {
id: v4(),
createdAt: now,
updatedAt: now,
author: { connect: { id: currentUser?.id ?? '' } },
type: ActivityType.Note,
activityTargets: {
createMany: {
data: commentableEntityArray.map((entity) => ({
commentableId: entity.id,
commentableType: entity.type,
id: v4(),
createdAt: new Date().toISOString(),
companyId:
entity.type === CommentableType.Company ? entity.id : null,
personId:
entity.type === CommentableType.Person ? entity.id : null,
})),
skipDuplicates: true,
},
},
},
},
refetchQueries: [
getOperationName(GET_COMPANIES) ?? '',
getOperationName(GET_PEOPLE) ?? '',
getOperationName(GET_ACTIVITY) ?? '',
getOperationName(GET_ACTIVITIES_BY_TARGETS) ?? '',
],
onCompleted(data) {
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
setViewableActivityId(data.createOneActivity.id);
setCommentableEntityArray(commentableEntityArray);
openRightDrawer(RightDrawerPages.CreateActivity);
},
});
}; };
} }

View File

@ -121,8 +121,8 @@ export function Timeline({ entity }: { entity: CommentableEntity }) {
<StyledEmptyTimelineTitle>No activity yet</StyledEmptyTimelineTitle> <StyledEmptyTimelineTitle>No activity yet</StyledEmptyTimelineTitle>
<StyledEmptyTimelineSubTitle>Create one:</StyledEmptyTimelineSubTitle> <StyledEmptyTimelineSubTitle>Create one:</StyledEmptyTimelineSubTitle>
<ActivityCreateButton <ActivityCreateButton
onNoteClick={() => openCreateActivity(ActivityType.Note, entity)} onNoteClick={() => openCreateActivity(ActivityType.Note, [entity])}
onTaskClick={() => openCreateActivity(ActivityType.Task, entity)} onTaskClick={() => openCreateActivity(ActivityType.Task, [entity])}
/> />
</StyledTimelineEmptyContainer> </StyledTimelineEmptyContainer>
); );
@ -132,8 +132,8 @@ export function Timeline({ entity }: { entity: CommentableEntity }) {
<StyledMainContainer> <StyledMainContainer>
<StyledTopActionBar> <StyledTopActionBar>
<ActivityCreateButton <ActivityCreateButton
onNoteClick={() => openCreateActivity(ActivityType.Note, entity)} onNoteClick={() => openCreateActivity(ActivityType.Note, [entity])}
onTaskClick={() => openCreateActivity(ActivityType.Task, entity)} onTaskClick={() => openCreateActivity(ActivityType.Task, [entity])}
/> />
</StyledTopActionBar> </StyledTopActionBar>
<StyledTimelineContainer> <StyledTimelineContainer>

View File

@ -1,14 +1,24 @@
import { useOpenCreateActivityDrawerForSelectedRowIds } from '@/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds'; import { useOpenCreateActivityDrawerForSelectedRowIds } from '@/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds';
import { TableActionBarButtonToggleComments } from '@/ui/table/action-bar/components/TableActionBarButtonOpenComments'; import { TableActionBarButtonToggleComments } from '@/ui/table/action-bar/components/TableActionBarButtonOpenComments';
import { CommentableType } from '~/generated/graphql'; import { TableActionBarButtonToggleTasks } from '@/ui/table/action-bar/components/TableActionBarButtonOpenTasks';
import { ActivityType, CommentableType } from '~/generated/graphql';
export function TableActionBarButtonCreateActivityCompany() { export function TableActionBarButtonCreateActivityCompany() {
const openCreateActivityRightDrawer = const openCreateActivityRightDrawer =
useOpenCreateActivityDrawerForSelectedRowIds(); useOpenCreateActivityDrawerForSelectedRowIds();
async function handleButtonClick() { async function handleButtonClick(type: ActivityType) {
openCreateActivityRightDrawer(CommentableType.Company); openCreateActivityRightDrawer(type, CommentableType.Company);
} }
return <TableActionBarButtonToggleComments onClick={handleButtonClick} />; return (
<>
<TableActionBarButtonToggleComments
onClick={() => handleButtonClick(ActivityType.Note)}
/>
<TableActionBarButtonToggleTasks
onClick={() => handleButtonClick(ActivityType.Task)}
/>
</>
);
} }

View File

@ -1,14 +1,24 @@
import { useOpenCreateActivityDrawerForSelectedRowIds } from '@/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds'; import { useOpenCreateActivityDrawerForSelectedRowIds } from '@/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds';
import { TableActionBarButtonToggleComments } from '@/ui/table/action-bar/components/TableActionBarButtonOpenComments'; import { TableActionBarButtonToggleComments } from '@/ui/table/action-bar/components/TableActionBarButtonOpenComments';
import { CommentableType } from '~/generated/graphql'; import { TableActionBarButtonToggleTasks } from '@/ui/table/action-bar/components/TableActionBarButtonOpenTasks';
import { ActivityType, CommentableType } from '~/generated/graphql';
export function TableActionBarButtonCreateActivityPeople() { export function TableActionBarButtonCreateActivityPeople() {
const openCreateActivityRightDrawer = const openCreateActivityRightDrawer =
useOpenCreateActivityDrawerForSelectedRowIds(); useOpenCreateActivityDrawerForSelectedRowIds();
async function handleButtonClick() { async function handleButtonClick(type: ActivityType) {
openCreateActivityRightDrawer(CommentableType.Person); openCreateActivityRightDrawer(type, CommentableType.Person);
} }
return <TableActionBarButtonToggleComments onClick={handleButtonClick} />; return (
<>
<TableActionBarButtonToggleComments
onClick={() => handleButtonClick(ActivityType.Note)}
/>
<TableActionBarButtonToggleTasks
onClick={() => handleButtonClick(ActivityType.Task)}
/>
</>
);
} }

View File

@ -0,0 +1,17 @@
import { IconCheckbox } from '@/ui/icon/index';
import { EntityTableActionBarButton } from './EntityTableActionBarButton';
type OwnProps = {
onClick: () => void;
};
export function TableActionBarButtonToggleTasks({ onClick }: OwnProps) {
return (
<EntityTableActionBarButton
label="Task"
icon={<IconCheckbox size={16} />}
onClick={onClick}
/>
);
}

View File

@ -186,14 +186,22 @@ export function AuthAutoRouter() {
label: 'Create Task', label: 'Create Task',
type: CommandType.Create, type: CommandType.Create,
icon: <IconCheckbox />, icon: <IconCheckbox />,
onCommandClick: () => openCreateActivity(ActivityType.Task, entity), onCommandClick: () =>
openCreateActivity(
ActivityType.Task,
entity ? [entity] : undefined,
),
}, },
{ {
to: '', to: '',
label: 'Create Note', label: 'Create Note',
type: CommandType.Create, type: CommandType.Create,
icon: <IconNotes />, icon: <IconNotes />,
onCommandClick: () => openCreateActivity(ActivityType.Note, entity), onCommandClick: () =>
openCreateActivity(
ActivityType.Note,
entity ? [entity] : undefined,
),
}, },
]); ]);
break; break;
@ -212,14 +220,22 @@ export function AuthAutoRouter() {
label: 'Create Task', label: 'Create Task',
type: CommandType.Create, type: CommandType.Create,
icon: <IconCheckbox />, icon: <IconCheckbox />,
onCommandClick: () => openCreateActivity(ActivityType.Task, entity), onCommandClick: () =>
openCreateActivity(
ActivityType.Task,
entity ? [entity] : undefined,
),
}, },
{ {
to: '', to: '',
label: 'Create Note', label: 'Create Note',
type: CommandType.Create, type: CommandType.Create,
icon: <IconNotes />, icon: <IconNotes />,
onCommandClick: () => openCreateActivity(ActivityType.Note, entity), onCommandClick: () =>
openCreateActivity(
ActivityType.Note,
entity ? [entity] : undefined,
),
}, },
]); ]);
break; break;