260123_ENH : Layout가지 완성된 최초 commit
7
.env.development
Normal file
@@ -0,0 +1,7 @@
|
||||
NEXT_PUBLIC_ENV=dev
|
||||
NEXT_PUBLIC_API_BASE=http://localhost:6100/api
|
||||
|
||||
ENV=dev
|
||||
API_BACK_SERVER=http://localhost:6101/api/v1
|
||||
API_KART_SERVER=https://rapi.kric.com/api/v1
|
||||
KART_API_KEY=4B726963-436F6E74616374-46726F6E74-402531213230
|
||||
7
.env.local
Normal file
@@ -0,0 +1,7 @@
|
||||
NEXT_PUBLIC_ENV=local
|
||||
NEXT_PUBLIC_API_BASE=http://localhost:6100/api
|
||||
|
||||
ENV=local
|
||||
API_CONTACT_SERVER=http://localhost:6101/api/v1
|
||||
API_KART_SERVER=https://rapi.kric.com/api/v1
|
||||
KART_API_KEY=4B726963-436F6E74616374-46726F6E74-402531213230
|
||||
7
.env.production
Normal file
@@ -0,0 +1,7 @@
|
||||
NEXT_PUBLIC_ENV=prod
|
||||
NEXT_PUBLIC_API_BASE=http://localhost:6100/api
|
||||
|
||||
ENV=prod
|
||||
API_CONTACT_SERVER=http://localhost:6101/api/v1
|
||||
API_KART_SERVER=https://rapi.kric.com/api/v1
|
||||
KART_API_KEY=4B726963-436F6E74616374-46726F6E74-402531213230
|
||||
3
.gitignore
vendored
@@ -31,7 +31,8 @@ yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
#.env* #하위 env 파일 모두 금지
|
||||
#.env.local #.env.local 파일만 금지
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
BIN
app/favicon.ico
|
Before Width: | Height: | Size: 25 KiB |
@@ -1,26 +0,0 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
65
app/page.tsx
@@ -1,65 +0,0 @@
|
||||
import Image from "next/image";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
||||
<main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
||||
<Image
|
||||
className="dark:invert"
|
||||
src="/next.svg"
|
||||
alt="Next.js logo"
|
||||
width={100}
|
||||
height={20}
|
||||
priority
|
||||
/>
|
||||
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
|
||||
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
|
||||
To get started, edit the page.tsx file.
|
||||
</h1>
|
||||
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
||||
Looking for a starting point or more instructions? Head over to{" "}
|
||||
<a
|
||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Templates
|
||||
</a>{" "}
|
||||
or the{" "}
|
||||
<a
|
||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Learning
|
||||
</a>{" "}
|
||||
center.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
className="dark:invert"
|
||||
src="/vercel.svg"
|
||||
alt="Vercel logomark"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Deploy Now
|
||||
</a>
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
|
||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Documentation
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
22
components.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"$schema": "https://ui.shadcn.com/schema.json",
|
||||
"style": "new-york",
|
||||
"rsc": true,
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "",
|
||||
"css": "src/app/globals.css",
|
||||
"baseColor": "neutral",
|
||||
"cssVariables": true,
|
||||
"prefix": ""
|
||||
},
|
||||
"iconLibrary": "lucide",
|
||||
"aliases": {
|
||||
"components": "@/components",
|
||||
"utils": "@/lib/utils",
|
||||
"ui": "@/components/ui",
|
||||
"lib": "@/lib",
|
||||
"hooks": "@/hooks"
|
||||
},
|
||||
"registries": {}
|
||||
}
|
||||
@@ -3,16 +3,26 @@ import nextVitals from "eslint-config-next/core-web-vitals";
|
||||
import nextTs from "eslint-config-next/typescript";
|
||||
|
||||
const eslintConfig = defineConfig([
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
".next/**",
|
||||
"out/**",
|
||||
"build/**",
|
||||
"next-env.d.ts",
|
||||
]),
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
".next/**",
|
||||
"out/**",
|
||||
"build/**",
|
||||
"next-env.d.ts",
|
||||
]),
|
||||
{
|
||||
rules: {
|
||||
"@typescript-eslint/no-floating-promises": "off",
|
||||
"@typescript-eslint/no-explicit-any": "warn",
|
||||
"react-hooks/exhaustive-deps": "off",
|
||||
"react/no-did-mount-set-state": "off",
|
||||
"react/no-direct-mutation-state": "warn",
|
||||
"react-hooks/set-state-in-effect":"off",
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
export default eslintConfig;
|
||||
|
||||
1637
package-lock.json
generated
32
package.json
@@ -3,24 +3,46 @@
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"dev": "next dev -p 6100",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"start": "next start -p 6100",
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@radix-ui/react-dialog": "^1.1.15",
|
||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||
"@radix-ui/react-label": "^2.1.8",
|
||||
"@radix-ui/react-select": "^2.2.6",
|
||||
"@radix-ui/react-separator": "^1.1.8",
|
||||
"@radix-ui/react-slot": "^1.2.4",
|
||||
"@radix-ui/react-tabs": "^1.1.13",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"crypto-js": "^4.2.0",
|
||||
"echarts": "^6.0.0",
|
||||
"echarts-for-react": "^3.0.5",
|
||||
"jotai": "^2.16.2",
|
||||
"lodash": "^4.17.21",
|
||||
"lucide-react": "^0.562.0",
|
||||
"next": "16.1.4",
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3"
|
||||
"react-dom": "19.2.3",
|
||||
"sonner": "^2.0.7",
|
||||
"tailwind-merge": "^3.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@tailwindcss/postcss": "^4.0.7",
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/lodash": "^4.17.23",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.1.4",
|
||||
"tailwindcss": "^4",
|
||||
"postcss": "^8.5.6",
|
||||
"tailwindcss": "^4.0.7",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
public/favicon.ico
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
@@ -1 +0,0 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
Before Width: | Height: | Size: 391 B |
@@ -1 +0,0 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
Before Width: | Height: | Size: 1.0 KiB |
BIN
public/logo.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
Before Width: | Height: | Size: 1.3 KiB |
@@ -1 +0,0 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
Before Width: | Height: | Size: 128 B |
@@ -1 +0,0 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
Before Width: | Height: | Size: 385 B |
7
src/app/(pages)/(main)/category/air-solution/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
const AirSolutionPage = () => {
|
||||
return (
|
||||
<div>AirSolutionPage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default AirSolutionPage;
|
||||
7
src/app/(pages)/(main)/category/ha-kitchen/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
const HAKitchenPage = () => {
|
||||
return (
|
||||
<div>HAKitchenPage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default HAKitchenPage;
|
||||
7
src/app/(pages)/(main)/category/ha-living/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
const HALivingPage = () => {
|
||||
return (
|
||||
<div>HALivingPage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default HALivingPage;
|
||||
7
src/app/(pages)/(main)/category/ms-digital/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
const MSDigitalPage = () => {
|
||||
return (
|
||||
<div>MSDigitalPage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MSDigitalPage;
|
||||
24
src/app/(pages)/(main)/layout.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import {cookies} from "next/headers";
|
||||
import {redirect} from "next/navigation";
|
||||
import MainLayout from "@/components/layout/MainLayout";
|
||||
|
||||
const MainLayoutWrapper = async ({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) => {
|
||||
const cookieStore = await cookies();
|
||||
const accessToken = cookieStore.get("access_token")?.value;
|
||||
|
||||
if (!accessToken) {
|
||||
redirect("/logout");
|
||||
}
|
||||
|
||||
return(
|
||||
<MainLayout>
|
||||
{children}
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
||||
|
||||
export default MainLayoutWrapper;
|
||||
7
src/app/(pages)/(main)/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import {redirect} from "next/navigation";
|
||||
|
||||
const MainPage = () => {
|
||||
redirect("/total/penetration");
|
||||
}
|
||||
|
||||
export default MainPage;
|
||||
7
src/app/(pages)/(main)/total/lg-penetration/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
const LGPenetrationPage = () => {
|
||||
return (
|
||||
<div>LGPenetrationPage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LGPenetrationPage;
|
||||
7
src/app/(pages)/(main)/total/lg-purchase/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
const LGPurchasePage = () => {
|
||||
return (
|
||||
<div>LGPurchasePage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LGPurchasePage;
|
||||
7
src/app/(pages)/(main)/total/penetration/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
const PenetrationPage = () => {
|
||||
return (
|
||||
<div>PenetrationPage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PenetrationPage;
|
||||
7
src/app/(pages)/(main)/total/purchase/page.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
const PurchasePage = () => {
|
||||
return (
|
||||
<div>PurchasePage</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PurchasePage;
|
||||
166
src/app/(pages)/login/page.tsx
Normal file
@@ -0,0 +1,166 @@
|
||||
"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 { nextApi } from "@/lib/http-client";
|
||||
import {LoginUser} from "@/types/auth";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useLoading } from "@/hooks/useLoading";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
import {NONE_HTTP_ERROR} from "@/const/commonConst";
|
||||
|
||||
const LoginPage = () => {
|
||||
const { auth, setFromLoginResponse } = useAuth();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [userId, setUserId] = useState<string>("");
|
||||
const [userPw, setUserPw] = useState<string>("");
|
||||
|
||||
const passwordInputRef = useRef<HTMLInputElement | null>(null);
|
||||
|
||||
const tryLogin = () => {
|
||||
if(!userId){
|
||||
alert("아이디를 입력해 주세요");
|
||||
return;
|
||||
}
|
||||
if(!userPw){
|
||||
alert("PW를 입력해 주세요");
|
||||
return;
|
||||
}
|
||||
|
||||
setError(null);
|
||||
const loginRequestBody = {userId, userPw};
|
||||
const loginRequestOptions = {autoLogoutOnAuthError: false};
|
||||
|
||||
// withLoading 래퍼로 API 호출 전/후 로딩 표시를 자동으로 처리
|
||||
return withLoadingAsync(() =>
|
||||
nextApi.post<LoginUser>(
|
||||
"/login", loginRequestBody, loginRequestOptions
|
||||
).then(async (data) => {
|
||||
// Jotai 기반 전역 인증 상태 갱신
|
||||
setFromLoginResponse(data);
|
||||
}).catch((e) => {
|
||||
const err = apiError(e);
|
||||
console.error(err.status, err.code, err.message);
|
||||
|
||||
if (err.status === 401 || err.status === 403) {
|
||||
setError("아이디 또는 비밀번호를 다시 확인해주세요.");
|
||||
}
|
||||
else if(err.code === NONE_HTTP_ERROR) {
|
||||
setError("알 수 없는 오류가 발생했습니다. 잠시 후 다시 시도해주세요.");
|
||||
}
|
||||
else {
|
||||
setError(`로그인에 실패했습니다. (status: ${err.status})`);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if(auth.user){
|
||||
window.location.replace("/");
|
||||
}
|
||||
}, [auth.user]);
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
const handleSeatNumberKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
tryLogin();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center p-4 bg-lg-login">
|
||||
<Card className="w-full max-w-md shadow-xl">
|
||||
<CardHeader className="space-y-4">
|
||||
<div className="flex justify-center">
|
||||
<div className="w-60 h-20 flex items-center justify-center">
|
||||
<Image
|
||||
src="/logo.png" // public/logo.png
|
||||
alt="브랜드 로고"
|
||||
width={500} // 원하는 크기로 줄이기
|
||||
height={500}
|
||||
className="object-contain"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-center">
|
||||
<span className="content-text-2xl font-bold">LG 보급률 조사 Dashboard</span>
|
||||
</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-destructive">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full mt-6 h-11"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
tryLogin();
|
||||
}}
|
||||
>
|
||||
로그인
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LoginPage;
|
||||
39
src/app/(pages)/logout/page.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
'use client'
|
||||
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
import {useRouter} from "next/navigation";
|
||||
import {useEffect} from "react";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
|
||||
const LogoutPage = () => {
|
||||
const { auth, logout } = useAuth();
|
||||
const { withLoadingAsync } = useLoading();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const runLogout = async () => {
|
||||
const userId = auth.user?.userId ?? "";
|
||||
logout();
|
||||
|
||||
try {
|
||||
if(userId !== ""){
|
||||
const logoutRequestOptions = {autoLogoutOnAuthError: false};
|
||||
await nextApi.post(`/logout/${userId}`, null, logoutRequestOptions);
|
||||
}
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
console.error(err.status, err.code, err.message);
|
||||
}
|
||||
|
||||
router.replace("/login");
|
||||
};
|
||||
|
||||
withLoadingAsync(runLogout);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default LogoutPage;
|
||||
42
src/app/api/login/route.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import {createBackApi} from "@/lib/server-api";
|
||||
import {LoginRequest, LoginUser} from "@/types/auth";
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {serverEnv} from "@/lib/env.server";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
|
||||
type LoginResponse = {
|
||||
accessToken: string;
|
||||
user: LoginUser;
|
||||
};
|
||||
|
||||
export const POST = async (req: NextRequest) => {
|
||||
try {
|
||||
const backApi = await createBackApi();
|
||||
|
||||
const body = (await req.json()) as LoginRequest;
|
||||
//const result = await backApi.post<LoginResponse>("/auth/login", body);
|
||||
const result:LoginResponse = {
|
||||
accessToken: "abcdefghijklmnopqrstuvwxyz0123456789",
|
||||
user: {
|
||||
userId: "TEST_USER",
|
||||
userName: "TEST_USER",
|
||||
userCmpn: "TEST",
|
||||
userTeam: "TEST",
|
||||
userRole: 9999,
|
||||
}
|
||||
}
|
||||
|
||||
const res = NextResponse.json(result.user, { status: 200 });
|
||||
res.cookies.set("access_token", result.accessToken, {
|
||||
httpOnly: true,
|
||||
secure: serverEnv.ENV === "prod",
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
maxAge: 24 * 60 * 60, // 24시간
|
||||
});
|
||||
|
||||
return res;
|
||||
} catch (error : unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
}
|
||||
36
src/app/api/logout/[[...slug]]/route.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import {createBackApi} from "@/lib/server-api";
|
||||
import {serverEnv} from "@/lib/env.server";
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
context: RouteContext
|
||||
) {
|
||||
try {
|
||||
const {slug = []} = await context.params;
|
||||
const backApi = await createBackApi();
|
||||
|
||||
const [userId] = slug;
|
||||
|
||||
const url = userId
|
||||
? `/auth/logout/${encodeURIComponent(userId)}`
|
||||
: "/auth/logout/";
|
||||
|
||||
//await backApi.post<boolean>(url);
|
||||
const res = NextResponse.json({ ok: true });
|
||||
|
||||
res.cookies.set("access_token", "", {
|
||||
httpOnly: true,
|
||||
secure: serverEnv.ENV === "prod",
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
maxAge: 0,
|
||||
});
|
||||
|
||||
return res;
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
}
|
||||
483
src/app/globals.css
Normal file
@@ -0,0 +1,483 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
/* =============================
|
||||
Tailwind v4 Theme Tokens
|
||||
(shadcn/ui + custom tokens)
|
||||
============================= */
|
||||
@theme inline {
|
||||
/* Fonts (사용 중이면 자동 반영) */
|
||||
--font-sans: var(--font-sans);
|
||||
--font-mono: var(--font-mono);
|
||||
|
||||
/* Radius scale */
|
||||
--radius-sm: calc(var(--radius) - 4px);
|
||||
--radius-md: calc(var(--radius) - 2px);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) + 4px);
|
||||
--radius-2xl: calc(var(--radius) + 8px);
|
||||
--radius-3xl: calc(var(--radius) + 12px);
|
||||
--radius-4xl: calc(var(--radius) + 16px);
|
||||
|
||||
/* Core semantic colors */
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
|
||||
--color-card: var(--card);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
|
||||
--color-popover: var(--popover);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
|
||||
--color-primary: var(--primary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
|
||||
--color-secondary: var(--secondary);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
|
||||
--color-muted: var(--muted);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
|
||||
--color-accent: var(--accent);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
|
||||
--color-destructive: var(--destructive);
|
||||
|
||||
--color-border: var(--border);
|
||||
--color-input: var(--input);
|
||||
--color-ring: var(--ring);
|
||||
|
||||
/* Status */
|
||||
--color-success: var(--success);
|
||||
--color-warning: var(--warning);
|
||||
--color-info: var(--info);
|
||||
|
||||
/* Chart */
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-chart-6: var(--chart-6);
|
||||
--color-chart-7: var(--chart-7);
|
||||
--color-chart-8: var(--chart-8);
|
||||
--color-chart-9: var(--chart-9);
|
||||
--color-chart-10: var(--chart-10);
|
||||
--color-chart-border: var(--chart-border);
|
||||
|
||||
/* Sidebar (shadcn sidebar 토큰) */
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
}
|
||||
|
||||
/* =============================
|
||||
Base Tokens
|
||||
============================= */
|
||||
@layer base {
|
||||
:root {
|
||||
--radius: 0.75rem;
|
||||
--content-font-size: 14px;
|
||||
|
||||
/* Surface (oklch 유지) */
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
|
||||
--card: oklch(1 0 0);
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
|
||||
--popover: oklch(1 0 0);
|
||||
--popover-foreground: oklch(0.145 0 0);
|
||||
|
||||
/* =============================
|
||||
LG Scale
|
||||
(원본은 HSL triple 유지)
|
||||
============================= */
|
||||
--lg-gray-900: 0 0% 16%; /* #292929 */
|
||||
--lg-gray-800: 0 0% 24%; /* #3D3D3D */
|
||||
--lg-gray-700: 0 0% 35%; /* #595959 */
|
||||
--lg-gray-600: 0 0% 42%; /* #6B6B6B */
|
||||
--lg-gray-500: 0 0% 46%; /* #757575 */
|
||||
--lg-gray-400: 0 0% 50%; /* #7F7F7F */
|
||||
--lg-gray-300: 0 0% 75%; /* #BFBFBF */
|
||||
--lg-gray-200: 0 0% 85%; /* #D9D9D9 */
|
||||
|
||||
--lg-red-600: 341.1 100% 32.4%; /* #A50034 */
|
||||
--lg-red-500: 341.1 95% 44.0%; /* #DB0649 */
|
||||
--lg-red-400: 341.1 85% 56.0%; /* #EE2F6C */
|
||||
--lg-red-300: 341.1 75% 68.0%; /* #EB7097 */
|
||||
|
||||
--lg-pink-600: 324.7 100% 46.3%; /* #EC008B */
|
||||
--lg-pink-500: 324.7 95% 56.0%; /* #F924A2 */
|
||||
--lg-pink-400: 324.7 85% 66.0%; /* #F25FB5 */
|
||||
--lg-pink-300: 324.7 75% 76.0%; /* #F094CA */
|
||||
|
||||
--lg-purple-600: 263.0 65.9% 44.9%; /* #6127BE */
|
||||
--lg-purple-500: 263.0 60.0% 56.0%;
|
||||
--lg-purple-400: 263.0 52.0% 66.0%;
|
||||
--lg-purple-300: 263.0 45.0% 76.0%;
|
||||
|
||||
--lg-orange-600: 29.6 100% 45.7%; /* #E97300 */
|
||||
--lg-orange-500: 29.6 95% 56.0%;
|
||||
--lg-orange-400: 29.6 85% 68.0%;
|
||||
--lg-orange-300: 29.6 75% 78.0%;
|
||||
|
||||
/* =============================
|
||||
Brand Core
|
||||
(semantic은 "실제 색"으로 정의)
|
||||
============================= */
|
||||
--primary: hsl(var(--lg-red-600));
|
||||
--primary-foreground: hsl(0 0% 100%);
|
||||
|
||||
--secondary: hsl(var(--lg-gray-600));
|
||||
--secondary-foreground: hsl(0 0% 100%);
|
||||
|
||||
--muted: hsl(var(--lg-purple-600));
|
||||
--muted-foreground: hsl(0 0% 35%);
|
||||
|
||||
--accent: hsl(285 70% 78%); /* #B159C5 */
|
||||
--accent-foreground: hsl(0 0% 100%);
|
||||
|
||||
--brand-pink: hsl(var(--lg-pink-600));
|
||||
--brand-orange: hsl(var(--lg-orange-600));
|
||||
|
||||
/* Status Colors */
|
||||
--success: hsl(142 71% 45%);
|
||||
--warning: hsl(38 100% 50%);
|
||||
--info: hsl(198 100% 48%);
|
||||
--destructive: hsl(4 90% 58%);
|
||||
|
||||
/* Excel Colors */
|
||||
--excel: hsl(142 70% 31%); /* #1D6F42 (Excel Green) */
|
||||
--excel-foreground: hsl(0 0% 100%);
|
||||
|
||||
/* Borders / Ring */
|
||||
--border: hsl(340 25% 90%);
|
||||
--input: hsl(340 25% 90%);
|
||||
--ring: hsl(var(--lg-red-600));
|
||||
|
||||
/* =============================
|
||||
Chart Colors
|
||||
============================= */
|
||||
--chart-1: hsl(var(--lg-red-600));
|
||||
--chart-2: hsl(var(--lg-red-300));
|
||||
--chart-3: hsl(var(--lg-pink-300));
|
||||
--chart-4: hsl(var(--lg-pink-400));
|
||||
--chart-5: hsl(var(--lg-pink-600));
|
||||
--chart-6: hsl(var(--lg-gray-900));
|
||||
--chart-7: hsl(var(--lg-gray-800));
|
||||
--chart-8: hsl(var(--lg-gray-700));
|
||||
--chart-9: hsl(var(--lg-gray-600));
|
||||
--chart-10: hsl(var(--lg-gray-500));
|
||||
--chart-border: hsl(0 0% 95%);
|
||||
|
||||
/* =============================
|
||||
Sidebar
|
||||
============================= */
|
||||
--sidebar: oklch(0.985 0 0);
|
||||
--sidebar-foreground: oklch(0.145 0 0);
|
||||
--sidebar-primary: hsl(var(--lg-red-600));
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.97 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||
--sidebar-border: hsl(var(--lg-gray-200));
|
||||
--sidebar-ring: var(--ring);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: hsl(25 20% 12%);
|
||||
--foreground: hsl(0 0% 95%);
|
||||
|
||||
--card: hsl(25 18% 15%);
|
||||
--card-foreground: hsl(0 0% 95%);
|
||||
|
||||
--popover: hsl(25 18% 15%);
|
||||
--popover-foreground: hsl(0 0% 95%);
|
||||
|
||||
--primary: hsl(341 80% 55%);
|
||||
--primary-foreground: hsl(0 0% 100%);
|
||||
|
||||
--secondary: hsl(325 80% 60%);
|
||||
--secondary-foreground: hsl(0 0% 100%);
|
||||
|
||||
--muted: hsl(267 70% 60%);
|
||||
--muted-foreground: hsl(0 0% 70%);
|
||||
|
||||
--accent: hsl(285 60% 70%);
|
||||
--accent-foreground: hsl(0 0% 100%);
|
||||
|
||||
--success: hsl(142 60% 50%);
|
||||
--warning: hsl(38 95% 55%);
|
||||
--info: hsl(198 90% 55%);
|
||||
--destructive: hsl(4 80% 65%);
|
||||
|
||||
--excel: hsl(142 65% 45%); /* #33A357 */
|
||||
--excel-foreground: hsl(0 0% 100%);
|
||||
|
||||
--border: hsl(340 15% 22%);
|
||||
--input: hsl(340 15% 22%);
|
||||
--ring: hsl(341 80% 55%);
|
||||
|
||||
--sidebar: hsl(25 18% 15%);
|
||||
--sidebar-foreground: hsl(0 0% 95%);
|
||||
--sidebar-primary: hsl(341 80% 55%);
|
||||
--sidebar-primary-foreground: hsl(0 0% 100%);
|
||||
--sidebar-accent: hsl(25 18% 15%);
|
||||
--sidebar-accent-foreground: hsl(0 0% 95%);
|
||||
--sidebar-border: hsl(340 15% 22%);
|
||||
--sidebar-ring: var(--ring);
|
||||
}
|
||||
|
||||
* {
|
||||
@apply border-border outline-ring/50;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
}
|
||||
|
||||
/* =============================
|
||||
Convenience Classes
|
||||
(기존 프로젝트 호환용)
|
||||
============================= */
|
||||
* { border-color: var(--border); }
|
||||
|
||||
/* Token 기반 bg/text */
|
||||
.bg-white-hover { background-color: #fff; }
|
||||
.bg-white-hover:hover {
|
||||
background-color: var(--primary);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.bg-background { background-color: var(--background); }
|
||||
.bg-card { background-color: var(--card); }
|
||||
.bg-primary { background-color: var(--primary); }
|
||||
.bg-secondary { background-color: var(--secondary); }
|
||||
.bg-accent { background-color: var(--accent); }
|
||||
.bg-muted { background-color: var(--muted); }
|
||||
.bg-success { background-color: var(--success); }
|
||||
.bg-warning { background-color: var(--warning); }
|
||||
.bg-info { background-color: var(--info); }
|
||||
.bg-destructive { background-color: var(--destructive); }
|
||||
.bg-excel { background-color: var(--excel); }
|
||||
|
||||
.text-foreground { color: var(--foreground); }
|
||||
.text-primary { color: var(--primary); }
|
||||
.text-secondary { color: var(--secondary); }
|
||||
.text-secondary-hover { color: var(--secondary); }
|
||||
.text-secondary-hover:hover { color: var(--primary) !important; }
|
||||
.text-primary-foreground { color: var(--primary-foreground); }
|
||||
.text-muted-foreground { color: var(--muted-foreground); }
|
||||
.text-success { color: var(--success); }
|
||||
.text-warning { color: var(--warning); }
|
||||
.text-info { color: var(--info); }
|
||||
.text-destructive { color: var(--destructive); }
|
||||
.text-excel { color: var(--excel); }
|
||||
.text-excel-foreground { color: var(--excel-foreground); }
|
||||
|
||||
.border-border { border-color: var(--border); }
|
||||
|
||||
/* LG gray scale (Tailwind gray override 의도 유지) */
|
||||
.bg-gray-900 { background-color: hsl(var(--lg-gray-900)) !important; }
|
||||
.bg-gray-800 { background-color: hsl(var(--lg-gray-800)) !important; }
|
||||
.bg-gray-700 { background-color: hsl(var(--lg-gray-700)) !important; }
|
||||
.bg-gray-600 { background-color: hsl(var(--lg-gray-600)) !important; }
|
||||
.bg-gray-500 { background-color: hsl(var(--lg-gray-500)) !important; }
|
||||
.bg-gray-400 { background-color: hsl(var(--lg-gray-400)) !important; }
|
||||
.bg-gray-300 { background-color: hsl(var(--lg-gray-300)) !important; }
|
||||
.bg-gray-200 { background-color: hsl(var(--lg-gray-200)) !important; }
|
||||
|
||||
.border-gray-900 { border-color: hsl(var(--lg-gray-900)) !important; }
|
||||
.border-gray-800 { border-color: hsl(var(--lg-gray-800)) !important; }
|
||||
.border-gray-700 { border-color: hsl(var(--lg-gray-700)) !important; }
|
||||
.border-gray-600 { border-color: hsl(var(--lg-gray-600)) !important; }
|
||||
.border-gray-500 { border-color: hsl(var(--lg-gray-500)) !important; }
|
||||
.border-gray-400 { border-color: hsl(var(--lg-gray-400)) !important; }
|
||||
.border-gray-300 { border-color: hsl(var(--lg-gray-300)) !important; }
|
||||
.border-gray-200 { border-color: hsl(var(--lg-gray-200)) !important; }
|
||||
|
||||
/* LG Red/Pink/Purple/Orange scale overrides */
|
||||
.bg-red-600 { background-color: hsl(var(--lg-red-600)) !important; }
|
||||
.bg-red-500 { background-color: hsl(var(--lg-red-500)) !important; }
|
||||
.bg-red-400 { background-color: hsl(var(--lg-red-400)) !important; }
|
||||
.bg-red-300 { background-color: hsl(var(--lg-red-300)) !important; }
|
||||
|
||||
.bg-pink-600 { background-color: hsl(var(--lg-pink-600)) !important; }
|
||||
.bg-pink-500 { background-color: hsl(var(--lg-pink-500)) !important; }
|
||||
.bg-pink-400 { background-color: hsl(var(--lg-pink-400)) !important; }
|
||||
.bg-pink-300 { background-color: hsl(var(--lg-pink-300)) !important; }
|
||||
|
||||
.bg-purple-600 { background-color: hsl(var(--lg-purple-600)) !important; }
|
||||
.bg-purple-500 { background-color: hsl(var(--lg-purple-500)) !important; }
|
||||
.bg-purple-400 { background-color: hsl(var(--lg-purple-400)) !important; }
|
||||
.bg-purple-300 { background-color: hsl(var(--lg-purple-300)) !important; }
|
||||
|
||||
.bg-orange-600 { background-color: hsl(var(--lg-orange-600)) !important; }
|
||||
.bg-orange-500 { background-color: hsl(var(--lg-orange-500)) !important; }
|
||||
.bg-orange-400 { background-color: hsl(var(--lg-orange-400)) !important; }
|
||||
.bg-orange-300 { background-color: hsl(var(--lg-orange-300)) !important; }
|
||||
|
||||
/* LG Gradient Styles */
|
||||
.lg-gradient-red-pink {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, var(--brand-pink) 100%);
|
||||
}
|
||||
.lg-gradient-red-yellow {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, #FFC20A 100%);
|
||||
}
|
||||
.lg-gradient-pink-light {
|
||||
background: linear-gradient(135deg, #EC008B 0%, #FCE4E9 100%);
|
||||
}
|
||||
.lg-gradient-purple-light {
|
||||
background: linear-gradient(135deg, #6127BE 0%, #B159C5 100%);
|
||||
}
|
||||
.lg-gradient-orange-yellow {
|
||||
background: linear-gradient(135deg, #E97300 0%, #FFC20A 100%);
|
||||
}
|
||||
|
||||
/* =============================
|
||||
Content Text Size Utilities
|
||||
============================= */
|
||||
.content-text-xs { font-size: calc(var(--content-font-size) * 0.75); }
|
||||
.content-text-sm { font-size: calc(var(--content-font-size) * 0.875); }
|
||||
.content-text-base { font-size: calc(var(--content-font-size) * 1); }
|
||||
.content-text-lg { font-size: calc(var(--content-font-size) * 1.125); }
|
||||
.content-text-xl { font-size: calc(var(--content-font-size) * 1.25); }
|
||||
.content-text-2xl { font-size: calc(var(--content-font-size) * 1.5); }
|
||||
.content-text-3xl { font-size: calc(var(--content-font-size) * 1.875); }
|
||||
.content-text-4xl { font-size: calc(var(--content-font-size) * 2.25); }
|
||||
|
||||
@layer utilities {
|
||||
.placeholder-content-text-xs::placeholder { font-size: calc(var(--content-font-size) * 0.75); }
|
||||
.placeholder-content-text-sm::placeholder { font-size: calc(var(--content-font-size) * 0.875); }
|
||||
.placeholder-content-text-base::placeholder { font-size: calc(var(--content-font-size) * 1); }
|
||||
.placeholder-content-text-lg::placeholder { font-size: calc(var(--content-font-size) * 1.125); }
|
||||
.placeholder-content-text-xl::placeholder { font-size: calc(var(--content-font-size) * 1.25); }
|
||||
.placeholder-content-text-2xl::placeholder { font-size: calc(var(--content-font-size) * 1.5); }
|
||||
.placeholder-content-text-3xl::placeholder { font-size: calc(var(--content-font-size) * 1.875); }
|
||||
.placeholder-content-text-4xl::placeholder { font-size: calc(var(--content-font-size) * 2.25); }
|
||||
|
||||
.bg-lg-login {
|
||||
background-color: hsl(var(--background));
|
||||
background-image: linear-gradient(
|
||||
135deg,
|
||||
hsl(var(--lg-red-600) / 0.16) 0%,
|
||||
var(--background) 50%,
|
||||
hsl(var(--lg-pink-600) / 0.14) 100%
|
||||
);
|
||||
}
|
||||
|
||||
.bg-lg-main-body {
|
||||
background-color: hsl(var(--background));
|
||||
background-image: linear-gradient(
|
||||
135deg,
|
||||
hsl(var(--lg-red-500) / 0.12) 0%,
|
||||
var(--background) 50%,
|
||||
hsl(var(--lg-pink-500) / 0.10) 100%
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* =============================
|
||||
LG Components
|
||||
(Table / Category Card)
|
||||
============================= */
|
||||
@layer components {
|
||||
.lg-table {
|
||||
width: 100%;
|
||||
min-width: 980px;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
border: 0px !important;
|
||||
border-bottom: 3px solid hsl(var(--lg-gray-200)) !important;
|
||||
}
|
||||
|
||||
.lg-table th,
|
||||
.lg-table td {
|
||||
border: 1px solid hsl(var(--lg-gray-200)) !important;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
line-height: 1.15;
|
||||
text-align: center;
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.lg-table thead tr.lg-table__group th {
|
||||
background: hsl(var(--lg-gray-400));
|
||||
color: #fff;
|
||||
font-weight: 700;
|
||||
}
|
||||
.lg-table thead tr.lg-table__subhead th {
|
||||
background: hsl(var(--lg-gray-600));
|
||||
color: #fff;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.lg-table tbody th.lg-table__rowhead {
|
||||
text-align: left;
|
||||
font-weight: 700;
|
||||
color: var(--foreground);
|
||||
background: var(--background);
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.lg-table .lg-table__sep-l { border-left: 3px solid hsl(var(--lg-gray-200)) !important; }
|
||||
.lg-table .lg-table__sep-r { border-right: 3px solid hsl(var(--lg-gray-200)) !important; }
|
||||
|
||||
.lg-num-pos { color: var(--destructive); font-weight: 700; }
|
||||
.lg-num-neg { color: #1d4ed8; font-weight: 700; }
|
||||
|
||||
.lg-tab-content {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
border: 2px solid hsl(var(--lg-gray-300)) !important;
|
||||
border-radius: 0px 10px 10px 10px;
|
||||
padding: 18px;
|
||||
box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.lg-category-card {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
border: 2px solid hsl(var(--lg-gray-300)) !important;
|
||||
border-radius: 10px;
|
||||
padding: 18px;
|
||||
box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.lg-category-card__label {
|
||||
position: absolute;
|
||||
top: -16px;
|
||||
left: 16px;
|
||||
background: hsl(var(--lg-gray-800));
|
||||
color: #fff;
|
||||
padding: 6px 16px;
|
||||
border-radius: 9999px;
|
||||
font-weight: 800;
|
||||
font-size: 13px;
|
||||
letter-spacing: -0.02em;
|
||||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.lg-category-card__slot {
|
||||
height: 240px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dark .lg-category-card {
|
||||
background: var(--card);
|
||||
border-color: hsl(var(--lg-gray-700)) !important;
|
||||
}
|
||||
}
|
||||
36
src/app/layout.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import {Toaster} from "sonner";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "LG 보급률 조사 Dashboard",
|
||||
description: "LG 보급률 조사 Dashboard",
|
||||
};
|
||||
|
||||
const RootLayout = ({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) => {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className={`${geistSans.variable} ${geistMono.variable} antialiased`}>
|
||||
{children}
|
||||
<Toaster />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
};
|
||||
|
||||
export default RootLayout;
|
||||
147
src/components/layout/CategoryFilter.tsx
Normal file
@@ -0,0 +1,147 @@
|
||||
"use client";
|
||||
|
||||
import { CategoryTargetData, CategoryTargetType } from "@/config/filter.types";
|
||||
import {categoryTarget, categoryTargetType} from "@/config/filter.data";
|
||||
import { ChevronRight } from "lucide-react";
|
||||
import { useMemo } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
const PRODUCTS = [
|
||||
{ value: "냉장고", label: "냉장고" },
|
||||
{ value: "세탁기", label: "세탁기" },
|
||||
{ value: "식기세척기", label: "식기세척기" },
|
||||
{ value: "건조기", label: "건조기" },
|
||||
{ value: "에어컨", label: "에어컨" },
|
||||
] as const;
|
||||
|
||||
export type CategoryTypeValue = {
|
||||
label: string;
|
||||
value: CategoryTargetType;
|
||||
};
|
||||
|
||||
export type CategoryFilterValue = {
|
||||
product: string;
|
||||
type: CategoryTypeValue
|
||||
target: CategoryTargetData;
|
||||
};
|
||||
|
||||
type CategoryFilterProps = {
|
||||
value: CategoryFilterValue;
|
||||
onChange: (next: CategoryFilterValue) => void;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
const CategoryFilter = ({ value, onChange, className }: CategoryFilterProps) => {
|
||||
|
||||
const currentTargetItem = useMemo(() => {
|
||||
return categoryTarget.find((item) => item.type === value.type.value);
|
||||
}, [value.type]);
|
||||
|
||||
const handlePick = (
|
||||
key: keyof CategoryFilterValue,
|
||||
v: string | CategoryTypeValue | CategoryTargetData
|
||||
) => {
|
||||
if (value[key] === v) return;
|
||||
|
||||
const next: CategoryFilterValue = { ...value, [key]: v } as CategoryFilterValue;
|
||||
|
||||
if (key === "type") {
|
||||
const nextItem = categoryTarget.find((item) => item.type === v);
|
||||
const firstTarget = nextItem?.children?.[0]?.target;
|
||||
if (firstTarget) next.target = firstTarget;
|
||||
}
|
||||
|
||||
onChange(next);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn("w-full border border-gray-300 bg-white/70 backdrop-blur-sm", className)}>
|
||||
{/* 제품 (1줄 나열) */}
|
||||
<div className="flex min-w-0 border-b border-gray-200">
|
||||
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
|
||||
<ChevronRight className="h-4 w-4 text-gray-700" />
|
||||
<span className="text-sm font-semibold text-gray-900 content-text-sm">제품</span>
|
||||
</div>
|
||||
|
||||
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
|
||||
<div className="flex w-max items-center gap-1 whitespace-nowrap">
|
||||
{PRODUCTS.map((p) => {
|
||||
const active = value.product === p.value;
|
||||
return (
|
||||
<Button
|
||||
key={p.value}
|
||||
type="button"
|
||||
variant={active ? "default" : "secondary"}
|
||||
onClick={() => handlePick("product", p.value)}
|
||||
className="h-6 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-sm"
|
||||
>
|
||||
{p.label}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 기준 (1줄 나열) */}
|
||||
<div className="flex min-w-0 border-b border-gray-200">
|
||||
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
|
||||
<ChevronRight className="h-4 w-4 text-gray-700" />
|
||||
<span className="text-sm font-semibold text-gray-900 content-text-sm">기준</span>
|
||||
</div>
|
||||
|
||||
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
|
||||
<div className="flex w-max items-center gap-1 whitespace-nowrap">
|
||||
{categoryTargetType.map((item) => {
|
||||
const active = value.type.label === item.label;
|
||||
|
||||
return (
|
||||
<Button
|
||||
key={item.label}
|
||||
type="button"
|
||||
variant={active ? "default" : "secondary"}
|
||||
onClick={() => {
|
||||
handlePick("type", {label:item.label, value:item.value});
|
||||
}}
|
||||
className="h-6 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-sm"
|
||||
>
|
||||
{item.label}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 데이터 (1줄 나열) */}
|
||||
<div className="flex min-w-0">
|
||||
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
|
||||
<ChevronRight className="h-4 w-4 text-gray-700" />
|
||||
<span className="text-sm font-semibold text-gray-900 content-text-sm">데이터</span>
|
||||
</div>
|
||||
|
||||
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
|
||||
<div className="flex w-max items-center gap-1 whitespace-nowrap">
|
||||
{currentTargetItem?.children?.map((child) => {
|
||||
const active = value.target === child.target;
|
||||
return (
|
||||
<Button
|
||||
key={child.target}
|
||||
type="button"
|
||||
variant={active ? "default" : "secondary"}
|
||||
onClick={() => handlePick("target", child.target)}
|
||||
className="h-6 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-sm"
|
||||
>
|
||||
{child.label}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CategoryFilter;
|
||||
98
src/components/layout/Header.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {useEffect, useState} from "react";
|
||||
import {LoginUser} from "@/types/auth";
|
||||
import Image from "next/image";
|
||||
import {topMenus} from "@/config/menu.data";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {LogOut} from "lucide-react";
|
||||
import {DASHBOARD_YEAR} from "@/const/commonConst";
|
||||
import {cn} from "@/lib/utils";
|
||||
|
||||
interface HeaderProps {
|
||||
activeTopId: string;
|
||||
onNavigate: (path: string) => void;
|
||||
}
|
||||
|
||||
const Header = ({
|
||||
activeTopId,
|
||||
onNavigate,
|
||||
}: HeaderProps) => {
|
||||
const { auth } = useAuth();
|
||||
const [userInfo, setUserInfo] = useState<LoginUser|undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
if(auth.user){
|
||||
setUserInfo(auth.user);
|
||||
}
|
||||
else{
|
||||
window.location.replace("/logout");
|
||||
}
|
||||
}, [auth.user])
|
||||
|
||||
return (
|
||||
<header className="bg-white border-b border-gray-200 sticky top-0 z-40">
|
||||
<div className="flex items-center justify-between px-4 h-16">
|
||||
<div className="flex items-center gap-4">
|
||||
{/* 로고 */}
|
||||
<div className="flex items-center gap-2 cursor-pointer w-30 h-15 justify-center">
|
||||
<Image
|
||||
src="/logo.png" // public/logo.png
|
||||
alt="브랜드 로고"
|
||||
width={200}
|
||||
height={80}
|
||||
className="object-contain"
|
||||
onClick={() => onNavigate("/total/penetration")}
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 상단 메뉴 */}
|
||||
<nav className="flex items-center gap-1 ml-5">
|
||||
{topMenus.map((m) => {
|
||||
const active = activeTopId === m.id;
|
||||
return (
|
||||
<button
|
||||
key={m.id}
|
||||
type="button"
|
||||
onClick={() => onNavigate(m.path)}
|
||||
className={cn(
|
||||
"relative h-10 inline-flex items-center font-semibold transition-colors cursor-pointer",
|
||||
"content-text-base bg-transparent px-1",
|
||||
active
|
||||
? "text-primary"
|
||||
: "text-secondary-hover"
|
||||
)}
|
||||
>
|
||||
{m.label}
|
||||
|
||||
{/* 선택 표시(밑줄) */}
|
||||
{active && (
|
||||
<span className="absolute left-0 right-0 -bottom-[2px] h-[2px] bg-primary" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
<div className="flex justify-between items-center">
|
||||
<h1 className="font-bold content-text-2xl">{DASHBOARD_YEAR}년도 가전보급률 Dashboard</h1>
|
||||
</div>
|
||||
{/* 우측 컨트롤 */}
|
||||
<div className="flex items-center gap-4">
|
||||
<span className="text-sm text-gray-600 hidden sm:inline font-bold">{userInfo?.userName || ""}</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
onClick={() => onNavigate("/logout")}
|
||||
>
|
||||
<LogOut className="w-4 h-4" />
|
||||
<span className="hidden sm:inline">로그아웃</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
export default Header;
|
||||
127
src/components/layout/MainLayout.tsx
Normal file
@@ -0,0 +1,127 @@
|
||||
"use client";
|
||||
|
||||
import {ReactNode, useState} from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import {topMenus, totalSubMenus, categorySubMenus} from "@/config/menu.data";
|
||||
import Header from "./Header";
|
||||
import SubMenu from "./SubMenu";
|
||||
import TotalFilter from "@/components/layout/TotalFilter";
|
||||
import CategoryFilter, {CategoryFilterValue} from "@/components/layout/CategoryFilter";
|
||||
import {cn} from "@/lib/utils";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {categoryTarget, totalFilters} from "@/config/filter.data";
|
||||
import {CategoryTargetData, CategoryTargetType} from "@/config/filter.types";
|
||||
|
||||
type MainLayoutProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
const buildDefaultTotalValue = (): SelectedMap => {
|
||||
const init: SelectedMap = {};
|
||||
totalFilters.forEach((f) => {
|
||||
// "전체"가 있으면 그 value, 없으면 첫 번째 값
|
||||
const all = f.children.find((c) => c.label === "전체");
|
||||
init[f.variable] = all?.value ?? f.children[0]?.value ?? "";
|
||||
});
|
||||
return init;
|
||||
};
|
||||
|
||||
export const buildDefaultCategoryValue = (): CategoryFilterValue => {
|
||||
const initType = {label:"보유", value:CategoryTargetType.PENETRATION}
|
||||
const firstTarget = categoryTarget.find((x) => x.type === initType.value)?.children?.[0]?.target;
|
||||
|
||||
return {
|
||||
product: "냉장고",
|
||||
type: initType,
|
||||
target: firstTarget ?? CategoryTargetData.PROFILE,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const MainLayout = ({ children }: MainLayoutProps) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
const isTotal = pathname.startsWith("/total");
|
||||
const activeTop = topMenus.find((m) => m.match?.(pathname)) ?? topMenus[0];
|
||||
const subMenus = isTotal ? totalSubMenus : categorySubMenus;
|
||||
const activeSub = subMenus.find((m) => m.path.startsWith(pathname)) ?? subMenus[0];
|
||||
|
||||
const [isTotalFilterOpen, setIsTotalFilterOpen] = useState(true);
|
||||
const [isCategoryFilterOpen, setIsCategoryFilterOpen] = useState(true);
|
||||
const isFilterOpen = isTotal ? isTotalFilterOpen : isCategoryFilterOpen;
|
||||
|
||||
const [totalValue, setTotalValue] = useState<SelectedMap>(() => buildDefaultTotalValue());
|
||||
const [categoryValue, setCategoryValue] = useState<CategoryFilterValue>(() => buildDefaultCategoryValue());
|
||||
|
||||
const movePage = (path: string) => {
|
||||
router.push(path);
|
||||
};
|
||||
|
||||
const toggleFilter = () => {
|
||||
if (isTotal) setIsTotalFilterOpen((v) => !v);
|
||||
else setIsCategoryFilterOpen((v) => !v);
|
||||
};
|
||||
|
||||
const handleExcelDownload = async () => {
|
||||
// TODO: 다운로드 구현 필요
|
||||
console.log("Excel download:", { pathname, top: activeTop.id, sub: activeSub.id });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col bg-transparent">
|
||||
<Header
|
||||
activeTopId={activeTop.id}
|
||||
onNavigate={movePage}
|
||||
/>
|
||||
<div className="flex-1 min-h-0 flex flex-col bg-lg-main-body p-1 pl-6">
|
||||
<SubMenu
|
||||
subMenu={subMenus}
|
||||
activeSubId={activeSub.id}
|
||||
onNavigate={movePage}
|
||||
/>
|
||||
<div className="flex-1 min-h-0 flex flex-col pr-4">
|
||||
<div className="bg-card lg-tab-content flex-1 min-h-0">
|
||||
<div className="shrink-0 flex items-center justify-between px-2 py-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleFilter}
|
||||
className={cn(
|
||||
"inline-flex items-center gap-2 font-semibold text-gray-900 content-text-sm",
|
||||
"select-none"
|
||||
)}
|
||||
>
|
||||
필터 <span className="text-sm leading-none">{isFilterOpen ? "▲" : "▼"}</span>
|
||||
</button>
|
||||
|
||||
<Button
|
||||
variant="excel"
|
||||
className="h-8 px-3 text-sm font-semibold content-text-sm"
|
||||
onClick={handleExcelDownload}>
|
||||
Excel 다운로드
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{isFilterOpen && (
|
||||
<div className="shrink-0">
|
||||
{isTotal ? (
|
||||
<TotalFilter filters={totalFilters} value={totalValue} onChange={setTotalValue} />
|
||||
) : (
|
||||
<CategoryFilter value={categoryValue} onChange={setCategoryValue} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ✅ 실제 콘텐츠만 스크롤 */}
|
||||
<div className="flex-1 min-h-0 overflow-auto">
|
||||
<div className="p-3">{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MainLayout;
|
||||
48
src/components/layout/SubMenu.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import {SubMenuItem} from "@/config/menu.types";
|
||||
import {cn} from "@/lib/utils";
|
||||
|
||||
interface SubMenuProps {
|
||||
subMenu: SubMenuItem[];
|
||||
activeSubId: string;
|
||||
onNavigate: (path: string) => void;
|
||||
}
|
||||
|
||||
const SubMenu = ({
|
||||
subMenu,
|
||||
activeSubId,
|
||||
onNavigate,
|
||||
}: SubMenuProps) => {
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between pt-3">
|
||||
<nav className="flex items-center gap-1">
|
||||
{subMenu.map((m, idx) => {
|
||||
const active = activeSubId === m.id;
|
||||
|
||||
return (
|
||||
<button
|
||||
key={m.id}
|
||||
type="button"
|
||||
onClick={() => onNavigate(m.path)}
|
||||
className={cn(
|
||||
"h-10 px-5 content-text-sm font-semibold transition-colors -mb-0.75",
|
||||
"border border-gray-200",
|
||||
"-ml-px first:ml-0 rounded-tl-lg rounded-tr-lg cursor-pointer", // 탭이 서로 '붙어' 보이게
|
||||
active
|
||||
? "bg-primary text-primary-foreground z-40"
|
||||
: "bg-white-hover text-secondary"
|
||||
)}
|
||||
style={active ? {
|
||||
boxShadow: '0 4px 6px -1px rgba(165, 0, 52, 0.15), 0 2px 4px -1px rgba(165, 0, 52, 0.1)'
|
||||
} : undefined}
|
||||
>
|
||||
{m.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default SubMenu;
|
||||
100
src/components/layout/TotalFilter.tsx
Normal file
@@ -0,0 +1,100 @@
|
||||
import {TotalFilterItem} from "@/config/filter.types";
|
||||
import {SelectedMap} from "@/types/common";
|
||||
import {useMemo} from "react";
|
||||
import {cn} from "@/lib/utils";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {ChevronRight} from "lucide-react";
|
||||
|
||||
|
||||
type TotalFilterProps = {
|
||||
filters: TotalFilterItem[];
|
||||
value: SelectedMap;
|
||||
onChange: (next: SelectedMap) => void;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
const TotalFilter = ({
|
||||
filters,
|
||||
value,
|
||||
onChange,
|
||||
className
|
||||
}: TotalFilterProps) => {
|
||||
|
||||
const handlePick = (variable: string, v: string) => {
|
||||
if (value[variable] === v) return;
|
||||
onChange({ ...value, [variable]: v });
|
||||
};
|
||||
|
||||
const arranged = useMemo(() => {
|
||||
const rows = filters ?? [];
|
||||
|
||||
/**
|
||||
* 현재 적용: 1 5 / 2 6 / 3 7 / 4 8
|
||||
* 1 2 / 3 4 / 5 6 / 7 8 으로 반환하려면 그냥 rows를 반환하면 됨
|
||||
* - 렌더링은 [1,5,2,6,3,7,4,8] 순서로 생성
|
||||
*/
|
||||
const half = Math.ceil(rows.length / 2);
|
||||
const out: TotalFilterItem[] = [];
|
||||
|
||||
for (let i = 0; i < half; i++) {
|
||||
if (rows[i]) out.push(rows[i]);
|
||||
if (rows[i + half]) out.push(rows[i + half]);
|
||||
}
|
||||
return out;
|
||||
}, [filters]);
|
||||
|
||||
const rowCount = Math.ceil(arranged.length / 2);
|
||||
|
||||
return (
|
||||
<div className={cn("w-full border border-gray-300 bg-white/70 backdrop-blur-sm", className)}>
|
||||
<div className="grid grid-cols-2">
|
||||
{arranged.map((row, idx) => {
|
||||
const current = value[row.variable] ?? "";
|
||||
const col = idx % 2; // 0: left, 1: right
|
||||
const r = Math.floor(idx / 2);
|
||||
const isLastRow = r === rowCount - 1;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={row.variable}
|
||||
className={cn(
|
||||
"flex min-w-0",
|
||||
!isLastRow && "border-b border-gray-200",
|
||||
col === 1 && "border-l-4 border-gray-300"
|
||||
)}
|
||||
>
|
||||
{/* 좌측 라벨 */}
|
||||
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
|
||||
<ChevronRight className="h-4 w-4 text-gray-700" />
|
||||
<span className="text-sm font-semibold text-gray-900 content-text-sm">
|
||||
{row.variableName}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 우측 옵션 */}
|
||||
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-1 px-2 py-2">
|
||||
{row.children.map((c) => {
|
||||
const active = current === c.value;
|
||||
|
||||
return (
|
||||
<Button
|
||||
key={`${row.variable}_${c.value}`}
|
||||
type="button"
|
||||
variant={active ? "default" : "secondary"}
|
||||
onClick={() => handlePick(row.variable, c.value)}
|
||||
className="h-6 rounded-sm px-3 text-sm font-semibold content-text-sm"
|
||||
>
|
||||
{c.label}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default TotalFilter;
|
||||
46
src/components/ui/badge.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
||||
secondary:
|
||||
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
||||
destructive:
|
||||
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"span"> &
|
||||
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "span"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="badge"
|
||||
className={cn(badgeVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
66
src/components/ui/button.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const buttonVariants = cva(
|
||||
"cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:opacity-90",
|
||||
destructive:
|
||||
"bg-destructive text-white hover:opacity-90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:hover:opacity-60",
|
||||
outline:
|
||||
"border bg-background shadow-xs hover:bg-secondary hover:text-secondary-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:opacity-80",
|
||||
excel:
|
||||
"bg-excel text-excel-foreground hover:opacity-80",
|
||||
accent:
|
||||
"bg-accent text-accent-foreground hover:opacity-60",
|
||||
ghost:
|
||||
"hover:bg-primary hover:text-primary-foreground dark:hover:opacity-50",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||
icon: "size-9",
|
||||
"icon-sm": "size-8",
|
||||
"icon-lg": "size-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="button"
|
||||
data-variant={variant}
|
||||
data-size={size}
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Button, buttonVariants }
|
||||
92
src/components/ui/card.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card"
|
||||
className={cn(
|
||||
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-header"
|
||||
className={cn(
|
||||
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-title"
|
||||
className={cn("leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-action"
|
||||
className={cn(
|
||||
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-content"
|
||||
className={cn("px-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-footer"
|
||||
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Card,
|
||||
CardHeader,
|
||||
CardFooter,
|
||||
CardTitle,
|
||||
CardAction,
|
||||
CardDescription,
|
||||
CardContent,
|
||||
}
|
||||
143
src/components/ui/dialog.tsx
Normal file
@@ -0,0 +1,143 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
||||
import { XIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Dialog({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
||||
}
|
||||
|
||||
function DialogTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
||||
}
|
||||
|
||||
function DialogPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
||||
}
|
||||
|
||||
function DialogClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
||||
}
|
||||
|
||||
function DialogOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
||||
return (
|
||||
<DialogPrimitive.Overlay
|
||||
data-slot="dialog-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogContent({
|
||||
className,
|
||||
children,
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DialogPortal data-slot="dialog-portal">
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
data-slot="dialog-content"
|
||||
className={cn(
|
||||
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close
|
||||
data-slot="dialog-close"
|
||||
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
||||
>
|
||||
<XIcon />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-header"
|
||||
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-footer"
|
||||
className={cn(
|
||||
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||
return (
|
||||
<DialogPrimitive.Title
|
||||
data-slot="dialog-title"
|
||||
className={cn("text-lg leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||
return (
|
||||
<DialogPrimitive.Description
|
||||
data-slot="dialog-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
}
|
||||
257
src/components/ui/dropdown-menu.tsx
Normal file
@@ -0,0 +1,257 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
|
||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function DropdownMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Trigger
|
||||
data-slot="dropdown-menu-trigger"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuContent({
|
||||
className,
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
data-slot="dropdown-menu-content"
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean
|
||||
variant?: "default" | "destructive"
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Item
|
||||
data-slot="dropdown-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
data-slot="dropdown-menu-checkbox-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioGroup
|
||||
data-slot="dropdown-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
data-slot="dropdown-menu-radio-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CircleIcon className="size-2 fill-current" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Label
|
||||
data-slot="dropdown-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
data-slot="dropdown-menu-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="dropdown-menu-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
data-slot="dropdown-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto size-4" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
data-slot="dropdown-menu-sub-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuSubContent,
|
||||
}
|
||||
21
src/components/ui/input.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Input }
|
||||
24
src/components/ui/label.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Label({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
return (
|
||||
<LabelPrimitive.Root
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Label }
|
||||
190
src/components/ui/select.tsx
Normal file
@@ -0,0 +1,190 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SelectPrimitive from "@radix-ui/react-select"
|
||||
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Select({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||
return <SelectPrimitive.Root data-slot="select" {...props} />
|
||||
}
|
||||
|
||||
function SelectGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||
return <SelectPrimitive.Group data-slot="select-group" {...props} />
|
||||
}
|
||||
|
||||
function SelectValue({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
||||
}
|
||||
|
||||
function SelectTrigger({
|
||||
className,
|
||||
size = "default",
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||
size?: "sm" | "default"
|
||||
}) {
|
||||
return (
|
||||
<SelectPrimitive.Trigger
|
||||
data-slot="select-trigger"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<ChevronDownIcon className="size-4 opacity-50" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectContent({
|
||||
className,
|
||||
children,
|
||||
position = "item-aligned",
|
||||
align = "center",
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||
return (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
data-slot="select-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
|
||||
position === "popper" &&
|
||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||
className
|
||||
)}
|
||||
position={position}
|
||||
align={align}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.Viewport
|
||||
className={cn(
|
||||
"p-1",
|
||||
position === "popper" &&
|
||||
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectLabel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||
return (
|
||||
<SelectPrimitive.Label
|
||||
data-slot="select-label"
|
||||
className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||
return (
|
||||
<SelectPrimitive.Item
|
||||
data-slot="select-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
data-slot="select-item-indicator"
|
||||
className="absolute right-2 flex size-3.5 items-center justify-center"
|
||||
>
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||
return (
|
||||
<SelectPrimitive.Separator
|
||||
data-slot="select-separator"
|
||||
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollUpButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollUpButton
|
||||
data-slot="select-scroll-up-button"
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUpIcon className="size-4" />
|
||||
</SelectPrimitive.ScrollUpButton>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollDownButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollDownButton
|
||||
data-slot="select-scroll-down-button"
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDownIcon className="size-4" />
|
||||
</SelectPrimitive.ScrollDownButton>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectScrollDownButton,
|
||||
SelectScrollUpButton,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
}
|
||||
28
src/components/ui/separator.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Separator({
|
||||
className,
|
||||
orientation = "horizontal",
|
||||
decorative = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
|
||||
return (
|
||||
<SeparatorPrimitive.Root
|
||||
data-slot="separator"
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Separator }
|
||||
40
src/components/ui/sonner.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
"use client"
|
||||
|
||||
import {
|
||||
CircleCheckIcon,
|
||||
InfoIcon,
|
||||
Loader2Icon,
|
||||
OctagonXIcon,
|
||||
TriangleAlertIcon,
|
||||
} from "lucide-react"
|
||||
import { useTheme } from "next-themes"
|
||||
import { Toaster as Sonner, type ToasterProps } from "sonner"
|
||||
|
||||
const Toaster = ({ ...props }: ToasterProps) => {
|
||||
const { theme = "system" } = useTheme()
|
||||
|
||||
return (
|
||||
<Sonner
|
||||
theme={theme as ToasterProps["theme"]}
|
||||
className="toaster group"
|
||||
icons={{
|
||||
success: <CircleCheckIcon className="size-4" />,
|
||||
info: <InfoIcon className="size-4" />,
|
||||
warning: <TriangleAlertIcon className="size-4" />,
|
||||
error: <OctagonXIcon className="size-4" />,
|
||||
loading: <Loader2Icon className="size-4 animate-spin" />,
|
||||
}}
|
||||
style={
|
||||
{
|
||||
"--normal-bg": "var(--popover)",
|
||||
"--normal-text": "var(--popover-foreground)",
|
||||
"--normal-border": "var(--border)",
|
||||
"--border-radius": "var(--radius)",
|
||||
} as React.CSSProperties
|
||||
}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Toaster }
|
||||
116
src/components/ui/table.tsx
Normal file
@@ -0,0 +1,116 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="table-container"
|
||||
className="relative w-full overflow-x-auto"
|
||||
>
|
||||
<table
|
||||
data-slot="table"
|
||||
className={cn("w-full caption-bottom text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
||||
return (
|
||||
<thead
|
||||
data-slot="table-header"
|
||||
className={cn("[&_tr]:border-b", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
||||
return (
|
||||
<tbody
|
||||
data-slot="table-body"
|
||||
className={cn("[&_tr:last-child]:border-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
||||
return (
|
||||
<tfoot
|
||||
data-slot="table-footer"
|
||||
className={cn(
|
||||
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
||||
return (
|
||||
<tr
|
||||
data-slot="table-row"
|
||||
className={cn(
|
||||
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
||||
return (
|
||||
<th
|
||||
data-slot="table-head"
|
||||
className={cn(
|
||||
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||
return (
|
||||
<td
|
||||
data-slot="table-cell"
|
||||
className={cn(
|
||||
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableCaption({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"caption">) {
|
||||
return (
|
||||
<caption
|
||||
data-slot="table-caption"
|
||||
className={cn("text-muted-foreground mt-4 text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableFooter,
|
||||
TableHead,
|
||||
TableRow,
|
||||
TableCell,
|
||||
TableCaption,
|
||||
}
|
||||
66
src/components/ui/tabs.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Tabs({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
|
||||
return (
|
||||
<TabsPrimitive.Root
|
||||
data-slot="tabs"
|
||||
className={cn("flex flex-col gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.List>) {
|
||||
return (
|
||||
<TabsPrimitive.List
|
||||
data-slot="tabs-list"
|
||||
className={cn(
|
||||
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsTrigger({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
|
||||
return (
|
||||
<TabsPrimitive.Trigger
|
||||
data-slot="tabs-trigger"
|
||||
className={cn(
|
||||
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
|
||||
return (
|
||||
<TabsPrimitive.Content
|
||||
data-slot="tabs-content"
|
||||
className={cn("flex-1 outline-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
||||
18
src/components/ui/textarea.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||
return (
|
||||
<textarea
|
||||
data-slot="textarea"
|
||||
className={cn(
|
||||
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Textarea }
|
||||
144
src/config/filter.data.ts
Normal file
@@ -0,0 +1,144 @@
|
||||
import {
|
||||
CategoryTargetData,
|
||||
CategoryTargetItem,
|
||||
CategoryTargetType,
|
||||
CategoryTargetTypeItem,
|
||||
TotalFilterItem
|
||||
} from "./filter.types";
|
||||
|
||||
export const totalFilters:TotalFilterItem[] = [
|
||||
{
|
||||
variable:"a1",
|
||||
variableName:"라이프 스테이지",
|
||||
children:[
|
||||
{ value: "0", label: "전체"},
|
||||
{ value: "1", label: "미혼"},
|
||||
{ value: "2", label: "기혼 무자녀"},
|
||||
{ value: "3", label: "기혼 미취학자녀"},
|
||||
{ value: "4", label: "기혼 학령기"},
|
||||
{ value: "5", label: "기혼 성인자녀"},
|
||||
{ value: "6", label: "독립 시니어"},
|
||||
]
|
||||
},
|
||||
{
|
||||
variable:"a2",
|
||||
variableName:"월 소득 규모",
|
||||
children:[
|
||||
{ value: "0", label: "전체"},
|
||||
{ value: "1", label: "299만원 이하"},
|
||||
{ value: "2", label: "300~599만원 이하"},
|
||||
{ value: "3", label: "600~899만원 이하"},
|
||||
{ value: "4", label: "900만원 이상"},
|
||||
]
|
||||
},
|
||||
{
|
||||
variable:"a3",
|
||||
variableName:"거주 형태",
|
||||
children:[
|
||||
{ value: "0", label: "전체"},
|
||||
{ value: "1", label: "자가"},
|
||||
{ value: "2", label: "전세"},
|
||||
{ value: "3", label: "전+월세(보증금有)"},
|
||||
{ value: "4", label: "월세(보증금無)"},
|
||||
{ value: "5", label: "기타"},
|
||||
]
|
||||
},
|
||||
{
|
||||
variable:"a4",
|
||||
variableName:"거주 평형",
|
||||
children:[
|
||||
{ value: "0", label: "19평 이하"},
|
||||
{ value: "1", label: "20평형 대"},
|
||||
{ value: "2", label: "30평형 대"},
|
||||
{ value: "3", label: "40평형 대"},
|
||||
{ value: "4", label: "50평형 이상"},
|
||||
]
|
||||
},
|
||||
{
|
||||
variable:"a5",
|
||||
variableName:"주택 형태",
|
||||
children:[
|
||||
{ value: "0", label: "전체"},
|
||||
{ value: "1", label: "아파트"},
|
||||
{ value: "2", label: "주택"},
|
||||
{ value: "3", label: "오피스텔"},
|
||||
{ value: "4", label: "(연립)빌라"},
|
||||
{ value: "5", label: "기타"},
|
||||
]
|
||||
},
|
||||
{
|
||||
variable:"a6",
|
||||
variableName:"지역",
|
||||
children:[
|
||||
{ value: "0", label: "전체"},
|
||||
{ value: "1", label: "서울, 인천, 경기도"},
|
||||
{ value: "2", label: "경남, 부산, 울산"},
|
||||
{ value: "3", label: "경북, 대구"},
|
||||
{ value: "4", label: "전라도, 광주"},
|
||||
{ value: "5", label: "충청, 대전, 세종"},
|
||||
{ value: "6", label: "강원, 제주"},
|
||||
]
|
||||
},
|
||||
{
|
||||
variable:"a7",
|
||||
variableName:"연령대",
|
||||
children:[
|
||||
{ value: "0", label: "20대"},
|
||||
{ value: "1", label: "30대"},
|
||||
{ value: "2", label: "40대"},
|
||||
{ value: "3", label: "50대"},
|
||||
{ value: "4", label: "60대"},
|
||||
]
|
||||
},
|
||||
{
|
||||
variable:"a8",
|
||||
variableName:"가구원 수",
|
||||
children:[
|
||||
{ value: "0", label: "전체"},
|
||||
{ value: "1", label: "1인 가구"},
|
||||
{ value: "2", label: "2인 가구"},
|
||||
{ value: "3", label: "3인 가구"},
|
||||
{ value: "4", label: "4인 이상 가구"},
|
||||
]
|
||||
},
|
||||
]
|
||||
|
||||
export const categoryTargetType: CategoryTargetTypeItem[] = [
|
||||
{
|
||||
label:"보유",
|
||||
value: CategoryTargetType.PENETRATION,
|
||||
},
|
||||
{
|
||||
label:"구매",
|
||||
value: CategoryTargetType.PURCHASE,
|
||||
},
|
||||
{
|
||||
label:"향후 구매",
|
||||
value: CategoryTargetType.PURCHASE,
|
||||
},
|
||||
]
|
||||
|
||||
export const categoryTarget: CategoryTargetItem[] = [
|
||||
{
|
||||
type: CategoryTargetType.PENETRATION,
|
||||
children:[
|
||||
{ target: CategoryTargetData.PROFILE, label: "Profile"},
|
||||
{ target: CategoryTargetData.PENETRATION_CHANGE, label: "보급률 변화"},
|
||||
{ target: CategoryTargetData.BRAND, label: "브랜드"},
|
||||
{ target: CategoryTargetData.TYPE_SPEC, label: "타입/스펙"},
|
||||
{ target: CategoryTargetData.OWNERSHIP_PATH, label: "보유 경로"},
|
||||
{ target: CategoryTargetData.PURCHASE_FORMAT, label: "구매 형식"},
|
||||
]
|
||||
},
|
||||
{
|
||||
type: CategoryTargetType.PURCHASE,
|
||||
children:[
|
||||
{ target: CategoryTargetData.PROFILE, label: "Profile"},
|
||||
{ target: CategoryTargetData.BRAND, label: "브랜드"},
|
||||
{ target: CategoryTargetData.TYPE_SPEC, label: "타입/스펙"},
|
||||
{ target: CategoryTargetData.PURCHASE_BEHAVIOR, label: "구입 행태"},
|
||||
{ target: CategoryTargetData.PURCHASE_CHANNEL, label: "구매 채널"},
|
||||
{ target: CategoryTargetData.PURCHASE_FORMAT, label: "구매 형식"},
|
||||
]
|
||||
},
|
||||
]
|
||||
41
src/config/filter.types.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
export type FilterChild = {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export type TotalFilterItem = {
|
||||
variable: string;
|
||||
variableName: string;
|
||||
children: FilterChild[];
|
||||
};
|
||||
|
||||
export enum CategoryTargetType {
|
||||
PENETRATION = "PENETRATION",
|
||||
PURCHASE = "PURCHASE",
|
||||
}
|
||||
|
||||
export enum CategoryTargetData {
|
||||
PROFILE = 11,
|
||||
PENETRATION_CHANGE = 21,
|
||||
BRAND = 12,
|
||||
TYPE_SPEC = 13,
|
||||
OWNERSHIP_PATH = 22,
|
||||
PURCHASE_BEHAVIOR = 31,
|
||||
PURCHASE_CHANNEL = 32,
|
||||
PURCHASE_FORMAT = 14,
|
||||
}
|
||||
|
||||
export type CategoryTargetTypeItem = {
|
||||
label: string;
|
||||
value: CategoryTargetType;
|
||||
}
|
||||
|
||||
export type TargetChild = {
|
||||
target: CategoryTargetData;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export type CategoryTargetItem = {
|
||||
type: CategoryTargetType;
|
||||
children: TargetChild[];
|
||||
}
|
||||
62
src/config/menu.data.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import {SubMenuItem, TopMenuItem} from "@/config/menu.types";
|
||||
|
||||
export const topMenus: TopMenuItem[] = [
|
||||
{
|
||||
id: "total",
|
||||
label: "전체",
|
||||
path: "/total/penetration",
|
||||
match: (pathname) => pathname.startsWith("/total"),
|
||||
},
|
||||
{
|
||||
id: "category",
|
||||
label: "카테고리",
|
||||
path: "/category/ha-kitchen",
|
||||
match: (pathname) => pathname.startsWith("/category"),
|
||||
},
|
||||
];
|
||||
|
||||
export const totalSubMenus: SubMenuItem[] = [
|
||||
{
|
||||
id: "penetration",
|
||||
label: "보급률",
|
||||
path: "/total/penetration",
|
||||
},
|
||||
{
|
||||
id: "lg-penetration",
|
||||
label: "LG제품 보급률",
|
||||
path: "/total/lg-penetration",
|
||||
},
|
||||
{
|
||||
id: "purchase",
|
||||
label: "구매율",
|
||||
path: "/total/purchase",
|
||||
},
|
||||
{
|
||||
id: "lg-purchase",
|
||||
label: "LG제품 구매율",
|
||||
path: "/total/lg-purchase",
|
||||
},
|
||||
]
|
||||
|
||||
export const categorySubMenus: SubMenuItem[] = [
|
||||
{
|
||||
id: "ha-kitchen",
|
||||
label: "H&A 주방가전(키친)",
|
||||
path: "/category/ha-kitchen",
|
||||
},
|
||||
{
|
||||
id: "ha-living",
|
||||
label: "H&A 리빙가전",
|
||||
path: "/category/ha-living",
|
||||
},
|
||||
{
|
||||
id: "air-solution",
|
||||
label: "에어솔루션",
|
||||
path: "/category/air-solution",
|
||||
},
|
||||
{
|
||||
id: "ms-digital",
|
||||
label: "MS 디지털가전",
|
||||
path: "/category/ms-digital",
|
||||
},
|
||||
]
|
||||
13
src/config/menu.types.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export type TopMenuItem = {
|
||||
id: string;
|
||||
label: string;
|
||||
path: string;
|
||||
/** 현재 경로가 이 탭에 해당하는지 판별하는 함수 */
|
||||
match?: (pathname: string) => boolean;
|
||||
};
|
||||
|
||||
export type SubMenuItem = {
|
||||
id: string;
|
||||
label: string;
|
||||
path: string;
|
||||
};
|
||||
3
src/const/commonConst.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const UNKNOWN_HTTP_ERROR = 'UNKNOWN_HTTP_ERROR';
|
||||
export const NONE_HTTP_ERROR = 'NONE_HTTP_ERROR';
|
||||
export const DASHBOARD_YEAR = 2026;
|
||||
42
src/hooks/useAuth.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback } from "react";
|
||||
import { useAtom } from "jotai";
|
||||
import { authStateAtom, type AuthState } from "@/store/jotai/auth";
|
||||
import type { LoginUser } from "@/types/auth";
|
||||
|
||||
export const useAuth = () => {
|
||||
const [auth, setAuth] = useAtom(authStateAtom);
|
||||
|
||||
// 로그인 성공 후 LoginResponse 를 바로 넣어줄 수 있게
|
||||
const setFromLoginResponse = useCallback(
|
||||
(res: LoginUser, loginSeatNumber:string|null = null) => {
|
||||
setAuth({
|
||||
user: res,
|
||||
seatNumber: loginSeatNumber,
|
||||
});
|
||||
},
|
||||
[setAuth],
|
||||
);
|
||||
|
||||
const updateAuth = useCallback(
|
||||
(next: AuthState | ((prev: AuthState) => AuthState)) => {
|
||||
setAuth(next);
|
||||
},
|
||||
[setAuth],
|
||||
);
|
||||
|
||||
const logout = useCallback(() => {
|
||||
setAuth({
|
||||
user: null,
|
||||
seatNumber: null,
|
||||
});
|
||||
}, [setAuth]);
|
||||
|
||||
return {
|
||||
auth,
|
||||
setAuth: updateAuth,
|
||||
setFromLoginResponse,
|
||||
logout,
|
||||
};
|
||||
}
|
||||
12
src/hooks/useDebouncedValue.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useDebouncedValue<T>(value: T, delayMs = 1200) {
|
||||
const [debounced, setDebounced] = useState(value);
|
||||
|
||||
useEffect(() => {
|
||||
const t = setTimeout(() => setDebounced(value), delayMs);
|
||||
return () => clearTimeout(t);
|
||||
}, [value, delayMs]);
|
||||
|
||||
return debounced;
|
||||
}
|
||||
56
src/hooks/useLoading.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
"use client";
|
||||
|
||||
import { useAtom } from "jotai";
|
||||
import { useCallback } from "react";
|
||||
import { loadingAtom } from "@/store/jotai/loading";
|
||||
|
||||
export const useLoading = () => {
|
||||
const [isLoading, setIsLoading] = useAtom(loadingAtom);
|
||||
|
||||
const showLoading = useCallback(() => {
|
||||
setIsLoading(true);
|
||||
}, [setIsLoading]);
|
||||
|
||||
const hideLoading = useCallback(() => {
|
||||
setIsLoading(false);
|
||||
}, [setIsLoading]);
|
||||
|
||||
/**
|
||||
* 비동기 함수 호출 시 편하게 쓸 수 있는 래퍼
|
||||
*
|
||||
* 예)
|
||||
* const { withLoading } = useLoading();
|
||||
* await withLoading(() => apiCall());
|
||||
*/
|
||||
const withLoadingAsync = useCallback(
|
||||
async <T,>(fn: () => Promise<T>): Promise<T> => {
|
||||
showLoading();
|
||||
try {
|
||||
return await fn();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
},
|
||||
[showLoading, hideLoading],
|
||||
);
|
||||
|
||||
const withLoading = useCallback(
|
||||
<T,>(fn: () => T): T => {
|
||||
showLoading();
|
||||
try {
|
||||
return fn();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
},
|
||||
[showLoading, hideLoading],
|
||||
);
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
showLoading,
|
||||
hideLoading,
|
||||
withLoading,
|
||||
withLoadingAsync,
|
||||
} as const;
|
||||
}
|
||||
7
src/hooks/useMounted.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export const useMounted = () => {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
useEffect(() => setMounted(true), []);
|
||||
return mounted;
|
||||
};
|
||||
49
src/hooks/useStorage.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
"use client";
|
||||
import {
|
||||
setLocalStorage,
|
||||
getLocalStorage,
|
||||
removeLocalStorage,
|
||||
setSessionStorage,
|
||||
getSessionStorage,
|
||||
removeSessionStorage,
|
||||
} from "@/store/storage/secure-storage";
|
||||
import { StorageKey, StorageType } from "@/store/storage/storage-keys";
|
||||
|
||||
|
||||
/**
|
||||
* 사용법:
|
||||
* const { set, get, remove } = useStorage(StorageKeys.SeatNumber);
|
||||
*/
|
||||
export const useStorage = (key: StorageKey) => {
|
||||
const storageType = StorageType[key]; // "local" | "session"
|
||||
|
||||
const set = (value: any): void => {
|
||||
if (storageType === "session") {
|
||||
setSessionStorage(key, value);
|
||||
} else {
|
||||
setLocalStorage(key, value);
|
||||
}
|
||||
};
|
||||
|
||||
const get = (): any => {
|
||||
if (storageType === "session") {
|
||||
return getSessionStorage(key);
|
||||
} else {
|
||||
return getLocalStorage(key);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = (): void => {
|
||||
if (storageType === "session") {
|
||||
removeSessionStorage(key);
|
||||
} else {
|
||||
removeLocalStorage(key);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
set,
|
||||
get,
|
||||
remove,
|
||||
} as const;
|
||||
};
|
||||
15
src/lib/env.client.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
const required = <K extends keyof typeof RAW_PUBLIC_ENV>(name: K) => {
|
||||
const v = RAW_PUBLIC_ENV[name];
|
||||
if (!v) throw new Error(`Missing env: ${name}`);
|
||||
return v;
|
||||
};
|
||||
|
||||
const RAW_PUBLIC_ENV = {
|
||||
NEXT_PUBLIC_ENV: process.env.NEXT_PUBLIC_ENV,
|
||||
NEXT_PUBLIC_API_BASE: process.env.NEXT_PUBLIC_API_BASE,
|
||||
} as const;
|
||||
|
||||
export const clientEnv = {
|
||||
ENV: required("NEXT_PUBLIC_ENV"),
|
||||
API_BASE: required("NEXT_PUBLIC_API_BASE"),
|
||||
};
|
||||
12
src/lib/env.server.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
const required = (name: string) => {
|
||||
const v = process.env[name];
|
||||
if (!v) throw new Error(`Missing env: ${name}`);
|
||||
return v;
|
||||
};
|
||||
|
||||
export const serverEnv = {
|
||||
ENV: required("ENV"),
|
||||
API_BACK_SERVER: required("API_BACK_SERVER"),
|
||||
API_KART_SERVER: required("API_KART_SERVER"),
|
||||
KART_API_KEY: required("KART_API_KEY"),
|
||||
};
|
||||
295
src/lib/http-client.ts
Normal file
@@ -0,0 +1,295 @@
|
||||
import { clientEnv } from "@/lib/env.client";
|
||||
|
||||
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
||||
|
||||
export class HttpError extends Error {
|
||||
public readonly status: number;
|
||||
public readonly data: unknown;
|
||||
public readonly url: string;
|
||||
private readonly headerMap: Record<string, string>;
|
||||
|
||||
constructor(status: number, data: unknown, url: string, headers?: Headers) {
|
||||
super(`HTTP ${status}`);
|
||||
this.name = "HttpError";
|
||||
this.status = status;
|
||||
this.data = data;
|
||||
this.url = url;
|
||||
this.headerMap =
|
||||
headers && typeof headers.entries === "function"
|
||||
? Object.fromEntries(headers.entries())
|
||||
: {};
|
||||
}
|
||||
|
||||
get headers(): Record<string, string> {
|
||||
return this.headerMap;
|
||||
}
|
||||
|
||||
get traceId(): string | undefined {
|
||||
return this.headerMap["x-trace-id"] ?? this.headerMap["x-request-id"];
|
||||
}
|
||||
}
|
||||
|
||||
export type QueryValue = string | string[] | undefined;
|
||||
export type Query = Record<string, QueryValue>;
|
||||
export type PathParams = Record<string, string | number | boolean>;
|
||||
|
||||
export type RequestOptions = {
|
||||
method?: HttpMethod;
|
||||
pathParams?: PathParams;
|
||||
query?: Query;
|
||||
json?: unknown;
|
||||
rawBody?: string;
|
||||
form?: FormData;
|
||||
headers?: Record<string, string>;
|
||||
timeoutMs?: number;
|
||||
suppressAlert?: boolean;
|
||||
onAuthError?: () => void;
|
||||
autoLogoutOnAuthError?: boolean;
|
||||
expectText?: boolean;
|
||||
expectBinary?: boolean;
|
||||
};
|
||||
|
||||
export type HttpClientOptions = {
|
||||
getToken?: () => string | null;
|
||||
defaultTimeoutMs?: number;
|
||||
defaultHeaders?: Record<string, string>;
|
||||
setErrorMessage?: (status: number, serverMsg?: string) => string;
|
||||
};
|
||||
|
||||
const replacePathParams = (path: string, params?: PathParams): string => {
|
||||
if (!params) return path;
|
||||
let out = path;
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
const ph = `:${k}`;
|
||||
if (out.includes(ph)) out = out.replace(ph, encodeURIComponent(String(v)));
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
const appendQuery = (u: URL, query?: Query): void => {
|
||||
if (!query) return;
|
||||
for (const [k, v] of Object.entries(query)) {
|
||||
if (Array.isArray(v)) v.forEach((it) => u.searchParams.append(k, it));
|
||||
else if (v !== undefined) u.searchParams.set(k, v);
|
||||
}
|
||||
};
|
||||
|
||||
const buildHeaders = (base: Record<string, string>, extra?: Record<string, string>): Headers => {
|
||||
const h = new Headers(base);
|
||||
if (extra) for (const [k, v] of Object.entries(extra)) h.set(k, v);
|
||||
return h;
|
||||
};
|
||||
|
||||
const isAbortError = (err: unknown): boolean => {
|
||||
if (!err || typeof err !== "object") return false;
|
||||
const e = err as { name?: unknown; code?: unknown; message?: unknown };
|
||||
return (
|
||||
e.name === "AbortError" || // browser fetch abort
|
||||
e.code === "ABORT_ERR" || // some runtimes
|
||||
(typeof e.message === "string" && e.message.toLowerCase().includes("aborted"))
|
||||
);
|
||||
};
|
||||
|
||||
const isJsonContentType = (ctype: string) => {
|
||||
const ct = (ctype ?? "").toLowerCase()
|
||||
return ct.includes("application/json") || ct.includes("+json")
|
||||
}
|
||||
|
||||
export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {}) => {
|
||||
const {
|
||||
getToken,
|
||||
defaultTimeoutMs = 60_000,
|
||||
defaultHeaders = { "content-type": "application/json" },
|
||||
setErrorMessage,
|
||||
} = opts;
|
||||
|
||||
const request = async <T = unknown>(path: string, options: RequestOptions = {}): Promise<T> => {
|
||||
const replaced = replacePathParams(path, options.pathParams);
|
||||
|
||||
let url: URL;
|
||||
if (/^https?:\/\//i.test(replaced)) {
|
||||
url = new URL(replaced);
|
||||
} else if (replaced.startsWith("/")) {
|
||||
const base = new URL(baseURL);
|
||||
const joinedPath = `${base.pathname.replace(/\/+$/, "")}/${replaced.replace(/^\/+/, "")}`;
|
||||
url = new URL(base.toString());
|
||||
url.pathname = joinedPath;
|
||||
} else {
|
||||
url = new URL(replaced, new URL(baseURL));
|
||||
}
|
||||
|
||||
appendQuery(url, options.query);
|
||||
|
||||
const base: Record<string, string> = { ...defaultHeaders };
|
||||
const token = getToken?.();
|
||||
if (token) base["authorization"] = `Bearer ${token}`;
|
||||
const headers = buildHeaders(base, options.headers);
|
||||
|
||||
let body: BodyInit | undefined;
|
||||
if (options.form) {
|
||||
headers.delete("content-type");
|
||||
body = options.form;
|
||||
} else if (options.rawBody !== undefined) {
|
||||
if (!headers.has("content-type")) headers.set("content-type", "text/plain;charset=utf-8");
|
||||
body = options.rawBody;
|
||||
} else if (options.json !== undefined) {
|
||||
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
||||
body = typeof options.json === "string" ? options.json : JSON.stringify(options.json);
|
||||
}
|
||||
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? defaultTimeoutMs);
|
||||
|
||||
try {
|
||||
const res = await fetch(url.toString(), {
|
||||
method: options.method ?? (body ? "POST" : "GET"),
|
||||
headers,
|
||||
body,
|
||||
cache: "no-store",
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
if (options.expectBinary) {
|
||||
if (!res.ok) {
|
||||
const rawText = await res.text().catch(() => "");
|
||||
const ctype = res.headers.get("content-type") ?? ""
|
||||
const isJson = isJsonContentType(ctype)
|
||||
|
||||
let parsedError: unknown;
|
||||
if (isJson && rawText) {
|
||||
try {
|
||||
parsedError = JSON.parse(rawText);
|
||||
} catch {
|
||||
parsedError = rawText;
|
||||
}
|
||||
} else {
|
||||
parsedError = rawText || null;
|
||||
}
|
||||
|
||||
const autoLogout = options.autoLogoutOnAuthError ?? true;
|
||||
const suppressAlert = options.suppressAlert ?? true;
|
||||
|
||||
if (res.status === 401) options.onAuthError?.();
|
||||
|
||||
if ((res.status === 401 || res.status === 403) && autoLogout && typeof window !== "undefined") {
|
||||
try {
|
||||
window.location.replace("/logout");
|
||||
} catch {}
|
||||
throw new HttpError(res.status, parsedError, url.toString(), res.headers);
|
||||
}
|
||||
|
||||
if (!suppressAlert && typeof window !== "undefined") {
|
||||
const serverMsg =
|
||||
typeof parsedError === "object" && parsedError !== null && "message" in parsedError
|
||||
? String((parsedError as { message?: unknown }).message ?? "")
|
||||
: typeof parsedError === "string"
|
||||
? parsedError
|
||||
: undefined;
|
||||
|
||||
const msg = setErrorMessage?.(res.status, serverMsg) ?? (serverMsg ?? `HTTP ${res.status}`);
|
||||
alert(`[${res.status}] ${msg}`);
|
||||
}
|
||||
|
||||
throw new HttpError(res.status, parsedError, url.toString(), res.headers);
|
||||
}
|
||||
|
||||
const buffer = await res.arrayBuffer();
|
||||
return buffer as T;
|
||||
}
|
||||
|
||||
const ctype = res.headers.get("content-type") ?? "";
|
||||
const isJson = isJsonContentType(ctype)
|
||||
const rawText = await res.text().catch(() => "");
|
||||
|
||||
const parsed: unknown = options.expectText
|
||||
? rawText
|
||||
: isJson
|
||||
? rawText
|
||||
? JSON.parse(rawText)
|
||||
: null
|
||||
: rawText;
|
||||
|
||||
if (!res.ok) {
|
||||
const autoLogout = options.autoLogoutOnAuthError ?? true;
|
||||
const suppressAlert = options.suppressAlert ?? true;
|
||||
|
||||
if (res.status === 401) options.onAuthError?.();
|
||||
|
||||
if ((res.status === 401 || res.status === 403) && autoLogout && typeof window !== "undefined") {
|
||||
try {
|
||||
window.location.replace("/logout");
|
||||
} catch {}
|
||||
throw new HttpError(res.status, parsed, url.toString(), res.headers);
|
||||
}
|
||||
|
||||
if (!suppressAlert && typeof window !== "undefined") {
|
||||
const serverMsg =
|
||||
typeof parsed === "object" && parsed !== null && "message" in parsed
|
||||
? String((parsed as { message?: unknown }).message ?? "")
|
||||
: typeof parsed === "string"
|
||||
? parsed
|
||||
: undefined;
|
||||
|
||||
const msg = setErrorMessage?.(res.status, serverMsg) ?? (serverMsg ?? `HTTP ${res.status}`);
|
||||
alert(`[${res.status}] ${msg}`);
|
||||
}
|
||||
|
||||
throw new HttpError(res.status, parsed, url.toString(), res.headers);
|
||||
}
|
||||
|
||||
return parsed as T;
|
||||
} catch (err: unknown) {
|
||||
if (isAbortError(err)) {
|
||||
throw new HttpError(
|
||||
408,
|
||||
{ message: "요청 시간이 초과되었습니다.", timeoutMs: options.timeoutMs ?? defaultTimeoutMs },
|
||||
url.toString()
|
||||
);
|
||||
}
|
||||
|
||||
let code: string | undefined;
|
||||
if (typeof err === "object" && err !== null) {
|
||||
const anyErr = err as { cause?: unknown; code?: unknown };
|
||||
|
||||
if (anyErr.cause && typeof anyErr.cause === "object") {
|
||||
const cause = anyErr.cause as { code?: unknown };
|
||||
if (typeof cause.code === "string") code = cause.code;
|
||||
}
|
||||
if (!code && typeof anyErr.code === "string") code = anyErr.code;
|
||||
}
|
||||
|
||||
if (code === "ECONNREFUSED") {
|
||||
throw new HttpError(404, { message: "백엔드 서버를 찾을 수 없습니다." }, url.toString());
|
||||
}
|
||||
|
||||
throw err;
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
};
|
||||
|
||||
const get = <T = unknown>(path: string, o?: Omit<RequestOptions, "method" | "json" | "rawBody" | "form">) =>
|
||||
request<T>(path, { ...o, method: "GET" });
|
||||
|
||||
const post = <T = unknown>(path: string, json?: unknown, o?: Omit<RequestOptions, "method" | "json" | "rawBody" | "form">) =>
|
||||
request<T>(path, { ...o, method: "POST", json });
|
||||
|
||||
const put = <T = unknown>(path: string, json?: unknown, o?: Omit<RequestOptions, "method" | "json" | "rawBody" | "form">) =>
|
||||
request<T>(path, { ...o, method: "PUT", json });
|
||||
|
||||
const patch = <T = unknown>(path: string, json?: unknown, o?: Omit<RequestOptions, "method" | "json" | "rawBody" | "form">) =>
|
||||
request<T>(path, { ...o, method: "PATCH", json });
|
||||
|
||||
const del = <T = unknown>(path: string, o?: Omit<RequestOptions, "method">) =>
|
||||
request<T>(path, { ...o, method: "DELETE" });
|
||||
|
||||
const postForm = <T = unknown>(path: string, form: FormData, o?: Omit<RequestOptions, "method" | "json" | "rawBody" | "form">) =>
|
||||
request<T>(path, { ...o, method: "POST", form });
|
||||
|
||||
const putForm = <T = unknown>(path: string, form: FormData, o?: Omit<RequestOptions, "method" | "json" | "rawBody" | "form">) =>
|
||||
request<T>(path, { ...o, method: "PUT", form });
|
||||
|
||||
return { request, get, post, put, patch, del, postForm, putForm };
|
||||
};
|
||||
|
||||
export const nextApi = createHttpClient(clientEnv.API_BASE);
|
||||
52
src/lib/http-util.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import {NextResponse} from "next/server";
|
||||
import {HttpError} from "@/lib/http-client";
|
||||
import {clientEnv} from "@/lib/env.client";
|
||||
import {NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR} from "@/const/commonConst";
|
||||
|
||||
export type ApiError = {
|
||||
status: number
|
||||
code: string
|
||||
message: string
|
||||
}
|
||||
|
||||
export const errorToResponse = (error: unknown) => {
|
||||
if (error instanceof HttpError) {
|
||||
const payload = error.data ?? { message: "서버에서 오류 응답을 받았습니다." }
|
||||
return NextResponse.json(payload, { status: error.status })
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ message: "서버 내부 오류가 발생했습니다." },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
|
||||
const isDev = clientEnv.ENV !== "prod"
|
||||
|
||||
export const apiError = (e: unknown): ApiError => {
|
||||
if (e instanceof HttpError) {
|
||||
const d = e.data as any
|
||||
const code = typeof d?.code === "string" ? d.code : UNKNOWN_HTTP_ERROR
|
||||
const message =
|
||||
(typeof d?.detail === "string" && d.detail) ||
|
||||
(typeof d?.message === "string" && d.message) ||
|
||||
(typeof d?.errMessage === "string" && d.errMessage) ||
|
||||
(typeof d === "string" && d) ||
|
||||
`HTTP ${e.status}`
|
||||
|
||||
if (isDev) {
|
||||
console.groupCollapsed(
|
||||
`[API ERROR] ${e.status}${code ? ` / ${code}` : ""}`
|
||||
)
|
||||
console.log("url:", e.url)
|
||||
if (e.traceId) console.log("traceId:", e.traceId)
|
||||
console.log("raw data:", d)
|
||||
console.groupEnd()
|
||||
}
|
||||
|
||||
return { status: e.status, code, message }
|
||||
}
|
||||
|
||||
if (isDev) console.error("[NON-HTTP ERROR]", e)
|
||||
return { status: 500, code: NONE_HTTP_ERROR, message: "저장에 실패했습니다." }
|
||||
}
|
||||
196
src/lib/security.ts
Normal file
@@ -0,0 +1,196 @@
|
||||
import CryptoJS from "crypto-js";
|
||||
|
||||
const KEY = CryptoJS.enc.Utf8.parse("kr!-c0nTacT-fr0nT-CrypT0-Key-STR");
|
||||
const IV = CryptoJS.enc.Utf8.parse("kr!-c0nTacT-IVST");
|
||||
|
||||
export type WordArray = CryptoJS.lib.WordArray;
|
||||
|
||||
export class Security {
|
||||
public static encryptBase64UrlObject(input: unknown): string {
|
||||
const data = JSON.stringify(input);
|
||||
return this.encryptBase64Url(data);
|
||||
}
|
||||
|
||||
public static decryptBase64UrlObject(input: string): unknown {
|
||||
const data = this.decryptBase64Url(input);
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
public static encryptBase64Object(input: unknown): string {
|
||||
const data = JSON.stringify(input);
|
||||
return this.encryptBase64(data);
|
||||
}
|
||||
|
||||
public static decryptBase64Object(input: string): unknown {
|
||||
const data = this.decryptBase64(input);
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
public static encryptBase64Url(input: string): string {
|
||||
const data = this.decodeUtf8(input);
|
||||
const params = this.encrypt(data);
|
||||
return this.encodeBase64Url(params);
|
||||
}
|
||||
|
||||
public static decryptBase64Url(input: string): string {
|
||||
const data = this.decodeBase64Url(input);
|
||||
const decryptedData = this.decrypt(data);
|
||||
return this.encodeUtf8(decryptedData);
|
||||
}
|
||||
|
||||
public static encryptBase64(input: string): string {
|
||||
const data = this.decodeUtf8(input);
|
||||
const params = this.encrypt(data);
|
||||
return this.encodeBase64(params);
|
||||
}
|
||||
public static decryptBase64(input: string): string {
|
||||
try {
|
||||
const data = this.decodeBase64(input);
|
||||
const decryptedData = this.decrypt(data);
|
||||
return this.encodeUtf8(decryptedData);
|
||||
} catch (error) {
|
||||
console.error("SecurityFunction.decryptBase64 오류:", {
|
||||
input: input?.substring(0, 50) + "...", // 처음 50자만 로그
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public static encrypt(input: WordArray): WordArray {
|
||||
const params = CryptoJS.AES.encrypt(input, KEY, {
|
||||
iv: IV,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
});
|
||||
return params.ciphertext;
|
||||
}
|
||||
|
||||
public static decrypt(input: WordArray): WordArray {
|
||||
const params = CryptoJS.lib.CipherParams.create({
|
||||
ciphertext: input,
|
||||
});
|
||||
return CryptoJS.AES.decrypt(params, KEY, {
|
||||
iv: IV,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
});
|
||||
}
|
||||
|
||||
public static convertUint8ArrayToWordArray(input: Uint8Array): WordArray {
|
||||
const words: number[] = [];
|
||||
let i = 0;
|
||||
while (i < input.length) {
|
||||
const word =
|
||||
(input[i++] << 24) |
|
||||
(input[i++] << 16) |
|
||||
(input[i++] << 8) |
|
||||
input[i++];
|
||||
words.push(word);
|
||||
}
|
||||
return CryptoJS.lib.WordArray.create(words, words.length * 4);
|
||||
}
|
||||
|
||||
public static convertWordArrayToUint8Array(input: WordArray): Uint8Array {
|
||||
const array = new Uint8Array(input.words.length << 2);
|
||||
for (let i = 0, j = 0; i < input.words.length; i++) {
|
||||
const word = input.words[i];
|
||||
array[j++] = word >> 24;
|
||||
array[j++] = (word >> 16) & 0xff;
|
||||
array[j++] = (word >> 8) & 0xff;
|
||||
array[j++] = word & 0xff;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static computeHmacSha256Hex(input: WordArray, key: WordArray): string {
|
||||
return this.encodeHex(this.computeHmacSha256(input, key));
|
||||
}
|
||||
|
||||
public static computeHmacSha256(input: WordArray, key: WordArray): WordArray {
|
||||
return CryptoJS.HmacSHA256(input, key);
|
||||
}
|
||||
|
||||
public static computeSha256Hex(input: WordArray): string {
|
||||
return this.encodeHex(this.computeSha256(input));
|
||||
}
|
||||
|
||||
public static computeSha256(input: WordArray): WordArray {
|
||||
return CryptoJS.SHA256(input);
|
||||
}
|
||||
|
||||
private static convertToSpecialChars(base64: string): string {
|
||||
return Array.from(base64)
|
||||
.map((char) => char.charCodeAt(0).toString(2).padStart(16, "0"))
|
||||
.map((binary) => binary.replace(/0/g, "\u200b").replace(/1/g, "\u200c"))
|
||||
.join("ㅤ");
|
||||
}
|
||||
|
||||
private static convertFromSpecialChars(input: string): string {
|
||||
return input
|
||||
.split("ㅤ")
|
||||
.map((bin) => bin.replace(/\u200b/g, "0").replace(/\u200c/g, "1"))
|
||||
.map((binary) => String.fromCharCode(parseInt(binary, 2)))
|
||||
.join("");
|
||||
}
|
||||
|
||||
public static encodeBase64UrlUtf8(input: string): string {
|
||||
return this.encodeBase64Url(this.decodeUtf8(input));
|
||||
}
|
||||
|
||||
public static decodeBase64UrlUtf8(input: string): string {
|
||||
return this.encodeUtf8(this.decodeBase64Url(input));
|
||||
}
|
||||
|
||||
public static encodeBase64Url(input: WordArray): string {
|
||||
const base64url = CryptoJS.enc.Base64url.stringify(input);
|
||||
return this.convertToSpecialChars(base64url);
|
||||
}
|
||||
|
||||
public static decodeBase64Url(input: string): WordArray {
|
||||
try {
|
||||
const base64url = this.convertFromSpecialChars(input);
|
||||
return CryptoJS.enc.Base64url.parse(base64url);
|
||||
} catch {
|
||||
return CryptoJS.enc.Base64url.parse(input);
|
||||
}
|
||||
}
|
||||
|
||||
public static encodeBase64Utf8(input: string): string {
|
||||
return this.encodeBase64(this.decodeUtf8(input));
|
||||
}
|
||||
|
||||
public static decodeBase64Utf8(input: string): string {
|
||||
return this.encodeUtf8(this.decodeBase64(input));
|
||||
}
|
||||
|
||||
public static encodeBase64(input: WordArray): string {
|
||||
const base64 = CryptoJS.enc.Base64.stringify(input);
|
||||
return this.convertToSpecialChars(base64);
|
||||
}
|
||||
|
||||
public static decodeBase64(input: string): WordArray {
|
||||
try {
|
||||
const base64 = this.convertFromSpecialChars(input);
|
||||
return CryptoJS.enc.Base64.parse(base64);
|
||||
} catch {
|
||||
return CryptoJS.enc.Base64.parse(input);
|
||||
}
|
||||
}
|
||||
|
||||
public static encodeHex(input: WordArray): string {
|
||||
return CryptoJS.enc.Hex.stringify(input);
|
||||
}
|
||||
|
||||
public static decodeHex(input: string): WordArray {
|
||||
return CryptoJS.enc.Hex.parse(input);
|
||||
}
|
||||
|
||||
public static encodeUtf8(input: WordArray): string {
|
||||
return CryptoJS.enc.Utf8.stringify(input);
|
||||
}
|
||||
|
||||
public static decodeUtf8(input: string): WordArray {
|
||||
return CryptoJS.enc.Utf8.parse(input);
|
||||
}
|
||||
}
|
||||
26
src/lib/server-api.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { createHttpClient } from "@/lib/http-client";
|
||||
import { serverEnv } from "@/lib/env.server";
|
||||
|
||||
const createServerApi = async (rootUrl: string, defaultHeaders?: Record<string, string>) => {
|
||||
const cookieStore = await cookies();
|
||||
const accessToken = cookieStore.get("access_token")?.value ?? null;
|
||||
|
||||
return createHttpClient(rootUrl, {
|
||||
getToken: () => accessToken, // 이미 위에서 읽은 값만 참조
|
||||
defaultHeaders: {
|
||||
"content-type": "application/json",
|
||||
...(defaultHeaders ?? {}),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const createBackApi = () => {
|
||||
return createServerApi(serverEnv.API_BACK_SERVER);
|
||||
}
|
||||
|
||||
export const createKartApi = () => {
|
||||
return createServerApi(serverEnv.API_KART_SERVER, {
|
||||
"X-API-Key": serverEnv.KART_API_KEY,
|
||||
});
|
||||
};
|
||||
102
src/lib/utils.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
export function getKeyByValue<
|
||||
const T extends Record<PropertyKey, string>
|
||||
>(map: T, value: T[keyof T]) {
|
||||
const entry = Object.entries(map).find(([, v]) => v === value);
|
||||
return entry ? (entry[0] as keyof T) : undefined;
|
||||
}
|
||||
|
||||
export function getNumberKeyByValue(
|
||||
map: Record<number, string>,
|
||||
value: string
|
||||
): number | undefined {
|
||||
const entry = Object.entries(map).find(([, v]) => v === value);
|
||||
return entry ? Number(entry[0]) : undefined;
|
||||
}
|
||||
|
||||
export function buildUrlWithParams(
|
||||
targetPath: string,
|
||||
from: Record<string, string | string[] | undefined>,
|
||||
extra?: Record<string, string | undefined>,
|
||||
) {
|
||||
const qs = new URLSearchParams();
|
||||
for (const [k, v] of Object.entries(from)) {
|
||||
if (Array.isArray(v)) v.forEach((val) => qs.append(k, val));
|
||||
else if (v !== undefined) qs.set(k, v);
|
||||
}
|
||||
if (extra) for (const [k, v] of Object.entries(extra)) if (v) qs.set(k, v);
|
||||
return `${targetPath}${qs.toString() ? `?${qs}` : ""}`;
|
||||
}
|
||||
|
||||
export const downloadFile = (blob: Blob, filename: string) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
export const downloadBase64File = (base64: string, filename: string) => {
|
||||
const byteString = atob(base64);
|
||||
const arrayBuffer = new ArrayBuffer(byteString.length);
|
||||
const uint8Array = new Uint8Array(arrayBuffer);
|
||||
|
||||
for (let i = 0; i < byteString.length; i++) {
|
||||
uint8Array[i] = byteString.charCodeAt(i);
|
||||
}
|
||||
|
||||
const blob = new Blob([arrayBuffer], {
|
||||
type:
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
});
|
||||
|
||||
downloadFile(blob, filename);
|
||||
};
|
||||
|
||||
export type DateTimeFormatOption =
|
||||
| "date" // 1-1. 날짜만
|
||||
| "dateHour" // 1-2. 날짜 + 시
|
||||
| "dateHourMin" // 1-3. 날짜 + 시 분
|
||||
| "dateTime"; // 1-4. 날짜 + 시 분 초
|
||||
|
||||
/**
|
||||
* 서버에서 받은 시간(ISO 문자열/Date/number)을 한국시간 기준으로 포맷팅
|
||||
* - 예: "2025-11-28T03:15:50Z" -> "2025-11-28 12:15:50" (KST)
|
||||
*/
|
||||
export const formatKst = (
|
||||
input: string | number | Date | null | undefined,
|
||||
opt: DateTimeFormatOption = "dateTime"
|
||||
): string => {
|
||||
if (!input) return "";
|
||||
|
||||
const d = input instanceof Date ? input : new Date(input);
|
||||
if (Number.isNaN(d.getTime())) return "";
|
||||
|
||||
// UTC -> KST(UTC+9) 변환
|
||||
const kst = new Date(d.getTime() + 9 * 60 * 60 * 1000);
|
||||
|
||||
const pad2 = (n: number) => String(n).padStart(2, "0");
|
||||
|
||||
const yyyy = kst.getUTCFullYear();
|
||||
const MM = pad2(kst.getUTCMonth() + 1);
|
||||
const dd = pad2(kst.getUTCDate());
|
||||
const HH = pad2(kst.getUTCHours());
|
||||
const mm = pad2(kst.getUTCMinutes());
|
||||
const ss = pad2(kst.getUTCSeconds());
|
||||
|
||||
if (opt === "date") return `${yyyy}-${MM}-${dd}`;
|
||||
if (opt === "dateHour") return `${yyyy}-${MM}-${dd} ${HH}`;
|
||||
if (opt === "dateHourMin") return `${yyyy}-${MM}-${dd} ${HH}:${mm}`;
|
||||
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`;
|
||||
};
|
||||
|
||||
export const isBlank = (v?: string | null) => !v || v.trim().length === 0;
|
||||
11
src/store/cookie/cookie-keys.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const CookieKeys = {
|
||||
//FontSize: "kri_fontSize",
|
||||
// 필요하면 여기 계속 추가 (예: Theme: "kri_theme", ...)
|
||||
} as const;
|
||||
|
||||
export const CookieType: Record<CookieKey, "session" | "persistence-http-only" | "persistence"> = {
|
||||
//[CookieKeys.FontSize]: "persistence",
|
||||
};
|
||||
|
||||
|
||||
export type CookieKey = (typeof CookieKeys)[keyof typeof CookieKeys];
|
||||
105
src/store/cookie/cookie.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
"use client";
|
||||
|
||||
import type { CookieKey } from "./cookie-keys";
|
||||
|
||||
export type CookieSetOptions = {
|
||||
days?: number; // 만료일: 기본 365일
|
||||
path?: string; // 기본 "/"
|
||||
secure?: boolean;
|
||||
sameSite?: "Lax" | "Strict" | "None";
|
||||
};
|
||||
|
||||
function isBrowser() {
|
||||
return typeof document !== "undefined";
|
||||
}
|
||||
|
||||
function buildCookieString(
|
||||
key: CookieKey,
|
||||
value: string,
|
||||
options: CookieSetOptions = {},
|
||||
): string {
|
||||
const {
|
||||
days = 365,
|
||||
path = "/",
|
||||
secure = false,
|
||||
sameSite = "Lax",
|
||||
} = options;
|
||||
|
||||
let cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
||||
|
||||
// 만료일
|
||||
if (Number.isFinite(days)) {
|
||||
const expires = new Date();
|
||||
expires.setDate(expires.getDate() + days);
|
||||
cookie += `; Expires=${expires.toUTCString()}`;
|
||||
}
|
||||
|
||||
if (path) {
|
||||
cookie += `; Path=${path}`;
|
||||
}
|
||||
|
||||
if (secure) {
|
||||
cookie += "; Secure";
|
||||
}
|
||||
|
||||
if (sameSite) {
|
||||
cookie += `; SameSite=${sameSite}`;
|
||||
}
|
||||
|
||||
return cookie;
|
||||
}
|
||||
|
||||
export const cookieStore = {
|
||||
/**
|
||||
* 문자열 값 가져오기 (없으면 null)
|
||||
*/
|
||||
get(key: CookieKey): string | null {
|
||||
if (!isBrowser()) return null;
|
||||
|
||||
try {
|
||||
const name = encodeURIComponent(key) + "=";
|
||||
const cookies = document.cookie ? document.cookie.split("; ") : [];
|
||||
|
||||
for (const c of cookies) {
|
||||
if (c.startsWith(name)) {
|
||||
const value = c.substring(name.length);
|
||||
return decodeURIComponent(value);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 문자열 값 저장
|
||||
*/
|
||||
set(key: CookieKey, value: string, options?: CookieSetOptions) {
|
||||
if (!isBrowser()) return;
|
||||
|
||||
try {
|
||||
const cookie = buildCookieString(key, value, options);
|
||||
document.cookie = cookie;
|
||||
} catch {
|
||||
// 쿠키 설정 실패는 조용히 무시
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 쿠키 삭제
|
||||
*/
|
||||
remove(key: CookieKey, options?: Omit<CookieSetOptions, "days">) {
|
||||
if (!isBrowser()) return;
|
||||
|
||||
try {
|
||||
document.cookie = buildCookieString(key, "", {
|
||||
...(options ?? {}),
|
||||
days: -1, // 과거로 설정해서 삭제
|
||||
});
|
||||
} catch {
|
||||
// 무시
|
||||
}
|
||||
},
|
||||
};
|
||||
20
src/store/jotai/auth.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { createLocalStorageAtom } from "@/store/jotai/utils";
|
||||
import { StorageKeys } from "@/store/storage/storage-keys";
|
||||
import type { LoginUser } from "@/types/auth";
|
||||
|
||||
export type AuthState = {
|
||||
user: LoginUser | null;
|
||||
};
|
||||
|
||||
const initialAuthState: AuthState = {
|
||||
user: null,
|
||||
};
|
||||
/**
|
||||
* AES 암호화된 localStorage 기반 로그인 상태 Atom
|
||||
*/
|
||||
export const authStateAtom = createLocalStorageAtom<AuthState>(
|
||||
StorageKeys.AuthState,
|
||||
initialAuthState,
|
||||
);
|
||||
8
src/store/jotai/loading.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { atom } from "jotai";
|
||||
|
||||
/**
|
||||
* 전역 로딩 상태
|
||||
*/
|
||||
export const loadingAtom = atom(false);
|
||||
108
src/store/jotai/utils.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
"use client";
|
||||
|
||||
import { atom, type PrimitiveAtom } from "jotai";
|
||||
import {
|
||||
setLocalStorage,
|
||||
getLocalStorage,
|
||||
removeLocalStorage,
|
||||
setSessionStorage,
|
||||
getSessionStorage,
|
||||
removeSessionStorage
|
||||
} from "@/store/storage/secure-storage";
|
||||
import {StorageKey} from "@/store/storage/storage-keys";
|
||||
|
||||
const loadInitialState = <T>(storageType: "local"|"session", key: StorageKey, initialValue: T): T => {
|
||||
if (typeof window === "undefined") {
|
||||
// SSR 시에는 그냥 기본값 사용
|
||||
return initialValue;
|
||||
}
|
||||
|
||||
const stored = storageType == "local" ? getLocalStorage(key) : getSessionStorage(key);
|
||||
|
||||
if (stored && typeof stored === "object") {
|
||||
return stored as T;
|
||||
}
|
||||
|
||||
return initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* localStorage(AES 암호화) + Jotai 연동용 Atom 생성기
|
||||
* - initialValue: SSR 시/최초 렌더 시 기본값
|
||||
* - 마운트 후 localStorage에서 실제 값 읽어와서 덮어씀
|
||||
*/
|
||||
export const createLocalStorageAtom = <T>(
|
||||
key: StorageKey,
|
||||
initialValue: T,
|
||||
) => {
|
||||
const realInitialValue = loadInitialState("local", key, initialValue);
|
||||
const baseAtom: PrimitiveAtom<T> = atom<T>(realInitialValue);
|
||||
|
||||
// 하이드레이션(저장소 주입)과 사용자 set 경합 방지용 플래그
|
||||
let wasOverridden = false; // 마운트 이후 사용자가 값을 쓴 적이 있는지
|
||||
|
||||
const persistentAtom = atom(
|
||||
(get) => get(baseAtom),
|
||||
(get, set, update: T | ((prev: T) => T)) => {
|
||||
const prev = get(baseAtom);
|
||||
const next =
|
||||
typeof update === "function"
|
||||
? (update as (prev: T) => T)(prev)
|
||||
: update;
|
||||
|
||||
// 메모리 상태 갱신
|
||||
set(baseAtom, next);
|
||||
// 사용자 쓰기 발생 표시 (하이드레이션이 도착해도 무시하도록)
|
||||
wasOverridden = true;
|
||||
|
||||
if (next === null || (next as unknown) === undefined) {
|
||||
// 암호화 localStorage 및 캐시 제거
|
||||
removeLocalStorage(key);
|
||||
} else {
|
||||
// 동기 API로 캐시를 먼저 기록하고 암호화 저장은 백그라운드 처리
|
||||
setLocalStorage(key, next);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return persistentAtom;
|
||||
}
|
||||
|
||||
/**
|
||||
* sessionStorage + Jotai 연동용 Atom 생성기
|
||||
* - 탭 단위로 유지, 탭/브라우저 닫히면 삭제
|
||||
* - 새로고침 시 유지
|
||||
*/
|
||||
export const createSessionStorageAtom = <T>(
|
||||
key: StorageKey,
|
||||
initialValue: T,
|
||||
) => {
|
||||
const realInitialValue = loadInitialState("session", key, initialValue);
|
||||
const baseAtom: PrimitiveAtom<T> = atom<T>(realInitialValue);
|
||||
|
||||
const persistentAtom = atom(
|
||||
(get) => get(baseAtom),
|
||||
(get, set, update: T | ((prev: T) => T)) => {
|
||||
const prev = get(baseAtom);
|
||||
const next =
|
||||
typeof update === "function"
|
||||
? (update as (prev: T) => T)(prev)
|
||||
: update;
|
||||
|
||||
set(baseAtom, next);
|
||||
|
||||
if (typeof window === "undefined") return;
|
||||
try {
|
||||
if (next === null || (next as unknown) === undefined) {
|
||||
removeSessionStorage(key)
|
||||
} else {
|
||||
setSessionStorage(key, next);
|
||||
}
|
||||
} catch {
|
||||
// sessionStorage 에러는 조용히 무시
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return persistentAtom;
|
||||
}
|
||||
128
src/store/storage/secure-storage.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import { Security } from "@/lib/security";
|
||||
import {clientEnv} from "@/lib/env.client";
|
||||
|
||||
type StorageValue = any; // 요청대로 any 유지
|
||||
|
||||
// --- 내부 헬퍼 함수들 ---
|
||||
|
||||
const getDecryptedValue = (value: string): StorageValue => {
|
||||
try {
|
||||
if (!value || value.trim() === "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const decryptValue = clientEnv.ENV ==="prod" ? Security.decryptBase64(value) : value;
|
||||
|
||||
if (!decryptValue || decryptValue.trim() === "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return JSON.parse(decryptValue);
|
||||
} catch (error) {
|
||||
// 손상된 데이터인 경우 null 반환
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const getEncryptedValue = (value: StorageValue): string => {
|
||||
const stringifyValue = JSON.stringify(value);
|
||||
return clientEnv.ENV ==="prod" ? Security.encryptBase64(stringifyValue) : stringifyValue;
|
||||
};
|
||||
|
||||
|
||||
// --- LocalStorage 함수들 ---
|
||||
|
||||
export const setLocalStorage = (key: string, value: StorageValue): void => {
|
||||
try {
|
||||
const encryptValue = getEncryptedValue(value);
|
||||
localStorage.setItem(key, encryptValue);
|
||||
} catch (error) {
|
||||
// 필요하면 로깅 추가
|
||||
}
|
||||
};
|
||||
|
||||
export const getLocalStorage = (key: string): StorageValue => {
|
||||
try {
|
||||
const encryptValue: string | null = localStorage.getItem(key);
|
||||
if (encryptValue === null || encryptValue === "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
let value: StorageValue = null;
|
||||
|
||||
try {
|
||||
// 암호화된 값 복호화 시도
|
||||
value = getDecryptedValue(encryptValue);
|
||||
} catch (decryptError) {
|
||||
// 복호화 실패 시 평문으로 파싱 시도 (fallback)
|
||||
try {
|
||||
value = JSON.parse(encryptValue);
|
||||
} catch (fallbackError) {
|
||||
// 완전히 실패한 경우 저장된 데이터 제거
|
||||
localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const removeLocalStorage = (key: string): void => {
|
||||
localStorage.removeItem(key);
|
||||
};
|
||||
|
||||
export const clearLocalStorage = (): void => {
|
||||
localStorage.clear();
|
||||
};
|
||||
|
||||
// --- SessionStorage 함수들 ---
|
||||
|
||||
// 세션스토리지는 테스트/실제 서버 모두 암호화 없음
|
||||
export const setSessionStorage = (key: string, value: StorageValue): void => {
|
||||
try {
|
||||
const encryptValue = getEncryptedValue(value);
|
||||
sessionStorage.setItem(key, encryptValue);
|
||||
} catch (error) {
|
||||
// 필요하면 로깅 추가
|
||||
}
|
||||
};
|
||||
|
||||
export const getSessionStorage = (key: string): StorageValue => {
|
||||
try {
|
||||
const encryptValue: string | null = sessionStorage.getItem(key);
|
||||
if (encryptValue === null || encryptValue === "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
let value: StorageValue = null;
|
||||
|
||||
try {
|
||||
// 암호화된 값 복호화 시도
|
||||
value = getDecryptedValue(encryptValue);
|
||||
} catch (decryptError) {
|
||||
// 복호화 실패 시 평문으로 파싱 시도 (fallback)
|
||||
try {
|
||||
value = JSON.parse(encryptValue);
|
||||
} catch (fallbackError) {
|
||||
// 완전히 실패한 경우 저장된 데이터 제거
|
||||
localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const removeSessionStorage = (key: string): void => {
|
||||
sessionStorage.removeItem(key);
|
||||
};
|
||||
|
||||
export const clearSessionStorage = (): void => {
|
||||
sessionStorage.clear();
|
||||
};
|
||||
11
src/store/storage/storage-keys.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const StorageKeys = {
|
||||
AuthState: "kri:authState",
|
||||
//SidebarCollapsed: "kri:sidebarCollapsed",
|
||||
// 필요하면 여기 계속 추가
|
||||
} as const;
|
||||
|
||||
export const StorageType: Record<StorageKey, "local" | "session"> = {
|
||||
[StorageKeys.AuthState]: "local",
|
||||
};
|
||||
|
||||
export type StorageKey = (typeof StorageKeys)[keyof typeof StorageKeys];
|
||||
12
src/types/auth.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export type LoginRequest = {
|
||||
userId: string;
|
||||
userPw: string;
|
||||
};
|
||||
|
||||
export type LoginUser = {
|
||||
userId: string;
|
||||
userName: string;
|
||||
userCmpn: string;
|
||||
userTeam: string;
|
||||
userRole: number;
|
||||
};
|
||||
28
src/types/common.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
export type DataVerification = {
|
||||
success: boolean;
|
||||
fieldName : string;
|
||||
errMessage: string;
|
||||
}
|
||||
|
||||
export type RouteContext = { params: Promise<{ slug?: string[] }> };
|
||||
|
||||
export type PageRequest = {
|
||||
pageIndex: number;
|
||||
pageSize: number;
|
||||
sortBy: string;
|
||||
sortDir: "asc" | "desc";
|
||||
}
|
||||
|
||||
export type PageResponse<T> = {
|
||||
content: T[];
|
||||
totalElements: number;
|
||||
totalPages: number;
|
||||
pageIndex: number;
|
||||
pageSize: number;
|
||||
numberOfElements: number;
|
||||
first: boolean;
|
||||
last: boolean;
|
||||
empty: boolean;
|
||||
}
|
||||
|
||||
export type SelectedMap = Record<string, string>;
|
||||
@@ -19,7 +19,7 @@
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
|
||||