diff --git a/apps/client/apis/studyDetailApi.ts b/apps/client/apis/studyDetailApi.ts index 508e8372..7cb0183f 100644 --- a/apps/client/apis/studyDetailApi.ts +++ b/apps/client/apis/studyDetailApi.ts @@ -1,10 +1,7 @@ import { fetcher } from "@wow-class/utils"; import { apiPath } from "constants/apiPath"; import { tags } from "constants/tags"; -import type { - StudyDetailDashboardDto, - UpcomingStudyDto, -} from "types/dtos/studyDetail"; +import type { StudyDetailDashboardDto } from "types/dtos/studyDetail"; export const studyDetailApi = { getStudyDetailDashboard: async (studyId: number) => { @@ -12,18 +9,7 @@ export const studyDetailApi = { `${apiPath.studyDetail}/dashboard?studyId=${studyId}`, { next: { tags: [tags.studyDetailDashboard] }, - cache: "force-cache", - } - ); - - return response.data; - }, - getUpcomingStudy: async (studyId: number) => { - const response = await fetcher.get( - `${apiPath.studyDetail}/upcoming?studyId=${studyId}`, - { - next: { tags: [tags.upcomingStudy] }, - cache: "force-cache", + cache: "no-store", } ); diff --git a/apps/client/apis/studyHistoryApi.ts b/apps/client/apis/studyHistoryApi.ts index 02e7dedd..1cac542e 100644 --- a/apps/client/apis/studyHistoryApi.ts +++ b/apps/client/apis/studyHistoryApi.ts @@ -9,7 +9,7 @@ export const studyHistoryApi = { `${apiPath.studyHistory}/assignments?studyId=${studyId}`, { next: { tags: [tags.studyHistory] }, - cache: "force-cache", + cache: "no-store", } ); diff --git a/apps/client/app/(afterLogin)/my-study/my-assignment/_components/AssignmentContent/AssignmentOverviewBox/AssignmentBoxButtons.tsx b/apps/client/app/(afterLogin)/my-study/my-assignment/_components/AssignmentContent/AssignmentOverviewBox/AssignmentBoxButtons.tsx index 32c7ab77..48a3b8d0 100644 --- a/apps/client/app/(afterLogin)/my-study/my-assignment/_components/AssignmentContent/AssignmentOverviewBox/AssignmentBoxButtons.tsx +++ b/apps/client/app/(afterLogin)/my-study/my-assignment/_components/AssignmentContent/AssignmentOverviewBox/AssignmentBoxButtons.tsx @@ -1,61 +1,34 @@ "use client"; import { Space } from "@wow-class/ui"; -import { myStudyApi } from "apis/myStudyApi"; -import { studyDetailApi } from "apis/studyDetailApi"; +import { padWithZero, parseISODate } from "@wow-class/utils"; import { studyHistoryApi } from "apis/studyHistoryApi"; import { tags } from "constants/tags"; import Link from "next/link"; -import { useEffect, useState } from "react"; +import { toast } from "react-toastify"; import type { Assignment } from "types/dtos/studyDetail"; import type { AssignmentSubmissionStatusType } from "types/entities/common/assignment"; -import { getIsAfterStartDate } from "utils/getIsAfterStartDate"; import { isDeadlinePassed } from "utils/isDeadlinePassed"; import { revalidateTagByName } from "utils/revalidateTagByName"; import { Link as LinkIcon, Reload as ReloadIcon } from "wowds-icons"; import Button from "wowds-ui/Button"; interface AssignmentBoxButtonsProps { assignment: Assignment; + repositoryLink?: string; buttonsDisabled?: boolean; } export const AssignmentBoxButtons = ({ - buttonsDisabled: buttonDisabledProp, + buttonsDisabled, assignment, + repositoryLink, }: AssignmentBoxButtonsProps) => { - const [startDate, setStartDate] = useState(""); - - const targetWeek = assignment.week; - - useEffect(() => { - const fetchAssignmentStartDate = async () => { - const ongoingStudyInfo = await myStudyApi.getMyOngoingStudyInfo(); - - if (ongoingStudyInfo?.studyId) { - const curriculumData = await myStudyApi.getStudyCurriculumList( - ongoingStudyInfo.studyId - ); - - const matchingWeek = curriculumData?.find( - (item) => item.week === targetWeek - ); - - if (matchingWeek) { - setStartDate(matchingWeek.period.startDate); - } - } - }; - - fetchAssignmentStartDate(); - }, [targetWeek]); - - const buttonsDisabled = buttonDisabledProp || !getIsAfterStartDate(startDate); - return ( <> { - const [repositoryLink, setRepositoryLink] = useState(""); - - useEffect(() => { - const fetchStudyDashBoard = async () => { - const ongoingStudyInfo = await myStudyApi.getMyOngoingStudyInfo(); - if (!ongoingStudyInfo) { - return; - } - const studyDashboard = await studyDetailApi.getStudyDetailDashboard( - ongoingStudyInfo.studyId - ); - - if (!studyDashboard) { - return; - } else { - setRepositoryLink(studyDashboard.repositoryLink); - } - }; - - fetchStudyDashBoard(); - }, []); - const { assignmentSubmissionStatus, submissionFailureType, submissionLink } = assignment; const { primaryButtonText } = @@ -105,14 +57,13 @@ const PrimaryButton = ({ return; } const stroke = buttonsDisabled ? "mono100" : "primary"; - const link = - assignmentSubmissionStatus === null ? repositoryLink : submissionLink; - + const primaryButtonHref = + assignmentSubmissionStatus === "SUCCESS" ? submissionLink : repositoryLink; return ( + ); + } const { secondaryButtonText } = assignmentSubmissionStatus === null ? buttonTextMap.INITIAL : buttonTextMap[assignmentSubmissionStatus]; + const handleClickSubmissionComplete = async () => { const response = await studyHistoryApi.submitAssignment(studyDetailId); if (response.success) { - //TODO: 과제 제출 이후에는 과제 상태에 대한 업데이트 필요 - //이번주 과제 조회 api, 대시보드 api revaliate - revalidateTagByName( - assignmentSubmissionStatus === null - ? tags.studyDetailDashboard - : tags.upcomingStudy - ); + revalidateTagByName(tags.studyDetailDashboard); revalidateTagByName(tags.studyHistory); + toast.success("과제 제출이 완료되었어요."); } }; - if (isDeadlinePassed(deadline)) { - return ( - - ); - } const stroke = buttonsDisabled ? "mono100" : "backgroundNormal"; + const { year, month, day, hours, minutes } = parseISODate( + committedAt as string + ); + const commitText = `최종 수정일자 ${year}년 ${month}월 ${day}일 ${padWithZero(hours)}:${padWithZero(minutes)}`; return (