Skip to content
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/public/ticket.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>EvenTee</title>
</head>
Expand Down
Binary file added public/default-event.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/ticket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 36 additions & 15 deletions src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createContext, useContext, useState, ReactNode } from 'react';
import { createContext, useContext, useState, ReactNode, useEffect } from "react";

export type User = {
id: string | null;
nickname: string | null;
email: string | null;
socialId: string | null;
profileImageUrl?: string | null;
role: 'user' | 'admin' | 'master_admin' | null;
role: "user" | "admin" | "master_admin" | null;
};

export type Event = {
Expand Down Expand Up @@ -35,27 +35,51 @@ type AppContextType = {
logout: () => void;
};


const AppContext = createContext<AppContextType | undefined>(undefined);

export function AppProvider({ children }: { children: ReactNode }) {
const [user, setUser] = useState<User | null>(null);
const [accessToken, setAccessToken] = useState<string | null>(null);
const [currentEvent, setCurrentEvent] = useState<Event | null>(null);

// inviteCode 기본값: null
const [currentEvent, _setCurrentEvent] = useState<Event | null>(null);
const [inviteCode, setInviteCode] = useState<string | null>(null);


useEffect(() => {
const saved = localStorage.getItem("currentEvent");
if (saved) {
try {
const parsed = JSON.parse(saved);

parsed.startDate = parsed.startDate ? new Date(parsed.startDate) : null;
parsed.endDate = parsed.endDate ? new Date(parsed.endDate) : null;

_setCurrentEvent(parsed);
} catch (err) {
console.error("currentEvent 복구 실패:", err);
}
}
}, []);


const setCurrentEvent = (event: Event | null) => {
_setCurrentEvent(event);

if (event) {
localStorage.setItem("currentEvent", JSON.stringify(event));
} else {
localStorage.removeItem("currentEvent");
}
};


const logout = () => {
setUser(null);
setAccessToken(null);
setCurrentEvent(null);


setInviteCode(null);

// localStorage 정리
localStorage.removeItem("accessToken");
localStorage.removeItem("currentEvent");
};

return (
Expand All @@ -72,16 +96,13 @@ export function AppProvider({ children }: { children: ReactNode }) {
logout,
}}
>

{children}
</AppContext.Provider>
);
}

export function useApp() {
const context = useContext(AppContext);
if (!context) {
throw new Error('useApp must be used within an AppProvider');
}
return context;
const ctx = useContext(AppContext);
if (!ctx) throw new Error("useApp must be used within AppProvider");
return ctx;
}
Loading