Skip to content

Commit

Permalink
feat: 프로필 수정하기 전역 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
uiop5809 committed Sep 2, 2024
1 parent 9e174d8 commit fdb7872
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/app/user/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import ActivityCount from '@/components/auth/ActivityCount'
import UserProfile from '@/components/user/UserProfile'
import Container from '@/components/common/Container'
import { useParams, useRouter } from 'next/navigation'
import { useUserInfo, useProfile } from '@/service/user/useUserService'
import { useProfile } from '@/service/user/useUserService'
import Button from '@/components/common/Button'
import MemberListCount from '@/components/auth/MemberListCount'
import { userInfoState } from '@/recoil/UserInfo'
import { useRecoilValue } from 'recoil'

const UserPage = () => {
const { id } = useParams()
const profileId = Number(id)
const router = useRouter()
const userInfo = useRecoilValue(userInfoState)

const { data: userInfo } = useUserInfo()
const { data: profile } = useProfile(Number(profileId))

if (!profile) return null
Expand Down
15 changes: 9 additions & 6 deletions src/app/user/[id]/update/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

import Container from '@/components/common/Container'
import { useParams, useRouter } from 'next/navigation'
import {
useProfile,
usePatchProfile,
useUserInfo,
} from '@/service/user/useUserService'
import { useProfile, usePatchProfile } from '@/service/user/useUserService'
import Button from '@/components/common/Button'
import UserUpdateProfile from '@/components/user/UserProfileUpdate'
import { useState, useEffect } from 'react'
import { useQueryClient } from '@tanstack/react-query'
import { useRecoilState } from 'recoil'
import { userInfoState } from '@/recoil/UserInfo'

const UserUpdatePage = () => {
const { id } = useParams()
const profileId = Number(id)
const router = useRouter()
const queryClient = useQueryClient()

const [userInfo, setUserInfo] = useRecoilState(userInfoState)

const { data: profile } = useProfile(profileId)
const { data: userInfo } = useUserInfo()
const { mutate: patchProfile } = usePatchProfile()

const [updatedProfile, setUpdatedProfile] = useState({})
Expand Down Expand Up @@ -51,6 +50,10 @@ const UserUpdatePage = () => {
const handleSubmit = () => {
patchProfile(updatedProfile, {
onSuccess: () => {
setUserInfo((prevUserInfo: any) => ({
...prevUserInfo,
...updatedProfile,
}))
queryClient.invalidateQueries({ queryKey: ['profile', profileId] }) // queryKey를 객체로 전달
router.back()
},
Expand Down
1 change: 0 additions & 1 deletion src/components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const Header = () => {
const [selected, setSelected] = useState<string | null>(null)
const userInfo = useRecoilValue(userInfoState)
const { showToast } = useToast()
console.log('userInfo:', userInfo)

useEffect(() => {
if (pathname) {
Expand Down

0 comments on commit fdb7872

Please sign in to comment.