Skip to content

Commit

Permalink
feat :: 전역 state로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
KANGYONGSU23 committed Dec 14, 2023
1 parent 7730b8a commit 7d8fc09
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
19 changes: 16 additions & 3 deletions src/apis/students/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -73,6 +75,7 @@ export const useSignup = () => {
};

export const useMyProfile = () => {
const { setUserProfile } = useContext(UserProfileContext);
return useQuery(
["myProfile"],
async () => {
Expand All @@ -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,
});
},
}
);
};
2 changes: 2 additions & 0 deletions src/apis/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -46,6 +47,7 @@ export const useLogin = (body: RequestBody, checkBoxValue: boolean) => {
}
navigator.push("/");
}
useMyProfile()
},
onError: (error: AxiosError) => {
switch (error.response?.status) {
Expand Down
7 changes: 4 additions & 3 deletions src/components/SuggestionHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
"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: {
title: "🏢 이런 기업은 어떠세요?",
router: "/companies",
},
Recruitments: {
title: `👩‍💻 ${profile?.student_name || "사용자"}님의 관심 분야에요`,
title: `👩‍💻 ${userProfile.student_name || "사용자"}님의 관심 분야에요`,

router: "/recruitments",
},
Expand Down
15 changes: 7 additions & 8 deletions src/components/common/Header.tsx
Original file line number Diff line number Diff line change
@@ -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 ||
Expand All @@ -25,7 +25,6 @@ function Header() {
return null;
}

const { data: profile } = useMyProfile();

return (
<div
Expand Down Expand Up @@ -73,15 +72,15 @@ function Header() {
width={28}
height={28}
src={`${
profile?.profile_image_url &&
userProfile.profile_image_url &&
process.env.NEXT_PUBLIC_IMAGE_URL +
"/" +
profile?.profile_image_url
userProfile.profile_image_url
}`}
alt="프로필사진"
/>
<p className="text-[#333333] text-b2 font-r">
{profile?.student_name}
{userProfile.student_name}
</p>
</div>
<div>{/* <Icon icon={"Chevron"} size={16} color="gray90" /> */}</div>
Expand Down
16 changes: 8 additions & 8 deletions src/components/mypage/DetailProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
"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 (
<div className="flex items-center gap-6">
<div className="w-[100px] h-[100px] rounded-[50%] shadow-elevaiton overflow-hidden flex items-center justify-center">
<Image
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="프로필 사진"
/>
</div>
<div className="flex-1">
<div className="flex items-center gap-2">
<p className="text-h5 leading-h5 font-m">{profile?.student_name}</p>
<GhostTag>{profile?.student_gcn}</GhostTag>
<p className="text-h5 leading-h5 font-m">{userProfile.student_name}</p>
<GhostTag>{userProfile.student_gcn}</GhostTag>
</div>
<p className="text-b3 leading-b3 font-r text-[#7F7F7F]">
{profile && departmentEnum[profile.department]}
{departmentEnum[userProfile.department]}
</p>
</div>
<KebabMenu items={getMypageKebabItems()} />
Expand Down

0 comments on commit 7d8fc09

Please sign in to comment.