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

[Deploy] 과제 제출 관련 버그 수정 (#155) #156

Merged
merged 1 commit into from
Oct 12, 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
2 changes: 1 addition & 1 deletion apps/admin/utils/revalidateTagByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import { revalidateTag } from "next/cache";

export const revalidateTagByName = (tag: string) => {
export const revalidateTagByName = async (tag: string) => {
revalidateTag(tag);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Space } from "@wow-class/ui";
import { padWithZero, parseISODate } from "@wow-class/utils";
import { studyDetailApi } from "apis/studyDetailApi";
import { studyHistoryApi } from "apis/studyHistoryApi";
import { tags } from "constants/tags";
import Link from "next/link";
Expand All @@ -16,12 +17,14 @@ interface AssignmentBoxButtonsProps {
assignment: Assignment;
repositoryLink?: string;
buttonsDisabled?: boolean;
studyId: number;
}

export const AssignmentBoxButtons = ({
buttonsDisabled,
assignment,
repositoryLink,
studyId,
}: AssignmentBoxButtonsProps) => {
return (
<>
Expand All @@ -34,6 +37,8 @@ export const AssignmentBoxButtons = ({
<SecondaryButton
assignment={assignment}
buttonsDisabled={buttonsDisabled}
key={assignment.assignmentSubmissionStatus}
studyId={studyId}
/>
</>
);
Expand All @@ -42,7 +47,7 @@ const PrimaryButton = ({
assignment,
buttonsDisabled,
repositoryLink,
}: AssignmentBoxButtonsProps) => {
}: Omit<AssignmentBoxButtonsProps, "studyId">) => {
const { assignmentSubmissionStatus, submissionFailureType, submissionLink } =
assignment;
const { primaryButtonText } =
Expand Down Expand Up @@ -77,9 +82,11 @@ const PrimaryButton = ({
const SecondaryButton = ({
assignment,
buttonsDisabled,
studyId,
}: Omit<AssignmentBoxButtonsProps, "repositoryLink">) => {
const { assignmentSubmissionStatus, studyDetailId, deadline, committedAt } =
assignment;

if (isDeadlinePassed(deadline)) {
return (
<Button disabled={true} style={buttonStyle}>
Expand All @@ -92,12 +99,28 @@ const SecondaryButton = ({
? buttonTextMap.INITIAL
: buttonTextMap[assignmentSubmissionStatus];

const fetchStudyDashboard = async () => {
const studyDashboard =
await studyDetailApi.getStudyDetailDashboard(studyId);
return studyDashboard;
};

const handleClickSubmissionComplete = async () => {
const response = await studyHistoryApi.submitAssignment(studyDetailId);
if (response.success) {
revalidateTagByName(tags.studyDetailDashboard);
revalidateTagByName(tags.studyHistory);
toast.success("과제 제출이 완료되었어요.");
await revalidateTagByName(tags.studyDetailDashboard);
await revalidateTagByName(tags.studyHistory);
const fetchedStudyDashBoardData = await fetchStudyDashboard();
const currentAssignmentSubmissionStatus =
fetchedStudyDashBoardData?.submittableAssignments.filter(
(item) => item.studyDetailId === studyDetailId
)[0]?.assignmentSubmissionStatus;

if (currentAssignmentSubmissionStatus === "SUCCESS") {
toast.success("과제 제출이 완료되었습니다.");
} else if (currentAssignmentSubmissionStatus === "FAILURE") {
toast.error("과제 제출에 실패했습니다.");
}
}
};

Expand All @@ -106,6 +129,7 @@ const SecondaryButton = ({
committedAt as string
);
const commitText = `최종 수정일자 ${year}년 ${month}월 ${day}일 ${padWithZero(hours)}:${padWithZero(minutes)}`;

return (
<Button
disabled={buttonsDisabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const AssignmentOverviewBox = async ({
assignment={assignment}
buttonsDisabled={buttonsDisabled || !isSubmittable}
repositoryLink={repositoryLink}
studyId={myOngoingStudyInfoData.studyId}
/>
</>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export const RepositorySubmissionBox = ({
if (success) {
revalidateTagByName(tags.studyDetailDashboard);
setRepositorySubmissionStatus("SUBMITTED");
onClose();
}
onClose();
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const StudyApplication = ({ params }: { params: { studyId: number } }) => {
const handleClickApplyButton = async () => {
const result = await studyApplyApi.applyStudy(Number(studyId));
if (result.success) {
revalidateTagByName(tags.studyApply);
revalidateTagByName(tags.myOngoingStudy);
await revalidateTagByName(tags.studyApply);
await revalidateTagByName(tags.myOngoingStudy);
setApplySuccess(true);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const StudyCancel = ({ params }: { params: { studyId: number } }) => {
const result = await studyApplyApi.cancelStudyApplication(Number(studyId));

if (result.success) {
revalidateTagByName(tags.studyApply);
revalidateTagByName(tags.myOngoingStudy);
await revalidateTagByName(tags.studyApply);
await revalidateTagByName(tags.myOngoingStudy);
setCancelSuccess(true);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Flex } from "@styled-system/jsx";
import { Text } from "@wow-class/ui";
import Image from "next/image";

const EmptyStudyApplication = () => {
return (
<Flex
alignItems="center"
direction="column"
gap="xl"
justifyContent="center"
minHeight="calc(100vh - 108px)"
>
<Image
alt="empty-study"
height={140}
src="/images/empty.svg"
width={186}
/>
<Text as="h2" color="sub" typo="h2">
현재 수강할 수 있는 스터디가 없어요
</Text>
</Flex>
);
};

export default EmptyStudyApplication;
19 changes: 12 additions & 7 deletions apps/client/app/(afterLogin)/study-apply/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Space, Text } from "@wow-class/ui";
import { studyApplyApi } from "apis/studyApplyApi";

import EmptyStudyApplication from "./_components/EmptyStudyApplication";
import StudyItem from "./_components/StudyItem";

const StudyApplyPage = async () => {
Expand All @@ -16,13 +17,17 @@ const StudyApplyPage = async () => {
신청 가능한 스터디
</Text>
<Space height={19} />
{studyList?.map((study) => (
<StudyItem
appliedStudyId={appliedStudyId}
key={study.studyId}
study={study}
/>
))}
{studyList.length > 0 ? (
studyList.map((study) => (
<StudyItem
appliedStudyId={appliedStudyId}
key={study.studyId}
study={study}
/>
))
) : (
<EmptyStudyApplication />
)}
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion apps/client/utils/revalidateTagByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import { revalidateTag } from "next/cache";

export const revalidateTagByName = (tag: string) => {
export const revalidateTagByName = async (tag: string) => {
revalidateTag(tag);
};
Loading