Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixbug: fix suggest daily plan modal #3148

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export const DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE = 'daily-plan-estimate-hours-m
export const DEFAULT_PLANNED_TASK_ID = 'default-planned-task-id';
export const LAST_OPTION__CREATE_DAILY_PLAN_MODAL = 'last-option--create-daily-plan-modal';
export const HAS_VISITED_OUTSTANDING_TASKS = 'has-visited-outstanding-tasks';
export const HAS_SEEN_DAILY_PLAN_SUGGESTION_MODAL = 'has-seen-daily-plan-suggestion-modal';

// OAuth provider's keys

Expand Down
24 changes: 12 additions & 12 deletions apps/web/app/hooks/features/useStartStopTimerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ export function useStartStopTimerHandler() {
if (tasksEstimateHoursModalDate != currentDate) {
openAddTasksEstimationHoursModal();
} else {
handleWarnings();
startTimerOrAskEstimate();
}
} else {
openEnforcePlannedTaskSoftModal();
}
} else {
handleWarnings();
startTimerOrAskEstimate();
}
};

Expand All @@ -106,10 +106,10 @@ export function useStartStopTimerHandler() {
if (!hasWorkedHours) {
openAddDailyPlanWorkHoursModal();
} else {
handleWarnings();
startTimerOrAskEstimate();
}
} else {
handleWarnings();
startTimerOrAskEstimate();
}
};

Expand All @@ -124,25 +124,25 @@ export function useStartStopTimerHandler() {
if (dailyPlanEstimateHoursModalDate != currentDate) {
handleMissingDailyPlanWorkHour();
} else {
handleWarnings();
startTimerOrAskEstimate();
}
} else {
if (tasksEstimateHoursModalDate != currentDate) {
openAddTasksEstimationHoursModal();
} else {
handleWarnings();
startTimerOrAskEstimate();
}
}
} else {
handleWarnings();
startTimerOrAskEstimate();
}
};

/**
* Check if there is warning for 'enforce' mode. If not,
* start tracking
*/
const handleWarnings = () => {
const startTimerOrAskEstimate = () => {
if (
requirePlan &&
(!areAllTasksEstimated ||
Expand Down Expand Up @@ -170,7 +170,7 @@ export function useStartStopTimerHandler() {
tasksEstimateHoursModalDate == currentDate &&
dailyPlanEstimateHoursModalDate == currentDate
) {
handleWarnings();
startTimerOrAskEstimate();
} else {
if (dailyPlanSuggestionModalDate != currentDate) {
if (!hasPlan) {
Expand All @@ -185,13 +185,13 @@ export function useStartStopTimerHandler() {
if (areAllTasksEstimated) {
handleMissingDailyPlanWorkHour();
} else {
handleWarnings();
startTimerOrAskEstimate();
}
} else {
handleWarnings();
startTimerOrAskEstimate();
}
} else {
handleWarnings();
startTimerOrAskEstimate();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
? canStartWorking && requirePlan && (planEditState.draft || warning)
? true
: false
: canStartWorking && requirePlan
: canStartWorking && requirePlan && Boolean(warning)
}
variant="outline"
type="submit"
Expand Down
12 changes: 8 additions & 4 deletions apps/web/lib/features/daily-plan/suggest-daily-plan-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Modal, Card, Text } from 'lib/components';
import { Button } from '@components/ui/button';
import { useCallback, useMemo } from 'react';
import { DAILY_PLAN_SUGGESTION_MODAL_DATE } from '@app/constants';
import { DAILY_PLAN_SUGGESTION_MODAL_DATE, HAS_SEEN_DAILY_PLAN_SUGGESTION_MODAL } from '@app/constants';
import { useTranslations } from 'next-intl';
import Link from 'next/link';
import { useAuthenticateUser } from '@app/hooks';
import { usePathname } from 'next/navigation';

interface ISuggestDailyPlanModalProps {
closeModal: () => void;
Expand All @@ -19,15 +20,18 @@ export function SuggestDailyPlanModal(props: ISuggestDailyPlanModalProps) {
() => user?.name || user?.firstName || user?.lastName || user?.username || '',
[user?.firstName, user?.lastName, user?.name, user?.username]
);

const path = usePathname();
const t = useTranslations();

const currentDate = useMemo(() => new Date().toISOString().split('T')[0], []);

const handleCloseModal = useCallback(() => {
localStorage.setItem(DAILY_PLAN_SUGGESTION_MODAL_DATE, currentDate);
localStorage.setItem(HAS_SEEN_DAILY_PLAN_SUGGESTION_MODAL, currentDate);
if (path.split('/')[1] == 'profile') {
localStorage.setItem(DAILY_PLAN_SUGGESTION_MODAL_DATE, currentDate);
}
closeModal();
}, [closeModal, currentDate]);
}, [closeModal, currentDate, path]);

return (
<Modal isOpen={isOpen} closeModal={handleCloseModal} showCloseIcon={false}>
Expand Down
11 changes: 9 additions & 2 deletions apps/web/lib/features/user-profile-plans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { useAuthenticateUser, useCanSeeActivityScreen, useDailyPlan, useUserProf
import { useDateRange } from '@app/hooks/useDateRange';
import { filterDailyPlan } from '@app/hooks/useFilterDateRange';
import { useLocalStorageState } from '@app/hooks/useLocalStorageState';
import { DAILY_PLAN_SUGGESTION_MODAL_DATE, HAS_VISITED_OUTSTANDING_TASKS } from '@app/constants';
import {
DAILY_PLAN_SUGGESTION_MODAL_DATE,
HAS_SEEN_DAILY_PLAN_SUGGESTION_MODAL,
HAS_VISITED_OUTSTANDING_TASKS
} from '@app/constants';
import { IDailyPlan, ITeamTask } from '@app/interfaces';
import { dataDailyPlanState } from '@app/stores';
import { fullWidthState } from '@app/stores/fullWidth';
Expand Down Expand Up @@ -72,14 +76,17 @@ export function UserProfilePlans() {
const [filterAllPlanData, setFilterAllPlanData] = useState<IDailyPlan[]>(sortedPlans);
const dailyPlanSuggestionModalDate = window && window?.localStorage.getItem(DAILY_PLAN_SUGGESTION_MODAL_DATE);
const path = usePathname();
const haveSeenDailyPlanSuggestionModal = window?.localStorage.getItem(HAS_SEEN_DAILY_PLAN_SUGGESTION_MODAL);

// Set the tab plan tab to outstanding if user has no daily plan and there are outstanding tasks (on first load)
useEffect(() => {
if (dailyPlanSuggestionModalDate != new Date().toISOString().split('T')[0] && path.split('/')[1] == 'profile') {
if (estimatedTotalTime(outstandingPlans).totalTasks) {
setCurrentTab('Outstanding');
}
window.localStorage.setItem(DAILY_PLAN_SUGGESTION_MODAL_DATE, new Date().toISOString().split('T')[0]);
if (haveSeenDailyPlanSuggestionModal == new Date().toISOString().split('T')[0]) {
window.localStorage.setItem(DAILY_PLAN_SUGGESTION_MODAL_DATE, new Date().toISOString().split('T')[0]);
}
}

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
Loading