From c0655be5fdd0433b759f7e5915a66e00651937f5 Mon Sep 17 00:00:00 2001 From: leejin_rho Date: Mon, 1 Jul 2024 21:55:39 +0900 Subject: [PATCH 1/3] feat: set isAdmin atom --- apis/calendar.ts | 4 +++- pages/calendar.tsx | 8 ++++---- pages/index.tsx | 6 ++++++ pages/login.tsx | 6 ++++++ utils/atom.tsx | 5 ++++- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apis/calendar.ts b/apis/calendar.ts index 49181e3..2be6699 100644 --- a/apis/calendar.ts +++ b/apis/calendar.ts @@ -7,6 +7,8 @@ interface GetMonthCalendarResponse extends ResponseBody { export interface MonthCalendarProps { programIdx: number; name: string; + category: string | null; + location: string | null; openDate: { year: number; month: number; @@ -38,7 +40,7 @@ interface GetProgramDetailBody { // 챌린지 월별 조회 export const getMonthCalendar = async (): Promise => { - const response = await client.get("/programs"); + const response = await client.get("/programs/list"); // console.log("calenderData", response.data.result); return response.data.result; }; diff --git a/pages/calendar.tsx b/pages/calendar.tsx index b071487..90b856f 100644 --- a/pages/calendar.tsx +++ b/pages/calendar.tsx @@ -11,7 +11,7 @@ interface DropProps { regionDrop: boolean; } -const categories = ["운동", "예술", "학술"]; +const categories = ["운동", "예술", "학술", "기타"]; const locations = ["서울", "경기", "그 외"]; const CalendarPage: NextPage = () => { @@ -32,7 +32,7 @@ const CalendarPage: NextPage = () => {
-
+
{ @@ -41,11 +41,11 @@ const CalendarPage: NextPage = () => { }} /> {isDrop.categoryDrop ? ( -
    +
      {categories.map((option, index) => (
    • {}} > {option} diff --git a/pages/index.tsx b/pages/index.tsx index d5b3001..55531bd 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -10,6 +10,8 @@ import { ToastContainer, Zoom, toast } from "react-toastify"; import Image from "next/image"; import "react-toastify/dist/ReactToastify.css"; import CheckIcon from "@/public/svgs/Check.svg"; +import { atom, useAtomValue } from "jotai"; +import { isAdminAtom } from "@/utils/atom"; const Home: NextPage = () => { const notify = (msg: string) => { @@ -19,6 +21,10 @@ const Home: NextPage = () => { }); }; + //isAdmin + const isAdmin = useAtomValue(isAdminAtom); + console.log("atom: ", isAdmin); + return ( diff --git a/pages/login.tsx b/pages/login.tsx index 6543f99..2af7d8c 100644 --- a/pages/login.tsx +++ b/pages/login.tsx @@ -7,6 +7,8 @@ import LogoLetterIcon from "@/public/svgs/LogoLetter.svg"; import { useMutation } from "@tanstack/react-query"; import { ResponseBody, setTokenFromLocalStorage } from "@/apis/client"; import { SignIn } from "@/apis/auth"; +import { atom, useAtom } from "jotai"; +import { isAdminAtom } from "@/utils/atom"; interface userProps { loginId: string; @@ -15,6 +17,7 @@ interface userProps { const Login: NextPage = () => { const router = useRouter(); + const [isAdmin, setIsAdmin] = useAtom(isAdminAtom); const [userInfo, setUserInfo] = useState({ loginId: "", @@ -50,7 +53,10 @@ const Login: NextPage = () => { console.log(data); const accessToken = data.result.accessToken; const refreshToken = data.result.refreshToken; + const isAdmin = data.result.isAdmin; + setIsAdmin(isAdmin); setTokenFromLocalStorage(accessToken); + router.push("/"); alert("로그인에 성공하였습니다"); }, diff --git a/utils/atom.tsx b/utils/atom.tsx index 1524799..b59f5f2 100644 --- a/utils/atom.tsx +++ b/utils/atom.tsx @@ -1,3 +1,6 @@ import { atom } from "jotai"; -export const isAdminAtom = atom(false); +export const isAdminAtom = atom({ + key: "isAdminState", + default: false, +}); From ada7aaa38eed9b033fbe0dd8fea36a7261f4782b Mon Sep 17 00:00:00 2001 From: leejin_rho Date: Mon, 1 Jul 2024 21:58:45 +0900 Subject: [PATCH 2/3] feat: set isAdmin atom --- utils/atom.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/utils/atom.tsx b/utils/atom.tsx index b59f5f2..1524799 100644 --- a/utils/atom.tsx +++ b/utils/atom.tsx @@ -1,6 +1,3 @@ import { atom } from "jotai"; -export const isAdminAtom = atom({ - key: "isAdminState", - default: false, -}); +export const isAdminAtom = atom(false); From 796b5fcd86a1a4788f755d2b2292f95b44a1045e Mon Sep 17 00:00:00 2001 From: leejin_rho Date: Mon, 1 Jul 2024 22:01:47 +0900 Subject: [PATCH 3/3] feat: set isAdmin atom at localStorage --- apis/client.ts | 12 ++++++++++++ pages/login.tsx | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apis/client.ts b/apis/client.ts index 04a1d94..3e200f3 100644 --- a/apis/client.ts +++ b/apis/client.ts @@ -22,6 +22,18 @@ const getTokenFromLocalStorage = () => { return accessToken; }; +export const setIsAdminAtLocalStorage = (is_admin: string) => { + localStorage.setItem("is_admin", is_admin); +}; + +const getIsAdminFromLocalStorage = () => { + const isAdmin = localStorage.getItem("is_admin"); + if (!isAdmin) { + return null; + } + return isAdmin; +}; + const client = axios.create({ baseURL: process.env.NEXT_PUBLIC_API_URL, withCredentials: true, diff --git a/pages/login.tsx b/pages/login.tsx index 2af7d8c..981c1a4 100644 --- a/pages/login.tsx +++ b/pages/login.tsx @@ -5,7 +5,11 @@ import { useRouter } from "next/router"; import Button from "@/components/Button"; import LogoLetterIcon from "@/public/svgs/LogoLetter.svg"; import { useMutation } from "@tanstack/react-query"; -import { ResponseBody, setTokenFromLocalStorage } from "@/apis/client"; +import { + ResponseBody, + setIsAdminAtLocalStorage, + setTokenFromLocalStorage, +} from "@/apis/client"; import { SignIn } from "@/apis/auth"; import { atom, useAtom } from "jotai"; import { isAdminAtom } from "@/utils/atom"; @@ -55,6 +59,7 @@ const Login: NextPage = () => { const refreshToken = data.result.refreshToken; const isAdmin = data.result.isAdmin; setIsAdmin(isAdmin); + setIsAdminAtLocalStorage(isAdmin); setTokenFromLocalStorage(accessToken); router.push("/");