Skip to content

Commit

Permalink
Merge pull request #40 from Pro-Pofol/feature/#27-Mypage
Browse files Browse the repository at this point in the history
Feature/#27 :: 유저 정보 수정 연동 완료
  • Loading branch information
wjknnn authored Jun 10, 2024
2 parents c677cd0 + d99fa08 commit e6594de
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/app/profile/ProfileInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<div className="flex justify-center h-[180px] w-full relative">
Expand Down Expand Up @@ -59,7 +60,7 @@ export const ProfileInfo = async () => {
</div>
<div className="flex flex-col items-center gap-[2px]">
<p className="text-bodySmall">전공</p>
<p className="text-labelMedium text-gray600">{major}</p>
<p className="text-labelMedium text-gray600">{user_major}</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/profile/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function AnotherProfilePage({
<div className="flex flex-col items-center gap-[2px]">
<p className="text-bodySmall">전공</p>
<p className="text-labelMedium text-gray600">
{userData?.major}
{userData?.user_major}
</p>
</div>
</div>
Expand Down
33 changes: 29 additions & 4 deletions src/app/profile/edit/ProfileEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,12 +17,30 @@ interface ImgDataType {

export const ProfileEdit = ({ myData }: { myData: UserType }) => {
const [generation, setGeneration] = useState<string>(`${myData.generation}`)
const [major, setMajor] = useState<string>(myData.major)
const [major, setMajor] = useState<string>(myData.user_major)
const [imgData, setImgData] = useState<ImgDataType>({
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 (
<>
Expand Down Expand Up @@ -71,7 +91,12 @@ export const ProfileEdit = ({ myData }: { myData: UserType }) => {
change={setMajor}
/>
</article>
<Button size="large" className="w-full" onClick={editProfile}>
<Button
size="large"
className="w-full"
onClick={editProfileHandler}
disabled={isChanged()}
>
프로필 수정하기
</Button>
</>
Expand Down
3 changes: 2 additions & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
export * from './tip'
19 changes: 19 additions & 0 deletions src/services/profile/editProfile.ts
Original file line number Diff line number Diff line change
@@ -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,
})
}
12 changes: 6 additions & 6 deletions src/types/userType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type UserType = {
generation: number
major: string
name: string
oauth_id: string
profile_image: string
}
generation: number
user_major: string
name: string
oauth_id: string
profile_image: string
}

0 comments on commit e6594de

Please sign in to comment.