-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] 유저 프로필 수정 UI 및 수정
- Loading branch information
Showing
15 changed files
with
483 additions
and
52 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
'use client' | ||
|
||
import Container from '@/components/common/Container' | ||
import { useParams, useRouter } from 'next/navigation' | ||
import { | ||
useProfile, | ||
usePatchProfile, | ||
useUserInfo, | ||
} from '@/service/user/useUserService' | ||
import Button from '@/components/common/Button' | ||
import UserUpdateProfile from '@/components/auth/UserProfileUpdate' | ||
import { useState, useEffect } from 'react' | ||
|
||
const UserUpdatePage = () => { | ||
const { id } = useParams() | ||
const profileId = Number(id) | ||
const router = useRouter() | ||
|
||
const { data: profile } = useProfile(profileId) | ||
const { data: userInfo } = useUserInfo() | ||
const { mutate: patchProfile } = usePatchProfile() | ||
|
||
const [updatedProfile, setUpdatedProfile] = useState({}) | ||
const [badgeId, setBadgeId] = useState<number | null>(null) | ||
|
||
useEffect(() => { | ||
if (userInfo) { | ||
setBadgeId(userInfo.badgeId) | ||
} | ||
}, [userInfo]) | ||
|
||
useEffect(() => { | ||
setUpdatedProfile((prevProfile) => ({ | ||
...prevProfile, | ||
badgeId: badgeId === userInfo?.badgeId ? null : badgeId, | ||
})) | ||
}, [badgeId, userInfo]) | ||
|
||
if (!profile) return null | ||
|
||
const handleUpdate = (data: any) => { | ||
setUpdatedProfile((prevProfile) => ({ | ||
...prevProfile, | ||
...data, | ||
badgeId: badgeId === userInfo?.badgeId ? null : badgeId, | ||
})) | ||
} | ||
|
||
const handleSubmit = () => { | ||
patchProfile(updatedProfile) | ||
router.back() | ||
} | ||
|
||
const handleBadgeClick = (badge: number) => { | ||
setBadgeId(badge) | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="text-title3 text-maindark font-semibold mt-6 mb-4"> | ||
{profile.teacherInfo.nickName} 프로필 수정 | ||
</div> | ||
<div className="grid gap-6 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-2"> | ||
<Container color="purple" className="col-span-1 items-center"> | ||
<UserUpdateProfile onUpdate={handleUpdate} /> | ||
</Container> | ||
<Container color="purple" className="col-span-1"> | ||
<div className="text-title3 text-gray1 items-start font-semibold mb-2.5"> | ||
수집한 칭호 | ||
</div> | ||
<div className="flex flex-wrap gap-2.5"> | ||
{profile.badgeInfos.map((badge, index) => ( | ||
<Button | ||
key={index} | ||
text={badge.name} | ||
color={badge.name} | ||
size="badge" | ||
onClick={() => handleBadgeClick(badge.id)} | ||
className={`${ | ||
badgeId === badge.id ? 'outline outline-4 outline-main' : '' | ||
}`} | ||
/> | ||
))} | ||
</div> | ||
</Container> | ||
</div> | ||
|
||
<div className="flex justify-end gap-2.5 my-4"> | ||
<Button | ||
color="LIGHTPURPLE" | ||
text="취소하기" | ||
size="small" | ||
onClick={() => { | ||
router.back() | ||
}} | ||
/> | ||
<Button | ||
color="PURPLE" | ||
text="수정하기" | ||
size="small" | ||
onClick={handleSubmit} | ||
/> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default UserUpdatePage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Meta, StoryFn } from '@storybook/react' | ||
import UserProfileUpdate from './UserProfileUpdate' | ||
|
||
export default { | ||
title: 'Auth/UserProfileUpdate', | ||
component: UserProfileUpdate, | ||
} as Meta | ||
|
||
const Template: StoryFn = (args) => <UserProfileUpdate {...args} /> | ||
|
||
export const Primary = Template.bind({}) | ||
Primary.args = {} |
Oops, something went wrong.