From 7d8fc09c0c1be5e010f36561d19af45773ff071b Mon Sep 17 00:00:00 2001 From: KANGYONGSU23 Date: Thu, 14 Dec 2023 17:02:43 +0900 Subject: [PATCH] =?UTF-8?q?feat=20::=20=EC=A0=84=EC=97=AD=20state=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/students/index.ts | 19 ++++++++++++++++--- src/apis/user/index.ts | 2 ++ src/components/SuggestionHeader.tsx | 7 ++++--- src/components/common/Header.tsx | 15 +++++++-------- src/components/mypage/DetailProfile.tsx | 16 ++++++++-------- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/apis/students/index.ts b/src/apis/students/index.ts index b3aa6f6..5942369 100644 --- a/src/apis/students/index.ts +++ b/src/apis/students/index.ts @@ -1,7 +1,9 @@ +import { UserProfileContext } from "@/context/UserContext"; import { useMutation, useQuery } from "@tanstack/react-query"; import { useToastStore } from "@team-return/design-system"; import axios, { AxiosError } from "axios"; import { useRouter } from "next/navigation"; +import { useContext } from "react"; import { useCookies } from "react-cookie"; import { instance } from "../axios"; import { ResponseBody } from "../user/type"; @@ -73,6 +75,7 @@ export const useSignup = () => { }; export const useMyProfile = () => { + const { setUserProfile } = useContext(UserProfileContext); return useQuery( ["myProfile"], async () => { @@ -81,9 +84,19 @@ export const useMyProfile = () => { }, { refetchOnWindowFocus: false, - onSuccess: ()=>{ - - } + onSuccess: ({ + student_name, + student_gcn, + department, + profile_image_url, + }) => { + setUserProfile({ + student_name, + student_gcn, + department, + profile_image_url, + }); + }, } ); }; diff --git a/src/apis/user/index.ts b/src/apis/user/index.ts index 3342bd0..5d30380 100644 --- a/src/apis/user/index.ts +++ b/src/apis/user/index.ts @@ -3,6 +3,7 @@ import { useToastStore } from "@team-return/design-system"; import axios, { AxiosError } from "axios"; import { useRouter } from "next/navigation"; import { useCookies } from "react-cookie"; +import { useMyProfile } from "../students"; import { RequestBody, ResponseBody } from "./type"; const router = "/users"; @@ -46,6 +47,7 @@ export const useLogin = (body: RequestBody, checkBoxValue: boolean) => { } navigator.push("/"); } + useMyProfile() }, onError: (error: AxiosError) => { switch (error.response?.status) { diff --git a/src/components/SuggestionHeader.tsx b/src/components/SuggestionHeader.tsx index 5a677f4..56bb591 100644 --- a/src/components/SuggestionHeader.tsx +++ b/src/components/SuggestionHeader.tsx @@ -1,15 +1,16 @@ "use client"; +import { UserProfileContext } from "@/context/UserContext"; import { Icon } from "@team-return/design-system"; -import { useMyProfile } from "@/apis/students"; import Link from "next/link"; +import { useContext } from "react"; interface PropsType { listType: "Company" | "Recruitments" | "Bookmark"; } export default function SuggestionHeader({ listType }: PropsType) { - const { data: profile } = useMyProfile(); + const { userProfile } = useContext(UserProfileContext); const suggestionHeaderDummy = { Company: { @@ -17,7 +18,7 @@ export default function SuggestionHeader({ listType }: PropsType) { router: "/companies", }, Recruitments: { - title: `πŸ‘©β€πŸ’» ${profile?.student_name || "μ‚¬μš©μž"}λ‹˜μ˜ 관심 λΆ„μ•Όμ—μš”`, + title: `πŸ‘©β€πŸ’» ${userProfile.student_name || "μ‚¬μš©μž"}λ‹˜μ˜ 관심 λΆ„μ•Όμ—μš”`, router: "/recruitments", }, diff --git a/src/components/common/Header.tsx b/src/components/common/Header.tsx index 6b90a08..1206353 100644 --- a/src/components/common/Header.tsx +++ b/src/components/common/Header.tsx @@ -1,15 +1,15 @@ "use client"; -import React, { useEffect } from "react"; -import Image from "next/image"; +import { UserProfileContext } from "@/context/UserContext"; import Logo from "@public/Logo.png"; -import { Icon } from "@team-return/design-system"; +import Image from "next/image"; import Link from "next/link"; import { usePathname } from "next/navigation"; -import { useMyProfile } from "@/apis/students"; +import React, { useContext, useEffect } from "react"; function Header() { const pathname = usePathname(); + const {userProfile} = useContext(UserProfileContext) useEffect(() => { if ( pathname.toString().indexOf("/apply") !== -1 || @@ -25,7 +25,6 @@ function Header() { return null; } - const { data: profile } = useMyProfile(); return (

- {profile?.student_name} + {userProfile.student_name}

{/* */}
diff --git a/src/components/mypage/DetailProfile.tsx b/src/components/mypage/DetailProfile.tsx index af85b8f..8795a43 100644 --- a/src/components/mypage/DetailProfile.tsx +++ b/src/components/mypage/DetailProfile.tsx @@ -1,15 +1,15 @@ "use client"; -import { useMyProfile } from "@/apis/students"; +import { UserProfileContext } from "@/context/UserContext"; import { departmentEnum } from "@/util/object/enum"; import { getMypageKebabItems } from "@/util/object/kebabMenuItems"; import Image from "next/image"; +import { useContext } from "react"; import KebabMenu from "../common/Dropdown/KebabMenu"; import GhostTag from "./GhostTag"; export default function DetailProfile() { - const { data: profile } = useMyProfile(); - + const { userProfile } = useContext(UserProfileContext); return (
@@ -17,8 +17,8 @@ export default function DetailProfile() { width={100} height={100} src={ - profile - ? `${process.env.NEXT_PUBLIC_IMAGE_URL}/${profile.profile_image_url}` + userProfile.profile_image_url + ? `${process.env.NEXT_PUBLIC_IMAGE_URL}/${userProfile.profile_image_url}` : "" } alt="ν”„λ‘œν•„ 사진" @@ -26,11 +26,11 @@ export default function DetailProfile() {
-

{profile?.student_name}

- {profile?.student_gcn} +

{userProfile.student_name}

+ {userProfile.student_gcn}

- {profile && departmentEnum[profile.department]} + {departmentEnum[userProfile.department]}