[tasks] add empty state and new task button (#1072)

* [tasks] add empty state

* add refetch + use spacing for padding

* create task auto assigned with dueAt as today

* add unscheduled tasks section

* remove unnecessary assigneeId fetching

* remove unnecessary refetchQueries

* add refetch for delete task

* rename createCommentMutation to deleteActivityMutation in activityActionBar
This commit is contained in:
Weiko
2023-08-04 20:04:06 +02:00
committed by GitHub
parent c6bec40c90
commit 0d16053c31
9 changed files with 140 additions and 74 deletions

View File

@ -2324,13 +2324,7 @@ export type CreateCommentMutationVariables = Exact<{
export type CreateCommentMutation = { __typename?: 'Mutation', createOneComment: { __typename?: 'Comment', id: string, createdAt: string, body: string, activityId?: string | null, author: { __typename?: 'User', id: string, displayName: string, firstName?: string | null, lastName?: string | null, avatarUrl?: string | null } } }; export type CreateCommentMutation = { __typename?: 'Mutation', createOneComment: { __typename?: 'Comment', id: string, createdAt: string, body: string, activityId?: string | null, author: { __typename?: 'User', id: string, displayName: string, firstName?: string | null, lastName?: string | null, avatarUrl?: string | null } } };
export type CreateActivityMutationVariables = Exact<{ export type CreateActivityMutationVariables = Exact<{
activityId: Scalars['String']; data: ActivityCreateInput;
body?: InputMaybe<Scalars['String']>;
title?: InputMaybe<Scalars['String']>;
type: ActivityType;
authorId: Scalars['String'];
createdAt: Scalars['DateTime'];
activityTargetArray: Array<ActivityTargetCreateManyActivityInput> | ActivityTargetCreateManyActivityInput;
}>; }>;
@ -2841,10 +2835,8 @@ export type CreateCommentMutationHookResult = ReturnType<typeof useCreateComment
export type CreateCommentMutationResult = Apollo.MutationResult<CreateCommentMutation>; export type CreateCommentMutationResult = Apollo.MutationResult<CreateCommentMutation>;
export type CreateCommentMutationOptions = Apollo.BaseMutationOptions<CreateCommentMutation, CreateCommentMutationVariables>; export type CreateCommentMutationOptions = Apollo.BaseMutationOptions<CreateCommentMutation, CreateCommentMutationVariables>;
export const CreateActivityDocument = gql` export const CreateActivityDocument = gql`
mutation CreateActivity($activityId: String!, $body: String, $title: String, $type: ActivityType!, $authorId: String!, $createdAt: DateTime!, $activityTargetArray: [ActivityTargetCreateManyActivityInput!]!) { mutation CreateActivity($data: ActivityCreateInput!) {
createOneActivity( createOneActivity(data: $data) {
data: {id: $activityId, createdAt: $createdAt, updatedAt: $createdAt, author: {connect: {id: $authorId}}, body: $body, title: $title, type: $type, activityTargets: {createMany: {data: $activityTargetArray, skipDuplicates: true}}}
) {
id id
createdAt createdAt
updatedAt updatedAt
@ -2885,13 +2877,7 @@ export type CreateActivityMutationFn = Apollo.MutationFunction<CreateActivityMut
* @example * @example
* const [createActivityMutation, { data, loading, error }] = useCreateActivityMutation({ * const [createActivityMutation, { data, loading, error }] = useCreateActivityMutation({
* variables: { * variables: {
* activityId: // value for 'activityId' * data: // value for 'data'
* body: // value for 'body'
* title: // value for 'title'
* type: // value for 'type'
* authorId: // value for 'authorId'
* createdAt: // value for 'createdAt'
* activityTargetArray: // value for 'activityTargetArray'
* }, * },
* }); * });
*/ */

View File

@ -5,7 +5,10 @@ import styled from '@emotion/styled';
import { ActivityBodyEditor } from '@/activities/components/ActivityBodyEditor'; import { ActivityBodyEditor } from '@/activities/components/ActivityBodyEditor';
import { ActivityComments } from '@/activities/components/ActivityComments'; import { ActivityComments } from '@/activities/components/ActivityComments';
import { ActivityTypeDropdown } from '@/activities/components/ActivityTypeDropdown'; import { ActivityTypeDropdown } from '@/activities/components/ActivityTypeDropdown';
import { GET_ACTIVITIES_BY_TARGETS } from '@/activities/queries'; import {
GET_ACTIVITIES,
GET_ACTIVITIES_BY_TARGETS,
} from '@/activities/queries';
import { PropertyBox } from '@/ui/editable-field/property-box/components/PropertyBox'; import { PropertyBox } from '@/ui/editable-field/property-box/components/PropertyBox';
import { DateEditableField } from '@/ui/editable-field/variants/components/DateEditableField'; import { DateEditableField } from '@/ui/editable-field/variants/components/DateEditableField';
import { IconCalendar } from '@/ui/icon/index'; import { IconCalendar } from '@/ui/icon/index';
@ -175,6 +178,7 @@ export function ActivityEditor({
dueAt: newDate, dueAt: newDate,
}, },
}, },
refetchQueries: [getOperationName(GET_ACTIVITIES) ?? ''],
}); });
}} }}
/> />

