Skip to content
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
18 changes: 18 additions & 0 deletions apps/admin/src/entities/member/api/getScore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import instance from "@repo/api";
import { AxiosError } from "axios";
import { toast } from "sonner";
import type { ScoreResponse } from "../model/score";

export const getScore = async (
id: string
): Promise<ScoreResponse | undefined> => {
try {
const res = await instance.get(`/score/${id}`);
return res.data as ScoreResponse;
} catch (error) {
if (error instanceof AxiosError) {
toast.error("์ ์ˆ˜ ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค");
}
}
return undefined;
};
9 changes: 9 additions & 0 deletions apps/admin/src/entities/member/model/score.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface ScoreResponse {
totalScore: number;
scores: Score[];
}

export interface Score {
categoryName: string;
value: number;
}
11 changes: 11 additions & 0 deletions apps/admin/src/entities/member/model/useGetScore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useQuery } from "@tanstack/react-query";
import { getScore } from "../api/getScore";
import type { ScoreResponse } from "./score";

export const useGetScore = (id: string) => {
return useQuery<ScoreResponse | undefined>({
queryKey: ["score", id],
queryFn: () => getScore(id),
enabled: !!id,
});
};
46 changes: 46 additions & 0 deletions apps/admin/src/entities/member/ui/scoreModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use client";

import { Button } from "@repo/shared/button";
import Card from "@repo/shared/card";
import List from "@repo/shared/list";
import { useGetScore } from "../model/useGetScore";
import { getCategoryName } from "@repo/utils/handleCategory";

interface ScoreModalProps {
close: () => void;
show: boolean;
id: string;
}

export default function ScoreModal({ show, close, id }: ScoreModalProps) {
const { data } = useGetScore(id as string);
if (!show) return null;
return (
<div className="fixed inset-0 z-10 bg-[rgba(17,17,17,0.2)] flex items-center justify-center">
<div className="gap-6 flex flex-col bg-white z-20 rounded-[1.25rem] px-[2.45rem] py-[2.25rem] max-sm:w-[20.5rem]">
<h3 className="text-tropicalblue-700 text-titleSmall">๋ถ€๋ถ„์ ์ˆ˜</h3>
<List className="p-0">
{data &&
data?.scores.map((v) => {
return (
<Card
key={v.categoryName}
front={
(() => {
const transformedCategoryName = getCategoryName(v.categoryName).replace(/^[^-]*-/, "");
return transformedCategoryName.length > 20
? transformedCategoryName.slice(0, 20) + "..."
: transformedCategoryName;
})()
}
id={v.categoryName}
back={v.value}
/>
);
})}
</List>
<Button variant="skyblue" onClick={close} label="๋’ค๋กœ๊ฐ€๊ธฐ" />
</div>
</div>
);
}
33 changes: 23 additions & 10 deletions apps/admin/src/widgets/member/ui/information.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import { Button } from "@repo/shared/button";
import { useRouter } from "next/navigation";
import { useCallback } from "react";
import { useCallback, useState } from "react";

import { useMember } from "@/entities/member/model/memberContext";
import ScoreModal from "@/entities/member/ui/scoreModal";

export default function Information() {
const [modal, setModal] = useState(false);
const R = useRouter();
const { member: student } = useMember();

Expand All @@ -18,6 +20,13 @@ export default function Information() {
R.push(`/score/${student?.email}`);
}, [R, student?.email]);

const open = useCallback(() => {
setModal(true);
}, []);
const close = useCallback(() => {
setModal(false);
}, []);

if (student === undefined) {
return <p className="text-center m-8">๋กœ๋”ฉ์ค‘...</p>;
}
Expand All @@ -31,19 +40,23 @@ export default function Information() {
<span className="text-body1 text-gray-600">{student.name}</span>
<small className="text-body2 text-gray-600">{`${student.grade}ํ•™๋…„ ${student.classNumber}๋ฐ˜ ${student.number}๋ฒˆ`}</small>
</div>
<div className="text-tropicalblue-700 mt-[1.25rem] md:mb-[2.56rem] sm:mb-[1.75rem] mb-[3rem] text-titleMedium h-[32rem] max-md:h-[10rem] max-lg:h-[10rem] flex items-center justify-center rounded-[0.75rem] bg-white">
<div
onClick={open}
className="text-tropicalblue-700 cursor-pointer mt-[1.25rem] md:mb-[2.56rem] sm:mb-[1.75rem] mb-[3rem] text-titleMedium h-[32rem] max-md:h-[10rem] max-lg:h-[10rem] flex items-center justify-center rounded-[0.75rem] bg-white"
>
{student.totalScore + "์ "}
</div>
</div>
<div className="flex flex-col gap-[0.75rem]">
<Button
label="๊ธ€ ๋ณด๋Ÿฌ๊ฐ€๊ธฐ"
variant="blue"
onClick={handleCheckPost}
/>
<Button label="์ ์ˆ˜ ๊ด€๋ฆฌ" variant="skyblue" onClick={handleScore} />
</div>
</div>
<div className="flex flex-col gap-[0.75rem]">
<Button label="๊ธ€ ๋ณด๋Ÿฌ๊ฐ€๊ธฐ" variant="blue" onClick={handleCheckPost} />
<Button label="์ ์ˆ˜ ๊ด€๋ฆฌ" variant="skyblue" onClick={handleScore} />
</div>
<ScoreModal
show={modal}
id={student?.email?.split("@")[0]?.slice(1) as string}
close={close}
/>
</div>
);
}
4 changes: 2 additions & 2 deletions packages/shared/src/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Filtered } from "./filtered.tsx";

interface ListProps {
children: React.ReactNode;
title: string;
title?: string;
className?: string;
isFilter?: boolean;
onClick?: () => void;
Expand All @@ -25,7 +25,7 @@ const List = ({
<h4
className={`${className ?? ""} text-tropicalblue-700 text-titleSmall`}
>
{title}
{title ?? ""}
</h4>
{isFilter ? (
<span className="cursor-pointer" onClick={onClick}>
Expand Down
Loading