diff --git a/src/components/GoalsComponents/MyGoal/GoalItemSummary/GoalSummary.tsx b/src/components/GoalsComponents/MyGoal/GoalItemSummary/GoalSummary.tsx index 2128e41c1..bb5a398db 100644 --- a/src/components/GoalsComponents/MyGoal/GoalItemSummary/GoalSummary.tsx +++ b/src/components/GoalsComponents/MyGoal/GoalItemSummary/GoalSummary.tsx @@ -1,4 +1,4 @@ -import useGoalSummaryStore from "@src/hooks/useGoalSummary"; +import useGoalSummaryStore from "@src/hooks/useGoalSummaryStore"; import { GoalItem } from "@src/models/GoalItem"; import React from "react"; diff --git a/src/hooks/useGoalSummary.ts b/src/hooks/useGoalSummary.ts deleted file mode 100644 index 6db4b1253..000000000 --- a/src/hooks/useGoalSummary.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { GoalItem } from "@src/models/GoalItem"; -import { formatSingularPlural, calculateDaysLeft } from "@src/utils"; -import { useTranslation } from "react-i18next"; -import { useSublistSummary } from "./useSublistSummary"; - -const useGoalSummaryStore = (goal: GoalItem) => { - const { t } = useTranslation(); - const { subGoalsCount, subBudgetsCount } = useSublistSummary({ goal }); - - const getSublistSummaryText = () => { - if (goal.due) { - return ""; - } - if (subGoalsCount > 0 && subBudgetsCount === 0) { - return formatSingularPlural(subGoalsCount, "goal"); - } - if (subBudgetsCount > 0 && subGoalsCount === 0) { - return formatSingularPlural(subBudgetsCount, "budget"); - } - if (subGoalsCount > 0 && subBudgetsCount > 0) { - return `${formatSingularPlural(subGoalsCount, "goal")}, ${formatSingularPlural(subBudgetsCount, "budget")}`; - } - return ""; - }; - - const getDurationSummaryText = () => { - if (goal.duration) { - return t("hourWithCount", { count: Number(goal.duration) }); - } - return ""; - }; - - const getDueDateSummaryText = () => { - if (goal.due) { - return calculateDaysLeft(goal.due); - } - return ""; - }; - - const getHabitSummaryText = () => { - if (goal.habit === "weekly") { - return t("everyWeek"); - } - return ""; - }; - - return { - sublistSummary: getSublistSummaryText(), - durationSummary: getDurationSummaryText(), - dueDateSummary: getDueDateSummaryText(), - habitSummary: getHabitSummaryText(), - }; -}; - -export default useGoalSummaryStore; diff --git a/src/hooks/useGoalSummaryStore.ts b/src/hooks/useGoalSummaryStore.ts new file mode 100644 index 000000000..25babf519 --- /dev/null +++ b/src/hooks/useGoalSummaryStore.ts @@ -0,0 +1,35 @@ +import { GoalItem } from "@src/models/GoalItem"; +import { formatSingularPlural, calculateDaysLeft } from "@src/utils"; +import { useTranslation } from "react-i18next"; +import { useSublistSummary } from "./useSublistSummary"; + +const useGoalSummaryStore = (goal: GoalItem) => { + const { t } = useTranslation(); + const { subGoalsCount, subBudgetsCount } = useSublistSummary({ goal }); + + const getSublistSummaryText = () => + goal.due + ? "" + : subGoalsCount > 0 && subBudgetsCount === 0 + ? formatSingularPlural(subGoalsCount, "goal") + : subBudgetsCount > 0 && subGoalsCount === 0 + ? formatSingularPlural(subBudgetsCount, "budget") + : subGoalsCount > 0 && subBudgetsCount > 0 + ? `${formatSingularPlural(subGoalsCount, "goal")}, ${formatSingularPlural(subBudgetsCount, "budget")}` + : ""; + + const getDurationSummaryText = () => (goal.duration ? t("hourWithCount", { count: Number(goal.duration) }) : ""); + + const getDueDateSummaryText = () => (goal.due ? calculateDaysLeft(goal.due) : ""); + + const getHabitSummaryText = () => (goal.habit === "weekly" ? t("everyWeek") : ""); + + return { + sublistSummary: getSublistSummaryText(), + durationSummary: getDurationSummaryText(), + dueDateSummary: getDueDateSummaryText(), + habitSummary: getHabitSummaryText(), + }; +}; + +export default useGoalSummaryStore;