diff --git a/src/app/newsletter/page.tsx b/src/app/newsletter/page.tsx index ce609d7..5cf44bb 100644 --- a/src/app/newsletter/page.tsx +++ b/src/app/newsletter/page.tsx @@ -10,20 +10,20 @@ import NewsCardHorizontal from '@/components/NewsCardHorizontal'; import Suggestions from '@/components/Suggestion'; import { articleCategory } from '@/constants/category'; import color from '@/constants/color'; -import useGetUser from '@/hooks/useGetUser'; +import { useGetUserProfile } from '@/hooks/useGetUser'; +import useUpdateUserProfile from '@/hooks/useUpdateUser'; import suggestionData from '@/mocks/suggestion'; import { Article } from '@/types'; import { getArticleAll, getPopularArticle } from '../api/newsletter'; -import { getUser } from '../api/user'; const Page = () => { const [selectedTab, setSelectedTab] = useState(articleCategory[0]); const [articles, setArticles] = useState([]); const [popularArticles, setPopularArticles] = useState([]); - const user = useGetUser(); - const [userName, setUserName] = useState(null); + const userProfile = useGetUserProfile(); + useUpdateUserProfile(); useEffect(() => { getArticleAll().then((res) => { @@ -42,18 +42,6 @@ const Page = () => { }); }, []); - useEffect(() => { - if (user?.isLogin) { - getUser(user.token).then((res) => { - if (res.status) { - setUserName(res.data.name); - } else { - throw res.message; - } - }); - } - }, [user]); - return ( @@ -93,10 +81,10 @@ const Page = () => { - {userName && ( + {userProfile && ( <> - - + + )} diff --git a/src/components/Header.tsx b/src/components/Header.tsx index d9f141c..b6ac862 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -3,21 +3,18 @@ import { useState, useEffect } from 'react'; import { Avatar, Box, Button, Link, Stack, Typography } from '@mui/material'; -import { useAtomValue } from 'jotai'; -import { getUser } from '@/app/api/user'; import { mainCategory } from '@/constants/category'; import color from '@/constants/color'; -import useCurrentPath from '@/hooks/useCurrentPath'; -import useGetUser from '@/hooks/useGetUser'; -import { loginBackPathAtom } from '@/state/atom'; +import { useGetUserProfile } from '@/hooks/useGetUser'; +import useUpdateUserProfile from '@/hooks/useUpdateUser'; const Header = () => { const [show, setShow] = useState(true); const [lastScrollY, setLastScrollY] = useState(0); - const user = useGetUser(); - const [userProfile, setUserProfile] = useState(null); + const userProfile = useGetUserProfile(); + useUpdateUserProfile(); useEffect(() => { const controlHeader = () => { @@ -36,26 +33,6 @@ const Header = () => { }; }, [lastScrollY]); - useEffect(() => { - if (user?.isLogin) { - getUser(user.token).then((res) => { - if (res.status) { - setUserProfile(res.data.profileImage); - } else { - throw res.message; - } - }); - } - }, [user]); - - useCurrentPath(); - - const loginBackPath = useAtomValue(loginBackPathAtom); - - useEffect(() => { - console.log('loginBackPathAtom', loginBackPath); - }, [loginBackPath]); - return ( <> { ))} {userProfile ? ( - + ) : (