View File

@ -1,13 +1,74 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconCheckbox } from '@tabler/icons-react';
import { Button, ButtonVariant } from '@/ui/button/components/Button';
import { ActivityType } from '~/generated/graphql';
import { useOpenCreateActivityDrawer } from '../hooks/useOpenCreateActivityDrawer';
import { useTasks } from '../hooks/useTasks'; import { useTasks } from '../hooks/useTasks';
import { TaskList } from './TaskList'; import { TaskList } from './TaskList';
const StyledTaskGroupEmptyContainer = styled.div`
align-items: center;
align-self: stretch;
display: flex;
flex: 1 0 0;
flex-direction: column;
gap: ${({ theme }) => theme.spacing(2)};
justify-content: center;
padding-bottom: ${({ theme }) => theme.spacing(16)};
padding-left: ${({ theme }) => theme.spacing(4)};
padding-right: ${({ theme }) => theme.spacing(4)};
padding-top: ${({ theme }) => theme.spacing(3)};
`;
const StyledEmptyTaskGroupTitle = styled.div`
color: ${({ theme }) => theme.font.color.secondary};
font-size: ${({ theme }) => theme.font.size.xxl};
font-weight: ${({ theme }) => theme.font.weight.semiBold};
line-height: ${({ theme }) => theme.text.lineHeight.md};
`;
const StyledEmptyTaskGroupSubTitle = styled.div`
color: ${({ theme }) => theme.font.color.extraLight};
font-size: ${({ theme }) => theme.font.size.xxl};
font-weight: ${({ theme }) => theme.font.weight.semiBold};
line-height: ${({ theme }) => theme.text.lineHeight.md};
margin-bottom: ${({ theme }) => theme.spacing(2)};
`;
export function TaskGroups() { export function TaskGroups() {
const { todayOrPreviousTasks, upcomingTasks } = useTasks(); const { todayOrPreviousTasks, upcomingTasks, unscheduledTasks } = useTasks();
const theme = useTheme();
const openCreateActivity = useOpenCreateActivityDrawer();
if (
todayOrPreviousTasks?.length === 0 &&
upcomingTasks?.length === 0 &&
unscheduledTasks?.length === 0
) {
return (
<StyledTaskGroupEmptyContainer>
<StyledEmptyTaskGroupTitle>No task yet</StyledEmptyTaskGroupTitle>
<StyledEmptyTaskGroupSubTitle>Create one:</StyledEmptyTaskGroupSubTitle>
<Button
icon={<IconCheckbox size={theme.icon.size.sm} />}
title="New task"
variant={ButtonVariant.Secondary}
onClick={() => openCreateActivity(ActivityType.Task)}
/>
</StyledTaskGroupEmptyContainer>
);
}
return ( return (
<> <>
<TaskList title="Today" tasks={todayOrPreviousTasks ?? []} /> <TaskList title="Today" tasks={todayOrPreviousTasks ?? []} />
<TaskList title="Upcoming" tasks={upcomingTasks ?? []} /> <TaskList title="Upcoming" tasks={upcomingTasks ?? []} />
<TaskList title="Unscheduled" tasks={unscheduledTasks ?? []} />
</> </>
); );
} }

