-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
모임 개설 대상 파트 Chip 으로 변경 #914
Changes from 6 commits
4207f00
a88d7d0
ccd3278
db887c8
ed28832
9e69686
e5b285c
231fdf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Option } from '@components/form/Select/OptionItem'; | ||
import { parts } from '@data/options'; | ||
import { Chip } from '@sopt-makers/ui'; | ||
import { useState, useEffect } from 'react'; | ||
|
||
interface JoinablePartsFieldProps { | ||
value: Option[]; | ||
onChange: (newSelectedParts: Option[]) => void; | ||
} | ||
|
||
const JoinablePartsField = ({ value, onChange }: JoinablePartsFieldProps) => { | ||
const [selectedParts, setSelectedParts] = useState<Option[]>([]); | ||
|
||
useEffect(() => { | ||
if (Array.isArray(value)) { | ||
setSelectedParts(value); // value prop이 변경되면 상태 동기화 | ||
} | ||
}, [value]); | ||
|
||
const handleClick = (selectedOption: Option) => { | ||
let updatedParts = [...selectedParts]; | ||
|
||
// 'all' 옵션을 클릭했을 때 처리 | ||
if (selectedOption.value === 'all') { | ||
if (selectedParts.some(part => part.value === 'all')) { | ||
// 전체 옵션이 이미 선택되어 있으면 해제 | ||
updatedParts = []; | ||
} else { | ||
// 전체 옵션을 선택하면 모든 부분을 선택 | ||
updatedParts = parts; | ||
} | ||
} else { | ||
// 개별 옵션을 선택할 때 | ||
if (selectedParts.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]); | ||
} | ||
} | ||
|
||
setSelectedParts(updatedParts); | ||
onChange(updatedParts); // 선택된 파트의 value만 전달 | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드가 조금 verbose 한 면이 있어서, 리팩토링을 해보면 좋을 것 같아! 지금 진이는, value 라는 사용자 입력 값을 useEffect 를 이용해서 지켜보면서, setState 를 해주고 있는데, 관점을 바꿔서 사용자 이벤트를 기반으로 리팩토링해보면 좋지 않을까 하는 생각이야~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 피드백 고마오 !! 코드리뷰 반영했는데 한 번 확인해줄 수 있어 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 훨씬 깔끔해진 거 같애! 충돌만 잡고 머지해보자~! |
||
|
||
return ( | ||
<> | ||
{parts.map(part => ( | ||
<Chip | ||
active={selectedParts.some(selected => selected.value === part.value)} | ||
onClick={() => handleClick(part)} | ||
key={part.value} | ||
style={{ width: '80px' }} | ||
> | ||
{part.label} | ||
</Chip> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default JoinablePartsField; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,11 @@ export const generationOptions = [ | |
]; | ||
|
||
export const parts = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 options 의 part 는 여기에서만 쓰이는 아이일까? 다른 곳에서도 쓰인다면 그곳에서도 잘 동작하는지 확인이 필요할 거 같애~! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ label: '대상 파트', value: null }, | ||
{ label: '전체', value: 'all', order: 1 }, | ||
{ label: '전체파트', value: 'all', order: 1 }, | ||
{ label: '기획', value: 'PM', order: 2 }, | ||
{ label: '디자인', value: 'DESIGN', order: 3 }, | ||
{ label: '웹', value: 'WEB', order: 4 }, | ||
{ label: '안드로이드', value: 'ANDROID', order: 5 }, | ||
{ label: 'iOS', value: 'IOS', order: 6 }, | ||
{ label: '서버', value: 'SERVER', order: 7 }, | ||
{ label: 'iOS', value: 'IOS', order: 6 }, | ||
{ label: 'Android', value: 'ANDROID', order: 5 }, | ||
{ label: '웹', value: 'WEB', order: 4 }, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
콘솔 제거 고마워~!