Skip to content

Commit

Permalink
[feat] EditProfile 부분 수정... ><
Browse files Browse the repository at this point in the history
  • Loading branch information
JAEMOONLEE committed Nov 14, 2023
1 parent 2fc2df6 commit d123db6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
21 changes: 11 additions & 10 deletions api/userInfo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-return-await */
import { UserInfoProps } from '@/context/UserInfoProvider.tsx';
import { RoomSearch } from '@/public/types/room';
import { Profile } from '@/public/types/user';
Expand All @@ -13,13 +14,13 @@ export const getProfile = async () => {
};

export const makeLikedRooms = async (id: number) => {
return await fetchData(`/api/v1/rooms/${id}/liked`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
});
}
return await fetchData(`/api/v1/rooms/${id}/liked`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
});
};

/**
* @TODO Api 나오면 url 및 params 바꿔줘야함!!
Expand All @@ -31,7 +32,7 @@ export const makeDisLikedRooms = async (id: number) => {
'Content-Type': 'application/json',
},
});
}
};

export const getLikedRooms = async (page: number) => {
let result;
Expand All @@ -55,6 +56,6 @@ export const modifyProfile = async (profileInfo: Profile) => {
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(profileInfo)
body: JSON.stringify(profileInfo),
});
}
};
28 changes: 17 additions & 11 deletions pages/userInfo/editProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, { useState, useEffect } from 'react';
import { FieldValues, SubmitHandler, FieldError, useForm as UseForm } from 'react-hook-form';
import DefaultImage from '@/public/icons/def_img.svg';
import { isValidEmail, isRequired } from '@/utils/validCheck.ts';
import toast from 'react-hot-toast';
import { Textarea, Button, Upload, Input, Calendar } from '@/components/index.tsx';
import ProfileCamera from '@/public/icons/profileCamera.svg';
import { User, Profile } from '@/public/types/user';
Expand Down Expand Up @@ -37,26 +38,31 @@ export default function EditProfile({ _imageSrc, userInfo }: ProfileProps) {

const [buttonState, setButtonState] = useState(capitalizeFirstLetter(userInfo?.gender || ''));

const formatMmDdYyyyToYyyyMmDd = (inputDate: string) => {
const parts = inputDate.split('-');
if (parts.length === 3) {
const month = parts[0];
const day = parts[1];
const year = parts[2];
return `${year}-${month}-${day}`;
}
return null;
};

const onSubmit: SubmitHandler<FieldValues> = async (data) => {
try {
// gender,
const profileData = data as Profile;
profileData.profileId = userInfo.id || 0;
profileData.description = data?.describe || '';
profileData.gender = buttonState;
profileData.birthDate = formatMmDdYyyyToYyyyMmDd(data.dateOfBirth) || profileData.birthDate;
const result = await modifyProfile(profileData);
alert('수정되었습니다');
// openModal({
// props: {
// title: 'My Postings',
// size: 'full',
// custom: true,
// customHeader: true,
// },
// children: <>hi</>,
// });
toast('Successfully saved');
} catch (error) {
console.error('[ERROR] EDIT PROFILE', error);
}
};

const isPostingComplete = () => {
return (
(imageSrc || '') === '' ||
Expand Down

0 comments on commit d123db6

Please sign in to comment.