Skip to content

Commit

Permalink
[Fix] Profile | tab 'Assigned' values in Action menu (#2745)
Browse files Browse the repository at this point in the history
* feat: hide plan for today and for tomorrow on already existing plans

* feat: dailyn plan creation disable dates already planned

* feat: dailyn plan creation disable dates using profile user plans

* fix: delete unncessary logs
  • Loading branch information
GloireMutaliko21 authored Jul 17, 2024
1 parent 3280c0f commit 07ca32d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
8 changes: 8 additions & 0 deletions apps/web/app/hooks/features/useTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ export function useTimer() {
plan.tasks?.length > 0
);

const tomorrow = moment().add(1, 'days');
const hasPlanForTomorrow = myDailyPlans.items.find(
(plan) => moment(plan.date).format('YYYY-MM-DD') === tomorrow.format('YYYY-MM-DD')
);

// Team setting that tells if each member must have a today plan for allowing tracking time
const requirePlan = activeTeam?.requirePlanToTrack;

Expand Down Expand Up @@ -420,6 +425,7 @@ export function useTimer() {
startTimer,
stopTimer,
hasPlan,
hasPlanForTomorrow,
canRunTimer,
canTrack,
isPlanVerified,
Expand Down Expand Up @@ -460,6 +466,7 @@ export function useTimerView() {
startTimer,
stopTimer,
hasPlan,
hasPlanForTomorrow,
canRunTimer,
canTrack,
isPlanVerified,
Expand Down Expand Up @@ -491,6 +498,7 @@ export function useTimerView() {
timerStatus,
activeTeamTask,
hasPlan,
hasPlanForTomorrow,
disabled: !canRunTimer,
canTrack,
isPlanVerified,
Expand Down
14 changes: 10 additions & 4 deletions apps/web/lib/features/daily-plan/create-daily-plan-form-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export function CreateDailyPlanFormModal({
const { handleSubmit, reset } = useForm();
const { user } = useAuthenticateUser();
const { activeTeam, activeTeamManagers } = useOrganizationTeams();
const { createDailyPlan, createDailyPlanLoading } = useDailyPlan();
const { createDailyPlan, createDailyPlanLoading, profileDailyPlans } = useDailyPlan();

const existingPlanDates = profileDailyPlans.items.map((plan) => new Date(plan.date));

const isManagerConnectedUser = activeTeamManagers.find((member) => member.employee?.user?.id == user?.id);

Expand Down Expand Up @@ -119,21 +121,25 @@ export function CreateDailyPlanFormModal({
<Button
variant={'outline'}
className={cn(
'justify-start text-left font-normal py-6 rounded-lg',
'justify-start text-left font-normal py-6 rounded-lg dark:bg-dark--theme-light dark:border-slate-700',
!date && 'text-muted-foreground'
)}
>
<CalendarIcon className="mr-2 h-4 w-4" />
{date ? moment(date).format('DD.MM.YYYY') : <span>Pick a date</span>}
</Button>
</PopoverTrigger>
<PopoverContent className="w-full p-0 z-[9999]">
<PopoverContent className="w-full p-0 z-[9999] dark:!border-slate-700">
<Calendar
mode="single"
className="dark:bg-dark--theme-light"
selected={date}
onSelect={(day) => setDate(day ? day : new Date(tomorrowDate))}
initialFocus
disabled={{ from: new Date(1970, 1, 1), to: tomorrowDate }}
disabled={[
...existingPlanDates,
{ from: new Date(1970, 1, 1), to: tomorrowDate }
]}
/>
</PopoverContent>
</Popover>
Expand Down
17 changes: 12 additions & 5 deletions apps/web/lib/features/task/task-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ function TaskCardMenu({
}, [memberInfo, task, viewType]);

const canSeeActivity = useCanSeeActivityScreen();
const { hasPlan, hasPlanForTomorrow } = useTimerView();

return (
<Popover>
Expand Down Expand Up @@ -556,13 +557,15 @@ function TaskCardMenu({
planMode="today"
taskId={task.id}
employeeId={profile?.member?.employeeId ?? ''}
hasTodayPlan={hasPlan}
/>
</li>
<li className="mb-2">
<PlanTask
planMode="tomorow"
taskId={task.id}
employeeId={profile?.member?.employeeId ?? ''}
hasPlanForTomorrow={hasPlanForTomorrow}
/>
</li>
<li className="mb-2">
Expand Down Expand Up @@ -599,7 +602,7 @@ function TaskCardMenu({
plan={plan}
/>
</div>
<div className='mt-2'>
<div className="mt-2">
<RemoveManyTaskFromPlan
task={task}
member={profile?.member}
Expand Down Expand Up @@ -642,12 +645,16 @@ export function PlanTask({
planMode,
taskId,
employeeId,
chooseMember
chooseMember,
hasTodayPlan,
hasPlanForTomorrow
}: {
taskId: string;
planMode: IDailyPlanMode;
employeeId?: string;
chooseMember?: boolean;
hasTodayPlan?: IDailyPlan;
hasPlanForTomorrow?: IDailyPlan;
}) {
const t = useTranslations();
const [isPending, startTransition] = useTransition();
Expand Down Expand Up @@ -702,7 +709,7 @@ export function PlanTask({
employeeId={employeeId}
chooseMember={chooseMember}
/>
{planMode === 'today' && (
{planMode === 'today' && !hasTodayPlan && (
<span>
{isPending ? (
<ReloadIcon className="animate-spin mr-2 h-4 w-4" />
Expand All @@ -711,7 +718,7 @@ export function PlanTask({
)}
</span>
)}
{planMode === 'tomorow' && (
{planMode === 'tomorow' && !hasPlanForTomorrow && (
<span>
{isPending ? (
<ReloadIcon className="animate-spin mr-2 h-4 w-4" />
Expand Down Expand Up @@ -763,7 +770,7 @@ export function RemoveTaskFromPlan({ task, plan, member }: { task: ITeamTask; me
);
}

export function RemoveManyTaskFromPlan({ task, member }: { task: ITeamTask; member?: OT_Member; }) {
export function RemoveManyTaskFromPlan({ task, member }: { task: ITeamTask; member?: OT_Member }) {
// const t = useTranslations();
const { removeManyTaskPlans } = useDailyPlan();
const data: IRemoveTaskFromManyPlans = { plansIds: [], employeeId: member?.employeeId };
Expand Down

0 comments on commit 07ca32d

Please sign in to comment.