From 7c70f2ee718c1fe690aa72caaa9e9e839b9df768 Mon Sep 17 00:00:00 2001 From: JAEMOONLEE Date: Tue, 24 Oct 2023 11:06:39 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=201=EC=B0=A8=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/userInfo.ts | 38 +++++++++++++++++++++++----------- components/Nav/Nav.tsx | 18 +++++++++------- pages/userInfo/editProfile.tsx | 37 +++++++++++++++++++++------------ public/types/user.ts | 9 ++++++++ 4 files changed, 69 insertions(+), 33 deletions(-) diff --git a/api/userInfo.ts b/api/userInfo.ts index fa3c978..1f3f171 100644 --- a/api/userInfo.ts +++ b/api/userInfo.ts @@ -1,5 +1,6 @@ import { UserInfoProps } from '@/context/UserInfoProvider.tsx'; import { RoomSearch } from '@/public/types/room'; +import { Profile } from '@/public/types/user'; import { fetchData } from '.'; export const getProfile = async () => { @@ -11,6 +12,27 @@ 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', + }, + }); +} + +/** + * @TODO Api 나오면 url 및 params 바꿔줘야함!! + */ +export const makeDisLikedRooms = async (id: number) => { + return await fetchData(`/api/v1/rooms/${id}/disLiked`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + }); +} + export const getLikedRooms = async (page: number) => { let result; try { @@ -27,20 +49,12 @@ export const getLikedRooms = async (page: number) => { return result; }; -export const makeLikedRooms = async (id: number) => { - return await fetchData(`/api/v1/rooms/${id}/liked`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json', - }, - }); -} - -export const makeDisLikedRooms = async (id: number) => { - return await fetchData(`/api/v1/rooms/${id}/disLiked`, { - method: 'DELETE', +export const modifyProfile = async (profileInfo: Profile) => { + return await fetchData(`/api/v1/my/profile`, { + method: 'PUT', headers: { 'Content-Type': 'application/json', }, + body: JSON.stringify(profileInfo) }); } \ No newline at end of file diff --git a/components/Nav/Nav.tsx b/components/Nav/Nav.tsx index bbae5fc..ab678d1 100644 --- a/components/Nav/Nav.tsx +++ b/components/Nav/Nav.tsx @@ -33,17 +33,19 @@ const menus = [ ]; export default function Nav({ initMenu, profile }: NavProps) { + // const { setUserInfoData, userInfoState } = useUserInfo(); const [hoverMenu, setHoverMenu] = useState(-1); // 초기화 const router = useRouter(); - const { setUserInfoData, userInfoState } = useUserInfo(); const handleNavClicked = (index: number) => { - router.push( - { - pathname: menus[index].router, - query: { data: profile && JSON.stringify(profile) }, - }, - `${menus[index].router}` - ); + if (menus[index].router || '' !== '' ) { + router.push( + { + pathname: menus[index].router, + query: { data: profile && JSON.stringify(profile) }, + }, + `${menus[index].router}` + ); + } }; return ( diff --git a/pages/userInfo/editProfile.tsx b/pages/userInfo/editProfile.tsx index c08b11b..dddebca 100644 --- a/pages/userInfo/editProfile.tsx +++ b/pages/userInfo/editProfile.tsx @@ -8,7 +8,8 @@ import useModal from '@/hooks/useModal.ts'; import { isValidEmail, isRequired } from '@/utils/validCheck.ts'; import { Textarea, Button, Upload, Input, Calendar } from '@/components/index.tsx'; import ProfileCamera from '@/public/icons/profileCamera.svg'; -import { User } from '@/public/types/user'; +import { User, Profile } from '@/public/types/user'; +import { modifyProfile } from '@/api/userInfo'; import isEmpty from 'lodash-es/isEmpty'; interface ProfileProps { @@ -34,21 +35,31 @@ export default function EditProfile({ _imageSrc, userInfo }: ProfileProps) { } = UseForm({ mode: 'onChange' }); const capitalizeFirstLetter = (str: string) => { - return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase(); + return (str || '').charAt(0).toUpperCase() + str.slice(1).toLowerCase(); } const [buttonState, setButtonState] = useState(capitalizeFirstLetter(userInfo?.gender)); - const onSubmit: SubmitHandler = (data) => { - openModal({ - props: { - title: 'My Postings', - size: 'full', - custom: true, - customHeader: true, - }, - children: <>hi, - }); + const onSubmit: SubmitHandler = async (data) => { + try { + const profileData = data as Profile; + profileData.profileId = userInfo.id || 0; + const result = await modifyProfile(profileData); + console.log("result in editprofile", result); + alert('수정되었습니다'); + + // openModal({ + // props: { + // title: 'My Postings', + // size: 'full', + // custom: true, + // customHeader: true, + // }, + // children: <>hi, + // }); + } catch (error) { + console.error('[ERROR] EDIT PROFILE', error); + } }; const isPostingComplete = () => { @@ -194,7 +205,7 @@ export default function EditProfile({ _imageSrc, userInfo }: ProfileProps) {
-
diff --git a/public/types/user.ts b/public/types/user.ts index 2604285..3517d20 100644 --- a/public/types/user.ts +++ b/public/types/user.ts @@ -25,3 +25,12 @@ export interface User { accountNonLocked: boolean; enabled: boolean; } + +export interface Profile { + profileId : number; + gender: string; + firstName: string; + lastName: string; + birthDate: string; + description: string; +}