Skip to content

Commit 2d85bbb

Browse files
committed
fix: Fix the error that prevented additional options from being saved (kookmin-sw#75)
1 parent 62a6036 commit 2d85bbb

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

src/app/pages/writing-post-page.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,14 @@ export function WritingPostPage() {
605605
});
606606
}, []);
607607

608+
console.log(selectedExtraOptions, {
609+
canPark: selectedExtraOptions.canPark ?? false,
610+
hasAirConditioner: selectedExtraOptions.hasAirConditioner ?? false,
611+
hasRefrigerator: selectedExtraOptions.hasRefrigerator ?? false,
612+
hasWasher: selectedExtraOptions.hasWasher ?? false,
613+
hasTerrace: selectedExtraOptions.hasTerrace ?? false,
614+
});
615+
608616
mutate(
609617
{
610618
imageFilesData: uploadedImages,
@@ -891,12 +899,12 @@ export function WritingPostPage() {
891899
</styles.optionRow>
892900
<styles.option>추가 옵션</styles.option>
893901
<styles.optionRow>
894-
{Object.keys(AdditionalInfoTypeValue).map(option => (
902+
{Object.entries(AdditionalInfoTypeValue).map(([option, value]) => (
895903
<styles.optionButtonContainer key={option}>
896904
<styles.customCheckBox
897-
$isSelected={isExtraOptionSelected(option)}
905+
$isSelected={isExtraOptionSelected(value)}
898906
onClick={() => {
899-
handleExtraOptionClick(option);
907+
handleExtraOptionClick(value);
900908
}}
901909
/>
902910
<span>{option}</span>

src/entities/shared-posts-filter/shared-posts-filter.type.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import { type SelectedExtraOptions } from '@/features/shared';
2+
13
export type AdditionalInfoType =
24
| '주차가능'
35
| '에어컨'
46
| '냉장고'
57
| '세탁기'
68
| '베란다/테라스';
7-
export const AdditionalInfoTypeValue: Record<AdditionalInfoType, string> = {
9+
export const AdditionalInfoTypeValue: Record<
10+
AdditionalInfoType,
11+
keyof SelectedExtraOptions
12+
> = {
813
주차가능: 'canPark',
914
에어컨: 'hasAirConditioner',
1015
냉장고: 'hasRefrigerator',

src/features/shared/shared.hook.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { sharedPostPropState } from './shared.atom';
1818
import { type GetSharedPostDTO } from './shared.dto';
1919
import {
20+
type SelectedExtraOptions,
2021
type CreateSharedPostProps,
2122
type GetSharedPostsProps,
2223
type SelectedOptions,
@@ -136,11 +137,11 @@ export const useSharedPostProps = () => {
136137
restRoomCount,
137138
},
138139
selectedExtraOptions: {
139-
주차가능: data.roomInfo.extraOption.canPark,
140-
에어컨: data.roomInfo.extraOption.hasAirConditioner,
141-
냉장고: data.roomInfo.extraOption.hasRefrigerator,
142-
세탁기: data.roomInfo.extraOption.hasWasher,
143-
'베란다/테라스': data.roomInfo.extraOption.hasTerrace,
140+
canPark: data.roomInfo.extraOption.canPark,
141+
hasAirConditioner: data.roomInfo.extraOption.hasAirConditioner,
142+
hasRefrigerator: data.roomInfo.extraOption.hasRefrigerator,
143+
hasWasher: data.roomInfo.extraOption.hasWasher,
144+
hasTerrace: data.roomInfo.extraOption.hasTerrace,
144145
},
145146
});
146147
};
@@ -149,7 +150,6 @@ export const useSharedPostProps = () => {
149150
optionName: keyof SelectedOptions,
150151
item: string,
151152
) => {
152-
console.log(state.selectedOptions, optionName, item);
153153
setState(prev => ({
154154
...prev,
155155
selectedOptions: {
@@ -159,22 +159,24 @@ export const useSharedPostProps = () => {
159159
}));
160160
};
161161

162-
const handleExtraOptionClick = (option: string) => {
163-
console.log(state.selectedExtraOptions, option);
164-
setState(prev => ({
165-
...prev,
166-
selectedExtraOptions: {
167-
...prev.selectedExtraOptions,
168-
[option]: !prev.selectedExtraOptions[option],
169-
},
170-
}));
162+
const handleExtraOptionClick = (option: keyof SelectedExtraOptions) => {
163+
setState(prev => {
164+
const value = prev.selectedExtraOptions[option] ?? false;
165+
return {
166+
...prev,
167+
selectedExtraOptions: {
168+
...prev.selectedExtraOptions,
169+
[option]: !value,
170+
},
171+
};
172+
});
171173
};
172174

173175
const isOptionSelected = (optionName: keyof SelectedOptions, item: string) =>
174176
state.selectedOptions[optionName] === item;
175177

176-
const isExtraOptionSelected = (item: string) =>
177-
state.selectedExtraOptions[item];
178+
const isExtraOptionSelected = (item: keyof SelectedExtraOptions) =>
179+
state.selectedExtraOptions[item] === true;
178180

179181
return {
180182
...state,

src/features/shared/shared.type.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ export interface SelectedOptions {
2929
floorType?: string;
3030
}
3131

32-
export type SelectedExtraOptions = Record<string, boolean>;
32+
export interface SelectedExtraOptions {
33+
canPark?: boolean;
34+
hasAirConditioner?: boolean;
35+
hasRefrigerator?: boolean;
36+
hasTerrace?: boolean;
37+
hasWasher?: boolean;
38+
}
3339

3440
export interface ImageFile {
3541
url: string;

0 commit comments

Comments
 (0)