Blame view

美国版/Food Labeling Management Platform/src/App.tsx 5.73 KB
699ea6e8   杨鑫   完善打印逻辑
1
  import { useCallback, useEffect, useState } from 'react';
ef6b3255   杨鑫   修改BUG
2
  import { Toaster, toast } from 'sonner';
884054fb   “wangming”   项目初始化
3
4
5
6
7
8
9
10
11
12
  import { Layout } from './components/layout/Layout';
  import { Dashboard } from './components/dashboard/Dashboard';
  import { PlaceholderView } from './components/PlaceholderView';
  
  import { LabelsView } from './components/labels/LabelsView';
  import { TrainingView } from './components/training/TrainingView';
  import { AlertsView } from './components/alerts/AlertsView';
  import { ProductsView } from './components/products/ProductsView';
  import { PeopleView } from './components/people/PeopleView';
  import { ReportsView } from './components/reports/ReportsView';
de8956f8   杨鑫   平台端 门店,菜单,角色
13
  import { SystemMenuView } from './components/system-menu/SystemMenuView';
699ea6e8   杨鑫   完善打印逻辑
14
15
16
  import { SupportView } from './components/support/SupportView';
  import { AuthProvider, useAuth } from './components/auth/AuthProvider';
  import { LoginView } from './components/auth/LoginView';
884054fb   “wangming”   项目初始化
17
  
