Skip to content

Commit

Permalink
fix: the same task should not be planned multiple times for the same day
Browse files Browse the repository at this point in the history
  • Loading branch information
CREDO23 committed Aug 5, 2024
1 parent 40bf40b commit 6c1e298
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions apps/web/lib/features/task/task-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -514,16 +514,23 @@ function TaskCardMenu({
const canSeeActivity = useCanSeeActivityScreen();
const { todayPlan, futurePlans } = useDailyPlan();

const taskPlannedToday = todayPlan[0]?.tasks?.find((_task) => _task.id === task.id);
const taskPlannedToday = useMemo(
() => todayPlan[todayPlan.length - 1]?.tasks?.find((_task) => _task.id === task.id),
[task.id, todayPlan]
);

const taskPlannedTomorrow = futurePlans
.filter((_plan) =>
moment(_plan.date)
.format('YYYY-MM-DD')
?.toString()
?.startsWith(moment()?.add(1, 'day').format('YYYY-MM-DD'))
)[0]
?.tasks?.find((_task) => _task.id === task.id);
const taskPlannedTomorrow = useMemo(
() =>
futurePlans
.filter((_plan) =>
moment(_plan.date)
.format('YYYY-MM-DD')
?.toString()
?.startsWith(moment()?.add(1, 'day').format('YYYY-MM-DD'))
)[0]
?.tasks?.find((_task) => _task.id === task.id),
[futurePlans, task.id]
);

return (
<Popover>
Expand Down Expand Up @@ -575,14 +582,17 @@ function TaskCardMenu({
<>
<Divider type="HORIZONTAL" />
<div className="mt-3">
<li className="mb-2">
<PlanTask
planMode="today"
taskId={task.id}
employeeId={profile?.member?.employeeId ?? ''}
taskPlannedToday={taskPlannedToday}
/>
</li>
{!taskPlannedToday && (
<li className="mb-2">
<PlanTask
planMode="today"
taskId={task.id}
employeeId={profile?.member?.employeeId ?? ''}
taskPlannedToday={taskPlannedToday}
/>
</li>
)}

<li className="mb-2">
<PlanTask
planMode="tomorow"
Expand Down Expand Up @@ -682,7 +692,7 @@ export function PlanTask({
const t = useTranslations();
const [isPending, startTransition] = useTransition();
const { closeModal, isOpen, openModal } = useModal();
const { createDailyPlan } = useDailyPlan();
const { createDailyPlan, createDailyPlanLoading } = useDailyPlan();
const { user } = useAuthenticateUser();

const handleOpenModal = () => {
Expand Down Expand Up @@ -717,12 +727,13 @@ export function PlanTask({

return (
<>
<span
<button
className={clsxm(
'font-normal whitespace-nowrap transition-all',
'hover:font-semibold hover:transition-all cursor-pointer'
'hover:font-semibold hover:transition-all cursor-pointer h-auto'
)}
onClick={handleOpenModal}
disabled={planMode === 'today' && createDailyPlanLoading}
>
<CreateDailyPlanFormModal
open={isOpen}
Expand All @@ -733,8 +744,8 @@ export function PlanTask({
chooseMember={chooseMember}
/>
{planMode === 'today' && !taskPlannedToday && (
<span>
{isPending ? (
<span className="">
{isPending || createDailyPlanLoading ? (
<ReloadIcon className="animate-spin mr-2 h-4 w-4" />
) : (
t('dailyPlan.PLAN_FOR_TODAY')
Expand All @@ -751,7 +762,7 @@ export function PlanTask({
</span>
)}
{planMode === 'custom' && t('dailyPlan.PLAN_FOR_SOME_DAY')}
</span>
</button>
</>
);
}
Expand Down

0 comments on commit 6c1e298

Please sign in to comment.