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

[Feat] 마이페이지 수료내역 api 연동 #166

Merged
merged 5 commits into from
Jan 5, 2025
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
16 changes: 15 additions & 1 deletion apps/client/apis/studyHistoryApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { fetcher } from "@wow-class/utils";
import { apiPath } from "constants/apiPath";
import { tags } from "constants/tags";
import type { AssignmentHistoryDto } from "types/dtos/studyHistory";
import type {
AssignmentHistoryDto,
CompletedStudyDto,
} from "types/dtos/studyHistory";

export const studyHistoryApi = {
getStudyHistory: async (studyId: number) => {
Expand Down Expand Up @@ -34,4 +37,15 @@ export const studyHistoryApi = {

return { success: response.ok };
},
getMyCompletedStudy: async () => {
const response = await fetcher.get<CompletedStudyDto[]>(
`${apiPath.studyHistory}/me/complete`,
{
next: { tags: [tags.studyHistory] },
cache: "force-cache",
}
);

return response.data;
},
};
149 changes: 149 additions & 0 deletions apps/client/app/(afterLogin)/my-page/_components/CompletedStudy.tsx
SeieunYoo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
"use client";

import { css } from "@styled-system/css";
import { Flex } from "@styled-system/jsx";
import { AwardIcon, Space, StarCheckIcon, Text } from "@wow-class/ui";
import { studyHistoryApi } from "apis/studyHistoryApi";
import Link from "next/link";
import type { ComponentProps, CSSProperties } from "react";
import type { AchievmentType, StudyType } from "types/entities/common/study";
import Table from "wowds-ui/Table";
import Tag from "wowds-ui/Tag";

export const CompletedStudy = async () => {
const data = await studyHistoryApi.getMyCompletedStudy();
if (!data) return null;

return (
<Table fullWidth>
<Table.Thead>
<Table.Th>스터디 이름 </Table.Th>
<Table.Th>멘토 </Table.Th>
<Table.Th>학기</Table.Th>
<Table.Th>코스 기간 </Table.Th>
<Table.Th>수료 </Table.Th>
<Table.Th>우수 </Table.Th>
</Table.Thead>
<Table.Tbody>
{data.map(
({
studyId,
title,
studyType,
notionLink,
introduction,
mentorName,
academicYear,
semesterType,
totalWeek,
studyHistoryStatus,
achievements,
}) => (
<div key={studyId}>
<Table.Tr value={studyId}>
<Table.Td style={tdStyle}>
<Flex>
<Text typo="h3">{title}</Text>
<Tag
color={curriculumColors[studyType] ?? "green"}
variant="solid1"
>
{studyType}
</Tag>
</Flex>
{introduction && (
<Link
className={introductionLinkTextStyle}
href={notionLink ?? ""}
target="_blank"
>
<Text color="sub" typo="body2">
{introduction}
</Text>
</Link>
)}
</Table.Td>
<Table.Td style={tdStyle}>
<Text className={mentorTextstyle}>{mentorName} 멘토</Text>
</Table.Td>
<Table.Td style={tdStyle}>
<Text>
{academicYear}-{semesterType === "FIRST" ? "1" : "2"}
</Text>
</Table.Td>
<Table.Td style={tdStyle}>
<Text>{totalWeek}주 코스</Text>
</Table.Td>
<Table.Td style={tdStyle}>
{studyHistoryStatus === "COMPLETED" ? (
<StarCheckIcon checked={true} />
) : (
<Text className={emptyTextStyle}>-</Text>
)}
</Table.Td>
<Table.Td style={tdStyle}>
<Flex gap="10px">
<AchievementIcons achievements={achievements} />
</Flex>
</Table.Td>
</Table.Tr>
<Space height={16} />
</div>
)
)}
</Table.Tbody>
</Table>
);
};

const AchievementIcons = ({ achievements }: { achievements: string[] }) => {
const achievementTypes: AchievmentType[] = [
"FIRST_ROUND_OUTSTANDING_STUDENT",
"SECOND_ROUND_OUTSTANDING_STUDENT",
];

const isAchievment = achievementTypes.some((type) =>
achievements.includes(type)
);

return isAchievment ? (
<>
{achievementTypes.map(
(type) =>
achievements.includes(type) && (
<AwardIcon disabled={false} key={type} />
)
)}
</>
) : (
<Text className={emptyTextStyle}>-</Text>
);
};

const curriculumColors: Record<StudyType, ComponentProps<typeof Tag>["color"]> =
{
"과제 스터디": "green",
"온라인 스터디": "blue",
"오프라인 스터디": "yellow",
};

const introductionLinkTextStyle = css({
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
textDecoration: "underline",
});

const mentorTextstyle = css({
display: "flex",
alignItems: "center",
});

const tdStyle: CSSProperties = {
paddingBottom: "20px",
paddingTop: "16px",
};

const emptyTextStyle = css({
paddingLeft: "5px",
});
3 changes: 3 additions & 0 deletions apps/client/app/(afterLogin)/my-page/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Space, Text } from "@wow-class/ui";

import { CompletedStudy } from "./_components/CompletedStudy";
import { MyInfoBox } from "./_components/MyInfoBox";

const MyPage = () => {
Expand All @@ -8,6 +9,8 @@ const MyPage = () => {
<Text typo="h1">마이 페이지</Text>
<Space height={16} />
<MyInfoBox />
<Space height={64} />
<CompletedStudy />
</>
);
};
Expand Down
15 changes: 15 additions & 0 deletions apps/client/types/dtos/studyHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
AssignmentSubmissionFailureType,
AssignmentSubmissionStatusType,
} from "types/entities/common/assignment";
import type { AchievmentType, StudyType } from "types/entities/common/study";

export interface AssignmentHistoryDto {
assignmentHistoryId: number;
Expand All @@ -15,3 +16,17 @@ export interface AssignmentHistoryDto {
submissionFailureType: AssignmentSubmissionFailureType;
week: number;
}

export interface CompletedStudyDto {
studyId: number;
academicYear: number;
semesterType: "FIRST" | "SECOND";
title: string;
studyType: StudyType;
notionLink?: string;
introduction?: string;
mentorName: string;
totalWeek: number;
studyHistoryStatus: "NONE" | "COMPLETED";
achievements: Array<AchievmentType>;
}
3 changes: 3 additions & 0 deletions apps/client/types/entities/common/study.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export type StudyType = "과제 스터디" | "온라인 스터디" | "오프라인 스터디";
export type AchievmentType =
| "FIRST_ROUND_OUTSTANDING_STUDENT"
| "SECOND_ROUND_OUTSTANDING_STUDENT";
Loading