Skip to content

Commit

Permalink
organize the code
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed Nov 9, 2024
1 parent 841b075 commit 2c5be17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/Interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ export interface ILocationState {
export interface ImpossibleGoal extends GoalItem {
impossible: boolean;
}

export type ScheduleStatus = "pending" | "scheduled" | "impossible" | "future" | null;
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@
.schedule-status {
margin-top: 8px;
font-size: 14px;
text-align: center;
}
29 changes: 10 additions & 19 deletions src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useParentGoalContext } from "@src/contexts/parentGoal-context";
import useGoalActions from "@src/hooks/useGoalActions";
import useGoalStore from "@src/hooks/useGoalStore";
import { unarchiveUserGoal } from "@src/api/GoalsAPI";
import { ILocationState } from "@src/Interfaces";
import { ILocationState, ScheduleStatus } from "@src/Interfaces";
import { useLocation, useNavigate } from "react-router-dom";
import { suggestedGoalState } from "@src/store/SuggestedGoalState";
import { getHistoryUptoGoal } from "@src/helpers/GoalProcessor";
Expand Down Expand Up @@ -49,6 +49,9 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf
const location = useLocation();
const navigate = useNavigate();

const { checkGoalSchedule } = useScheduler();
const [scheduleStatus, setScheduleStatus] = useState<ScheduleStatus>(null);

let defaultColorIndex = Math.floor(Math.random() * colorPalleteList.length - 1) + 1;
let defaultAfterTime = isEditMode ? (goal.afterTime ?? 9) : 9;
let defaultBeforeTime = isEditMode ? (goal.beforeTime ?? 18) : 18;
Expand Down Expand Up @@ -279,14 +282,8 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf
setHintOption(hint?.hintOptionEnabled || false);
};

const { checkGoalSchedule } = useScheduler();

const titlePlaceholder = t(`${type !== "Budget" ? "goal" : "budget"}Title`);

type ScheduleStatus = "pending" | "scheduled" | "impossible" | "future" | null;

const [scheduleStatus, setScheduleStatus] = useState<ScheduleStatus>(null);

const checkSchedulingStatus = async (schedulerOutput: ISchedulerOutput | undefined, goalId: string) => {
if (!schedulerOutput) return "pending";

Expand Down Expand Up @@ -315,12 +312,6 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf
};

const checkSchedule = async () => {
// if (t) {
// setScheduleStatus(null);
// console.log("no duration");
// return;
// }

setScheduleStatus("pending");
const schedulerOutput = await checkGoalSchedule(getFinalTags());
console.log("schedulerOutput", schedulerOutput);
Expand Down Expand Up @@ -474,10 +465,10 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf
<button type="submit" className="action-btn place-middle gap-16">
{t(`${action} Budget`)}
</button>
{scheduleStatus && (
<div className={`schedule-status ${scheduleStatus}`}>{getScheduleStatusText(scheduleStatus)}</div>
)}
</div>
{scheduleStatus && (
<div className={`schedule-status ${scheduleStatus}`}>{getScheduleStatusText(scheduleStatus)}</div>
)}
</>
) : (
<div className="d-flex f-col gap-16">
Expand All @@ -487,9 +478,6 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf
{t(`${action} Goal`)}
</button>
</div>
{scheduleStatus && (
<div className={`schedule-status ${scheduleStatus}`}>{getScheduleStatusText(scheduleStatus)}</div>
)}
<div className="place-middle justify-fs gap-16">
<span>{t("duration")}</span>
<input
Expand All @@ -511,6 +499,9 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf
disablePastDates
/>
</div>
{scheduleStatus && tags.duration && (
<div className={`schedule-status ${scheduleStatus}`}>{getScheduleStatusText(scheduleStatus)}</div>
)}
</div>
)}
</div>
Expand Down

0 comments on commit 2c5be17

Please sign in to comment.