Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/components/Auth/SignUp/helper/HelperInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ export default function HelperInfo() {

<FormField label='성별' required className='mb-5'>
<Radio cols={2} onValueChange={(value) => setHelperInfoField('gender', value)}>
<RadioItem value={false}>남성</RadioItem>
<RadioItem value={true}>여성</RadioItem>
<RadioItem value={false} checked={signUpForm.helperInfo.gender === false}>
남성
</RadioItem>
<RadioItem value={true} checked={signUpForm.helperInfo.gender === true}>
여성
</RadioItem>
</Radio>
{!isFirstCheck && !gender && (
<p className='text-start text-sm text-[var(--required-red)] font-medium'>
Expand Down Expand Up @@ -117,8 +121,12 @@ export default function HelperInfo() {

<FormField label='차량소유여부' required className='mb-5'>
<Radio cols={2} onValueChange={(value) => setHelperInfoField('carOwnYn', value)}>
<RadioItem value={true}>예</RadioItem>
<RadioItem value={false}>아니오</RadioItem>
<RadioItem value={true} checked={signUpForm.helperInfo.carOwnYn === true}>
</RadioItem>
<RadioItem value={false} checked={signUpForm.helperInfo.carOwnYn === false}>
아니오
</RadioItem>
</Radio>
{!isFirstCheck && !carOwnYn && (
<p className='text-start text-sm text-[var(--required-red)] font-medium'>
Expand All @@ -129,8 +137,12 @@ export default function HelperInfo() {

<FormField label='치매교육 이수 여부' required className='mb-5'>
<Radio cols={2} onValueChange={(value) => setHelperInfoField('eduYn', value)}>
<RadioItem value={true}>예</RadioItem>
<RadioItem value={false}>아니오</RadioItem>
<RadioItem value={true} checked={signUpForm.helperInfo.eduYn === true}>
</RadioItem>
<RadioItem value={false} checked={signUpForm.helperInfo.eduYn === false}>
아니오
</RadioItem>
</Radio>
{!isFirstCheck && !eduYn && (
<p className='text-start text-sm text-[var(--required-red)] font-medium'>
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/custom/multiRadio.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const Radio = ({ className, children, onValueChange, cols, multiple = false, ...
{...props}
>
{children.map((child, idx) => {
let value = child.props.value || child.props.children;
let value = child.props.value ?? child.props.children;

return child
? React.cloneElement(child, {
key: idx,
onClick: () => {
handleChecked(value);
},
checked: multiple ? checkedItems.includes(value) : checkedItems === value,
// checked: multiple ? checkedItems.includes(value) : checkedItems === value,
})
: null;
})}
Expand All @@ -41,7 +41,7 @@ const Radio = ({ className, children, onValueChange, cols, multiple = false, ...
};

const RadioItem = ({ className, children, value, checked, ...props }) => {
const radioValue = value || children;
const radioValue = value ?? children;
return (
<button type='button' role='radio' value={radioValue} {...props}>
<div
Expand Down
134 changes: 56 additions & 78 deletions src/store/helper/useHelperAccoutStore.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,64 @@
import { create } from 'zustand';
import { persist, devtools } from 'zustand/middleware';
import { persist } from 'zustand/middleware';

// const useHelperAccountStore = create(
// persist((set) => ({
// helper: {
// id: 1,
// userEmail: 'emailAddress@gmail.com',
// name: 'tempName',
// phone: '010-0000-0000',
// addressDetail: '서울특별시 강남구',
// certificates: [],
// carOwnYn: true,
// eduYn: false,
// wage: null,
// wageState: null,
// },
const useHelperAccountStore = create((set) => ({
helper: {
id: 1,
userEmail: 'emailAddress@gmail.com',
name: 'tempName',
phone: '010-0000-0000',
addressDetail: '서울특별시 강남구',
img: null,
helperWorkLocation: [],
helperWorkTime: [],
careLevel: 0,
inmateState: 0,
workType: 0,
careGender: 0,
serviceMeal: 0,
serviceMobility: 0,
serviceDaily: 0,
certificates: [
{
certName: '',
certNum: '',
certDateIssue: null,
certSerialNum: null,
},
],
carOwnYn: true,
eduYn: false,
wage: null,
wageState: null,
introduce: '',
careExperience: false,
wageNegotiation: null,
},

// setPart: (newPart) => set((state) => ({ helper: { ...state.helper, ...newPart } })),
// setHelper: (newInfo) => set(() => ({ helper: newInfo })),
// })),
// );
workTypeNames: [],

const useHelperAccountStore = create(
devtools((set) => ({
helper: {
id: 1,
userEmail: 'emailAddress@gmail.com',
name: 'tempName',
phone: '010-0000-0000',
addressDetail: '서울특별시 강남구',
img: null,
helperWorkLocation: [],
helperWorkTime: [],
careLevel: 0,
inmateState: 0,
workType: 0,
careGender: 0,
serviceMeal: 0,
serviceMobility: 0,
serviceDaily: 0,
certificates: [
{
certName: '',
certNum: '',
certDateIssue: null,
certSerialNum: null,
},
],
carOwnYn: true,
eduYn: false,
wage: null,
wageState: null,
introduce: '',
careExperience: false,
wageNegotiation: null,
},
setPart: (newPart) => set((state) => ({ helper: { ...state.helper, ...newPart } })),
setHelper: (newInfo) => set(() => ({ helper: newInfo })),

workTypeNames: [],
addWorkTypeNames: (newNames) =>
set((state) => ({ workTypeNames: [...state.workTypeNames, newNames] })),
deleteWorkTypeName: (removingItem) =>
set((state) => ({
workTypeNames: state.workTypeNames.filter((item) => item !== removingItem),
})),
setWorkTypeNames: (newArr) => set({ workTypeNames: newArr }),

setPart: (newPart) => set((state) => ({ helper: { ...state.helper, ...newPart } })),
setHelper: (newInfo) => set(() => ({ helper: newInfo })),

addWorkTypeNames: (newNames) =>
set((state) => ({ workTypeNames: [...state.workTypeNames, newNames] })),
deleteWorkTypeName: (removingItem) =>
set((state) => ({
workTypeNames: state.workTypeNames.filter((item) => item !== removingItem),
})),
setWorkTypeNames: (newArr) => set({ workTypeNames: newArr }),

addCertificate: (newItem) =>
set((state) => ({
helper: { ...state.helper, certificates: [...state.helper.certificates, newItem] },
})),
deleteCertificate: (deleted) =>
set((state) => ({
helper: {
...state.helper,
certificates: state.helper.certificates.filter((x) => x.certName !== deleted),
},
})),
})),
);
addCertificate: (newItem) =>
set((state) => ({
helper: { ...state.helper, certificates: [...state.helper.certificates, newItem] },
})),
deleteCertificate: (deleted) =>
set((state) => ({
helper: {
...state.helper,
certificates: state.helper.certificates.filter((x) => x.certName !== deleted),
},
})),
}));

export default useHelperAccountStore;
145 changes: 71 additions & 74 deletions src/store/suho/useHelperLocationStore.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,88 @@
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';

const useHelperLocationStore = create(
devtools((set, get) => ({
selectedDistricts: {},
const useHelperLocationStore = create((set, get) => ({
selectedDistricts: {},

// 지역 설정
setDistricts: (districts) => set({ selectedDistricts: districts }),
// 지역 설정
setDistricts: (districts) => set({ selectedDistricts: districts }),

// 특정 도시의 구/군 추가
addDistrict: (city, district, subDistrict) =>
set((state) => {
if (
city in state.selectedDistricts &&
district in state.selectedDistricts[city] &&
subDistrict in state.selectedDistricts[city][district]
) {
return state;
}
return {
selectedDistricts: {
...state.selectedDistricts,
[city]: {
...state.selectedDistricts[city],
[district]: [...(state.selectedDistricts[city]?.[district] || []), subDistrict],
},
},
};
}),

// 특정 도시의 구/군 제거
removeDistrict: (city, district, subDistrict) =>
set((state) => {
const updatedDistricts = {
// 특정 도시의 구/군 추가
addDistrict: (city, district, subDistrict) =>
set((state) => {
if (
city in state.selectedDistricts &&
district in state.selectedDistricts[city] &&
subDistrict in state.selectedDistricts[city][district]
) {
return state;
}
return {
selectedDistricts: {
...state.selectedDistricts,
[city]: {
...state.selectedDistricts[city],
[district]:
state.selectedDistricts[city]?.[district]?.filter((d) => d !== subDistrict) || [],
[district]: [...(state.selectedDistricts[city]?.[district] || []), subDistrict],
},
};
},
};
}),

// 특정 도시의 구/군 제거
removeDistrict: (city, district, subDistrict) =>
set((state) => {
const updatedDistricts = {
...state.selectedDistricts,
[city]: {
...state.selectedDistricts[city],
[district]:
state.selectedDistricts[city]?.[district]?.filter((d) => d !== subDistrict) || [],
},
};

// 만약 특정 구/군이 빈 배열이 되면 제거
if (updatedDistricts[city][district].length === 0) {
delete updatedDistricts[city][district];
}
// 만약 특정 구/군이 빈 배열이 되면 제거
if (updatedDistricts[city][district].length === 0) {
delete updatedDistricts[city][district];
}

// 만약 특정 도시가 완전히 빈 객체가 되면 제거
if (Object.keys(updatedDistricts[city]).length === 0) {
delete updatedDistricts[city];
}
// 만약 특정 도시가 완전히 빈 객체가 되면 제거
if (Object.keys(updatedDistricts[city]).length === 0) {
delete updatedDistricts[city];
}

return { selectedDistricts: updatedDistricts };
}),
return { selectedDistricts: updatedDistricts };
}),

getTotalSelectedCount: () => {
const { selectedDistricts } = get();
return Object.values(selectedDistricts).reduce(
(total, districts) =>
total +
Object.values(districts).reduce(
(subTotal, subDistricts) => subTotal + subDistricts.length,
0,
),
0,
);
},
getTotalSelectedCount: () => {
const { selectedDistricts } = get();
return Object.values(selectedDistricts).reduce(
(total, districts) =>
total +
Object.values(districts).reduce(
(subTotal, subDistricts) => subTotal + subDistricts.length,
0,
),
0,
);
},

// 초기화
resetDistricts: () => set({ selectedDistricts: {} }),
// 초기화
resetDistricts: () => set({ selectedDistricts: {} }),

// ✅ 선택된 지역 정보를 텍스트로 변환하는 selector 함수 (스타일 수정됨)
// getFormattedLocation: () => {
// const selectedDistricts = get().selectedDistricts;
// if (Object.keys(selectedDistricts).length === 0) {
// return [];
// }
// ✅ 선택된 지역 정보를 텍스트로 변환하는 selector 함수 (스타일 수정됨)
// getFormattedLocation: () => {
// const selectedDistricts = get().selectedDistricts;
// if (Object.keys(selectedDistricts).length === 0) {
// return [];
// }

// return Object.entries(selectedDistricts).flatMap(([city, districts]) => {
// // flatMap 사용
// return Object.entries(districts).map(([district, subDistricts]) => {
// const subDistrictNames = subDistricts.join(", ");
// return `${city} > ${district} (${subDistrictNames})`;
// });
// });
// },
})),
);
// return Object.entries(selectedDistricts).flatMap(([city, districts]) => {
// // flatMap 사용
// return Object.entries(districts).map(([district, subDistricts]) => {
// const subDistrictNames = subDistricts.join(", ");
// return `${city} > ${district} (${subDistrictNames})`;
// });
// });
// },
}));

export default useHelperLocationStore;