Skip to content

Commit 5e8787e

Browse files
committed
refactor(web): centralize Term type definition and helper
1 parent dbfe4cc commit 5e8787e

File tree

8 files changed

+10
-20
lines changed

8 files changed

+10
-20
lines changed

apps/web/src/app/dashboard/@header/register/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useNextTerm, useNextYear } from "@/components/AppConfigProvider";
44
import { Skeleton } from "@/components/ui/skeleton";
5-
import { formatTermTitle } from "@/utils/format-term";
5+
import { formatTermTitle } from "@/utils/term";
66
import { AppHeader } from "../../components/app-header";
77

88
export default function ScheduleHeader() {

apps/web/src/app/dashboard/@header/schedule/page-disabled.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useCurrentTerm, useCurrentYear } from "@/components/AppConfigProvider";
44
import { Skeleton } from "@/components/ui/skeleton";
5-
import { formatTermTitle } from "@/utils/format-term";
5+
import { formatTermTitle } from "@/utils/term";
66
import { AppHeader } from "../../components/app-header";
77

88
export default function ScheduleHeader() {

apps/web/src/components/AppConfigProvider.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import { api } from "@albert-plus/server/convex/_generated/api";
44
import { useConvexAuth, useQuery } from "convex/react";
55
import { createContext, type ReactNode, useContext, useMemo } from "react";
6-
7-
export type Term = "spring" | "summer" | "fall" | "j-term";
6+
import type { Term } from "@/utils/term";
87

98
export type AppConfig = {
109
current_term: Term | null;

apps/web/src/modules/report-parsing/components/confirm-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Term } from "@/components/AppConfigProvider";
21
import { Button } from "@/components/ui/button";
32
import {
43
Dialog,
@@ -9,6 +8,7 @@ import {
98
DialogHeader,
109
DialogTitle,
1110
} from "@/components/ui/dialog";
11+
import type { Term } from "@/utils/term";
1212
import type { UserCourse } from "../types";
1313

1414
type ConfirmModalProps = {

apps/web/src/modules/report-parsing/utils/transform-to-user-courses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Term } from "@/components/AppConfigProvider";
1+
import type { Term } from "@/utils/term";
22
import type { Grade, UserCourse } from "../types";
33

44
interface ParsedCourse {

apps/web/src/modules/schedule-calendar/components/info-dialog.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
DialogHeader,
1414
DialogTitle,
1515
} from "@/components/ui/dialog";
16+
import { formatTermTitle } from "@/utils/term";
1617
import type { Class } from "../schedule-calendar";
1718

1819
interface CourseInfoDialogProps {
@@ -49,16 +50,6 @@ export function CourseInfoDialog({
4950
return `${format(slot.start, "EEEE, h:mm a")} - ${format(slot.end, "h:mm a")}`;
5051
};
5152

52-
const formatTerm = (term: string, year: number) => {
53-
const termMap: Record<string, string> = {
54-
spring: "Spring",
55-
summer: "Summer",
56-
fall: "Fall",
57-
"j-term": "J-Term",
58-
};
59-
return `${termMap[term] || term} ${year}`;
60-
};
61-
6253
const getStatusBadgeColor = (status: string) => {
6354
switch (status) {
6455
case "open":
@@ -118,7 +109,7 @@ export function CourseInfoDialog({
118109
Term
119110
</p>
120111
<p className="text-sm text-muted-foreground">
121-
{formatTerm(course.term, course.year)}
112+
{formatTermTitle(course.term, course.year)}
122113
</p>
123114
</div>
124115
</div>

apps/web/src/modules/schedule-calendar/schedule-calendar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { api } from "@albert-plus/server/convex/_generated/api";
44
import type { Doc } from "@albert-plus/server/convex/_generated/dataModel";
55
import type { FunctionReturnType } from "convex/server";
66
import { addDays, startOfWeek } from "date-fns";
7-
import type { Term } from "@/components/AppConfigProvider";
87
import { Skeleton } from "@/components/ui/skeleton";
8+
import type { Term } from "@/utils/term";
99
import { WeekView } from "./components/week-view";
1010

1111
export const EventHeight = 24;
@@ -31,7 +31,7 @@ export interface Class {
3131
isPreview?: boolean;
3232
section: string;
3333
year: number;
34-
term: "spring" | "summer" | "fall" | "j-term";
34+
term: Term;
3535
instructor: string[];
3636
location?: string;
3737
startTime: string;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Term } from "@/components/AppConfigProvider";
1+
export type Term = "spring" | "summer" | "fall" | "j-term";
22

33
export function formatTermTitle(term: Term | null, year: number | null) {
44
if (!term || !year) {

0 commit comments

Comments
 (0)