@farmzone/fz-template-react 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +46 -50
  2. package/package.json +1 -1
  3. package/template/.env.example +5 -5
  4. package/template/package.json +55 -55
  5. package/template/pnpm-lock.yaml +4214 -4214
  6. package/template/public/mockServiceWorker.js +349 -349
  7. package/template/src/app/api/api.ts +178 -178
  8. package/template/src/app/api/queries.ts +326 -321
  9. package/template/src/app/api/queryKey.ts +7 -7
  10. package/template/src/app/api/token.ts +7 -7
  11. package/template/src/app/layout/Layout.tsx +33 -33
  12. package/template/src/app/layout/ListContents.tsx +9 -9
  13. package/template/src/app/layout/ListHeader.tsx +41 -41
  14. package/template/src/app/layout/MultiTabNav.tsx +101 -101
  15. package/template/src/app/layout/Sidebar.tsx +33 -33
  16. package/template/src/app/layout/UserInfo.tsx +94 -94
  17. package/template/src/app/layout/tabSwitchStore.ts +11 -11
  18. package/template/src/app/router/Router.tsx +56 -56
  19. package/template/src/app/store/index.ts +26 -26
  20. package/template/src/index.tsx +21 -21
  21. package/template/src/mocks/browser.ts +17 -17
  22. package/template/src/mocks/handlers.ts +43 -43
  23. package/template/src/mocks/scenarios.ts +57 -57
  24. package/template/src/pages/dashboard/index.tsx +541 -541
  25. package/template/src/pages/error/Error.tsx +29 -29
  26. package/template/src/pages/error/NotFound.tsx +27 -27
  27. package/template/src/pages/login/index.tsx +317 -317
  28. package/template/src/pages/post/PostFormModal.tsx +128 -128
  29. package/template/src/pages/post/detail/index.tsx +548 -548
  30. package/template/src/pages/post/index.tsx +266 -267
  31. package/template/src/pages/sample/SampleFormModal.tsx +115 -77
  32. package/template/src/pages/sample/detail/index.tsx +400 -424
  33. package/template/src/pages/sample/index.tsx +278 -269
  34. package/template/src/pages/sample/modal/index.tsx +300 -253
  35. package/template/src/pages/system/log/index.tsx +173 -173
  36. package/template/src/pages/user/config/columns.tsx +102 -109
  37. package/template/src/pages/user/config/schema.ts +54 -54
  38. package/template/src/pages/user/index.tsx +641 -641
  39. package/template/src/shared/components/CommentInput.tsx +243 -243
  40. package/template/src/shared/config/text.ts +27 -27
  41. package/template/src/shared/utils/format.ts +11 -11
  42. package/template/src/types/auth.ts +10 -10
  43. package/template/src/types/comment.ts +33 -33
  44. package/template/src/types/common.ts +19 -19
  45. package/template/src/types/dashboard.ts +53 -53
  46. package/template/src/types/index.ts +16 -16
  47. package/template/src/types/log.ts +21 -21
  48. package/template/src/types/post.ts +32 -32
  49. package/template/src/types/sample.ts +29 -28
  50. package/template/src/types/user.ts +51 -51
  51. package/template/src/vite-env.d.ts +10 -10
