From 86b929224f5a0f4870ffaca106474f28c04def0e Mon Sep 17 00:00:00 2001 From: Lee jin <83453646+j-nary@users.noreply.github.com> Date: Mon, 14 Oct 2024 21:29:00 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Chip=20=ED=95=9C=EA=B0=9C=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D=20=EC=9D=B4=EC=8A=88=20=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presentation/JoinablePartsField/index.tsx | 59 +++++++++++++++++++ src/components/form/Presentation/index.tsx | 56 +++++++++--------- .../Information/InformationPanel.tsx | 10 +++- src/constants/option.ts | 4 +- src/data/options.ts | 3 +- 5 files changed, 98 insertions(+), 34 deletions(-) create mode 100644 src/components/form/Presentation/JoinablePartsField/index.tsx diff --git a/src/components/form/Presentation/JoinablePartsField/index.tsx b/src/components/form/Presentation/JoinablePartsField/index.tsx new file mode 100644 index 00000000..24cedf52 --- /dev/null +++ b/src/components/form/Presentation/JoinablePartsField/index.tsx @@ -0,0 +1,59 @@ +import { Option } from '@components/form/Select/OptionItem'; +import { parts } from '@data/options'; +import { Chip } from '@sopt-makers/ui'; + +interface JoinablePartsFieldProps { + value: Option[]; + onChange: (newSelectedParts: Option[]) => void; +} + +const JoinablePartsField = ({ value, onChange }: JoinablePartsFieldProps) => { + const handleClick = (selectedOption: Option) => { + const isValidValue = Array.isArray(value); + let updatedParts = isValidValue ? [...value] : []; + + // 'all' 옵션을 클릭했을 때 처리 + if (selectedOption.value === 'all') { + // 전체 옵션이 이미 선택되어 있으면 해제, 아니면 전체 선택 + updatedParts = isValidValue && value.some(part => part.value === 'all') ? [] : parts; + } else { + // 개별 옵션을 선택할 때 + if (isValidValue && value.some(part => part.value === selectedOption.value)) { + // 이미 선택된 항목이면 해제 + updatedParts = updatedParts.filter(part => part.value !== selectedOption.value); + } else { + // 선택되지 않은 항목이면 추가 + updatedParts.push(selectedOption); + } + + // 개별 옵션 해제 시 전체 옵션도 해제 + if (updatedParts.some(part => part.value === 'all') && updatedParts.length < parts.length) { + updatedParts = updatedParts.filter(part => part.value !== 'all'); + } + + // 모든 개별 파트가 선택되었으면 'all' 옵션도 활성화 + if (updatedParts.length === parts.length - 1) { + updatedParts.push(parts[0]); // 'all'을 활성화 + } + } + + onChange(updatedParts); + }; + + return ( + <> + {parts.map(part => ( + selected.value === part.value)} + onClick={() => handleClick(part)} + key={part.value} + style={{ width: '80px' }} + > + {part.label} + + ))} + + ); +}; + +export default JoinablePartsField; diff --git a/src/components/form/Presentation/index.tsx b/src/components/form/Presentation/index.tsx index 360582cc..f90eab35 100644 --- a/src/components/form/Presentation/index.tsx +++ b/src/components/form/Presentation/index.tsx @@ -13,7 +13,6 @@ import TextInput from '../TextInput'; import ImagePreview from './ImagePreview'; import { MAX_FILE_SIZE } from '@type/form'; import NeedMentor from '../CheckBox/NeedMentor'; -import { parts } from '@data/options'; import { useRouter } from 'next/router'; import { getPresignedUrl, uploadImage } from '@api/API_LEGACY/meeting'; import { imageS3Bucket } from '@constants/url'; @@ -26,6 +25,7 @@ import { IconAlertCircle } from '@sopt-makers/icons'; import { useDialog } from '@sopt-makers/ui'; import sopt_schedule_tooltip from 'public/assets/images/sopt_schedule_tooltip.png'; import BubblePointIcon from 'public/assets/svg/bubble_point.svg'; +import JoinablePartsField from '@components/form/Presentation/JoinablePartsField'; interface PresentationProps { submitButtonLabel: React.ReactNode; @@ -431,23 +431,24 @@ function Presentation({ }; return ( - ( -