Skip to content

Commit

Permalink
Merge pull request #30 from team-Ollie/15-feature-Calendar-Detail-Modal
Browse files Browse the repository at this point in the history
feat: set isAdmin atom
  • Loading branch information
leejin-rho authored Jul 1, 2024
2 parents efb281a + 796b5fc commit be88840
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
4 changes: 3 additions & 1 deletion apis/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +40,7 @@ interface GetProgramDetailBody {

// 챌린지 월별 조회
export const getMonthCalendar = async (): Promise<GetMonthCalendarResponse> => {
const response = await client.get("/programs");
const response = await client.get("/programs/list");
// console.log("calenderData", response.data.result);
return response.data.result;
};
Expand Down
12 changes: 12 additions & 0 deletions apis/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pages/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface DropProps {
regionDrop: boolean;
}

const categories = ["운동", "예술", "학술"];
const categories = ["운동", "예술", "학술", "기타"];
const locations = ["서울", "경기", "그 외"];

const CalendarPage: NextPage = () => {
Expand All @@ -32,7 +32,7 @@ const CalendarPage: NextPage = () => {
<HeadFunction title="캘린더" />
<div className="flex flex-col flex-grow pt-[1.5rem] items-center overflow-auto scrollbar-hide">
<div className="h-fit w-full flex flex-row justify-start items-end px-[1rem] gap-3">
<div>
<div className="">
<FilterBox
filterName="카테고리"
onClick={() => {
Expand All @@ -41,11 +41,11 @@ const CalendarPage: NextPage = () => {
}}
/>
{isDrop.categoryDrop ? (
<ul className="absolute top-[8rem]">
<ul className="absolute bg-white w-[5rem] text-center top-[7rem]">
{categories.map((option, index) => (
<li
key={index}
className="cursor-pointer hover:bg-gray-200 p-2"
className="cursor-pointer hover:bg-gray-200"
onClick={() => {}}
>
{option}
Expand Down
6 changes: 6 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -19,6 +21,10 @@ const Home: NextPage = () => {
});
};

//isAdmin
const isAdmin = useAtomValue(isAdminAtom);
console.log("atom: ", isAdmin);

return (
<FlexBox direction="col" className="w-full h-full justify-between">
<HomeChallenge onNotify={notify} />
Expand Down
13 changes: 12 additions & 1 deletion pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ 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";

interface userProps {
loginId: string;
Expand All @@ -15,6 +21,7 @@ interface userProps {

const Login: NextPage = () => {
const router = useRouter();
const [isAdmin, setIsAdmin] = useAtom(isAdminAtom);

const [userInfo, setUserInfo] = useState<userProps>({
loginId: "",
Expand Down Expand Up @@ -50,7 +57,11 @@ const Login: NextPage = () => {
console.log(data);
const accessToken = data.result.accessToken;
const refreshToken = data.result.refreshToken;
const isAdmin = data.result.isAdmin;
setIsAdmin(isAdmin);
setIsAdminAtLocalStorage(isAdmin);
setTokenFromLocalStorage(accessToken);

router.push("/");
alert("로그인에 성공하였습니다");
},
Expand Down

0 comments on commit be88840

Please sign in to comment.