From 2d66a5000a81537d50f19ee479f448a4f708d9ca Mon Sep 17 00:00:00 2001 From: SeungWoo Date: Mon, 10 Jun 2024 14:24:07 +0900 Subject: [PATCH 1/2] =?UTF-8?q?ADD=20::=20Profile=20Edit=20=EC=97=B0?= =?UTF-8?q?=EB=8F=99=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/profile/ProfileInfo.tsx | 5 +++-- src/app/profile/edit/ProfileEdit.tsx | 33 ++++++++++++++++++++++++---- src/services/index.ts | 3 ++- src/services/profile/editProfile.ts | 19 ++++++++++++++++ src/types/userType.ts | 12 +++++----- 5 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 src/services/profile/editProfile.ts diff --git a/src/app/profile/ProfileInfo.tsx b/src/app/profile/ProfileInfo.tsx index 14432ac..4eb17dc 100644 --- a/src/app/profile/ProfileInfo.tsx +++ b/src/app/profile/ProfileInfo.tsx @@ -7,7 +7,8 @@ import Link from 'next/link' import { LogoutButton } from './LogoutButton' export const ProfileInfo = async () => { - const { generation, major, name, oauth_id, profile_image } = await getMe() + const { generation, user_major, name, oauth_id, profile_image } = + await getMe() return ( <>
@@ -59,7 +60,7 @@ export const ProfileInfo = async () => {

전공

-

{major}

+

{user_major}

diff --git a/src/app/profile/edit/ProfileEdit.tsx b/src/app/profile/edit/ProfileEdit.tsx index 361061d..c4cef1f 100644 --- a/src/app/profile/edit/ProfileEdit.tsx +++ b/src/app/profile/edit/ProfileEdit.tsx @@ -6,7 +6,9 @@ import Image from 'next/image' import { UserType } from '@/types' import { majorOption } from '@/constants' import { useState } from 'react' -import { uploadFile } from '@/utils' +import { getCookie, uploadFile } from '@/utils' +import { editProfile } from '@/services' +import { useRouter } from 'next/navigation' interface ImgDataType { img?: File @@ -15,12 +17,30 @@ interface ImgDataType { export const ProfileEdit = ({ myData }: { myData: UserType }) => { const [generation, setGeneration] = useState(`${myData.generation}`) - const [major, setMajor] = useState(myData.major) + const [major, setMajor] = useState(myData.user_major) const [imgData, setImgData] = useState({ imgString: myData.profile_image, }) - const editProfile = () => {} + const router = useRouter() + + const isChanged = () => { + if (generation !== `${myData.generation}`) return false + else if (major !== myData.user_major) return false + else if (imgData.imgString !== myData.profile_image) return false + else return true + } + + const editProfileHandler = async () => { + const editedData = { + profile_image: myData.profile_image, + generation: +generation, + user_major: major, + } + const token = getCookie('access_token') || '' + await editProfile(token, editedData) + router.replace('/profile') + } return ( <> @@ -71,7 +91,12 @@ export const ProfileEdit = ({ myData }: { myData: UserType }) => { change={setMajor} /> - diff --git a/src/services/index.ts b/src/services/index.ts index 8b2abf6..9151ee8 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -7,6 +7,7 @@ export { getMe } from './getMe' export { getUser } from './getUser' export { deleteApplication } from './deleteApplication' export { userFollow } from './userFollow' +export { editProfile } from './profile/editProfile' export * from './post' -export * from './tip' \ No newline at end of file +export * from './tip' diff --git a/src/services/profile/editProfile.ts b/src/services/profile/editProfile.ts new file mode 100644 index 0000000..492599f --- /dev/null +++ b/src/services/profile/editProfile.ts @@ -0,0 +1,19 @@ +import { instance } from '../interceptor' + +export const editProfile = async ( + token: string, + editedData: { + profile_image: string + generation: number + user_major: string + }, +) => { + return await instance({ + method: 'PATCH', + url: '/users/me', + headers: { + Authorization: `Bearer ${token}`, + }, + data: editedData, + }) +} diff --git a/src/types/userType.ts b/src/types/userType.ts index 8e2062f..c02daf7 100644 --- a/src/types/userType.ts +++ b/src/types/userType.ts @@ -1,7 +1,7 @@ export type UserType = { - generation: number - major: string - name: string - oauth_id: string - profile_image: string -} \ No newline at end of file + generation: number + user_major: string + name: string + oauth_id: string + profile_image: string +} From d99fa0884906ca408689464ff0f099bf9a82f5ad Mon Sep 17 00:00:00 2001 From: SeungWoo Date: Mon, 10 Jun 2024 14:41:29 +0900 Subject: [PATCH 2/2] FIX :: build error --- src/app/profile/[id]/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/profile/[id]/page.tsx b/src/app/profile/[id]/page.tsx index b45f1ee..77726e0 100644 --- a/src/app/profile/[id]/page.tsx +++ b/src/app/profile/[id]/page.tsx @@ -94,7 +94,7 @@ export default function AnotherProfilePage({

전공

- {userData?.major} + {userData?.user_major}