View File

@ -11,7 +11,11 @@ import { RightDrawerPages } from '@/ui/right-drawer/types/RightDrawerPages';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { ActivityType, useCreateActivityMutation } from '~/generated/graphql'; import { ActivityType, useCreateActivityMutation } from '~/generated/graphql';
import { GET_ACTIVITIES_BY_TARGETS, GET_ACTIVITY } from '../queries'; import {
GET_ACTIVITIES,
GET_ACTIVITIES_BY_TARGETS,
GET_ACTIVITY,
} from '../queries';
import { commentableEntityArrayState } from '../states/commentableEntityArrayState'; import { commentableEntityArrayState } from '../states/commentableEntityArrayState';
import { viewableActivityIdState } from '../states/viewableActivityIdState'; import { viewableActivityIdState } from '../states/viewableActivityIdState';
import { CommentableEntity } from '../types/CommentableEntity'; import { CommentableEntity } from '../types/CommentableEntity';
@ -28,34 +32,48 @@ export function useOpenCreateActivityDrawer() {
const [, setViewableActivityId] = useRecoilState(viewableActivityIdState); const [, setViewableActivityId] = useRecoilState(viewableActivityIdState);
return function openCreateActivityDrawer( return function openCreateActivityDrawer(
entity: CommentableEntity,
type: ActivityType, type: ActivityType,
entity?: CommentableEntity,
) { ) {
createActivityMutation({ const now = new Date().toISOString();
return createActivityMutation({
variables: { variables: {
authorId: currentUser?.id ?? '', data: {
activityId: v4(), id: v4(),
createdAt: new Date().toISOString(), createdAt: now,
type: type, updatedAt: now,
activityTargetArray: [ author: { connect: { id: currentUser?.id ?? '' } },
{ assignee: { connect: { id: currentUser?.id ?? '' } },
commentableId: entity.id, type: type,
commentableType: entity.type, activityTargets: {
id: v4(), createMany: {
createdAt: new Date().toISOString(), data: entity
? [
{
commentableId: entity.id,
commentableType: entity.type,
id: v4(),
createdAt: now,
},
]
: [],
skipDuplicates: true,
},
}, },
], },
}, },
refetchQueries: [ refetchQueries: [
getOperationName(GET_COMPANIES) ?? '', getOperationName(GET_COMPANIES) ?? '',
getOperationName(GET_PEOPLE) ?? '', getOperationName(GET_PEOPLE) ?? '',
getOperationName(GET_ACTIVITY) ?? '', getOperationName(GET_ACTIVITY) ?? '',
getOperationName(GET_ACTIVITIES_BY_TARGETS) ?? '', getOperationName(GET_ACTIVITIES_BY_TARGETS) ?? '',
getOperationName(GET_ACTIVITIES) ?? '',
], ],
onCompleted(data) { onCompleted(data) {
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false }); setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
setViewableActivityId(data.createOneActivity.id); setViewableActivityId(data.createOneActivity.id);
setCommentableEntityArray([entity]); setCommentableEntityArray(entity ? [entity] : []);
openRightDrawer(RightDrawerPages.CreateActivity); openRightDrawer(RightDrawerPages.CreateActivity);
}, },
}); });

View File

@ -44,19 +44,28 @@ export function useOpenCreateActivityDrawerForSelectedRowIds() {
id, id,
}), }),
); );
const now = new Date().toISOString();
createActivityMutation({ createActivityMutation({
variables: { variables: {
authorId: currentUser?.id ?? '', data: {
activityId: v4(),
createdAt: new Date().toISOString(),
type: ActivityType.Note,
activityTargetArray: commentableEntityArray.map((entity) => ({
commentableId: entity.id,
commentableType: entity.type,
id: v4(), id: v4(),
createdAt: new Date().toISOString(), 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(),
})),
skipDuplicates: true,
},
},
},
}, },
refetchQueries: [ refetchQueries: [
getOperationName(GET_COMPANIES) ?? '', getOperationName(GET_COMPANIES) ?? '',

View File

@ -96,8 +96,13 @@ export function useTasks() {
return dueDate > today; return dueDate > today;
}); });
const unscheduledTasks = tasksData?.findManyActivities.filter((task) => {
return !task.dueAt;
});
return { return {
todayOrPreviousTasks, todayOrPreviousTasks,
upcomingTasks, upcomingTasks,
unscheduledTasks,
}; };
} }

