refactor: config 패키지 추가

This commit is contained in:
2025-04-30 15:23:26 +09:00
parent c52c602daf
commit 9da7aff85a
44 changed files with 504 additions and 112 deletions
@@ -2,23 +2,24 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ConfirmProvider } from "@frontend-opensource/use-react-hooks";
import { AuthWrapper } from "@/entities/auth";
import { MenuWrapper } from "@/entities/menu";
import { StoreProvider } from "@/shared/providers";
import { AlertDialog } from "@/shared/ui/alert-dialog";
import { ConfirmDialog } from "@/shared/ui/confirm-dialog";
import { initializeNextClientConfig } from "@common/config";
const AppProvider = ({ children }: Readonly<{ children: React.ReactNode }>) => {
const queryClient = new QueryClient();
initializeNextClientConfig();
return (
<QueryClientProvider client={queryClient}>
<StoreProvider>
<ConfirmProvider>
<AuthWrapper>
<MenuWrapper>{children}</MenuWrapper>
<AlertDialog />
<ConfirmDialog />
</AuthWrapper>
<MenuWrapper>{children}</MenuWrapper>
<AlertDialog />
<ConfirmDialog />
</ConfirmProvider>
</StoreProvider>
</QueryClientProvider>
@@ -1,2 +1 @@
export { LoginApi } from "./api/login-service";
export { AuthWrapper } from "./lib/auth-wrapper";
@@ -1,49 +0,0 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { client } from "@/shared/api";
import type { IUserInfo } from "@/shared/store";
import { getCookie, useUserStore } from "@/shared/lib";
import { ENDPOINT, AUTH_USER_ID } from "@/shared/config";
import { LoginApi } from "../api/login-service";
const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
const router = useRouter();
const { userInfo, setUserInfo } = useUserStore((state) => state);
async function authCheck() {
const userId = getCookie(AUTH_USER_ID);
if (!userId) {
throw new Error("Missing required authentication tokens");
}
const response = await client.get<IUserInfo>(
`${ENDPOINT.USER_SERVICE.USERS}/${userId}`,
);
if (!userInfo) setUserInfo(response.data);
}
useEffect(() => {
(async () => {
try {
await authCheck();
} catch (error) {
console.error(error);
try {
await LoginApi.silentRefresh();
await authCheck();
} catch (refreshError) {
console.error("Token refresh failed:", refreshError);
setUserInfo(null);
router.push("/auth/login");
}
}
})();
}, []);
return <>{children}</>;
};
export { AuthWrapper };
@@ -1,6 +1,6 @@
import type { ColumnDef } from "@tanstack/react-table";
import type { UseFormReturn } from "react-hook-form";
import { Checkbox } from "@common/components/ui";
import { Checkbox } from "@common/components";
import type {
MenuAuthority,
MenuAuthorityFormData,
@@ -13,7 +13,7 @@ import {
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@common/components/ui";
} from "@common/components";
import { ENDPOINT } from "@/shared/config";
import { useAlertStore } from "@/shared/lib/use-alert-store";
import {
@@ -1,4 +1,4 @@
import { client } from "@common/components/api";
import { client } from "@/shared/api";
import { ENDPOINT } from "@/shared/config";
import type { MenuItem, MenuService } from "../model/menu-interface";
@@ -1 +1,2 @@
export { MenuWrapper } from "./lib/menu-wrapper";
export type { MenuItem } from "./model/menu-interface";
@@ -23,8 +23,8 @@ import {
DateRangePicker,
DialogClose,
DialogFooter,
} from "@common/components/ui";
import { cn } from "@common/components/lib";
cn,
} from "@common/components";
import { CodeSelect } from "@/entities/code/@x/posting";
import { SiteApi, type Site } from "@/entities/site/@x/posting";
import type { PageableList } from "@/shared/model";
@@ -1,7 +1,7 @@
import dayjs from "dayjs";
import type { ColumnDef } from "@tanstack/react-table";
import type { Post } from "@/entities/post";
import { Badge, Button } from "@common/components/ui";
import { Badge, Button } from "@common/components";
export const columns: ColumnDef<Post>[] = [
{
@@ -19,7 +19,7 @@ import {
SelectItem,
SelectTrigger,
SelectValue,
} from "@common/components/ui";
} from "@common/components";
import { PostApi, type Post, type PostParams } from "@/entities/post";
import { ENDPOINT } from "@/shared/config";
import { columns } from "../model/notice-table-columns";
@@ -1,5 +1,5 @@
import { createStore } from "zustand/vanilla";
import type { MenuItem } from "@common/components/api";
import type { MenuItem } from "@/entities/menu";
export type MenuState = {
currentMenuInfo: MenuItem | null;
@@ -4,7 +4,7 @@ import {
DialogFooter,
DialogClose,
Button,
} from "@common/components/ui";
} from "@common/components";
import { useAlertStore } from "../lib/use-alert-store";
function AlertDialog() {
@@ -6,7 +6,7 @@ import {
DialogClose,
Button,
type ButtonProps,
} from "@common/components/ui";
} from "@common/components";
type ConfirmDialogProps = {
isOpen?: boolean;
+1 -1
View File
@@ -9,7 +9,7 @@ import {
type FieldPath,
type FieldValues,
} from "react-hook-form";
import { cn, Label } from "@common/components";
import { Label, cn } from "@common/components";
const Form = FormProvider;
@@ -1,4 +1,6 @@
import { Skeleton } from "@common/components/ui/skeleton";
"use client";
import { Skeleton } from "@common/components";
function SkeletonPage() {
return (
@@ -1,7 +1,6 @@
import { useEffect, useState } from "react";
import type { NodeModel, TreeMethods } from "@minoru/react-dnd-treeview";
import { Button } from "@common/components/ui";
import { cn } from "@common/components/lib";
import { Button, cn } from "@common/components";
import { EditableNode } from "./editable-node";
interface TreeData extends Record<string, unknown> {
@@ -68,7 +67,9 @@ function CustomNode<T extends TreeData>({
{editMode ? (
<EditableNode
value={nodeName}
onChange={(e) => setNodeName(e.target.value)}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setNodeName(e.target.value)
}
onSave={handleSave}
onCancel={handleCancel}
/>
@@ -11,8 +11,7 @@ import {
type DropOptions,
type Classes,
} from "@minoru/react-dnd-treeview";
import { Button } from "@common/components/ui";
import { cn } from "@common/components/lib";
import { Button, cn } from "@common/components";
import { CustomNode } from "./custom-node";
interface TreeData extends Record<string, unknown> {
@@ -1,5 +1,5 @@
import type { ComponentProps } from "react";
import { Button, Input } from "@common/components/ui";
import { Button, Input } from "@common/components";
type EditableNodeProps = {
depth?: number;
@@ -1,7 +1,7 @@
import { useRouter } from "next/navigation";
import { useConfirm } from "@frontend-opensource/use-react-hooks";
import { type FieldValues, type UseFormReturn } from "react-hook-form";
import { Button } from "@common/components/ui";
import { Button } from "@common/components";
import { Form } from "@/shared/ui/form";
type FormWrapperProps<T extends FieldValues> = {
@@ -1,7 +1,7 @@
import { useRouter } from "next/navigation";
import { useMutation } from "@tanstack/react-query";
import { useConfirm } from "@frontend-opensource/use-react-hooks";
import { Button } from "@common/components/ui";
import { Button } from "@common/components";
import { PostApi } from "@/entities/post";
type PostActionProps = {