From 16e78ef982815b10e9e9b62a8319b952e61794b3 Mon Sep 17 00:00:00 2001 From: Lee jin <83453646+j-nary@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:48:35 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Chip,=20dialog=20=EB=B0=B0=ED=8F=AC=20(#938?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Chip 파트 한 개 이슈 대응 (#932) * test: 임시로 Chip 구현 (MDS 문의 필요) * feat: chip 구현 및 반응형 작업 * feat: 전체파트 클릭 로직 + MDS Chip 연결 * docs: 불필요한 파일 삭제 * docs: 불필요한 코드 삭제 * fix: 개별 옵션 해제 시 전체파트 해제 로직 추가 * refactor: 코드리뷰 반영 * refactor: input 높이 반응형 제거 * feat: 모임 안내 모집 대상 chip 변경 * style: 색상변경 * style: QA 반영 * fix: 이슈대응 * fix: Chip 한개 선택 이슈 대응 * fix: Chip 5개 선택 시 이슈 해결 (#934) * feat: 모임 삭제 dialog mds 마이그레이션 (#937) --- package.json | 2 +- pages/edit/index.tsx | 5 +- .../Presentation/JoinablePartsField/index.tsx | 59 +++++++++++++++++++ src/components/form/Presentation/index.tsx | 56 +++++++++--------- src/components/form/TableOfContents/index.tsx | 4 +- .../Information/InformationPanel.tsx | 10 +++- .../Modal/Confirm/HostConfirmModal.tsx | 22 ------- .../meetingDetail/MeetingController/index.tsx | 45 +++++++------- src/constants/option.ts | 4 +- src/data/options.ts | 3 +- src/types/form.ts | 2 +- yarn.lock | 10 ++-- 12 files changed, 133 insertions(+), 89 deletions(-) create mode 100644 src/components/form/Presentation/JoinablePartsField/index.tsx delete mode 100644 src/components/page/meetingDetail/MeetingController/Modal/Confirm/HostConfirmModal.tsx diff --git a/package.json b/package.json index fe44b089..dd03c085 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "@sopt-makers/fonts": "^2.0.1", "@sopt-makers/icons": "^1.0.5", "@sopt-makers/playground-common": "^1.5.2", - "@sopt-makers/ui": "^2.4.2", + "@sopt-makers/ui": "^2.4.4", "@stitches/react": "^1.2.8", "@tanstack/react-query": "^4.10.3", "@types/autosize": "^4.0.3", diff --git a/pages/edit/index.tsx b/pages/edit/index.tsx index b1c4eb50..37f11882 100644 --- a/pages/edit/index.tsx +++ b/pages/edit/index.tsx @@ -73,10 +73,10 @@ const EditPage = () => { const joinableParts = // NOTE: null(디폴트), all(전체) 옵션을 제외한 나머지 옵션 개수와 서버에서 내려온 개수가 같으면 '전체' 옵션이 선택된 것 처럼 여겨져야 한다. // NOTE: 그게 아니라면, 서버에서 저장된 옵션에 더해 null(디폴트) 옵션을 추가해준다. - parts.length - 2 === formData?.joinableParts.length + parts.length - 1 === formData?.joinableParts.length ? parts : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - [parts[0], ...formData!.joinableParts.map(partString => parts.find(part => part.value === partString))]; + [...formData!.joinableParts.map(partString => parts.find(part => part.value === partString))]; formMethods.reset({ ...formData, @@ -94,7 +94,6 @@ const EditPage = () => { isMentorNeeded: formData?.isMentorNeeded, joinableParts, canJoinOnlyActiveGeneration: formData?.canJoinOnlyActiveGeneration, - //targetDesc: formData?.targetDesc, note: formData?.note ?? '', }, }); 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 ( - ( -