Skip to content

Commit

Permalink
πŸ› fix: 고용주 νšŒμ›κ°€μž… 및 μ •λ³΄μˆ˜μ • api μˆ˜μ • #73
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeona01 committed Nov 1, 2024
1 parent 89ea791 commit bf22faf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const withdraw = async (): Promise<RESTYPE<null>> => {

// 고용주 νšŒμ›κ°€μž…
export const signUpEmployer = async (
signupInfo: EmployerRegistrationRequest,
signupInfo: FormData,
): Promise<RESTYPE<SignUpResponse>> => {
const response = await api.post(`/auth/owners`, signupInfo);
return response.data;
Expand Down
17 changes: 16 additions & 1 deletion src/components/Employer/EditProfile/EmployerEditInputSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type EmployerEditInputSectionProps = {
newEmployData: EmployerProfileRequestBody;
setNewEmployData: (newData: EmployerProfileRequestBody) => void;
setLogoFile: (file: File | undefined) => void;
initialPhonNum: string;
};

const enum LogoType {
Expand All @@ -31,6 +32,7 @@ const EmployerEditInputSection = ({
newEmployData,
setNewEmployData,
setLogoFile,
initialPhonNum,
}: EmployerEditInputSectionProps) => {
// μ£Όμ†Œ κ²€μƒ‰μš© input μ €μž₯ν•˜λŠ” state
const [addressInput, setAddressInput] = useState('');
Expand All @@ -49,6 +51,18 @@ const EmployerEditInputSection = ({
middle: '',
end: '',
});

useEffect(() => {
if (initialPhonNum) {
const splitPhoneNum = initialPhonNum.split('-');
setPhoneNum({
start: splitPhoneNum[0] || '',
middle: splitPhoneNum[1] || '',
end: splitPhoneNum[2] || '',
});
}
}, [initialPhonNum]);

const [logoStatus, setLogoStatus] = useState<LogoType>(LogoType.NONE);
const [selectedImage, setSelectedImage] = useState<string>();
// ν˜„μž¬ μ’Œν‘œ κΈ°μ€€ μ£Όμ†Œ νšλ“
Expand Down Expand Up @@ -143,14 +157,15 @@ const EmployerEditInputSection = ({
// 둜고 선택
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) {
if (file && file.type.startsWith('image/')) {
const reader = new FileReader();
reader.onloadend = () => {
setSelectedImage(reader.result as string);
setLogoFile(file);
setLogoStatus(LogoType.SELECTED);
};
reader.readAsDataURL(file);
console.log(file);
}
};
// Giggle 기본둜고 선택 handler
Expand Down
25 changes: 14 additions & 11 deletions src/pages/Employer/EditProfile/EmployerEditProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,29 @@ const EmployerEditProfilePage = () => {

const handleSubmit = () => {
if (isValidEmployerProfile(newEmployData)) {
// 둜고 이미지 λ³€κ²½ μ—¬λΆ€
if (originalData?.logo_img_url === logoFile) {
setNewEmployData({ ...newEmployData, is_icon_img_changed: false });
} else {
setNewEmployData({ ...newEmployData, is_icon_img_changed: true });
}
// patch ν›… 호좜
// 이미지 λ³€κ²½ μ—¬λΆ€λ₯Ό μ„€μ •ν•˜μ—¬ ν”„λ‘œν•„ μˆ˜μ • 데이터λ₯Ό μ—…λ°μ΄νŠΈν•©λ‹ˆλ‹€.
const updatedEmployData = {
...newEmployData,
is_icon_img_changed: Boolean(logoFile),
};

const formData = new FormData();
// 이미지가 μžˆμ„ 경우 FormData에 μΆ”κ°€

// 이미지 파일이 μžˆμ„ 경우 image둜 μΆ”κ°€
if (logoFile) {
formData.append('image', logoFile);
}
// JSON 데이터λ₯Ό Blob으둜 λ³€ν™˜ ν›„ FormData에 μΆ”κ°€

// JSON 데이터λ₯Ό Blob으둜 λ³€ν™˜ν•˜μ—¬ bodyλΌλŠ” μ΄λ¦„μœΌλ‘œ μΆ”κ°€
formData.append(
'body',
new Blob([JSON.stringify(newEmployData)], {
new Blob([JSON.stringify(updatedEmployData)], {
type: 'application/json',
}),
);
mutate(formData);

console.log('formData μ€€λΉ„ μ™„λ£Œ');
mutate(formData); // PATCH μš”μ²­ 전솑
}
};

Expand All @@ -81,6 +83,7 @@ const EmployerEditProfilePage = () => {
newEmployData={newEmployData}
setNewEmployData={setNewEmployData}
setLogoFile={(file: File | undefined) => setLogoFile(file)}
initialPhonNum={newEmployData.owner_info.phone_number}
/>
<BottomButtonPanel>
<Button
Expand Down
24 changes: 18 additions & 6 deletions src/pages/Employer/signup/EmployerSignupInfoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,26 @@ const EmployerSignupInfoPage = () => {
// μ΅œμ’… μ™„λ£Œ μ‹œ 호좜, μ„œλ²„ api 호좜 및 μ™„λ£Œ modal ν‘œμ‹œ
const handleSubmit = () => {
if (isValidEmployerRegistration(newEmployData)) {
mutate({
image: logoFile,
body: {
...newEmployData,
},
});
const formData = new FormData();

// 이미지 파일이 μžˆλŠ” κ²½μš°μ—λ§Œ μΆ”κ°€
if (logoFile) {
formData.append('image', logoFile);
}

// JSON 데이터λ₯Ό Blob으둜 λ³€ν™˜ν•˜μ—¬ μΆ”κ°€
formData.append(
'body',
new Blob([JSON.stringify(newEmployData)], {
type: 'application/json',
}),
);

// mutate 호좜둜 μ„œλ²„μ— 전솑
mutate(formData);
}
};

return (
<div className="last:pb-[10rem]">
<BaseHeader
Expand Down

0 comments on commit bf22faf

Please sign in to comment.