Fixed bug for refectch activities and create activity on the currently filtered user. (#1493)
* Fixed bug for refectch activities and create activity on the currently filtered user. * Refactor optimistif effect --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -5,13 +5,13 @@ import { IconPlus } from '@/ui/icon';
|
||||
import { ActivityType } from '~/generated/graphql';
|
||||
|
||||
export function AddTaskButton({
|
||||
entity,
|
||||
activityTargetEntity,
|
||||
}: {
|
||||
entity?: ActivityTargetableEntity;
|
||||
activityTargetEntity?: ActivityTargetableEntity;
|
||||
}) {
|
||||
const openCreateActivity = useOpenCreateActivityDrawer();
|
||||
|
||||
if (!entity) {
|
||||
if (!activityTargetEntity) {
|
||||
return <></>;
|
||||
}
|
||||
|
||||
@ -21,7 +21,12 @@ export function AddTaskButton({
|
||||
size="small"
|
||||
variant="secondary"
|
||||
title="Add task"
|
||||
onClick={() => openCreateActivity(ActivityType.Task, [entity])}
|
||||
onClick={() =>
|
||||
openCreateActivity({
|
||||
type: ActivityType.Task,
|
||||
targetableEntities: [activityTargetEntity],
|
||||
})
|
||||
}
|
||||
></Button>
|
||||
);
|
||||
}
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
|
||||
import { TasksRecoilScopeContext } from '@/activities/states/recoil-scope-contexts/TasksRecoilScopeContext';
|
||||
import { DropdownRecoilScopeContext } from '@/ui/dropdown/states/recoil-scope-contexts/DropdownRecoilScopeContext';
|
||||
import { PageAddButton } from '@/ui/layout/components/PageAddButton';
|
||||
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
||||
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
||||
import { filtersScopedState } from '@/ui/view-bar/states/filtersScopedState';
|
||||
import { ActivityType } from '~/generated/graphql';
|
||||
|
||||
export function PageAddTaskButton() {
|
||||
const openCreateActivity = useOpenCreateActivityDrawer();
|
||||
|
||||
const filters = useRecoilScopedValue(
|
||||
filtersScopedState,
|
||||
TasksRecoilScopeContext,
|
||||
);
|
||||
|
||||
const assigneeIdFilter = filters.find(
|
||||
(filter) => filter.key === 'assigneeId',
|
||||
);
|
||||
|
||||
function handleClick() {
|
||||
openCreateActivity({
|
||||
type: ActivityType.Task,
|
||||
assigneeId: assigneeIdFilter?.value,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<RecoilScope SpecificContext={DropdownRecoilScopeContext}>
|
||||
<PageAddButton onClick={handleClick} />
|
||||
</RecoilScope>
|
||||
);
|
||||
}
|
||||
@ -83,7 +83,10 @@ export function TaskGroups({ entity, showAddButton }: OwnProps) {
|
||||
title="New task"
|
||||
variant={'secondary'}
|
||||
onClick={() =>
|
||||
openCreateActivity(ActivityType.Task, entity ? [entity] : undefined)
|
||||
openCreateActivity({
|
||||
type: ActivityType.Task,
|
||||
targetableEntities: entity ? [entity] : undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</StyledTaskGroupEmptyContainer>
|
||||
@ -95,21 +98,27 @@ export function TaskGroups({ entity, showAddButton }: OwnProps) {
|
||||
{activeTabId === 'done' ? (
|
||||
<TaskList
|
||||
tasks={completedTasks ?? []}
|
||||
button={showAddButton && <AddTaskButton entity={entity} />}
|
||||
button={
|
||||
showAddButton && <AddTaskButton activityTargetEntity={entity} />
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<TaskList
|
||||
title="Today"
|
||||
tasks={todayOrPreviousTasks ?? []}
|
||||
button={showAddButton && <AddTaskButton entity={entity} />}
|
||||
button={
|
||||
showAddButton && <AddTaskButton activityTargetEntity={entity} />
|
||||
}
|
||||
/>
|
||||
<TaskList
|
||||
title="Upcoming"
|
||||
tasks={upcomingTasks ?? []}
|
||||
button={
|
||||
showAddButton &&
|
||||
!todayOrPreviousTasks?.length && <AddTaskButton entity={entity} />
|
||||
!todayOrPreviousTasks?.length && (
|
||||
<AddTaskButton activityTargetEntity={entity} />
|
||||
)
|
||||
}
|
||||
/>
|
||||
<TaskList
|
||||
@ -118,7 +127,9 @@ export function TaskGroups({ entity, showAddButton }: OwnProps) {
|
||||
button={
|
||||
showAddButton &&
|
||||
!todayOrPreviousTasks?.length &&
|
||||
!upcomingTasks?.length && <AddTaskButton entity={entity} />
|
||||
!upcomingTasks?.length && (
|
||||
<AddTaskButton activityTargetEntity={entity} />
|
||||
)
|
||||
}
|
||||
/>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user