Skip to content

Commit

Permalink
fix: do not repeat chip
Browse files Browse the repository at this point in the history
  • Loading branch information
ooooorobo committed Dec 5, 2024
1 parent d906bcb commit 6e49b8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/processes/my_profile/QuestionForm/PetForm/PetForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const makeItem = (name: string) => ({
const hasItem = (itemList: { name: string }[], targetItem: { name: string }) =>
itemList.some((item) => item.name === targetItem.name);

const isSameItem = (a: { name: string }, b: { name: string }) => a.name === b.name;

export const PetForm = () => {
const name = useProfileFirstName();
const { pets, setPets } = useMyProfileStore(({ pets, setPets }) => ({ pets, setPets }));
Expand All @@ -39,6 +41,7 @@ export const PetForm = () => {
selectedList={selectedPetList}
setSelectedList={onSelectPet}
hasItem={hasItem}
isSameItem={isSameItem}
makeItem={makeItem}
customInputTitle={'추가 할 반려동물을 입력해주세요.'}
customInputPlaceholder={'ex. 구피, 기니피그...'}
Expand Down
4 changes: 3 additions & 1 deletion src/shared/ui/ChipList/ChipList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const ChipList = <T extends { name: string }>({
customInputTitle,
customInputPlaceholder,
}: Props<T>) => {
const [customList, setCustomList] = useState<T[]>(selectedList.filter((item) => !defaultList.includes(item)));
const [customList, setCustomList] = useState<T[]>(
selectedList.filter((item) => !defaultList.some((d) => d.name === item.name)),
);

const [openInputBottomSheet, setOpenInputBottomSheet] = useState(false);

Expand Down

0 comments on commit 6e49b8d

Please sign in to comment.