Skip to content

Commit 6ce6fa3

Browse files
authored
[EC-220] FE/fix: 학습자 관리 버튼 수정 (#229)
* [EC-220] refactor: 안쓰는 컴포넌트 삭제 * [EC-220] fix: 버튼 수정
1 parent 969778e commit 6ce6fa3

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

client/src/components/tag/Tag.jsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import styles from './Tag.module.css';
33
import { getTagColors, getIsClickable, tagList } from '../../utils/buttonContentList';
44
import DropBoxButton from '../buttons/dropBoxButton/DropBoxButton';
55

6-
export default function Tag({ title, onTagChange }) {
6+
export default function Tag({ title }) {
77
const tagColors = getTagColors(title);
88
const isClickable = getIsClickable(title);
99

1010
// TODO : 관리자 페이지의 학습자 관리 tag에만 사용
1111
const [isOpen, setIsOpen] = useState(false);
12+
const containerRef = useRef(null);
1213

13-
const handleOpenDropBox = () => {
14-
setIsOpen(true);
14+
const handleToggleDropBox = () => {
15+
setIsOpen((prev) => !prev);
1516
};
1617

1718
const handleCloseDropBox = () => {
1819
setIsOpen(false);
1920
};
2021

2122
const handleTagClick = (newTagTitle) => {
22-
onTagChange(newTagTitle);
23+
// TODO : patch 요청
2324
setIsOpen(false);
2425
};
2526

2627
const dropBoxButtonList = tagList.map((item, index) => (
2728
<DropBoxButton key={index} title={item} handleClick={() => handleTagClick(item)} />
2829
));
2930

31+
useEffect(() => {
32+
const handleClickOutside = (event) => {
33+
if (containerRef.current && !containerRef.current.contains(event.target)) {
34+
setIsOpen(false);
35+
}
36+
};
37+
38+
document.addEventListener('mousedown', handleClickOutside);
39+
return () => {
40+
document.removeEventListener('mousedown', handleClickOutside);
41+
};
42+
}, []);
43+
3044
return (
31-
<div className={styles.tagBox}>
45+
<div ref={containerRef} className={styles.tagBox}>
3246
<button
3347
disabled={!isClickable}
34-
onClick={handleOpenDropBox}
35-
// onBlur={handleCloseDropBox}
48+
onClick={handleToggleDropBox}
3649
className={`${styles.tag} ${tagColors ? styles[tagColors] : ''}`}
3750
>
3851
{title}

client/src/pages/Test.jsx

Lines changed: 0 additions & 14 deletions
This file was deleted.

client/src/router/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import StaffStudentManage from '../pages/staffStudentManage/StaffStudentManage';
1515
import TmpLayout from '../layout/TmpLayout';
1616
import { URL_PATHS } from '../constants/urlPaths';
1717
import RoomReservation from '../pages/roomReservation/RoomReservation';
18-
import Test from '../pages/Test';
1918
import AttendanceSheet from '../pages/attendanceSheet/AttendanceSheet';
2019

2120
const router = createBrowserRouter([

0 commit comments

Comments
 (0)