View File

@ -33,29 +33,8 @@ export const CREATE_COMMENT = gql`
`; `;
export const CREATE_ACTIVITY_WITH_COMMENT = gql` export const CREATE_ACTIVITY_WITH_COMMENT = gql`
mutation CreateActivity( mutation CreateActivity($data: ActivityCreateInput!) {
$activityId: String! createOneActivity(data: $data) {
$body: String
$title: String
$type: ActivityType!
$authorId: String!
$createdAt: DateTime!
$activityTargetArray: [ActivityTargetCreateManyActivityInput!]!
) {
createOneActivity(
data: {
id: $activityId
createdAt: $createdAt
updatedAt: $createdAt
author: { connect: { id: $authorId } }
body: $body
title: $title
type: $type
activityTargets: {
createMany: { data: $activityTargetArray, skipDuplicates: true }
}
}
) {
id id
createdAt createdAt
updatedAt updatedAt

View File

@ -3,7 +3,10 @@ import { useTheme } from '@emotion/react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { useRecoilState } from 'recoil'; import { useRecoilState } from 'recoil';
import { GET_ACTIVITIES_BY_TARGETS } from '@/activities/queries'; import {
GET_ACTIVITIES,
GET_ACTIVITIES_BY_TARGETS,
} from '@/activities/queries';
import { GET_COMPANIES } from '@/companies/queries'; import { GET_COMPANIES } from '@/companies/queries';
import { GET_PEOPLE } from '@/people/queries'; import { GET_PEOPLE } from '@/people/queries';
import { IconButton } from '@/ui/button/components/IconButton'; import { IconButton } from '@/ui/button/components/IconButton';
@ -22,16 +25,17 @@ type OwnProps = {
export function ActivityActionBar({ activityId }: OwnProps) { export function ActivityActionBar({ activityId }: OwnProps) {
const theme = useTheme(); const theme = useTheme();
const [createCommentMutation] = useDeleteActivityMutation(); const [deleteActivityMutation] = useDeleteActivityMutation();
const [, setIsRightDrawerOpen] = useRecoilState(isRightDrawerOpenState); const [, setIsRightDrawerOpen] = useRecoilState(isRightDrawerOpenState);
function deleteActivity() { function deleteActivity() {
createCommentMutation({ deleteActivityMutation({
variables: { activityId }, variables: { activityId },
refetchQueries: [ refetchQueries: [
getOperationName(GET_COMPANIES) ?? '', getOperationName(GET_COMPANIES) ?? '',
getOperationName(GET_PEOPLE) ?? '', getOperationName(GET_PEOPLE) ?? '',
getOperationName(GET_ACTIVITIES_BY_TARGETS) ?? '', getOperationName(GET_ACTIVITIES_BY_TARGETS) ?? '',
getOperationName(GET_ACTIVITIES) ?? '',
], ],
}); });
setIsRightDrawerOpen(false); setIsRightDrawerOpen(false);

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(entity, ActivityType.Note)} onNoteClick={() => openCreateActivity(ActivityType.Note, entity)}
onTaskClick={() => openCreateActivity(entity, ActivityType.Task)} 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(entity, ActivityType.Note)} onNoteClick={() => openCreateActivity(ActivityType.Note, entity)}
onTaskClick={() => openCreateActivity(entity, ActivityType.Task)} onTaskClick={() => openCreateActivity(ActivityType.Task, entity)}
/> />
</StyledTopActionBar> </StyledTopActionBar>
<StyledTimelineContainer> <StyledTimelineContainer>