Skip to content

Commit

Permalink
feat: add input in info drinking form
Browse files Browse the repository at this point in the history
  • Loading branch information
ooooorobo committed Dec 22, 2024
1 parent e675a53 commit 741b7a6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions public/locales/ko/common.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"MALE": "",
"FEMALE": "",
"INFO_DRINKING_DRINKER": "합니다",
"INFO_DRINKING_NON_DRINKER": "안합니다",
"INFO_SMOKING_SMOKER": "합니다",
"INFO_SMOKING_NON_SMOKER": "안합니다",
"INFO_SMOKING_ETC": "기타",
Expand Down
4 changes: 3 additions & 1 deletion src/entities/profile/model/myProfileStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Action = {
setReligionName: (description: string) => void;
setHobbies: (hobbies: Hobby[]) => void;
setDrinkingCategory: (value: UserInfoDrinkingDrinkingCategory) => void;
setDrinkingAmount: (value: string) => void;
setSmokingCategory: (value: UserInfoSmokingSmokingCategory) => void;
setSmokingAmount: (value: string) => void;
setIntroduction: (value: string) => void;
Expand Down Expand Up @@ -125,7 +126,8 @@ const createStoreHook = (initialState?: MyProfile) =>
hobbies: [],
setHobbies: (hobbies) => set({ hobbies: hobbies }),
drinking: { drinkingCategory: 'DRINKER', drinkingAmount: '' },
setDrinkingCategory: (value) => set({ drinking: { drinkingCategory: value } }),
setDrinkingCategory: (value) => set({ drinking: { ...get().drinking, drinkingCategory: value } }),
setDrinkingAmount: (value) => set({ drinking: { ...get().drinking, drinkingAmount: value } }),
smoking: {
smokingCategory: 'ETC',
smokingAmount: '',
Expand Down
26 changes: 16 additions & 10 deletions src/processes/my_profile/SmokeAlcoholForm/SmokeAlcoholForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RadioList, RadioMeta } from 'src/shared/ui/RadioList/RadioList';
import { useMyProfileStore } from 'src/entities/profile/model/myProfileStore';
import { DistributedOmit } from '../../../shared/types/distributedOmit';
import { useTranslation } from 'react-i18next';
import { useMemo } from 'react';
import { useMemo, useState } from 'react';
import { useMyProfileFormProcessStore } from '../_store/myProfileFormProcessStore';
import { UserInfoDrinkingDrinkingCategory, UserInfoSmokingSmokingCategory } from 'src/types';

Expand All @@ -14,13 +14,20 @@ const smokingRadioMeta: DistributedOmit<RadioMeta<UserInfoSmokingSmokingCategory
];

const drinkingRadioMeta: DistributedOmit<RadioMeta<UserInfoDrinkingDrinkingCategory>, 'name'>[] = [
{ key: 'DRINKER', allowInput: false },
{ key: 'NON_DRINKER', allowInput: false },
{ key: 'DRINKER', allowInput: true, placeholder: '빈도는 어떻게 되시나요?' },
];

export const SmokeAlcoholForm = () => {
const touchedSteps = useMyProfileFormProcessStore((state) => state.touchedSteps);
const [touchedDrinking, setTouchedDrinking] = useState(() => touchedSteps.has('PROFILE_SMOKE_ALCOHOL'));
const [touchedSmoking, setTouchedSmoking] = useState(() => touchedSteps.has('PROFILE_SMOKE_ALCOHOL'));

const drinkingCategory = useMyProfileStore((state) => state.drinking.drinkingCategory);
const drinkingAmount = useMyProfileStore((state) => state.drinking.drinkingAmount);
const setDrinkingCategory = useMyProfileStore((state) => state.setDrinkingCategory);
const setDrinkingAmount = useMyProfileStore((state) => state.setDrinkingAmount);

const smokingCategory = useMyProfileStore((state) => state.smoking.smokingCategory);
const smokingAmount = useMyProfileStore((state) => state.smoking.smokingAmount);
const setSmokingCategory = useMyProfileStore((state) => state.setSmokingCategory);
Expand All @@ -44,17 +51,14 @@ export const SmokeAlcoholForm = () => {
[t],
);

const addTouchedStep = useMyProfileFormProcessStore((state) => state.addTouchedStep);
const touchedSteps = useMyProfileFormProcessStore((state) => state.touchedSteps);

const onSelectDrinking = (category: UserInfoDrinkingDrinkingCategory) => {
setDrinkingCategory(category);
addTouchedStep('PROFILE_SMOKE_ALCOHOL');
setTouchedDrinking(true);
};

const onSelectSmoking = (category: UserInfoSmokingSmokingCategory) => {
setSmokingCategory(category);
addTouchedStep('PROFILE_SMOKE_ALCOHOL');
setTouchedSmoking(true);
};

return (
Expand All @@ -63,15 +67,17 @@ export const SmokeAlcoholForm = () => {
<legend className={`strong ${styles.Legend}`}>음주 여부</legend>
<RadioList
radioMetaList={drinkingMeta}
selected={touchedSteps.has('PROFILE_SMOKE_ALCOHOL') ? drinkingCategory : null}
selected={touchedDrinking ? drinkingCategory : null}
onSelect={onSelectDrinking}
inputValue={drinkingAmount}
onChangeInputValue={setDrinkingAmount}
/>
</fieldset>{' '}
</fieldset>
<fieldset>
<legend className={`strong ${styles.Legend}`}>흡연 여부</legend>
<RadioList
radioMetaList={meta}
selected={touchedSteps.has('PROFILE_SMOKE_ALCOHOL') ? smokingCategory : null}
selected={touchedSmoking ? smokingCategory : null}
inputValue={smokingAmount}
onSelect={onSelectSmoking}
onChangeInputValue={setSmokingAmount}
Expand Down

0 comments on commit 741b7a6

Please sign in to comment.