699ea6e8   杨鑫   完善打印逻辑
18
19
  function AuthedApp() {
    const auth = useAuth();
884054fb   “wangming”   项目初始化
20
    const [currentView, setCurrentView] = useState('Dashboard');
699ea6e8   杨鑫   完善打印逻辑
21
22
    /** 侧栏点「Location Manager」时打开 Account Management 并切到门店 Tab */
    const [pendingPeopleSubTab, setPendingPeopleSubTab] = useState<'Location Manager' | null>(null);
699ea6e8   杨鑫   完善打印逻辑
23
24
25
    /** Dashboard「View Reports」:与 reportsTargetTab 配合,仅在意图跳转时递增 */
    const [reportsOpenKey, setReportsOpenKey] = useState(0);
    const [reportsTargetTab, setReportsTargetTab] = useState<'print-log' | 'label-report'>('print-log');
63289723   杨鑫   提交
26
27
    /** 标签模板编辑器全屏:Layout 隐藏侧栏/顶栏 */
    const [labelTemplateEditorFullscreen, setLabelTemplateEditorFullscreen] = useState(false);
ef6b3255   杨鑫   修改BUG
28
29
30
    /** 顶栏点头像:打开 Account Management → Team Member 中当前用户编辑弹窗 */
    const [profileEditIntent, setProfileEditIntent] = useState<{ userId: string; nonce: number } | null>(null);
    const clearProfileEditIntent = useCallback(() => setProfileEditIntent(null), []);
699ea6e8   杨鑫   完善打印逻辑
31
32
33
34
35
36
37
38
  
    const resolveView = (name: string) => {
      const s = (name ?? "").trim();
      if (!s) return "Dashboard";
      // 后端菜单可能会返回更偏“模块名”的英文,这里做一次别名兼容
      if (s === "System Management") return "System Menu";
      if (s === "Location Management") return "Location Manager";
      if (s === "Account Manager") return "Account Management";
ef6b3255   杨鑫   修改BUG
39
      if (s === "Multiple Options") return "Multiple Option Sets";
699ea6e8   杨鑫   完善打印逻辑
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
      return s;
    };
  
    const resolvedView = resolveView(currentView);
  
    const navigateToView = useCallback((view: string) => {
      const v = resolveView(view);
      if (v === 'Location Manager') {
        setPendingPeopleSubTab('Location Manager');
        setCurrentView('Account Management');
        return;
      }
      setCurrentView(v);
    }, []);
  
ef6b3255   杨鑫   修改BUG
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    const handleOpenMyProfileEditor = useCallback(() => {
      const id = (auth.user?.id ?? "").trim();
      if (!id) {
        toast.error("Profile unavailable", {
          description: "User information is still loading. Please try again in a moment.",
        });
        return;
      }
      setProfileEditIntent((prev) => ({
        userId: id,
        nonce: (prev?.nonce ?? 0) + 1,
      }));
      setPendingPeopleSubTab(null);
      navigateToView("Account Management");
    }, [auth.user, navigateToView]);
699ea6e8   杨鑫   完善打印逻辑
70
71
  
    useEffect(() => {
699ea6e8   杨鑫   完善打印逻辑
72
73
74
      if (resolvedView !== 'Reports') {
        setReportsOpenKey(0);
      }
63289723   杨鑫   提交
75
76
77
      if (resolvedView !== 'Label Templates') {
        setLabelTemplateEditorFullscreen(false);
      }
699ea6e8   杨鑫   完善打印逻辑
78
79
80
81
82
    }, [resolvedView]);
  
    if (!auth.token) {
      return <LoginView />;
    }
884054fb   “wangming”   项目初始化
83
84
  
    const renderView = () => {
699ea6e8   杨鑫   完善打印逻辑
85
86
      const view = resolvedView;
      switch (view) {
884054fb   “wangming”   项目初始化
87
        case 'Dashboard':
699ea6e8   杨鑫   完善打印逻辑
88
89
          return (
            <Dashboard
699ea6e8   杨鑫   完善打印逻辑
90
91
92
93
94
95
96
97
98
99
100
101
              onViewReports={() => {
                setReportsTargetTab('label-report');
                setReportsOpenKey((k) => k + 1);
                setCurrentView('Reports');
              }}
              onViewAllRecentLabels={() => {
                setReportsTargetTab('print-log');
                setReportsOpenKey((k) => k + 1);
                setCurrentView('Reports');
              }}
            />
          );
884054fb   “wangming”   项目初始化
102
103
104
105
        case 'Training':
          return <TrainingView />;
        case 'Alerts':
          return <AlertsView />;
de8956f8   杨鑫   平台端 门店,菜单,角色
106
107
        case 'Menu Management':
          // 还原:Menu Management 对应“商品管理/新增”页面
884054fb   “wangming”   项目初始化
108
          return <ProductsView />;
de8956f8   杨鑫   平台端 门店,菜单,角色
109
110
        case 'System Menu':
          return <SystemMenuView />;
884054fb   “wangming”   项目初始化
111
        case 'Account Management':
699ea6e8   杨鑫   完善打印逻辑
112
113
114
115
          return (
            <PeopleView
              initialSubTab={pendingPeopleSubTab}
              onInitialSubTabConsumed={() => setPendingPeopleSubTab(null)}
ef6b3255   杨鑫   修改BUG
116
117
              profileEditIntent={profileEditIntent}
              onProfileEditIntentConsumed={clearProfileEditIntent}
699ea6e8   杨鑫   完善打印逻辑
118
119
            />
          );
884054fb   “wangming”   项目初始化
120
        case 'Reports':
699ea6e8   杨鑫   完善打印逻辑
121
122
123
124
125
          return (
            <ReportsView layoutReportsOpenKey={reportsOpenKey} layoutReportsTargetTab={reportsTargetTab} />
          );
        case 'Support':
          return <SupportView />;
884054fb   “wangming”   项目初始化
126
127
128
129
        case 'Labels':
        case 'Label Categories':
        case 'Label Types':
        case 'Label Templates':
ef6b3255   杨鑫   修改BUG
130
        case 'Multiple Option Sets':
699ea6e8   杨鑫   完善打印逻辑
131
132
133
134
          return (
            <LabelsView
              currentView={view}
              onViewChange={setCurrentView}
63289723   杨鑫   提交
135
              onLabelTemplateEditorLayoutOverlay={setLabelTemplateEditorFullscreen}
699ea6e8   杨鑫   完善打印逻辑
136
137
            />
          );
884054fb   “wangming”   项目初始化
138
        default:
699ea6e8   杨鑫   完善打印逻辑
139
          return <PlaceholderView title={view} />;
884054fb   “wangming”   项目初始化
140
141
142
143
      }
    };
  
    return (
3d4c10ac   杨鑫   对接,标签产品
144
      <>
63289723   杨鑫   提交
145
146
147
148
149
        <Layout
          currentView={resolvedView}
          setCurrentView={navigateToView}
          menus={auth.menus}
          onLogout={auth.logout}
ef6b3255   杨鑫   修改BUG
150
          onProfileClick={handleOpenMyProfileEditor}
63289723   杨鑫   提交
151
152
          hideAppChrome={labelTemplateEditorFullscreen}
        >
3d4c10ac   杨鑫   对接,标签产品
153
154
          {renderView()}
        </Layout>
699ea6e8   杨鑫   完善打印逻辑
155
156
157
158
159
160
161
162
163
164
      </>
    );
  }
  
  export default function App() {
    return (
      <>
        <AuthProvider>
          <AuthedApp />
        </AuthProvider>
3d4c10ac   杨鑫   对接,标签产品
165
166
        <Toaster position="top-center" richColors closeButton expand={false} />
      </>
884054fb   “wangming”   项目初始化
167
168
    );
  }