@@ -1,7 +1,7 @@
1
- import Cookies from "js-cookie";
2
-
3
- export const clearUserToken = () => {
4
- Cookies.remove("AccessToken");
5
- Cookies.remove("RefreshToken");
6
- localStorage.removeItem("currentId");
7
- };
1
+ import Cookies from "js-cookie";
2
+
3
+ export const clearUserToken = () => {
4
+ Cookies.remove("AccessToken");
5
+ Cookies.remove("RefreshToken");
6
+ localStorage.removeItem("currentId");
7
+ };
@@ -1,33 +1,33 @@
1
- import { useEffect, useRef } from "react";
2
- import { Outlet, useLocation } from "react-router";
3
- import { toast } from "@farmzone/fz-react-ui";
4
-
5
- import { useTabSwitchStore } from "./tabSwitchStore";
6
- import MultiTabNav from "./MultiTabNav";
7
- import Sidebar from "./Sidebar";
8
-
9
- export default function Layout() {
10
- const { pathname } = useLocation();
11
- const prevPathnameRef = useRef(pathname);
12
- const { tabSwitchKey } = useTabSwitchStore();
13
-
14
- // 페이지 전환 시 success toast 외 모두 제거
15
- useEffect(() => {
16
- const prev = prevPathnameRef.current;
17
- prevPathnameRef.current = pathname;
18
- if (prev === pathname) return;
19
- toast.dismissAllExcept("success");
20
- }, [pathname]);
21
-
22
- return (
23
- <div className="flex h-screen bg-gray-50">
24
- <Sidebar />
25
- <div className="flex flex-1 flex-col overflow-hidden">
26
- <MultiTabNav />
27
- <main className="flex-1 overflow-y-auto">
28
- <Outlet key={tabSwitchKey} />
29
- </main>
30
- </div>
31
- </div>
32
- );
33
- }
1
+ import { useEffect, useRef } from "react";
2
+ import { Outlet, useLocation } from "react-router";
3
+ import { toast } from "@farmzone/fz-react-ui";
4
+
5
+ import { useTabSwitchStore } from "./tabSwitchStore";
6
+ import MultiTabNav from "./MultiTabNav";
7
+ import Sidebar from "./Sidebar";
8
+
9
+ export default function Layout() {
10
+ const { pathname } = useLocation();
11
+ const prevPathnameRef = useRef(pathname);
12
+ const { tabSwitchKey } = useTabSwitchStore();
13
+
14
+ // 페이지 전환 시 success toast 외 모두 제거
15
+ useEffect(() => {
16
+ const prev = prevPathnameRef.current;
17
+ prevPathnameRef.current = pathname;
18
+ if (prev === pathname) return;
19
+ toast.dismissAllExcept("success");
20
+ }, [pathname]);
21
+
22
+ return (
23
+ <div className="flex h-screen bg-gray-50">
24
+ <Sidebar />
25
+ <div className="flex flex-1 flex-col overflow-hidden">
26
+ <MultiTabNav />
27
+ <main className="flex-1 overflow-y-auto">
28
+ <Outlet key={tabSwitchKey} />
29
+ </main>
30
+ </div>
31
+ </div>
32
+ );
33
+ }
@@ -1,9 +1,9 @@
1
- import type { ReactNode } from "react";
2
-
3
- interface ListContentsProps {
4
- children: ReactNode;
5
- }
6
-
7
- export default function ListContents({ children }: ListContentsProps) {
8
- return <div className="mt-4 flex flex-col gap-3">{children}</div>;
9
- }
1
+ import type { ReactNode } from "react";
2
+
3
+ interface ListContentsProps {
4
+ children: ReactNode;
5
+ }
6
+
7
+ export default function ListContents({ children }: ListContentsProps) {
8
+ return <div className="mt-4 flex flex-col gap-3">{children}</div>;
9
+ }
@@ -1,41 +1,41 @@
1
- import type { ReactNode } from "react";
2
- import { useLocation } from "react-router";
3
-
4
- import { MENU_SECTIONS } from "./menu";
5
-
6
- function findPathText(pathname: string): string {
7
- for (const section of MENU_SECTIONS) {
8
- for (const item of section.items) {
9
- if (item.children?.length) {
10
- for (const child of item.children) {
11
- if (child.path && (pathname === child.path || pathname.startsWith(`${child.path}/`))) {
12
- return `${item.label} > ${child.label}`;
13
- }
14
- }
15
- } else if (item.path && (pathname === item.path || pathname.startsWith(`${item.path}/`))) {
16
- return section.title ? `${section.title} > ${item.label}` : item.label;
17
- }
18
- }
19
- }
20
- return "";
21
- }
22
-
23
- interface ListHeaderProps {
24
- title: string;
25
- rightArea?: ReactNode;
26
- }
27
-
28
- export default function ListHeader({ title, rightArea }: ListHeaderProps) {
29
- const { pathname } = useLocation();
30
- const pathText = findPathText(pathname);
31
-
32
- return (
33
- <div className="flex min-h-8 items-end justify-between">
34
- <div className="flex flex-col gap-0.5">
35
- {pathText && <span className="text-xs text-gray-400">{pathText}</span>}
36
- <h2 className="text-2xl font-bold text-gray-900">{title}</h2>
37
- </div>
38
- {rightArea && <div className="flex items-center">{rightArea}</div>}
39
- </div>
40
- );
41
- }
1
+ import type { ReactNode } from "react";
2
+ import { useLocation } from "react-router";
3
+
4
+ import { MENU_SECTIONS } from "./menu";
5
+
6
+ function findPathText(pathname: string): string {
7
+ for (const section of MENU_SECTIONS) {
8
+ for (const item of section.items) {
9
+ if (item.children?.length) {
10
+ for (const child of item.children) {
11
+ if (child.path && (pathname === child.path || pathname.startsWith(`${child.path}/`))) {
12
+ return `${item.label} > ${child.label}`;
13
+ }
14
+ }
15
+ } else if (item.path && (pathname === item.path || pathname.startsWith(`${item.path}/`))) {
16
+ return section.title ? `${section.title} > ${item.label}` : item.label;
17
+ }
18
+ }
19
+ }
20
+ return "";
21
+ }
22
+
23
+ interface ListHeaderProps {
24
+ title: string;
25
+ rightArea?: ReactNode;
26
+ }
27
+
28
+ export default function ListHeader({ title, rightArea }: ListHeaderProps) {
29
+ const { pathname } = useLocation();
30
+ const pathText = findPathText(pathname);
31
+
32
+ return (
33
+ <div className="flex min-h-8 items-end justify-between">
34
+ <div className="flex flex-col gap-0.5">
35
+ {pathText && <span className="text-xs text-gray-400">{pathText}</span>}
36
+ <h2 className="text-2xl font-bold text-gray-900">{title}</h2>
37
+ </div>
38
+ {rightArea && <div className="flex items-center">{rightArea}</div>}
39
+ </div>
40
+ );
41
+ }
@@ -1,101 +1,101 @@
1
- import { useEffect, useRef } from "react";
2
- import { useLocation, useNavigate } from "react-router";
3
- import { MultiTab, useMultiTabStore } from "@farmzone/fz-react-ui";
4
-
5
- import { findTabInfoForPath } from "./menu";
6
- import { useTabSwitchStore } from "./tabSwitchStore";
7
-
8
- const DASHBOARD_TAB = { basePath: "/", label: "대시보드" } as const;
9
-
10
- export default function MultiTabNav() {
11
- const { tabs, activeTabId, hasHydrated, openTab, addTab, switchToTab, closeTab, updateCurrentPath } =
12
- useMultiTabStore();
13
- const { commitTabSwitch } = useTabSwitchStore();
14
- const navigate = useNavigate();
15
- const location = useLocation();
16
- const { pathname } = location;
17
- const pendingSwitch = useRef(false);
18
-
19
- // hydration 완료 후 최초 1회: 탭 없으면 대시보드 생성, 있으면 활성 탭 경로 복원
20
- useEffect(() => {
21
- if (!hasHydrated) return;
22
- if (tabs.length === 0) {
23
- openTab(DASHBOARD_TAB.basePath, DASHBOARD_TAB.label);
24
- navigate(DASHBOARD_TAB.basePath);
25
- return;
26
- }
27
- const activeTab = tabs.find((t) => t.id === activeTabId);
28
- if (activeTab && pathname !== activeTab.currentPath) {
29
- navigate(activeTab.currentPath, { replace: true });
30
- }
31
- // hasHydrated 변경 시 1회만 실행
32
- // eslint-disable-next-line react-hooks/exhaustive-deps
33
- }, [hasHydrated]);
34
-
35
- // 탭 전환 후 URL이 실제로 바뀌면 commitTabSwitch 호출 → Outlet 강제 리마운트
36
- useEffect(() => {
37
- if (!pendingSwitch.current) return;
38
- pendingSwitch.current = false;
39
- commitTabSwitch();
40
- // location.key 변경 시 실행 (실제 URL 변경 감지)
41
- // eslint-disable-next-line react-hooks/exhaustive-deps
42
- }, [location.key]);
43
-
44
- // pathname 변경 시: 탭 소유권 확인 → auto-switch / auto-create / currentPath 동기화
45
- // getState() 사용으로 stale closure 방지
46
- useEffect(() => {
47
- if (!hasHydrated) return;
48
- const { tabs: currentTabs, activeTabId: currentActiveTabId } = useMultiTabStore.getState();
49
-
50
- const ownerTab = currentTabs.find(
51
- (t) => pathname === t.basePath || pathname.startsWith(`${t.basePath}/`),
52
- );
53
-
54
- if (ownerTab) {
55
- if (ownerTab.id !== currentActiveTabId) {
56
- // Sidebar 등에서 다른 탭 도메인으로 직접 navigate된 경우 — 활성 탭 전환
57
- const fromTab = currentTabs.find((t) => t.id === currentActiveTabId);
58
- useMultiTabStore.getState().switchToTab(ownerTab.id, fromTab?.currentPath ?? pathname);
59
- }
60
- if (ownerTab.currentPath !== pathname) {
61
- updateCurrentPath(ownerTab.id, pathname);
62
- }
63
- } else {
64
- // 어떤 탭에도 속하지 않는 경로 — 메뉴 정보로 탭 자동 생성
65
- const info = findTabInfoForPath(pathname);
66
- if (info) openTab(info.basePath, info.label, pathname);
67
- }
68
- }, [pathname, hasHydrated]);
69
-
70
- if (!tabs.length) return null;
71
-
72
- const activeTab = tabs.find((t) => t.id === activeTabId);
73
-
74
- const handleTabClick = (tabId: string) => {
75
- if (tabId === activeTabId) return;
76
- pendingSwitch.current = true;
77
- const targetPath = switchToTab(tabId, pathname);
78
- navigate(targetPath);
79
- };
80
-
81
- const handleTabClose = (tabId: string) => {
82
- const nextPath = closeTab(tabId);
83
- if (nextPath != null) navigate(nextPath);
84
- };
85
-
86
- const handleTabAdd = () => {
87
- if (!activeTab) return;
88
- const newPath = addTab(activeTab.basePath, activeTab.label, activeTab.currentPath);
89
- navigate(newPath);
90
- };
91
-
92
- return (
93
- <MultiTab
94
- tabs={tabs}
95
- activeTabId={activeTabId}
96
- onTabClick={handleTabClick}
97
- onTabClose={handleTabClose}
98
- onTabAdd={handleTabAdd}
99
- />
100
- );
101
- }
1
+ import { useEffect, useRef } from "react";
2
+ import { useLocation, useNavigate } from "react-router";
3
+ import { MultiTab, useMultiTabStore } from "@farmzone/fz-react-ui";
4
+
5
+ import { findTabInfoForPath } from "./menu";
6
+ import { useTabSwitchStore } from "./tabSwitchStore";
7
+
8
+ const DASHBOARD_TAB = { basePath: "/", label: "대시보드" } as const;
9
+
10
+ export default function MultiTabNav() {
11
+ const { tabs, activeTabId, hasHydrated, openTab, addTab, switchToTab, closeTab, updateCurrentPath } =
12
+ useMultiTabStore();
13
+ const { commitTabSwitch } = useTabSwitchStore();
14
+ const navigate = useNavigate();
15
+ const location = useLocation();
16
+ const { pathname } = location;
17
+ const pendingSwitch = useRef(false);
18
+
19
+ // hydration 완료 후 최초 1회: 탭 없으면 대시보드 생성, 있으면 활성 탭 경로 복원
20
+ useEffect(() => {
21
+ if (!hasHydrated) return;
22
+ if (tabs.length === 0) {
23
+ openTab(DASHBOARD_TAB.basePath, DASHBOARD_TAB.label);
24
+ navigate(DASHBOARD_TAB.basePath);
25
+ return;
26
+ }
27
+ const activeTab = tabs.find((t) => t.id === activeTabId);
28
+ if (activeTab && pathname !== activeTab.currentPath) {
29
+ navigate(activeTab.currentPath, { replace: true });
30
+ }
31
+ // hasHydrated 변경 시 1회만 실행
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, [hasHydrated]);
34
+
35
+ // 탭 전환 후 URL이 실제로 바뀌면 commitTabSwitch 호출 → Outlet 강제 리마운트
36
+ useEffect(() => {
37
+ if (!pendingSwitch.current) return;
38
+ pendingSwitch.current = false;
39
+ commitTabSwitch();
40
+ // location.key 변경 시 실행 (실제 URL 변경 감지)
41
+ // eslint-disable-next-line react-hooks/exhaustive-deps
42
+ }, [location.key]);
43
+
44
+ // pathname 변경 시: 탭 소유권 확인 → auto-switch / auto-create / currentPath 동기화
45
+ // getState() 사용으로 stale closure 방지
46
+ useEffect(() => {
47
+ if (!hasHydrated) return;
48
+ const { tabs: currentTabs, activeTabId: currentActiveTabId } = useMultiTabStore.getState();
49
+
50
+ const ownerTab = currentTabs.find(
51
+ (t) => pathname === t.basePath || pathname.startsWith(`${t.basePath}/`),
52
+ );
53
+
54
+ if (ownerTab) {
55
+ if (ownerTab.id !== currentActiveTabId) {
56
+ // Sidebar 등에서 다른 탭 도메인으로 직접 navigate된 경우 — 활성 탭 전환
57
+ const fromTab = currentTabs.find((t) => t.id === currentActiveTabId);
58
+ useMultiTabStore.getState().switchToTab(ownerTab.id, fromTab?.currentPath ?? pathname);
59
+ }
60
+ if (ownerTab.currentPath !== pathname) {
61
+ updateCurrentPath(ownerTab.id, pathname);
62
+ }
63
+ } else {
64
+ // 어떤 탭에도 속하지 않는 경로 — 메뉴 정보로 탭 자동 생성
65
+ const info = findTabInfoForPath(pathname);
66
+ if (info) openTab(info.basePath, info.label, pathname);
67
+ }
68
+ }, [pathname, hasHydrated]);
69
+
70
+ if (!tabs.length) return null;
71
+
72
+ const activeTab = tabs.find((t) => t.id === activeTabId);
73
+
74
+ const handleTabClick = (tabId: string) => {
75
+ if (tabId === activeTabId) return;
76
+ pendingSwitch.current = true;
77
+ const targetPath = switchToTab(tabId, pathname);
78
+ navigate(targetPath);
79
+ };
80
+
81
+ const handleTabClose = (tabId: string) => {
82
+ const nextPath = closeTab(tabId);
83
+ if (nextPath != null) navigate(nextPath);
84
+ };
85
+
86
+ const handleTabAdd = () => {
87
+ if (!activeTab) return;
88
+ const newPath = addTab(activeTab.basePath, activeTab.label, activeTab.currentPath);
89
+ navigate(newPath);
90
+ };
91
+
92
+ return (
93
+ <MultiTab
94
+ tabs={tabs}
95
+ activeTabId={activeTabId}
96
+ onTabClick={handleTabClick}
97
+ onTabClose={handleTabClose}
98
+ onTabAdd={handleTabAdd}
99
+ />
100
+ );
101
+ }
@@ -1,33 +1,33 @@
1
- import { useState } from "react";
2
- import { useNavigate } from "react-router";
3
- import { Sidebar as FzSidebar } from "@farmzone/fz-react-ui";
4
-
5
- import { MENU_SECTIONS } from "./menu";
6
- import UserInfo from "./UserInfo";
7
-
8
- function SidebarHeader() {
9
- const navigate = useNavigate();
10
- return (
11
- <div className="flex flex-col gap-4 my-4">
12
- <div className="text-center cursor-pointer" onClick={() => navigate("/")}>
13
- <div className="inline-flex items-center justify-center">
14
- <img src="/favicon.ico" alt="logo" className="w-44 pr-4 object-contain" />
15
- </div>
16
- </div>
17
- <UserInfo />
18
- </div>
19
- );
20
- }
21
-
22
- export default function Sidebar() {
23
- const [isOpen, setIsOpen] = useState(true);
24
- return (
25
- <FzSidebar
26
- isOpen={isOpen}
27
- onClose={() => setIsOpen(false)}
28
- menuSections={MENU_SECTIONS}
29
- header={<SidebarHeader />}
30
- showCollapseButton
31
- />
32
- );
33
- }
1
+ import { useState } from "react";
2
+ import { useNavigate } from "react-router";
3
+ import { Sidebar as FzSidebar } from "@farmzone/fz-react-ui";
4
+
5
+ import { MENU_SECTIONS } from "./menu";
6
+ import UserInfo from "./UserInfo";
7
+
8
+ function SidebarHeader() {
9
+ const navigate = useNavigate();
10
+ return (
11
+ <div className="flex flex-col gap-4 my-4">
12
+ <div className="text-center cursor-pointer" onClick={() => navigate("/")}>
13
+ <div className="inline-flex items-center justify-center">
14
+ <img src="/favicon.ico" alt="logo" className="w-44 pr-4 object-contain" />
15
+ </div>
16
+ </div>
17
+ <UserInfo />
18
+ </div>
19
+ );
20
+ }
21
+
22
+ export default function Sidebar() {
23
+ const [isOpen, setIsOpen] = useState(true);
24
+ return (
25
+ <FzSidebar
26
+ isOpen={isOpen}
27
+ onClose={() => setIsOpen(false)}
28
+ menuSections={MENU_SECTIONS}
29
+ header={<SidebarHeader />}
30
+ showCollapseButton
31
+ />
32
+ );
33
+ }
@@ -1,94 +1,94 @@
1
- import { Edit, EllipsisVertical, LogOut } from "lucide-react";
2
- import { useState } from "react";
3
- import { useNavigate } from "react-router";
4
- import { confirmModal, Popover, PopoverContent, PopoverTrigger } from "@farmzone/fz-react-ui";
5
-
6
- import { clearUserToken } from "@/app/api/token";
7
- import { useUserStore } from "@/app/store";
8
-
9
- export default function UserInfo() {
10
- const navigate = useNavigate();
11
- const { user, clearUser } = useUserStore();
12
- const [open, setOpen] = useState(false);
13
-
14
- const roleLabel = user?.role === "ADMIN" ? "관리자" : user?.role ? "사용자" : "";
15
-
16
- const handleLogout = () => {
17
- setOpen(false);
18
- confirmModal({
19
- content: "로그아웃 하시겠습니까?",
20
- onOk: async () => {
21
- clearUserToken();
22
- clearUser();
23
- navigate("/login");
24
- },
25
- onCancel: async () => {},
26
- okText: "예",
27
- cancelText: "아니오",
28
- className: "max-w-100",
29
- });
30
- };
31
-
32
- return (
33
- <div className="group flex items-center gap-1 py-3 pl-3 pr-2 transition-all duration-200 border border-[var(--color-basic-gray)]/50 rounded-sm">
34
- <div className="flex flex-row items-center min-w-0 flex-1">
35
- <span className="w-[60px] text-xs text-gray-400 truncate mt-0.5">
36
- {roleLabel && (
37
- <span className="shrink-0 text-[10px] font-medium px-1.5 py-0.5 mr-1 rounded-full bg-[var(--color-main)]/10 text-[var(--color-main)] leading-none">
38
- {roleLabel}
39
- </span>
40
- )}
41
- </span>
42
- <p className="w-full text-sm font-normal text-gray-900 leading-4 tracking-tight truncate">
43
- {user?.name || ""}
44
- </p>
45
- </div>
46
-
47
- <Popover open={open} onOpenChange={setOpen}>
48
- <PopoverTrigger>
49
- <EllipsisVertical className="shrink-0 w-4 h-4 text-gray-300 group-hover:text-gray-500 transition-colors duration-200 cursor-pointer" />
50
- </PopoverTrigger>
51
- <PopoverContent position="right" sideOffset={15} align="start" className="w-56 p-0">
52
- <div className="flex flex-col">
53
- {/* 사용자 ID */}
54
- <div className="flex items-center px-4 py-3 border-b border-gray-100">
55
- <span className="text-sm text-gray-500 font-normal">{user?.userId || ""}</span>
56
- </div>
57
-
58
- {/* 버튼 영역 */}
59
- <div className="flex flex-col gap-2 p-3">
60
- <div className="flex gap-2">
61
- <button
62
- type="button"
63
- onClick={handleLogout}
64
- className="w-full flex items-center justify-center gap-1 py-2 px-4 text-xs font-medium text-gray-700 hover:text-red-900 hover:bg-red-50 transition-all duration-150 bg-gray-50 border border-gray-200 rounded-sm cursor-pointer"
65
- >
66
- <LogOut size={12} />
67
- <span>로그아웃</span>
68
- </button>
69
- <button
70
- type="button"
71
- onClick={() => {
72
- setOpen(false);
73
- navigate("/user");
74
- }}
75
- className="w-full flex items-center justify-center gap-1 py-2 px-4 text-xs font-medium text-gray-700 hover:text-gray-900 hover:bg-gray-100 transition-all duration-150 bg-gray-50 border border-gray-200 rounded-sm cursor-pointer"
76
- >
77
- <Edit size={12} />
78
- <span>정보수정</span>
79
- </button>
80
- </div>
81
- <button
82
- type="button"
83
- onClick={() => setOpen(false)}
84
- className="w-full flex items-center justify-center gap-1 py-2 px-4 text-xs font-medium text-gray-700 hover:text-gray-900 hover:bg-gray-100 transition-all duration-150 bg-gray-50 border border-gray-200 rounded-sm cursor-pointer"
85
- >
86
- <span>닫기</span>
87
- </button>
88
- </div>
89
- </div>
90
- </PopoverContent>
91
- </Popover>
92
- </div>
93
- );
94
- }
1
+ import { Edit, EllipsisVertical, LogOut } from "lucide-react";
2
+ import { useState } from "react";
3
+ import { useNavigate } from "react-router";
4
+ import { confirmModal, Popover, PopoverContent, PopoverTrigger } from "@farmzone/fz-react-ui";
5
+
6
+ import { clearUserToken } from "@/app/api/token";
7
+ import { useUserStore } from "@/app/store";
8
+
9
+ export default function UserInfo() {
10
+ const navigate = useNavigate();
11
+ const { user, clearUser } = useUserStore();
12
+ const [open, setOpen] = useState(false);
13
+
14
+ const roleLabel = user?.role === "ADMIN" ? "관리자" : user?.role ? "사용자" : "";
15
+
16
+ const handleLogout = () => {
17
+ setOpen(false);
18
+ confirmModal({
19
+ content: "로그아웃 하시겠습니까?",
20
+ onOk: async () => {
21
+ clearUserToken();
22
+ clearUser();
23
+ navigate("/login");
24
+ },
25
+ onCancel: async () => {},
26
+ okText: "예",
27
+ cancelText: "아니오",
28
+ className: "max-w-100",
29
+ });
30
+ };
31
+
32
+ return (
33
+ <div className="group flex items-center gap-1 py-3 pl-3 pr-2 transition-all duration-200 border border-[var(--color-basic-gray)]/50 rounded-sm">
34
+ <div className="flex flex-row items-center min-w-0 flex-1">
35
+ <span className="w-[60px] text-xs text-gray-400 truncate mt-0.5">
36
+ {roleLabel && (
37
+ <span className="shrink-0 text-[10px] font-medium px-1.5 py-0.5 mr-1 rounded-full bg-[var(--color-main)]/10 text-[var(--color-main)] leading-none">
38
+ {roleLabel}
39
+ </span>
40
+ )}
41
+ </span>
42
+ <p className="w-full text-sm font-normal text-gray-900 leading-4 tracking-tight truncate">
43
+ {user?.name || ""}
44
+ </p>
45
+ </div>
46
+
47
+ <Popover open={open} onOpenChange={setOpen}>
48
+ <PopoverTrigger>
49
+ <EllipsisVertical className="shrink-0 w-4 h-4 text-gray-300 group-hover:text-gray-500 transition-colors duration-200 cursor-pointer" />
50
+ </PopoverTrigger>
51
+ <PopoverContent position="right" sideOffset={15} align="start" className="w-56 p-0">
52
+ <div className="flex flex-col">
53
+ {/* 사용자 ID */}
54
+ <div className="flex items-center px-4 py-3 border-b border-gray-100">
55
+ <span className="text-sm text-gray-500 font-normal">{user?.userId || ""}</span>
56
+ </div>
57
+
58
+ {/* 버튼 영역 */}
59
+ <div className="flex flex-col gap-2 p-3">
60
+ <div className="flex gap-2">
61
+ <button
62
+ type="button"
63
+ onClick={handleLogout}
64
+ className="w-full flex items-center justify-center gap-1 py-2 px-4 text-xs font-medium text-gray-700 hover:text-red-900 hover:bg-red-50 transition-all duration-150 bg-gray-50 border border-gray-200 rounded-sm cursor-pointer"
65
+ >
66
+ <LogOut size={12} />
67
+ <span>로그아웃</span>
68
+ </button>
69
+ <button
70
+ type="button"
71
+ onClick={() => {
72
+ setOpen(false);
73
+ navigate("/user");
74
+ }}
75
+ className="w-full flex items-center justify-center gap-1 py-2 px-4 text-xs font-medium text-gray-700 hover:text-gray-900 hover:bg-gray-100 transition-all duration-150 bg-gray-50 border border-gray-200 rounded-sm cursor-pointer"
76
+ >
77
+ <Edit size={12} />
78
+ <span>정보수정</span>
79
+ </button>
80
+ </div>
81
+ <button
82
+ type="button"
83
+ onClick={() => setOpen(false)}
84
+ className="w-full flex items-center justify-center gap-1 py-2 px-4 text-xs font-medium text-gray-700 hover:text-gray-900 hover:bg-gray-100 transition-all duration-150 bg-gray-50 border border-gray-200 rounded-sm cursor-pointer"
85
+ >
86
+ <span>닫기</span>
87
+ </button>
88
+ </div>
89
+ </div>
90
+ </PopoverContent>
91
+ </Popover>
92
+ </div>
93
+ );
94
+ }