260615_01_FST: First Commit
This commit is contained in:
23
src/app/(pages)/(main)/layout.tsx
Normal file
23
src/app/(pages)/(main)/layout.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import MainLayout from "@/components/layout/MainLayout";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import {CookieKeys} from "@/store/cookie/cookie-keys";
|
||||
|
||||
export default async function MainLayoutWrapper({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const cookieStore = await cookies();
|
||||
const accessToken = cookieStore.get(CookieKeys.AuthToken)?.value;
|
||||
|
||||
if (!accessToken) {
|
||||
//redirect("/logout");
|
||||
}
|
||||
|
||||
return (
|
||||
<MainLayout>
|
||||
{children}
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
||||
9
src/app/(pages)/(main)/monitoring/page.tsx
Normal file
9
src/app/(pages)/(main)/monitoring/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
'use client'
|
||||
|
||||
const MonitoringPage = () => {
|
||||
return (
|
||||
<div>MonitoringPage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MonitoringPage;
|
||||
31
src/app/(pages)/(main)/page.tsx
Normal file
31
src/app/(pages)/(main)/page.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
'use client'
|
||||
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {useEffect} from "react";
|
||||
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
import {MONITORING_USER_ROLE} from "@/config/gwcf.config";
|
||||
import {useRouter} from "next/navigation";
|
||||
|
||||
const MainPage = () => {
|
||||
const router = useRouter();
|
||||
const mounted = useMounted();
|
||||
const { auth, isMonitoring } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
if(auth && auth.user){
|
||||
if(isMonitoring){
|
||||
router.push("/monitoring");
|
||||
}
|
||||
else{
|
||||
router.push("/performance");
|
||||
}
|
||||
}
|
||||
}, [auth.user])
|
||||
|
||||
if (!mounted) return <LoadingOverlay force />;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default MainPage;
|
||||
9
src/app/(pages)/(main)/performance/page.tsx
Normal file
9
src/app/(pages)/(main)/performance/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
'use client'
|
||||
|
||||
const PerformancePage = () => {
|
||||
return (
|
||||
<div>PerformancePage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PerformancePage;
|
||||
9
src/app/(pages)/(main)/user/page.tsx
Normal file
9
src/app/(pages)/(main)/user/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
'use client'
|
||||
|
||||
const UserPage = () => {
|
||||
return (
|
||||
<div>UserPage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserPage;
|
||||
134
src/app/(pages)/login/page.tsx
Normal file
134
src/app/(pages)/login/page.tsx
Normal file
@@ -0,0 +1,134 @@
|
||||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Card, CardContent, CardHeader} from "@/components/ui/card";
|
||||
import {Input} from "@/components/ui/input";
|
||||
import React, {useEffect, useRef, useState} from "react";
|
||||
import {useRouter, useSearchParams} from "next/navigation";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
|
||||
import {useLoginMutation} from "@/query/auth";
|
||||
import {NONE_HTTP_ERROR} from "@/const/common.const";
|
||||
|
||||
const LoginPage = () => {
|
||||
const router = useRouter();
|
||||
const loginMutation = useLoginMutation();
|
||||
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [userId, setUserId] = useState<string>("");
|
||||
const [userPw, setUserPw] = useState<string>("");
|
||||
|
||||
const passwordInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const seatNumberInputRef = useRef<HTMLInputElement | null>(null);
|
||||
|
||||
const tryLogin = async () => {
|
||||
if (!userId) return alert("아이디를 입력해 주세요");
|
||||
if (!userPw) return alert("PW를 입력해 주세요");
|
||||
|
||||
setError(null);
|
||||
try {
|
||||
await loginMutation.mutateAsync({ userId, userPw });
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
if (err.status === 401 || err.status === 403) setError("아이디 또는 비밀번호를 다시 확인해주세요.");
|
||||
else if (err.code === NONE_HTTP_ERROR) setError("알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해주세요.");
|
||||
else setError(`로그인에 실패했습니다. (${err.message})`);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (loginMutation.isSuccess) {
|
||||
router.replace("/");
|
||||
}
|
||||
}, [loginMutation.isSuccess, router]);
|
||||
|
||||
const handleIdKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
passwordInputRef.current?.focus();
|
||||
}
|
||||
};
|
||||
|
||||
const handlePwKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
tryLogin();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gwcf-login-body p-4">
|
||||
<Card className="w-full max-w-md shadow-xl">
|
||||
<CardHeader className="space-y-4">
|
||||
<div className="flex justify-center">
|
||||
<div className="w-60 h-32 flex items-center justify-center">
|
||||
<Image
|
||||
src="/logo_short.png" // public/kri_logo.png
|
||||
alt="강원문화재단"
|
||||
width={200} // 원하는 크기로 줄이기
|
||||
height={200}
|
||||
className="object-contain"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">ID</label>
|
||||
<Input
|
||||
id="id"
|
||||
name="id"
|
||||
type="text"
|
||||
required
|
||||
placeholder="아이디를 입력하세요"
|
||||
value={userId}
|
||||
onChange={(e) => setUserId(e.currentTarget.value)}
|
||||
onKeyDown={handleIdKeyDown}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Password</label>
|
||||
<Input
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
required
|
||||
placeholder="PW를 입력하세요"
|
||||
value={userPw}
|
||||
onChange={(e) => setUserPw(e.currentTarget.value)}
|
||||
onKeyDown={handlePwKeyDown}
|
||||
ref={passwordInputRef}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="text-sm text-red-500">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full mt-6 h-11"
|
||||
disabled={loginMutation.isPending}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
tryLogin();
|
||||
}}
|
||||
>
|
||||
로그인
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LoginPage;
|
||||
20
src/app/(pages)/logout/page.tsx
Normal file
20
src/app/(pages)/logout/page.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
'use client'
|
||||
import { useLogoutMutation } from "@/query/auth";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
|
||||
const LogoutPage = () => {
|
||||
const router = useRouter();
|
||||
const logoutMutation = useLogoutMutation();
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
await logoutMutation.mutateAsync()
|
||||
router.replace("/login");
|
||||
})();
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default LogoutPage;
|
||||
Reference in New Issue
Block a user