diff --git a/api/userInfo.ts b/api/userInfo.ts index 1f3f171..e4fc088 100644 --- a/api/userInfo.ts +++ b/api/userInfo.ts @@ -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'; @@ -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 바꿔줘야함!! @@ -31,7 +32,7 @@ export const makeDisLikedRooms = async (id: number) => { 'Content-Type': 'application/json', }, }); -} +}; export const getLikedRooms = async (page: number) => { let result; @@ -55,6 +56,6 @@ export const modifyProfile = async (profileInfo: Profile) => { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(profileInfo) + body: JSON.stringify(profileInfo), }); -} \ No newline at end of file +}; diff --git a/pages/userInfo/editProfile.tsx b/pages/userInfo/editProfile.tsx index df6ff5f..b4c5e17 100644 --- a/pages/userInfo/editProfile.tsx +++ b/pages/userInfo/editProfile.tsx @@ -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'; @@ -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 = 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 || '') === '' ||