Skip to content

Commit

Permalink
feat: 첫 번째 선택된 학생 이름 렌더링
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo-o committed Nov 17, 2024
1 parent 0e88202 commit a1f8a0c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
13 changes: 5 additions & 8 deletions apps/admin/app/students/_components/OutstandingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {

const OutstandingModal = () => {
const study = useAtomValue(studyAtom);
const selectedStudents = useAtomValue(selectedStudentsAtom);
const STUDENTS_NUM = selectedStudents.length;
const { firstStudentName, students } = useAtomValue(selectedStudentsAtom);
const STUDENTS_NUM = students.length;

const [outstandingStudents, setOutstandingStudents] = useAtom(
outstandingStudentsAtom
Expand All @@ -39,7 +39,7 @@ const OutstandingModal = () => {
: studyAchievementApi.deleteStudyAchievement;

const result = await fetch(study.studyId, {
studentIds: selectedStudents,
studentIds: students,
achievementType: achievement,
});

Expand Down Expand Up @@ -79,11 +79,8 @@ const OutstandingModal = () => {
)}

<Text color="sub">
{
// TODO: 가장 앞 사람 정보 요청
/* 이현영 님 외{" "} */
}
<styled.span color="primary">{STUDENTS_NUM}</styled.span>
{firstStudentName} 님 외{" "}
<styled.span color="primary">{STUDENTS_NUM - 1}</styled.span>
</Text>
{enabled ? (
<Button onClick={handleClickOutstanding}>
Expand Down
6 changes: 3 additions & 3 deletions apps/admin/app/students/_components/StudentHeaderButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const StudentsHeaderButtons = () => {
outstandingStudentsAtom
);
const { type, achievement, enabled } = outstandingStudents;
const selectedStudents = useAtomValue(selectedStudentsAtom);
const { students } = useAtomValue(selectedStudentsAtom);

const handleClickCancelButton = () => {
setOutstandingStudents({
Expand All @@ -30,8 +30,8 @@ const StudentsHeaderButtons = () => {
</Button>
<Button
asProp={Link}
disabled={!selectedStudents.length}
href={selectedStudents.length ? "/students/outstanding" : ""}
disabled={!students.length}
href={students.length ? "/students/outstanding" : ""}
size="sm"
>
{achievement && `${outstandingRoundMap[achievement]} ${type}`}
Expand Down
11 changes: 9 additions & 2 deletions apps/admin/app/students/_components/StudentTable/StudentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ const StudentList = ({
if (!studentList.length) return <Text>스터디 수강생이 없어요.</Text>;

const handleChangeSelectedStudents = (rows: number[]) => {
setSelectedStudents(rows);
const firstStudent = studentList.find(
(student) => student.memberId === rows[0]
);

setSelectedStudents({
firstStudentName: firstStudent && firstStudent.name,
students: rows,
});
};

return (
<Table
fullWidth
selectedRowsProp={selectedStudents}
selectedRowsProp={selectedStudents.students}
showCheckbox={enabled}
onChange={handleChangeSelectedStudents}
>
Expand Down
9 changes: 8 additions & 1 deletion apps/admin/app/students/_contexts/StudyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ export type OutstandingStudentsProps = {
enabled: boolean;
};

export type SelectedStudentsProps = {
firstStudentName?: string;
students: number[] | [];
};

export const studyAtom = atom<StudyAtomprops>();
studyIdStore.set(studyAtom, undefined);

export const outstandingStudentsAtom = atom<OutstandingStudentsProps>({
enabled: false,
});

export const selectedStudentsAtom = atom<number[] | []>([]);
export const selectedStudentsAtom = atom<SelectedStudentsProps>({
students: [],
});

export const StudyProvider = ({ children }: PropsWithChildren) => {
return <Provider store={studyIdStore}>{children}</Provider>;
Expand Down

0 comments on commit a1f8a0c

Please sign in to comment.