@famgia/omnify-react-sso 2.2.1 → 2.2.3
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.
- package/README.md +404 -113
- package/dist/@omnify-base/schemas/Branch.ts +12 -12
- package/dist/@omnify-base/schemas/BranchCache.ts +131 -0
- package/dist/@omnify-base/schemas/OrganizationCache.ts +117 -0
- package/dist/@omnify-base/schemas/Permission.ts +10 -10
- package/dist/@omnify-base/schemas/Role.ts +19 -12
- package/dist/@omnify-base/schemas/RolePermission.ts +6 -6
- package/dist/@omnify-base/schemas/Team.ts +6 -6
- package/dist/@omnify-base/schemas/TeamCache.ts +110 -0
- package/dist/@omnify-base/schemas/TeamPermission.ts +6 -6
- package/dist/@omnify-base/schemas/User.ts +13 -13
- package/dist/@omnify-base/schemas/UserCache.ts +142 -0
- package/dist/index.cjs +1846 -427
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +623 -14
- package/dist/index.d.ts +623 -14
- package/dist/index.js +1790 -400
- package/dist/index.js.map +1 -1
- package/dist/schemas/index.cjs +245 -167
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +67 -28
- package/dist/schemas/index.d.ts +67 -28
- package/dist/schemas/index.js +217 -146
- package/dist/schemas/index.js.map +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/{types-BCBSfJJr.d.cts → types-bD5deLxs.d.cts} +102 -1
- package/dist/{types-BCBSfJJr.d.ts → types-bD5deLxs.d.ts} +102 -1
- package/package.json +121 -106
- package/scripts/build-schemas.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -53,34 +53,34 @@ function getMessages(locale) {
|
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// node_modules/@omnify-base/schemas/
|
|
56
|
+
// node_modules/@omnify-base/schemas/BranchCache.ts
|
|
57
57
|
import { z } from "zod";
|
|
58
|
-
var
|
|
58
|
+
var branchCacheI18n = {
|
|
59
59
|
/** Model display name */
|
|
60
|
-
label: { "en": "Branch" },
|
|
60
|
+
label: { "ja": "\u652F\u5E97\u30AD\u30E3\u30C3\u30B7\u30E5", "en": "Branch Cache" },
|
|
61
61
|
/** Field labels and placeholders */
|
|
62
62
|
fields: {
|
|
63
63
|
console_branch_id: {
|
|
64
|
-
label: { "en": "Console Branch ID" }
|
|
64
|
+
label: { "ja": "Console Branch ID", "en": "Console Branch ID" }
|
|
65
65
|
},
|
|
66
66
|
console_org_id: {
|
|
67
|
-
label: { "en": "Console Organization ID" }
|
|
67
|
+
label: { "ja": "Console Organization ID", "en": "Console Organization ID" }
|
|
68
68
|
},
|
|
69
69
|
code: {
|
|
70
|
-
label: { "en": "Branch Code" }
|
|
70
|
+
label: { "ja": "\u652F\u5E97\u30B3\u30FC\u30C9", "en": "Branch Code" }
|
|
71
71
|
},
|
|
72
72
|
name: {
|
|
73
|
-
label: { "en": "Branch Name" }
|
|
73
|
+
label: { "ja": "\u652F\u5E97\u540D", "en": "Branch Name" }
|
|
74
74
|
},
|
|
75
75
|
is_headquarters: {
|
|
76
|
-
label: { "en": "Is Headquarters" }
|
|
76
|
+
label: { "ja": "\u672C\u793E", "en": "Is Headquarters" }
|
|
77
77
|
},
|
|
78
78
|
is_active: {
|
|
79
|
-
label: { "en": "Active" }
|
|
79
|
+
label: { "ja": "\u6709\u52B9", "en": "Active" }
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
var
|
|
83
|
+
var baseBranchCacheSchemas = {
|
|
84
84
|
console_branch_id: z.string(),
|
|
85
85
|
console_org_id: z.string(),
|
|
86
86
|
code: z.string().min(1).max(20),
|
|
@@ -88,62 +88,116 @@ var baseBranchSchemas = {
|
|
|
88
88
|
is_headquarters: z.boolean(),
|
|
89
89
|
is_active: z.boolean()
|
|
90
90
|
};
|
|
91
|
-
var
|
|
92
|
-
console_branch_id:
|
|
93
|
-
console_org_id:
|
|
94
|
-
code:
|
|
95
|
-
name:
|
|
96
|
-
is_headquarters:
|
|
97
|
-
is_active:
|
|
91
|
+
var baseBranchCacheCreateSchema = z.object({
|
|
92
|
+
console_branch_id: baseBranchCacheSchemas.console_branch_id,
|
|
93
|
+
console_org_id: baseBranchCacheSchemas.console_org_id,
|
|
94
|
+
code: baseBranchCacheSchemas.code,
|
|
95
|
+
name: baseBranchCacheSchemas.name,
|
|
96
|
+
is_headquarters: baseBranchCacheSchemas.is_headquarters,
|
|
97
|
+
is_active: baseBranchCacheSchemas.is_active
|
|
98
98
|
});
|
|
99
|
-
var
|
|
100
|
-
function
|
|
101
|
-
return
|
|
99
|
+
var baseBranchCacheUpdateSchema = baseBranchCacheCreateSchema.partial();
|
|
100
|
+
function getBranchCacheLabel(locale) {
|
|
101
|
+
return branchCacheI18n.label[locale] ?? branchCacheI18n.label["en"] ?? "BranchCache";
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
const fieldI18n =
|
|
103
|
+
function getBranchCacheFieldLabel(field, locale) {
|
|
104
|
+
const fieldI18n = branchCacheI18n.fields[field];
|
|
105
105
|
if (!fieldI18n) return field;
|
|
106
106
|
return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
const fieldI18n =
|
|
108
|
+
function getBranchCacheFieldPlaceholder(field, locale) {
|
|
109
|
+
const fieldI18n = branchCacheI18n.fields[field];
|
|
110
110
|
if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
|
|
111
111
|
const placeholder = fieldI18n.placeholder;
|
|
112
112
|
return placeholder[locale] ?? placeholder["en"] ?? "";
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
// src/schemas/
|
|
116
|
-
var
|
|
117
|
-
var
|
|
118
|
-
var
|
|
115
|
+
// src/schemas/BranchCache.ts
|
|
116
|
+
var branchCacheSchemas = { ...baseBranchCacheSchemas };
|
|
117
|
+
var branchCacheCreateSchema = baseBranchCacheCreateSchema;
|
|
118
|
+
var branchCacheUpdateSchema = baseBranchCacheUpdateSchema;
|
|
119
119
|
|
|
120
|
-
// node_modules/@omnify-base/schemas/
|
|
120
|
+
// node_modules/@omnify-base/schemas/OrganizationCache.ts
|
|
121
121
|
import { z as z2 } from "zod";
|
|
122
|
+
var organizationCacheI18n = {
|
|
123
|
+
/** Model display name */
|
|
124
|
+
label: { "ja": "\u7D44\u7E54\u30AD\u30E3\u30C3\u30B7\u30E5", "en": "Organization Cache" },
|
|
125
|
+
/** Field labels and placeholders */
|
|
126
|
+
fields: {
|
|
127
|
+
console_org_id: {
|
|
128
|
+
label: { "ja": "Console Organization ID", "en": "Console Organization ID" }
|
|
129
|
+
},
|
|
130
|
+
name: {
|
|
131
|
+
label: { "ja": "\u7D44\u7E54\u540D", "en": "Organization Name" }
|
|
132
|
+
},
|
|
133
|
+
code: {
|
|
134
|
+
label: { "ja": "\u7D44\u7E54\u30B3\u30FC\u30C9", "en": "Organization Code" }
|
|
135
|
+
},
|
|
136
|
+
is_active: {
|
|
137
|
+
label: { "ja": "\u6709\u52B9", "en": "Active" }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
var baseOrganizationCacheSchemas = {
|
|
142
|
+
console_org_id: z2.string(),
|
|
143
|
+
name: z2.string().min(1).max(100),
|
|
144
|
+
code: z2.string().min(1).max(20),
|
|
145
|
+
is_active: z2.boolean()
|
|
146
|
+
};
|
|
147
|
+
var baseOrganizationCacheCreateSchema = z2.object({
|
|
148
|
+
console_org_id: baseOrganizationCacheSchemas.console_org_id,
|
|
149
|
+
name: baseOrganizationCacheSchemas.name,
|
|
150
|
+
code: baseOrganizationCacheSchemas.code,
|
|
151
|
+
is_active: baseOrganizationCacheSchemas.is_active
|
|
152
|
+
});
|
|
153
|
+
var baseOrganizationCacheUpdateSchema = baseOrganizationCacheCreateSchema.partial();
|
|
154
|
+
function getOrganizationCacheLabel(locale) {
|
|
155
|
+
return organizationCacheI18n.label[locale] ?? organizationCacheI18n.label["en"] ?? "OrganizationCache";
|
|
156
|
+
}
|
|
157
|
+
function getOrganizationCacheFieldLabel(field, locale) {
|
|
158
|
+
const fieldI18n = organizationCacheI18n.fields[field];
|
|
159
|
+
if (!fieldI18n) return field;
|
|
160
|
+
return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
|
|
161
|
+
}
|
|
162
|
+
function getOrganizationCacheFieldPlaceholder(field, locale) {
|
|
163
|
+
const fieldI18n = organizationCacheI18n.fields[field];
|
|
164
|
+
if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
|
|
165
|
+
const placeholder = fieldI18n.placeholder;
|
|
166
|
+
return placeholder[locale] ?? placeholder["en"] ?? "";
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/schemas/OrganizationCache.ts
|
|
170
|
+
var organizationCacheSchemas = { ...baseOrganizationCacheSchemas };
|
|
171
|
+
var organizationCacheCreateSchema = baseOrganizationCacheCreateSchema;
|
|
172
|
+
var organizationCacheUpdateSchema = baseOrganizationCacheUpdateSchema;
|
|
173
|
+
|
|
174
|
+
// node_modules/@omnify-base/schemas/Permission.ts
|
|
175
|
+
import { z as z3 } from "zod";
|
|
122
176
|
var permissionI18n = {
|
|
123
177
|
/** Model display name */
|
|
124
|
-
label: { "en": "Permission" },
|
|
178
|
+
label: { "ja": "\u6A29\u9650", "en": "Permission" },
|
|
125
179
|
/** Field labels and placeholders */
|
|
126
180
|
fields: {
|
|
127
181
|
name: {
|
|
128
|
-
label: { "en": "Permission Name" }
|
|
182
|
+
label: { "ja": "\u6A29\u9650\u540D", "en": "Permission Name" }
|
|
129
183
|
},
|
|
130
184
|
slug: {
|
|
131
|
-
label: { "en": "Slug" }
|
|
185
|
+
label: { "ja": "\u30B9\u30E9\u30C3\u30B0", "en": "Slug" }
|
|
132
186
|
},
|
|
133
187
|
group: {
|
|
134
|
-
label: { "en": "Group" }
|
|
188
|
+
label: { "ja": "\u30B0\u30EB\u30FC\u30D7", "en": "Group" }
|
|
135
189
|
},
|
|
136
190
|
roles: {
|
|
137
|
-
label: { "en": "Roles" }
|
|
191
|
+
label: { "ja": "\u30ED\u30FC\u30EB", "en": "Roles" }
|
|
138
192
|
}
|
|
139
193
|
}
|
|
140
194
|
};
|
|
141
195
|
var basePermissionSchemas = {
|
|
142
|
-
name:
|
|
143
|
-
slug:
|
|
144
|
-
group:
|
|
196
|
+
name: z3.string().min(1).max(100),
|
|
197
|
+
slug: z3.string().min(1).max(100),
|
|
198
|
+
group: z3.string().max(50).optional().nullable()
|
|
145
199
|
};
|
|
146
|
-
var basePermissionCreateSchema =
|
|
200
|
+
var basePermissionCreateSchema = z3.object({
|
|
147
201
|
name: basePermissionSchemas.name,
|
|
148
202
|
slug: basePermissionSchemas.slug,
|
|
149
203
|
group: basePermissionSchemas.group
|
|
@@ -170,36 +224,41 @@ var permissionCreateSchema = basePermissionCreateSchema;
|
|
|
170
224
|
var permissionUpdateSchema = basePermissionUpdateSchema;
|
|
171
225
|
|
|
172
226
|
// node_modules/@omnify-base/schemas/Role.ts
|
|
173
|
-
import { z as
|
|
227
|
+
import { z as z4 } from "zod";
|
|
174
228
|
var roleI18n = {
|
|
175
229
|
/** Model display name */
|
|
176
|
-
label: { "en": "Role" },
|
|
230
|
+
label: { "ja": "\u30ED\u30FC\u30EB", "en": "Role" },
|
|
177
231
|
/** Field labels and placeholders */
|
|
178
232
|
fields: {
|
|
233
|
+
console_org_id: {
|
|
234
|
+
label: { "ja": "\u7D44\u7E54ID", "en": "Organization ID" }
|
|
235
|
+
},
|
|
179
236
|
name: {
|
|
180
|
-
label: { "en": "Role Name" }
|
|
237
|
+
label: { "ja": "\u30ED\u30FC\u30EB\u540D", "en": "Role Name" }
|
|
181
238
|
},
|
|
182
239
|
slug: {
|
|
183
|
-
label: { "en": "Slug" }
|
|
240
|
+
label: { "ja": "\u30B9\u30E9\u30C3\u30B0", "en": "Slug" }
|
|
184
241
|
},
|
|
185
242
|
description: {
|
|
186
|
-
label: { "en": "Description" }
|
|
243
|
+
label: { "ja": "\u8AAC\u660E", "en": "Description" }
|
|
187
244
|
},
|
|
188
245
|
level: {
|
|
189
|
-
label: { "en": "Level" }
|
|
246
|
+
label: { "ja": "\u30EC\u30D9\u30EB", "en": "Level" }
|
|
190
247
|
},
|
|
191
248
|
permissions: {
|
|
192
|
-
label: { "en": "Permissions" }
|
|
249
|
+
label: { "ja": "\u6A29\u9650", "en": "Permissions" }
|
|
193
250
|
}
|
|
194
251
|
}
|
|
195
252
|
};
|
|
196
253
|
var baseRoleSchemas = {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
254
|
+
console_org_id: z4.string().max(36).optional().nullable(),
|
|
255
|
+
name: z4.string().min(1).max(100),
|
|
256
|
+
slug: z4.string().min(1).max(100),
|
|
257
|
+
description: z4.string().optional().nullable(),
|
|
258
|
+
level: z4.number().int()
|
|
201
259
|
};
|
|
202
|
-
var baseRoleCreateSchema =
|
|
260
|
+
var baseRoleCreateSchema = z4.object({
|
|
261
|
+
console_org_id: baseRoleSchemas.console_org_id,
|
|
203
262
|
name: baseRoleSchemas.name,
|
|
204
263
|
slug: baseRoleSchemas.slug,
|
|
205
264
|
description: baseRoleSchemas.description,
|
|
@@ -227,22 +286,22 @@ var roleCreateSchema = baseRoleCreateSchema;
|
|
|
227
286
|
var roleUpdateSchema = baseRoleUpdateSchema;
|
|
228
287
|
|
|
229
288
|
// node_modules/@omnify-base/schemas/RolePermission.ts
|
|
230
|
-
import { z as
|
|
289
|
+
import { z as z5 } from "zod";
|
|
231
290
|
var rolePermissionI18n = {
|
|
232
291
|
/** Model display name */
|
|
233
|
-
label: { "en": "Role Permission" },
|
|
292
|
+
label: { "ja": "\u30ED\u30FC\u30EB\u6A29\u9650", "en": "Role Permission" },
|
|
234
293
|
/** Field labels and placeholders */
|
|
235
294
|
fields: {
|
|
236
295
|
role: {
|
|
237
|
-
label: { "en": "Role" }
|
|
296
|
+
label: { "ja": "\u30ED\u30FC\u30EB", "en": "Role" }
|
|
238
297
|
},
|
|
239
298
|
permission: {
|
|
240
|
-
label: { "en": "Permission" }
|
|
299
|
+
label: { "ja": "\u6A29\u9650", "en": "Permission" }
|
|
241
300
|
}
|
|
242
301
|
}
|
|
243
302
|
};
|
|
244
303
|
var baseRolePermissionSchemas = {};
|
|
245
|
-
var baseRolePermissionCreateSchema =
|
|
304
|
+
var baseRolePermissionCreateSchema = z5.object({});
|
|
246
305
|
var baseRolePermissionUpdateSchema = baseRolePermissionCreateSchema.partial();
|
|
247
306
|
function getRolePermissionLabel(locale) {
|
|
248
307
|
return rolePermissionI18n.label[locale] ?? rolePermissionI18n.label["en"] ?? "RolePermission";
|
|
@@ -264,78 +323,78 @@ var rolePermissionSchemas = { ...baseRolePermissionSchemas };
|
|
|
264
323
|
var rolePermissionCreateSchema = baseRolePermissionCreateSchema;
|
|
265
324
|
var rolePermissionUpdateSchema = baseRolePermissionUpdateSchema;
|
|
266
325
|
|
|
267
|
-
// node_modules/@omnify-base/schemas/
|
|
268
|
-
import { z as
|
|
269
|
-
var
|
|
326
|
+
// node_modules/@omnify-base/schemas/TeamCache.ts
|
|
327
|
+
import { z as z6 } from "zod";
|
|
328
|
+
var teamCacheI18n = {
|
|
270
329
|
/** Model display name */
|
|
271
|
-
label: { "en": "Team" },
|
|
330
|
+
label: { "ja": "\u30C1\u30FC\u30E0\u30AD\u30E3\u30C3\u30B7\u30E5", "en": "Team Cache" },
|
|
272
331
|
/** Field labels and placeholders */
|
|
273
332
|
fields: {
|
|
274
333
|
console_team_id: {
|
|
275
|
-
label: { "en": "Console Team ID" }
|
|
334
|
+
label: { "ja": "Console Team ID", "en": "Console Team ID" }
|
|
276
335
|
},
|
|
277
336
|
console_org_id: {
|
|
278
|
-
label: { "en": "Console Organization ID" }
|
|
337
|
+
label: { "ja": "Console Organization ID", "en": "Console Organization ID" }
|
|
279
338
|
},
|
|
280
339
|
name: {
|
|
281
|
-
label: { "en": "Team Name" }
|
|
340
|
+
label: { "ja": "\u30C1\u30FC\u30E0\u540D", "en": "Team Name" }
|
|
282
341
|
}
|
|
283
342
|
}
|
|
284
343
|
};
|
|
285
|
-
var
|
|
286
|
-
console_team_id:
|
|
287
|
-
console_org_id:
|
|
288
|
-
name:
|
|
344
|
+
var baseTeamCacheSchemas = {
|
|
345
|
+
console_team_id: z6.string(),
|
|
346
|
+
console_org_id: z6.string(),
|
|
347
|
+
name: z6.string().min(1).max(100)
|
|
289
348
|
};
|
|
290
|
-
var
|
|
291
|
-
console_team_id:
|
|
292
|
-
console_org_id:
|
|
293
|
-
name:
|
|
349
|
+
var baseTeamCacheCreateSchema = z6.object({
|
|
350
|
+
console_team_id: baseTeamCacheSchemas.console_team_id,
|
|
351
|
+
console_org_id: baseTeamCacheSchemas.console_org_id,
|
|
352
|
+
name: baseTeamCacheSchemas.name
|
|
294
353
|
});
|
|
295
|
-
var
|
|
296
|
-
function
|
|
297
|
-
return
|
|
354
|
+
var baseTeamCacheUpdateSchema = baseTeamCacheCreateSchema.partial();
|
|
355
|
+
function getTeamCacheLabel(locale) {
|
|
356
|
+
return teamCacheI18n.label[locale] ?? teamCacheI18n.label["en"] ?? "TeamCache";
|
|
298
357
|
}
|
|
299
|
-
function
|
|
300
|
-
const fieldI18n =
|
|
358
|
+
function getTeamCacheFieldLabel(field, locale) {
|
|
359
|
+
const fieldI18n = teamCacheI18n.fields[field];
|
|
301
360
|
if (!fieldI18n) return field;
|
|
302
361
|
return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
|
|
303
362
|
}
|
|
304
|
-
function
|
|
305
|
-
const fieldI18n =
|
|
363
|
+
function getTeamCacheFieldPlaceholder(field, locale) {
|
|
364
|
+
const fieldI18n = teamCacheI18n.fields[field];
|
|
306
365
|
if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
|
|
307
366
|
const placeholder = fieldI18n.placeholder;
|
|
308
367
|
return placeholder[locale] ?? placeholder["en"] ?? "";
|
|
309
368
|
}
|
|
310
369
|
|
|
311
|
-
// src/schemas/
|
|
312
|
-
var
|
|
313
|
-
var
|
|
314
|
-
var
|
|
370
|
+
// src/schemas/TeamCache.ts
|
|
371
|
+
var teamCacheSchemas = { ...baseTeamCacheSchemas };
|
|
372
|
+
var teamCacheCreateSchema = baseTeamCacheCreateSchema;
|
|
373
|
+
var teamCacheUpdateSchema = baseTeamCacheUpdateSchema;
|
|
315
374
|
|
|
316
375
|
// node_modules/@omnify-base/schemas/TeamPermission.ts
|
|
317
|
-
import { z as
|
|
376
|
+
import { z as z7 } from "zod";
|
|
318
377
|
var teamPermissionI18n = {
|
|
319
378
|
/** Model display name */
|
|
320
|
-
label: { "en": "Team Permission" },
|
|
379
|
+
label: { "ja": "\u30C1\u30FC\u30E0\u6A29\u9650", "en": "Team Permission" },
|
|
321
380
|
/** Field labels and placeholders */
|
|
322
381
|
fields: {
|
|
323
382
|
console_org_id: {
|
|
324
|
-
label: { "en": "Console Organization ID" }
|
|
383
|
+
label: { "ja": "Console Organization ID", "en": "Console Organization ID" }
|
|
325
384
|
},
|
|
326
385
|
console_team_id: {
|
|
327
|
-
label: { "en": "Console Team ID" }
|
|
386
|
+
label: { "ja": "Console Team ID", "en": "Console Team ID" }
|
|
328
387
|
},
|
|
329
388
|
permission: {
|
|
330
|
-
label: { "en": "Permission" }
|
|
389
|
+
label: { "ja": "\u6A29\u9650", "en": "Permission" }
|
|
331
390
|
}
|
|
332
391
|
}
|
|
333
392
|
};
|
|
334
393
|
var baseTeamPermissionSchemas = {
|
|
335
|
-
console_org_id:
|
|
336
|
-
console_team_id:
|
|
394
|
+
console_org_id: z7.string(),
|
|
395
|
+
console_team_id: z7.string()
|
|
337
396
|
};
|
|
338
|
-
var baseTeamPermissionCreateSchema =
|
|
397
|
+
var baseTeamPermissionCreateSchema = z7.object({
|
|
339
398
|
console_org_id: baseTeamPermissionSchemas.console_org_id,
|
|
340
399
|
console_team_id: baseTeamPermissionSchemas.console_team_id
|
|
341
400
|
});
|
|
@@ -360,72 +419,77 @@ var teamPermissionSchemas = { ...baseTeamPermissionSchemas };
|
|
|
360
419
|
var teamPermissionCreateSchema = baseTeamPermissionCreateSchema;
|
|
361
420
|
var teamPermissionUpdateSchema = baseTeamPermissionUpdateSchema;
|
|
362
421
|
|
|
363
|
-
// node_modules/@omnify-base/schemas/
|
|
364
|
-
import { z as
|
|
365
|
-
var
|
|
422
|
+
// node_modules/@omnify-base/schemas/UserCache.ts
|
|
423
|
+
import { z as z8 } from "zod";
|
|
424
|
+
var userCacheI18n = {
|
|
366
425
|
/** Model display name */
|
|
367
|
-
label: { "en": "User" },
|
|
426
|
+
label: { "ja": "\u30E6\u30FC\u30B6\u30FC\u30AD\u30E3\u30C3\u30B7\u30E5", "en": "User Cache" },
|
|
368
427
|
/** Field labels and placeholders */
|
|
369
428
|
fields: {
|
|
370
429
|
name: {
|
|
371
|
-
label: { "en": "Name" }
|
|
430
|
+
label: { "ja": "\u540D\u524D", "en": "Name" }
|
|
372
431
|
},
|
|
373
432
|
email: {
|
|
374
|
-
label: { "en": "Email" }
|
|
433
|
+
label: { "ja": "\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9", "en": "Email" }
|
|
375
434
|
},
|
|
376
435
|
console_user_id: {
|
|
377
|
-
label: { "en": "Console User ID" }
|
|
436
|
+
label: { "ja": "Console User ID", "en": "Console User ID" }
|
|
437
|
+
},
|
|
438
|
+
console_org_id: {
|
|
439
|
+
label: { "ja": "\u6240\u5C5E\u7D44\u7E54ID", "en": "Organization ID" }
|
|
378
440
|
},
|
|
379
441
|
console_access_token: {
|
|
380
|
-
label: { "en": "Console Access Token" }
|
|
442
|
+
label: { "ja": "Console Access Token", "en": "Console Access Token" }
|
|
381
443
|
},
|
|
382
444
|
console_refresh_token: {
|
|
383
|
-
label: { "en": "Console Refresh Token" }
|
|
445
|
+
label: { "ja": "Console Refresh Token", "en": "Console Refresh Token" }
|
|
384
446
|
},
|
|
385
447
|
console_token_expires_at: {
|
|
386
|
-
label: { "en": "Console Token Expiry" }
|
|
448
|
+
label: { "ja": "Console Token\u6709\u52B9\u671F\u9650", "en": "Console Token Expiry" }
|
|
387
449
|
},
|
|
388
450
|
roles: {
|
|
389
|
-
label: { "en": "Roles" }
|
|
451
|
+
label: { "ja": "\u30ED\u30FC\u30EB", "en": "Roles" }
|
|
390
452
|
}
|
|
391
453
|
}
|
|
392
454
|
};
|
|
393
|
-
var
|
|
394
|
-
name:
|
|
395
|
-
email:
|
|
396
|
-
console_user_id:
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
455
|
+
var baseUserCacheSchemas = {
|
|
456
|
+
name: z8.string().min(1),
|
|
457
|
+
email: z8.string().min(1),
|
|
458
|
+
console_user_id: z8.string().optional().nullable(),
|
|
459
|
+
console_org_id: z8.string().optional().nullable(),
|
|
460
|
+
console_access_token: z8.string().optional().nullable(),
|
|
461
|
+
console_refresh_token: z8.string().optional().nullable(),
|
|
462
|
+
console_token_expires_at: z8.string().datetime({ offset: true }).optional().nullable()
|
|
400
463
|
};
|
|
401
|
-
var
|
|
402
|
-
name:
|
|
403
|
-
email:
|
|
404
|
-
console_user_id:
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
464
|
+
var baseUserCacheCreateSchema = z8.object({
|
|
465
|
+
name: baseUserCacheSchemas.name,
|
|
466
|
+
email: baseUserCacheSchemas.email,
|
|
467
|
+
console_user_id: baseUserCacheSchemas.console_user_id,
|
|
468
|
+
console_org_id: baseUserCacheSchemas.console_org_id,
|
|
469
|
+
console_access_token: baseUserCacheSchemas.console_access_token,
|
|
470
|
+
console_refresh_token: baseUserCacheSchemas.console_refresh_token,
|
|
471
|
+
console_token_expires_at: baseUserCacheSchemas.console_token_expires_at
|
|
408
472
|
});
|
|
409
|
-
var
|
|
410
|
-
function
|
|
411
|
-
return
|
|
473
|
+
var baseUserCacheUpdateSchema = baseUserCacheCreateSchema.partial();
|
|
474
|
+
function getUserCacheLabel(locale) {
|
|
475
|
+
return userCacheI18n.label[locale] ?? userCacheI18n.label["en"] ?? "UserCache";
|
|
412
476
|
}
|
|
413
|
-
function
|
|
414
|
-
const fieldI18n =
|
|
477
|
+
function getUserCacheFieldLabel(field, locale) {
|
|
478
|
+
const fieldI18n = userCacheI18n.fields[field];
|
|
415
479
|
if (!fieldI18n) return field;
|
|
416
480
|
return fieldI18n.label[locale] ?? fieldI18n.label["en"] ?? field;
|
|
417
481
|
}
|
|
418
|
-
function
|
|
419
|
-
const fieldI18n =
|
|
482
|
+
function getUserCacheFieldPlaceholder(field, locale) {
|
|
483
|
+
const fieldI18n = userCacheI18n.fields[field];
|
|
420
484
|
if (!fieldI18n || !("placeholder" in fieldI18n)) return "";
|
|
421
485
|
const placeholder = fieldI18n.placeholder;
|
|
422
486
|
return placeholder[locale] ?? placeholder["en"] ?? "";
|
|
423
487
|
}
|
|
424
488
|
|
|
425
|
-
// src/schemas/
|
|
426
|
-
var
|
|
427
|
-
var
|
|
428
|
-
var
|
|
489
|
+
// src/schemas/UserCache.ts
|
|
490
|
+
var userCacheSchemas = { ...baseUserCacheSchemas };
|
|
491
|
+
var userCacheCreateSchema = baseUserCacheCreateSchema;
|
|
492
|
+
var userCacheUpdateSchema = baseUserCacheUpdateSchema;
|
|
429
493
|
|
|
430
494
|
// src/context/SsoContext.tsx
|
|
431
495
|
import { createContext, useContext } from "react";
|
|
@@ -651,20 +715,360 @@ function SsoProvider({ children, config, onAuthChange }) {
|
|
|
651
715
|
return /* @__PURE__ */ jsx(SsoContext.Provider, { value, children });
|
|
652
716
|
}
|
|
653
717
|
|
|
718
|
+
// src/context/BranchContext.tsx
|
|
719
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
720
|
+
var BranchContext = createContext2(null);
|
|
721
|
+
function useBranchContext() {
|
|
722
|
+
const context = useContext2(BranchContext);
|
|
723
|
+
if (!context) {
|
|
724
|
+
throw new Error("useBranchContext must be used within a BranchProvider");
|
|
725
|
+
}
|
|
726
|
+
return context;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// src/context/BranchProvider.tsx
|
|
730
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
731
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
|
732
|
+
|
|
733
|
+
// src/queryKeys.ts
|
|
734
|
+
var ssoQueryKeys = {
|
|
735
|
+
all: ["sso"],
|
|
736
|
+
// =========================================================================
|
|
737
|
+
// Auth (authService)
|
|
738
|
+
// =========================================================================
|
|
739
|
+
auth: {
|
|
740
|
+
all: () => [...ssoQueryKeys.all, "auth"],
|
|
741
|
+
user: () => [...ssoQueryKeys.auth.all(), "user"],
|
|
742
|
+
globalLogoutUrl: (redirectUri) => [...ssoQueryKeys.auth.all(), "global-logout-url", redirectUri]
|
|
743
|
+
},
|
|
744
|
+
// =========================================================================
|
|
745
|
+
// Tokens (tokenService)
|
|
746
|
+
// =========================================================================
|
|
747
|
+
tokens: {
|
|
748
|
+
all: () => [...ssoQueryKeys.all, "tokens"],
|
|
749
|
+
list: () => [...ssoQueryKeys.tokens.all(), "list"]
|
|
750
|
+
},
|
|
751
|
+
// =========================================================================
|
|
752
|
+
// Roles (roleService)
|
|
753
|
+
// =========================================================================
|
|
754
|
+
roles: {
|
|
755
|
+
all: () => [...ssoQueryKeys.all, "roles"],
|
|
756
|
+
list: () => [...ssoQueryKeys.roles.all(), "list"],
|
|
757
|
+
detail: (id) => [...ssoQueryKeys.roles.all(), "detail", id],
|
|
758
|
+
permissions: (id) => [...ssoQueryKeys.roles.all(), id, "permissions"]
|
|
759
|
+
},
|
|
760
|
+
// =========================================================================
|
|
761
|
+
// Permissions (permissionService)
|
|
762
|
+
// =========================================================================
|
|
763
|
+
permissions: {
|
|
764
|
+
all: () => [...ssoQueryKeys.all, "permissions"],
|
|
765
|
+
list: (params) => [...ssoQueryKeys.permissions.all(), "list", params],
|
|
766
|
+
detail: (id) => [...ssoQueryKeys.permissions.all(), "detail", id],
|
|
767
|
+
matrix: () => [...ssoQueryKeys.permissions.all(), "matrix"]
|
|
768
|
+
},
|
|
769
|
+
// =========================================================================
|
|
770
|
+
// Teams (teamService)
|
|
771
|
+
// =========================================================================
|
|
772
|
+
teams: {
|
|
773
|
+
all: () => [...ssoQueryKeys.all, "teams"],
|
|
774
|
+
list: () => [...ssoQueryKeys.teams.all(), "list"],
|
|
775
|
+
permissions: (teamId) => [...ssoQueryKeys.teams.all(), teamId, "permissions"],
|
|
776
|
+
orphaned: () => [...ssoQueryKeys.teams.all(), "orphaned"]
|
|
777
|
+
},
|
|
778
|
+
// =========================================================================
|
|
779
|
+
// User Roles (userRoleService) - Scoped Role Assignments
|
|
780
|
+
// =========================================================================
|
|
781
|
+
userRoles: {
|
|
782
|
+
all: () => [...ssoQueryKeys.all, "user-roles"],
|
|
783
|
+
list: (userId) => [...ssoQueryKeys.userRoles.all(), userId],
|
|
784
|
+
byBranch: (userId, orgId, branchId) => [...ssoQueryKeys.userRoles.all(), userId, orgId, branchId]
|
|
785
|
+
},
|
|
786
|
+
// =========================================================================
|
|
787
|
+
// Users (userService)
|
|
788
|
+
// =========================================================================
|
|
789
|
+
users: {
|
|
790
|
+
all: () => [...ssoQueryKeys.all, "users"],
|
|
791
|
+
list: (params) => [...ssoQueryKeys.users.all(), "list", params],
|
|
792
|
+
detail: (id) => [...ssoQueryKeys.users.all(), "detail", id]
|
|
793
|
+
},
|
|
794
|
+
// =========================================================================
|
|
795
|
+
// Branches (branchService)
|
|
796
|
+
// =========================================================================
|
|
797
|
+
branches: {
|
|
798
|
+
all: () => [...ssoQueryKeys.all, "branches"],
|
|
799
|
+
list: (orgSlug) => [...ssoQueryKeys.branches.all(), "list", orgSlug],
|
|
800
|
+
detail: (branchId) => [...ssoQueryKeys.branches.all(), "detail", branchId],
|
|
801
|
+
headquarters: (orgSlug) => [...ssoQueryKeys.branches.all(), "headquarters", orgSlug],
|
|
802
|
+
primary: (orgSlug) => [...ssoQueryKeys.branches.all(), "primary", orgSlug]
|
|
803
|
+
},
|
|
804
|
+
// =========================================================================
|
|
805
|
+
// Admin variants (with org context)
|
|
806
|
+
// =========================================================================
|
|
807
|
+
admin: {
|
|
808
|
+
users: {
|
|
809
|
+
all: (orgSlug) => [...ssoQueryKeys.all, "admin", orgSlug, "users"],
|
|
810
|
+
list: (orgSlug, params) => [...ssoQueryKeys.admin.users.all(orgSlug), "list", params],
|
|
811
|
+
detail: (orgSlug, id) => [...ssoQueryKeys.admin.users.all(orgSlug), "detail", id]
|
|
812
|
+
},
|
|
813
|
+
roles: {
|
|
814
|
+
all: (orgSlug) => [...ssoQueryKeys.all, "admin", orgSlug, "roles"],
|
|
815
|
+
list: (orgSlug) => [...ssoQueryKeys.admin.roles.all(orgSlug), "list"],
|
|
816
|
+
detail: (orgSlug, id) => [...ssoQueryKeys.admin.roles.all(orgSlug), "detail", id],
|
|
817
|
+
permissions: (orgSlug, id) => [...ssoQueryKeys.admin.roles.all(orgSlug), id, "permissions"]
|
|
818
|
+
},
|
|
819
|
+
permissions: {
|
|
820
|
+
all: (orgSlug) => [...ssoQueryKeys.all, "admin", orgSlug, "permissions"],
|
|
821
|
+
list: (orgSlug, params) => [...ssoQueryKeys.admin.permissions.all(orgSlug), "list", params],
|
|
822
|
+
detail: (orgSlug, id) => [...ssoQueryKeys.admin.permissions.all(orgSlug), "detail", id],
|
|
823
|
+
matrix: (orgSlug) => [...ssoQueryKeys.admin.permissions.all(orgSlug), "matrix"]
|
|
824
|
+
},
|
|
825
|
+
teams: {
|
|
826
|
+
all: (orgSlug) => [...ssoQueryKeys.all, "admin", orgSlug, "teams"],
|
|
827
|
+
list: (orgSlug) => [...ssoQueryKeys.admin.teams.all(orgSlug), "list"],
|
|
828
|
+
permissions: (orgSlug, teamId) => [...ssoQueryKeys.admin.teams.all(orgSlug), teamId, "permissions"],
|
|
829
|
+
orphaned: (orgSlug) => [...ssoQueryKeys.admin.teams.all(orgSlug), "orphaned"]
|
|
830
|
+
},
|
|
831
|
+
userRoles: {
|
|
832
|
+
all: (orgSlug) => [...ssoQueryKeys.all, "admin", orgSlug, "user-roles"],
|
|
833
|
+
list: (orgSlug, userId) => [...ssoQueryKeys.admin.userRoles.all(orgSlug), userId],
|
|
834
|
+
byBranch: (orgSlug, userId, orgId, branchId) => [...ssoQueryKeys.admin.userRoles.all(orgSlug), userId, orgId, branchId]
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
// src/services/utils.ts
|
|
840
|
+
function getXsrfToken2() {
|
|
841
|
+
if (typeof document === "undefined") return void 0;
|
|
842
|
+
return document.cookie.split("; ").find((row) => row.startsWith("XSRF-TOKEN="))?.split("=")[1];
|
|
843
|
+
}
|
|
844
|
+
function buildHeaders(orgSlug) {
|
|
845
|
+
const headers = {
|
|
846
|
+
"Content-Type": "application/json",
|
|
847
|
+
Accept: "application/json"
|
|
848
|
+
};
|
|
849
|
+
const xsrfToken = getXsrfToken2();
|
|
850
|
+
if (xsrfToken) {
|
|
851
|
+
headers["X-XSRF-TOKEN"] = decodeURIComponent(xsrfToken);
|
|
852
|
+
}
|
|
853
|
+
if (orgSlug) {
|
|
854
|
+
headers["X-Org-Id"] = orgSlug;
|
|
855
|
+
}
|
|
856
|
+
return headers;
|
|
857
|
+
}
|
|
858
|
+
async function csrf(apiUrl) {
|
|
859
|
+
await fetch(`${apiUrl}/sanctum/csrf-cookie`, {
|
|
860
|
+
credentials: "include"
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
async function request(apiUrl, path, options = {}) {
|
|
864
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
865
|
+
...options,
|
|
866
|
+
credentials: "include"
|
|
867
|
+
});
|
|
868
|
+
if (!response.ok) {
|
|
869
|
+
const error = await response.json().catch(() => ({}));
|
|
870
|
+
throw new Error(error.message || `HTTP ${response.status}`);
|
|
871
|
+
}
|
|
872
|
+
if (response.status === 204) {
|
|
873
|
+
return void 0;
|
|
874
|
+
}
|
|
875
|
+
return response.json();
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// src/services/branchService.ts
|
|
879
|
+
function createBranchService(config) {
|
|
880
|
+
const { apiUrl } = config;
|
|
881
|
+
return {
|
|
882
|
+
/**
|
|
883
|
+
* Get branches for current user in organization
|
|
884
|
+
* GET /api/sso/branches
|
|
885
|
+
*/
|
|
886
|
+
list: async (orgSlug) => {
|
|
887
|
+
const params = orgSlug ? `?organization_slug=${orgSlug}` : "";
|
|
888
|
+
return request(apiUrl, `/api/sso/branches${params}`, {
|
|
889
|
+
headers: buildHeaders()
|
|
890
|
+
});
|
|
891
|
+
},
|
|
892
|
+
/**
|
|
893
|
+
* Get a specific branch by ID
|
|
894
|
+
* GET /api/sso/branches/{id}
|
|
895
|
+
*/
|
|
896
|
+
get: async (branchId) => {
|
|
897
|
+
const response = await request(
|
|
898
|
+
apiUrl,
|
|
899
|
+
`/api/sso/branches/${branchId}`,
|
|
900
|
+
{ headers: buildHeaders() }
|
|
901
|
+
);
|
|
902
|
+
return "data" in response ? response.data : response;
|
|
903
|
+
},
|
|
904
|
+
/**
|
|
905
|
+
* Get headquarters branch for organization
|
|
906
|
+
*/
|
|
907
|
+
getHeadquarters: async (orgSlug) => {
|
|
908
|
+
try {
|
|
909
|
+
const params = orgSlug ? `?organization_slug=${orgSlug}` : "";
|
|
910
|
+
const data = await request(
|
|
911
|
+
apiUrl,
|
|
912
|
+
`/api/sso/branches${params}`,
|
|
913
|
+
{ headers: buildHeaders() }
|
|
914
|
+
);
|
|
915
|
+
return data.branches.find((b) => b.is_headquarters) ?? null;
|
|
916
|
+
} catch {
|
|
917
|
+
return null;
|
|
918
|
+
}
|
|
919
|
+
},
|
|
920
|
+
/**
|
|
921
|
+
* Get primary branch for current user
|
|
922
|
+
*/
|
|
923
|
+
getPrimary: async (orgSlug) => {
|
|
924
|
+
try {
|
|
925
|
+
const params = orgSlug ? `?organization_slug=${orgSlug}` : "";
|
|
926
|
+
const data = await request(
|
|
927
|
+
apiUrl,
|
|
928
|
+
`/api/sso/branches${params}`,
|
|
929
|
+
{ headers: buildHeaders() }
|
|
930
|
+
);
|
|
931
|
+
if (data.primary_branch_id) {
|
|
932
|
+
return data.branches.find((b) => b.id === data.primary_branch_id) ?? null;
|
|
933
|
+
}
|
|
934
|
+
return null;
|
|
935
|
+
} catch {
|
|
936
|
+
return null;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/context/BranchProvider.tsx
|
|
943
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
944
|
+
var DEFAULT_STORAGE_KEY = "omnify_selected_branch";
|
|
945
|
+
function BranchProvider({
|
|
946
|
+
children,
|
|
947
|
+
storage = "localStorage",
|
|
948
|
+
storageKey = DEFAULT_STORAGE_KEY,
|
|
949
|
+
onBranchChange
|
|
950
|
+
}) {
|
|
951
|
+
const { config, currentOrg, isAuthenticated } = useSsoContext();
|
|
952
|
+
const queryClient = useQueryClient();
|
|
953
|
+
const branchService = useMemo2(
|
|
954
|
+
() => createBranchService({ apiUrl: config.apiUrl }),
|
|
955
|
+
[config.apiUrl]
|
|
956
|
+
);
|
|
957
|
+
const getSavedBranchId = useCallback2(() => {
|
|
958
|
+
if (typeof window === "undefined") return null;
|
|
959
|
+
const storageObj = storage === "localStorage" ? localStorage : sessionStorage;
|
|
960
|
+
const saved = storageObj.getItem(`${storageKey}_${currentOrg?.slug}`);
|
|
961
|
+
return saved ? parseInt(saved, 10) : null;
|
|
962
|
+
}, [storage, storageKey, currentOrg?.slug]);
|
|
963
|
+
const saveBranchId = useCallback2((branchId) => {
|
|
964
|
+
if (typeof window === "undefined" || !currentOrg?.slug) return;
|
|
965
|
+
const storageObj = storage === "localStorage" ? localStorage : sessionStorage;
|
|
966
|
+
if (branchId) {
|
|
967
|
+
storageObj.setItem(`${storageKey}_${currentOrg.slug}`, String(branchId));
|
|
968
|
+
} else {
|
|
969
|
+
storageObj.removeItem(`${storageKey}_${currentOrg.slug}`);
|
|
970
|
+
}
|
|
971
|
+
}, [storage, storageKey, currentOrg?.slug]);
|
|
972
|
+
const [selectedBranchId, setSelectedBranchId] = useState2(() => getSavedBranchId());
|
|
973
|
+
const {
|
|
974
|
+
data: branchesData,
|
|
975
|
+
isLoading,
|
|
976
|
+
error,
|
|
977
|
+
refetch
|
|
978
|
+
} = useQuery({
|
|
979
|
+
queryKey: ssoQueryKeys.branches.list(currentOrg?.slug),
|
|
980
|
+
queryFn: () => branchService.list(currentOrg?.slug),
|
|
981
|
+
enabled: isAuthenticated && !!currentOrg,
|
|
982
|
+
staleTime: 5 * 60 * 1e3
|
|
983
|
+
// 5 minutes
|
|
984
|
+
});
|
|
985
|
+
const branches = branchesData?.branches ?? [];
|
|
986
|
+
const allBranchesAccess = branchesData?.all_branches_access ?? false;
|
|
987
|
+
const primaryBranchId = branchesData?.primary_branch_id ?? null;
|
|
988
|
+
const hasMultipleBranches = branches.length > 1;
|
|
989
|
+
const currentBranch = useMemo2(() => {
|
|
990
|
+
if (!branches.length) return null;
|
|
991
|
+
if (branches.length === 1) {
|
|
992
|
+
return branches[0];
|
|
993
|
+
}
|
|
994
|
+
if (selectedBranchId) {
|
|
995
|
+
const found = branches.find((b) => b.id === selectedBranchId);
|
|
996
|
+
if (found) return found;
|
|
997
|
+
}
|
|
998
|
+
if (primaryBranchId) {
|
|
999
|
+
const primary = branches.find((b) => b.id === primaryBranchId);
|
|
1000
|
+
if (primary) return primary;
|
|
1001
|
+
}
|
|
1002
|
+
const hq = branches.find((b) => b.is_headquarters);
|
|
1003
|
+
if (hq) return hq;
|
|
1004
|
+
return branches[0];
|
|
1005
|
+
}, [branches, selectedBranchId, primaryBranchId]);
|
|
1006
|
+
useEffect2(() => {
|
|
1007
|
+
if (currentBranch && currentBranch.id !== selectedBranchId) {
|
|
1008
|
+
setSelectedBranchId(currentBranch.id);
|
|
1009
|
+
saveBranchId(currentBranch.id);
|
|
1010
|
+
onBranchChange?.(currentBranch);
|
|
1011
|
+
}
|
|
1012
|
+
}, [currentBranch, selectedBranchId, saveBranchId, onBranchChange]);
|
|
1013
|
+
useEffect2(() => {
|
|
1014
|
+
const savedId = getSavedBranchId();
|
|
1015
|
+
setSelectedBranchId(savedId);
|
|
1016
|
+
}, [currentOrg?.slug, getSavedBranchId]);
|
|
1017
|
+
const switchBranch = useCallback2((branchId) => {
|
|
1018
|
+
const branch = branches.find((b) => b.id === branchId);
|
|
1019
|
+
if (branch) {
|
|
1020
|
+
setSelectedBranchId(branchId);
|
|
1021
|
+
saveBranchId(branchId);
|
|
1022
|
+
onBranchChange?.(branch);
|
|
1023
|
+
}
|
|
1024
|
+
}, [branches, saveBranchId, onBranchChange]);
|
|
1025
|
+
const refreshBranches = useCallback2(async () => {
|
|
1026
|
+
await queryClient.invalidateQueries({
|
|
1027
|
+
queryKey: ssoQueryKeys.branches.list(currentOrg?.slug)
|
|
1028
|
+
});
|
|
1029
|
+
await refetch();
|
|
1030
|
+
}, [queryClient, currentOrg?.slug, refetch]);
|
|
1031
|
+
const contextValue = useMemo2(
|
|
1032
|
+
() => ({
|
|
1033
|
+
branches,
|
|
1034
|
+
currentBranch,
|
|
1035
|
+
allBranchesAccess,
|
|
1036
|
+
primaryBranchId,
|
|
1037
|
+
isLoading,
|
|
1038
|
+
error,
|
|
1039
|
+
hasMultipleBranches,
|
|
1040
|
+
switchBranch,
|
|
1041
|
+
refreshBranches
|
|
1042
|
+
}),
|
|
1043
|
+
[
|
|
1044
|
+
branches,
|
|
1045
|
+
currentBranch,
|
|
1046
|
+
allBranchesAccess,
|
|
1047
|
+
primaryBranchId,
|
|
1048
|
+
isLoading,
|
|
1049
|
+
error,
|
|
1050
|
+
hasMultipleBranches,
|
|
1051
|
+
switchBranch,
|
|
1052
|
+
refreshBranches
|
|
1053
|
+
]
|
|
1054
|
+
);
|
|
1055
|
+
return /* @__PURE__ */ jsx2(BranchContext.Provider, { value: contextValue, children });
|
|
1056
|
+
}
|
|
1057
|
+
|
|
654
1058
|
// src/hooks/useAuth.ts
|
|
655
|
-
import { useCallback as
|
|
1059
|
+
import { useCallback as useCallback3 } from "react";
|
|
656
1060
|
function useAuth() {
|
|
657
1061
|
const { user, isLoading, isAuthenticated, login, logout, globalLogout, refreshUser } = useSsoContext();
|
|
658
|
-
const handleLogin =
|
|
1062
|
+
const handleLogin = useCallback3(
|
|
659
1063
|
(redirectTo) => {
|
|
660
1064
|
login(redirectTo);
|
|
661
1065
|
},
|
|
662
1066
|
[login]
|
|
663
1067
|
);
|
|
664
|
-
const handleLogout =
|
|
1068
|
+
const handleLogout = useCallback3(async () => {
|
|
665
1069
|
await logout();
|
|
666
1070
|
}, [logout]);
|
|
667
|
-
const handleGlobalLogout =
|
|
1071
|
+
const handleGlobalLogout = useCallback3(
|
|
668
1072
|
(redirectTo) => {
|
|
669
1073
|
globalLogout(redirectTo);
|
|
670
1074
|
},
|
|
@@ -682,7 +1086,7 @@ function useAuth() {
|
|
|
682
1086
|
}
|
|
683
1087
|
|
|
684
1088
|
// src/hooks/useOrganization.ts
|
|
685
|
-
import { useCallback as
|
|
1089
|
+
import { useCallback as useCallback4, useMemo as useMemo3 } from "react";
|
|
686
1090
|
var ROLE_LEVELS = {
|
|
687
1091
|
admin: 100,
|
|
688
1092
|
manager: 50,
|
|
@@ -692,7 +1096,7 @@ function useOrganization() {
|
|
|
692
1096
|
const { organizations, currentOrg, switchOrg } = useSsoContext();
|
|
693
1097
|
const hasMultipleOrgs = organizations.length > 1;
|
|
694
1098
|
const currentRole = currentOrg?.serviceRole ?? null;
|
|
695
|
-
const hasRole =
|
|
1099
|
+
const hasRole = useCallback4(
|
|
696
1100
|
(role) => {
|
|
697
1101
|
if (!currentRole) return false;
|
|
698
1102
|
const requiredLevel = ROLE_LEVELS[role] ?? 0;
|
|
@@ -701,13 +1105,13 @@ function useOrganization() {
|
|
|
701
1105
|
},
|
|
702
1106
|
[currentRole]
|
|
703
1107
|
);
|
|
704
|
-
const handleSwitchOrg =
|
|
1108
|
+
const handleSwitchOrg = useCallback4(
|
|
705
1109
|
(orgSlug) => {
|
|
706
1110
|
switchOrg(orgSlug);
|
|
707
1111
|
},
|
|
708
1112
|
[switchOrg]
|
|
709
1113
|
);
|
|
710
|
-
return
|
|
1114
|
+
return useMemo3(
|
|
711
1115
|
() => ({
|
|
712
1116
|
organizations,
|
|
713
1117
|
currentOrg,
|
|
@@ -721,10 +1125,10 @@ function useOrganization() {
|
|
|
721
1125
|
}
|
|
722
1126
|
|
|
723
1127
|
// src/hooks/useSso.ts
|
|
724
|
-
import { useMemo as
|
|
1128
|
+
import { useMemo as useMemo4 } from "react";
|
|
725
1129
|
function useSso() {
|
|
726
1130
|
const context = useSsoContext();
|
|
727
|
-
return
|
|
1131
|
+
return useMemo4(
|
|
728
1132
|
() => ({
|
|
729
1133
|
// Auth
|
|
730
1134
|
user: context.user,
|
|
@@ -747,9 +1151,14 @@ function useSso() {
|
|
|
747
1151
|
);
|
|
748
1152
|
}
|
|
749
1153
|
|
|
1154
|
+
// src/hooks/useBranch.ts
|
|
1155
|
+
function useBranch() {
|
|
1156
|
+
return useBranchContext();
|
|
1157
|
+
}
|
|
1158
|
+
|
|
750
1159
|
// src/components/SsoCallback.tsx
|
|
751
|
-
import { useEffect as
|
|
752
|
-
import { Fragment, jsx as
|
|
1160
|
+
import { useEffect as useEffect3, useRef, useState as useState3 } from "react";
|
|
1161
|
+
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
753
1162
|
function transformUser2(data) {
|
|
754
1163
|
return {
|
|
755
1164
|
id: data.id,
|
|
@@ -768,12 +1177,12 @@ function transformOrganizations2(data) {
|
|
|
768
1177
|
}));
|
|
769
1178
|
}
|
|
770
1179
|
function DefaultLoading() {
|
|
771
|
-
return /* @__PURE__ */
|
|
1180
|
+
return /* @__PURE__ */ jsx3("div", { style: {
|
|
772
1181
|
display: "flex",
|
|
773
1182
|
justifyContent: "center",
|
|
774
1183
|
alignItems: "center",
|
|
775
1184
|
minHeight: "200px"
|
|
776
|
-
}, children: /* @__PURE__ */
|
|
1185
|
+
}, children: /* @__PURE__ */ jsx3("div", { children: "Authenticating..." }) });
|
|
777
1186
|
}
|
|
778
1187
|
function DefaultError({ error }) {
|
|
779
1188
|
return /* @__PURE__ */ jsxs("div", { style: {
|
|
@@ -784,8 +1193,8 @@ function DefaultError({ error }) {
|
|
|
784
1193
|
minHeight: "200px",
|
|
785
1194
|
color: "red"
|
|
786
1195
|
}, children: [
|
|
787
|
-
/* @__PURE__ */
|
|
788
|
-
/* @__PURE__ */
|
|
1196
|
+
/* @__PURE__ */ jsx3("div", { children: "Authentication Error" }),
|
|
1197
|
+
/* @__PURE__ */ jsx3("div", { style: { fontSize: "0.875rem", marginTop: "0.5rem" }, children: error.message })
|
|
789
1198
|
] });
|
|
790
1199
|
}
|
|
791
1200
|
function SsoCallback({
|
|
@@ -796,10 +1205,10 @@ function SsoCallback({
|
|
|
796
1205
|
errorComponent
|
|
797
1206
|
}) {
|
|
798
1207
|
const { config, refreshUser } = useSsoContext();
|
|
799
|
-
const [error, setError] =
|
|
800
|
-
const [isProcessing, setIsProcessing] =
|
|
1208
|
+
const [error, setError] = useState3(null);
|
|
1209
|
+
const [isProcessing, setIsProcessing] = useState3(true);
|
|
801
1210
|
const isProcessingRef = useRef(false);
|
|
802
|
-
|
|
1211
|
+
useEffect3(() => {
|
|
803
1212
|
if (isProcessingRef.current) {
|
|
804
1213
|
return;
|
|
805
1214
|
}
|
|
@@ -850,24 +1259,24 @@ function SsoCallback({
|
|
|
850
1259
|
}, []);
|
|
851
1260
|
if (error) {
|
|
852
1261
|
if (errorComponent) {
|
|
853
|
-
return /* @__PURE__ */
|
|
1262
|
+
return /* @__PURE__ */ jsx3(Fragment, { children: errorComponent(error) });
|
|
854
1263
|
}
|
|
855
|
-
return /* @__PURE__ */
|
|
1264
|
+
return /* @__PURE__ */ jsx3(DefaultError, { error });
|
|
856
1265
|
}
|
|
857
1266
|
if (isProcessing) {
|
|
858
1267
|
if (loadingComponent) {
|
|
859
|
-
return /* @__PURE__ */
|
|
1268
|
+
return /* @__PURE__ */ jsx3(Fragment, { children: loadingComponent });
|
|
860
1269
|
}
|
|
861
|
-
return /* @__PURE__ */
|
|
1270
|
+
return /* @__PURE__ */ jsx3(DefaultLoading, {});
|
|
862
1271
|
}
|
|
863
1272
|
return null;
|
|
864
1273
|
}
|
|
865
1274
|
|
|
866
1275
|
// src/components/OrganizationSwitcher.tsx
|
|
867
|
-
import React3, { useCallback as useCallback4, useMemo as useMemo4 } from "react";
|
|
868
|
-
import { Dropdown, Button, Space, Typography, Badge } from "antd";
|
|
869
1276
|
import { SwapOutlined, CheckOutlined } from "@ant-design/icons";
|
|
870
|
-
import {
|
|
1277
|
+
import { Dropdown, Button, Space, Typography, Badge } from "antd";
|
|
1278
|
+
import React4, { useCallback as useCallback5, useMemo as useMemo5 } from "react";
|
|
1279
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
871
1280
|
var { Text } = Typography;
|
|
872
1281
|
function OrganizationSwitcher({
|
|
873
1282
|
className,
|
|
@@ -876,8 +1285,8 @@ function OrganizationSwitcher({
|
|
|
876
1285
|
onChange
|
|
877
1286
|
}) {
|
|
878
1287
|
const { organizations, currentOrg, hasMultipleOrgs, switchOrg } = useOrganization();
|
|
879
|
-
const [isOpen, setIsOpen] =
|
|
880
|
-
const handleSelect =
|
|
1288
|
+
const [isOpen, setIsOpen] = React4.useState(false);
|
|
1289
|
+
const handleSelect = useCallback5(
|
|
881
1290
|
(org) => {
|
|
882
1291
|
switchOrg(org.slug);
|
|
883
1292
|
setIsOpen(false);
|
|
@@ -885,23 +1294,23 @@ function OrganizationSwitcher({
|
|
|
885
1294
|
},
|
|
886
1295
|
[switchOrg, onChange]
|
|
887
1296
|
);
|
|
888
|
-
const menuItems =
|
|
1297
|
+
const menuItems = useMemo5(() => {
|
|
889
1298
|
return organizations.map((org) => {
|
|
890
1299
|
const isSelected = currentOrg?.slug === org.slug;
|
|
891
1300
|
if (renderOption) {
|
|
892
1301
|
return {
|
|
893
1302
|
key: org.slug,
|
|
894
|
-
label: /* @__PURE__ */
|
|
1303
|
+
label: /* @__PURE__ */ jsx4("div", { onClick: () => handleSelect(org), children: renderOption(org, isSelected) })
|
|
895
1304
|
};
|
|
896
1305
|
}
|
|
897
1306
|
return {
|
|
898
1307
|
key: org.slug,
|
|
899
1308
|
label: /* @__PURE__ */ jsxs2(Space, { style: { width: "100%", justifyContent: "space-between" }, children: [
|
|
900
1309
|
/* @__PURE__ */ jsxs2(Space, { direction: "vertical", size: 0, children: [
|
|
901
|
-
/* @__PURE__ */
|
|
902
|
-
org.serviceRole && /* @__PURE__ */
|
|
1310
|
+
/* @__PURE__ */ jsx4(Text, { strong: isSelected, children: org.name }),
|
|
1311
|
+
org.serviceRole && /* @__PURE__ */ jsx4(Text, { type: "secondary", style: { fontSize: 12 }, children: org.serviceRole })
|
|
903
1312
|
] }),
|
|
904
|
-
isSelected && /* @__PURE__ */
|
|
1313
|
+
isSelected && /* @__PURE__ */ jsx4(CheckOutlined, { style: { color: "#1890ff" } })
|
|
905
1314
|
] }),
|
|
906
1315
|
onClick: () => handleSelect(org)
|
|
907
1316
|
};
|
|
@@ -911,7 +1320,7 @@ function OrganizationSwitcher({
|
|
|
911
1320
|
return null;
|
|
912
1321
|
}
|
|
913
1322
|
if (renderTrigger) {
|
|
914
|
-
return /* @__PURE__ */
|
|
1323
|
+
return /* @__PURE__ */ jsx4(
|
|
915
1324
|
Dropdown,
|
|
916
1325
|
{
|
|
917
1326
|
menu: { items: menuItems },
|
|
@@ -919,11 +1328,11 @@ function OrganizationSwitcher({
|
|
|
919
1328
|
open: isOpen,
|
|
920
1329
|
onOpenChange: setIsOpen,
|
|
921
1330
|
className,
|
|
922
|
-
children: /* @__PURE__ */
|
|
1331
|
+
children: /* @__PURE__ */ jsx4("div", { style: { cursor: "pointer" }, children: renderTrigger(currentOrg, isOpen) })
|
|
923
1332
|
}
|
|
924
1333
|
);
|
|
925
1334
|
}
|
|
926
|
-
return /* @__PURE__ */
|
|
1335
|
+
return /* @__PURE__ */ jsx4(
|
|
927
1336
|
Dropdown,
|
|
928
1337
|
{
|
|
929
1338
|
menu: { items: menuItems },
|
|
@@ -931,25 +1340,25 @@ function OrganizationSwitcher({
|
|
|
931
1340
|
open: isOpen,
|
|
932
1341
|
onOpenChange: setIsOpen,
|
|
933
1342
|
className,
|
|
934
|
-
children: /* @__PURE__ */
|
|
935
|
-
/* @__PURE__ */
|
|
936
|
-
/* @__PURE__ */
|
|
937
|
-
/* @__PURE__ */
|
|
1343
|
+
children: /* @__PURE__ */ jsx4(Button, { children: /* @__PURE__ */ jsxs2(Space, { children: [
|
|
1344
|
+
/* @__PURE__ */ jsx4(Badge, { status: "success" }),
|
|
1345
|
+
/* @__PURE__ */ jsx4("span", { children: currentOrg?.name ?? "Select Organization" }),
|
|
1346
|
+
/* @__PURE__ */ jsx4(SwapOutlined, {})
|
|
938
1347
|
] }) })
|
|
939
1348
|
}
|
|
940
1349
|
);
|
|
941
1350
|
}
|
|
942
1351
|
|
|
943
1352
|
// src/components/ProtectedRoute.tsx
|
|
944
|
-
import { useEffect as
|
|
945
|
-
import { Fragment as Fragment2, jsx as
|
|
1353
|
+
import { useEffect as useEffect4 } from "react";
|
|
1354
|
+
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
946
1355
|
function DefaultLoading2() {
|
|
947
|
-
return /* @__PURE__ */
|
|
1356
|
+
return /* @__PURE__ */ jsx5("div", { style: {
|
|
948
1357
|
display: "flex",
|
|
949
1358
|
justifyContent: "center",
|
|
950
1359
|
alignItems: "center",
|
|
951
1360
|
minHeight: "200px"
|
|
952
|
-
}, children: /* @__PURE__ */
|
|
1361
|
+
}, children: /* @__PURE__ */ jsx5("div", { children: "Loading..." }) });
|
|
953
1362
|
}
|
|
954
1363
|
function DefaultLoginFallback({ login }) {
|
|
955
1364
|
return /* @__PURE__ */ jsxs3("div", { style: {
|
|
@@ -960,8 +1369,8 @@ function DefaultLoginFallback({ login }) {
|
|
|
960
1369
|
minHeight: "200px",
|
|
961
1370
|
gap: "1rem"
|
|
962
1371
|
}, children: [
|
|
963
|
-
/* @__PURE__ */
|
|
964
|
-
/* @__PURE__ */
|
|
1372
|
+
/* @__PURE__ */ jsx5("div", { children: "Please log in to continue" }),
|
|
1373
|
+
/* @__PURE__ */ jsx5(
|
|
965
1374
|
"button",
|
|
966
1375
|
{
|
|
967
1376
|
onClick: login,
|
|
@@ -987,85 +1396,1104 @@ function DefaultAccessDenied({ reason }) {
|
|
|
987
1396
|
minHeight: "200px",
|
|
988
1397
|
color: "#dc2626"
|
|
989
1398
|
}, children: [
|
|
990
|
-
/* @__PURE__ */
|
|
991
|
-
/* @__PURE__ */
|
|
1399
|
+
/* @__PURE__ */ jsx5("div", { style: { fontSize: "1.5rem", fontWeight: 600 }, children: "Access Denied" }),
|
|
1400
|
+
/* @__PURE__ */ jsx5("div", { style: { marginTop: "0.5rem" }, children: reason })
|
|
992
1401
|
] });
|
|
993
1402
|
}
|
|
994
|
-
function ProtectedRoute({
|
|
995
|
-
children,
|
|
996
|
-
fallback,
|
|
997
|
-
loginFallback,
|
|
998
|
-
requiredRole,
|
|
999
|
-
requiredPermission,
|
|
1000
|
-
onAccessDenied
|
|
1403
|
+
function ProtectedRoute({
|
|
1404
|
+
children,
|
|
1405
|
+
fallback,
|
|
1406
|
+
loginFallback,
|
|
1407
|
+
requiredRole,
|
|
1408
|
+
requiredPermission,
|
|
1409
|
+
onAccessDenied
|
|
1410
|
+
}) {
|
|
1411
|
+
const { user, isLoading, isAuthenticated, login } = useAuth();
|
|
1412
|
+
const { hasRole, currentOrg } = useOrganization();
|
|
1413
|
+
useEffect4(() => {
|
|
1414
|
+
if (isLoading) return;
|
|
1415
|
+
if (!isAuthenticated) {
|
|
1416
|
+
onAccessDenied?.("unauthenticated");
|
|
1417
|
+
} else if (requiredRole && !hasRole(requiredRole)) {
|
|
1418
|
+
onAccessDenied?.("insufficient_role");
|
|
1419
|
+
}
|
|
1420
|
+
}, [isLoading, isAuthenticated, requiredRole, hasRole, onAccessDenied]);
|
|
1421
|
+
if (isLoading) {
|
|
1422
|
+
return /* @__PURE__ */ jsx5(Fragment2, { children: fallback ?? /* @__PURE__ */ jsx5(DefaultLoading2, {}) });
|
|
1423
|
+
}
|
|
1424
|
+
if (!isAuthenticated) {
|
|
1425
|
+
if (loginFallback) {
|
|
1426
|
+
return /* @__PURE__ */ jsx5(Fragment2, { children: loginFallback });
|
|
1427
|
+
}
|
|
1428
|
+
return /* @__PURE__ */ jsx5(DefaultLoginFallback, { login: () => login() });
|
|
1429
|
+
}
|
|
1430
|
+
if (requiredRole && !hasRole(requiredRole)) {
|
|
1431
|
+
return /* @__PURE__ */ jsx5(
|
|
1432
|
+
DefaultAccessDenied,
|
|
1433
|
+
{
|
|
1434
|
+
reason: `This page requires ${requiredRole} role. Your role: ${currentOrg?.serviceRole ?? "none"}`
|
|
1435
|
+
}
|
|
1436
|
+
);
|
|
1437
|
+
}
|
|
1438
|
+
return /* @__PURE__ */ jsx5(Fragment2, { children });
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// src/components/OrgBranchSelectorModal.tsx
|
|
1442
|
+
import { BankOutlined, ApartmentOutlined, CheckCircleFilled } from "@ant-design/icons";
|
|
1443
|
+
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
1444
|
+
import { Modal, Select, Form, Space as Space2, Typography as Typography2, Spin, Alert, Badge as Badge2 } from "antd";
|
|
1445
|
+
import { useCallback as useCallback6, useEffect as useEffect5, useMemo as useMemo6, useState as useState4 } from "react";
|
|
1446
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1447
|
+
var { Text: Text2, Title } = Typography2;
|
|
1448
|
+
function OrgBranchSelectorModal({
|
|
1449
|
+
open,
|
|
1450
|
+
onClose,
|
|
1451
|
+
onConfirm,
|
|
1452
|
+
title = "Select Organization & Branch",
|
|
1453
|
+
requireBranch = true,
|
|
1454
|
+
loadingComponent
|
|
1455
|
+
}) {
|
|
1456
|
+
const { config } = useSsoContext();
|
|
1457
|
+
const { organizations, currentOrg, hasMultipleOrgs } = useOrganization();
|
|
1458
|
+
const { currentBranch } = useBranch();
|
|
1459
|
+
const [form] = Form.useForm();
|
|
1460
|
+
const [selectedOrgSlug, setSelectedOrgSlug] = useState4(
|
|
1461
|
+
currentOrg?.slug ?? null
|
|
1462
|
+
);
|
|
1463
|
+
const branchService = useMemo6(
|
|
1464
|
+
() => createBranchService({ apiUrl: config.apiUrl }),
|
|
1465
|
+
[config.apiUrl]
|
|
1466
|
+
);
|
|
1467
|
+
const {
|
|
1468
|
+
data: branchesData,
|
|
1469
|
+
isLoading: branchesLoading,
|
|
1470
|
+
error: branchesError
|
|
1471
|
+
} = useQuery2({
|
|
1472
|
+
queryKey: ssoQueryKeys.branches.list(selectedOrgSlug ?? void 0),
|
|
1473
|
+
queryFn: () => branchService.list(selectedOrgSlug ?? void 0),
|
|
1474
|
+
enabled: open && !!selectedOrgSlug
|
|
1475
|
+
});
|
|
1476
|
+
const branches = branchesData?.branches ?? [];
|
|
1477
|
+
const hasMultipleBranches = branches.length > 1;
|
|
1478
|
+
const selectedOrg = useMemo6(
|
|
1479
|
+
() => {
|
|
1480
|
+
if (selectedOrgSlug) {
|
|
1481
|
+
return organizations.find((o) => o.slug === selectedOrgSlug) ?? null;
|
|
1482
|
+
}
|
|
1483
|
+
if (organizations.length === 1) {
|
|
1484
|
+
return organizations[0];
|
|
1485
|
+
}
|
|
1486
|
+
return null;
|
|
1487
|
+
},
|
|
1488
|
+
[organizations, selectedOrgSlug]
|
|
1489
|
+
);
|
|
1490
|
+
useEffect5(() => {
|
|
1491
|
+
if (!open) return;
|
|
1492
|
+
if (selectedOrgSlug && form.getFieldValue("organization_id")) return;
|
|
1493
|
+
if (currentOrg) {
|
|
1494
|
+
setSelectedOrgSlug(currentOrg.slug);
|
|
1495
|
+
form.setFieldValue("organization_id", currentOrg.id);
|
|
1496
|
+
} else if (organizations.length === 1) {
|
|
1497
|
+
setSelectedOrgSlug(organizations[0].slug);
|
|
1498
|
+
form.setFieldValue("organization_id", organizations[0].id);
|
|
1499
|
+
}
|
|
1500
|
+
}, [open, organizations, currentOrg, selectedOrgSlug, form]);
|
|
1501
|
+
useEffect5(() => {
|
|
1502
|
+
if (!open || branchesLoading) return;
|
|
1503
|
+
if (branches.length === 1) {
|
|
1504
|
+
form.setFieldValue("branch_id", branches[0].id);
|
|
1505
|
+
} else if (branches.length > 0) {
|
|
1506
|
+
if (currentBranch && branches.some((b) => b.id === currentBranch.id)) {
|
|
1507
|
+
form.setFieldValue("branch_id", currentBranch.id);
|
|
1508
|
+
} else {
|
|
1509
|
+
const primaryId = branchesData?.primary_branch_id;
|
|
1510
|
+
if (primaryId) {
|
|
1511
|
+
form.setFieldValue("branch_id", primaryId);
|
|
1512
|
+
} else {
|
|
1513
|
+
const hq = branches.find((b) => b.is_headquarters);
|
|
1514
|
+
if (hq) {
|
|
1515
|
+
form.setFieldValue("branch_id", hq.id);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}, [open, branches, branchesLoading, branchesData, currentBranch, form]);
|
|
1521
|
+
useEffect5(() => {
|
|
1522
|
+
if (!open || branchesLoading) return;
|
|
1523
|
+
const orgId = form.getFieldValue("organization_id");
|
|
1524
|
+
const branchId = form.getFieldValue("branch_id");
|
|
1525
|
+
if (orgId && branchId && !hasMultipleOrgs && !hasMultipleBranches) {
|
|
1526
|
+
const timer = setTimeout(() => {
|
|
1527
|
+
onConfirm(orgId, branchId);
|
|
1528
|
+
}, 100);
|
|
1529
|
+
return () => clearTimeout(timer);
|
|
1530
|
+
}
|
|
1531
|
+
}, [open, branchesLoading, hasMultipleOrgs, hasMultipleBranches, form, onConfirm]);
|
|
1532
|
+
const handleOrgChange = useCallback6((orgId) => {
|
|
1533
|
+
const org = organizations.find((o) => o.id === orgId);
|
|
1534
|
+
if (org) {
|
|
1535
|
+
setSelectedOrgSlug(org.slug);
|
|
1536
|
+
form.setFieldValue("branch_id", void 0);
|
|
1537
|
+
}
|
|
1538
|
+
}, [organizations, form]);
|
|
1539
|
+
const handleSubmit = useCallback6(() => {
|
|
1540
|
+
form.validateFields().then((values) => {
|
|
1541
|
+
onConfirm(values.organization_id, values.branch_id);
|
|
1542
|
+
});
|
|
1543
|
+
}, [form, onConfirm]);
|
|
1544
|
+
const handleClose = useCallback6(() => {
|
|
1545
|
+
form.resetFields();
|
|
1546
|
+
setSelectedOrgSlug(currentOrg?.slug ?? null);
|
|
1547
|
+
onClose();
|
|
1548
|
+
}, [form, currentOrg, onClose]);
|
|
1549
|
+
const isInitialLoading = open && (!organizations.length || selectedOrgSlug && branchesLoading && !branches.length);
|
|
1550
|
+
const needsSelection = hasMultipleOrgs || hasMultipleBranches;
|
|
1551
|
+
return /* @__PURE__ */ jsx6(
|
|
1552
|
+
Modal,
|
|
1553
|
+
{
|
|
1554
|
+
title: /* @__PURE__ */ jsxs4(Space2, { children: [
|
|
1555
|
+
/* @__PURE__ */ jsx6(BankOutlined, {}),
|
|
1556
|
+
/* @__PURE__ */ jsx6("span", { children: title })
|
|
1557
|
+
] }),
|
|
1558
|
+
open,
|
|
1559
|
+
onCancel: handleClose,
|
|
1560
|
+
onOk: handleSubmit,
|
|
1561
|
+
okText: "Confirm",
|
|
1562
|
+
cancelText: "Cancel",
|
|
1563
|
+
destroyOnHidden: true,
|
|
1564
|
+
width: 480,
|
|
1565
|
+
children: isInitialLoading ? /* @__PURE__ */ jsxs4("div", { style: { textAlign: "center", padding: 40 }, children: [
|
|
1566
|
+
loadingComponent ?? /* @__PURE__ */ jsx6(Spin, { size: "large" }),
|
|
1567
|
+
/* @__PURE__ */ jsx6("div", { style: { marginTop: 16 }, children: /* @__PURE__ */ jsx6(Text2, { type: "secondary", children: "Loading..." }) })
|
|
1568
|
+
] }) : /* @__PURE__ */ jsxs4(
|
|
1569
|
+
Form,
|
|
1570
|
+
{
|
|
1571
|
+
form,
|
|
1572
|
+
layout: "vertical",
|
|
1573
|
+
style: { marginTop: 16 },
|
|
1574
|
+
children: [
|
|
1575
|
+
branchesError && /* @__PURE__ */ jsx6(
|
|
1576
|
+
Alert,
|
|
1577
|
+
{
|
|
1578
|
+
type: "error",
|
|
1579
|
+
message: "Failed to load branches",
|
|
1580
|
+
description: branchesError.message,
|
|
1581
|
+
style: { marginBottom: 16 }
|
|
1582
|
+
}
|
|
1583
|
+
),
|
|
1584
|
+
/* @__PURE__ */ jsx6(
|
|
1585
|
+
Form.Item,
|
|
1586
|
+
{
|
|
1587
|
+
name: "organization_id",
|
|
1588
|
+
label: /* @__PURE__ */ jsxs4(Space2, { children: [
|
|
1589
|
+
/* @__PURE__ */ jsx6(BankOutlined, {}),
|
|
1590
|
+
/* @__PURE__ */ jsx6("span", { children: "Organization" }),
|
|
1591
|
+
!hasMultipleOrgs && selectedOrg && /* @__PURE__ */ jsx6(Badge2, { status: "success", text: "Auto-selected" })
|
|
1592
|
+
] }),
|
|
1593
|
+
rules: [{ required: true, message: "Please select an organization" }],
|
|
1594
|
+
children: hasMultipleOrgs ? /* @__PURE__ */ jsx6(
|
|
1595
|
+
Select,
|
|
1596
|
+
{
|
|
1597
|
+
placeholder: "Select organization",
|
|
1598
|
+
onChange: handleOrgChange,
|
|
1599
|
+
size: "large",
|
|
1600
|
+
optionLabelProp: "label",
|
|
1601
|
+
children: organizations.map((org) => /* @__PURE__ */ jsx6(
|
|
1602
|
+
Select.Option,
|
|
1603
|
+
{
|
|
1604
|
+
value: org.id,
|
|
1605
|
+
label: org.name,
|
|
1606
|
+
children: /* @__PURE__ */ jsxs4(Space2, { style: { width: "100%", justifyContent: "space-between" }, children: [
|
|
1607
|
+
/* @__PURE__ */ jsxs4("div", { children: [
|
|
1608
|
+
/* @__PURE__ */ jsx6(Text2, { strong: true, children: org.name }),
|
|
1609
|
+
org.serviceRole && /* @__PURE__ */ jsxs4(Text2, { type: "secondary", style: { marginLeft: 8, fontSize: 12 }, children: [
|
|
1610
|
+
"(",
|
|
1611
|
+
org.serviceRole,
|
|
1612
|
+
")"
|
|
1613
|
+
] })
|
|
1614
|
+
] }),
|
|
1615
|
+
org.slug === currentOrg?.slug && /* @__PURE__ */ jsx6(CheckCircleFilled, { style: { color: "#52c41a" } })
|
|
1616
|
+
] })
|
|
1617
|
+
},
|
|
1618
|
+
org.id
|
|
1619
|
+
))
|
|
1620
|
+
}
|
|
1621
|
+
) : /* @__PURE__ */ jsx6(
|
|
1622
|
+
"div",
|
|
1623
|
+
{
|
|
1624
|
+
style: {
|
|
1625
|
+
padding: "8px 12px",
|
|
1626
|
+
background: "#f5f5f5",
|
|
1627
|
+
borderRadius: 6,
|
|
1628
|
+
border: "1px solid #d9d9d9"
|
|
1629
|
+
},
|
|
1630
|
+
children: /* @__PURE__ */ jsxs4(Space2, { children: [
|
|
1631
|
+
/* @__PURE__ */ jsx6(BankOutlined, { style: { color: "#1677ff" } }),
|
|
1632
|
+
/* @__PURE__ */ jsx6(Text2, { strong: true, children: selectedOrg?.name })
|
|
1633
|
+
] })
|
|
1634
|
+
}
|
|
1635
|
+
)
|
|
1636
|
+
}
|
|
1637
|
+
),
|
|
1638
|
+
selectedOrgSlug && /* @__PURE__ */ jsx6(
|
|
1639
|
+
Form.Item,
|
|
1640
|
+
{
|
|
1641
|
+
name: "branch_id",
|
|
1642
|
+
label: /* @__PURE__ */ jsxs4(Space2, { children: [
|
|
1643
|
+
/* @__PURE__ */ jsx6(ApartmentOutlined, {}),
|
|
1644
|
+
/* @__PURE__ */ jsx6("span", { children: "Branch" }),
|
|
1645
|
+
!hasMultipleBranches && branches.length === 1 && /* @__PURE__ */ jsx6(Badge2, { status: "success", text: "Auto-selected" })
|
|
1646
|
+
] }),
|
|
1647
|
+
rules: requireBranch ? [{ required: true, message: "Please select a branch" }] : void 0,
|
|
1648
|
+
children: branchesLoading ? /* @__PURE__ */ jsxs4("div", { style: { padding: "8px 12px", textAlign: "center" }, children: [
|
|
1649
|
+
/* @__PURE__ */ jsx6(Spin, { size: "small" }),
|
|
1650
|
+
/* @__PURE__ */ jsx6(Text2, { type: "secondary", style: { marginLeft: 8 }, children: "Loading branches..." })
|
|
1651
|
+
] }) : hasMultipleBranches ? /* @__PURE__ */ jsx6(
|
|
1652
|
+
Select,
|
|
1653
|
+
{
|
|
1654
|
+
placeholder: "Select branch",
|
|
1655
|
+
size: "large",
|
|
1656
|
+
optionLabelProp: "label",
|
|
1657
|
+
children: branches.map((branch) => /* @__PURE__ */ jsx6(
|
|
1658
|
+
Select.Option,
|
|
1659
|
+
{
|
|
1660
|
+
value: branch.id,
|
|
1661
|
+
label: branch.name,
|
|
1662
|
+
children: /* @__PURE__ */ jsxs4(Space2, { style: { width: "100%", justifyContent: "space-between" }, children: [
|
|
1663
|
+
/* @__PURE__ */ jsxs4("div", { children: [
|
|
1664
|
+
/* @__PURE__ */ jsx6(Text2, { strong: true, children: branch.name }),
|
|
1665
|
+
/* @__PURE__ */ jsx6(Text2, { type: "secondary", style: { marginLeft: 8, fontSize: 12 }, children: branch.code })
|
|
1666
|
+
] }),
|
|
1667
|
+
/* @__PURE__ */ jsxs4(Space2, { size: 4, children: [
|
|
1668
|
+
branch.is_headquarters && /* @__PURE__ */ jsx6(Badge2, { color: "blue", text: "HQ" }),
|
|
1669
|
+
branch.is_primary && /* @__PURE__ */ jsx6(Badge2, { color: "green", text: "Primary" })
|
|
1670
|
+
] })
|
|
1671
|
+
] })
|
|
1672
|
+
},
|
|
1673
|
+
branch.id
|
|
1674
|
+
))
|
|
1675
|
+
}
|
|
1676
|
+
) : branches.length === 1 ? /* @__PURE__ */ jsx6(
|
|
1677
|
+
"div",
|
|
1678
|
+
{
|
|
1679
|
+
style: {
|
|
1680
|
+
padding: "8px 12px",
|
|
1681
|
+
background: "#f5f5f5",
|
|
1682
|
+
borderRadius: 6,
|
|
1683
|
+
border: "1px solid #d9d9d9"
|
|
1684
|
+
},
|
|
1685
|
+
children: /* @__PURE__ */ jsxs4(Space2, { children: [
|
|
1686
|
+
/* @__PURE__ */ jsx6(ApartmentOutlined, { style: { color: "#1677ff" } }),
|
|
1687
|
+
/* @__PURE__ */ jsx6(Text2, { strong: true, children: branches[0].name }),
|
|
1688
|
+
/* @__PURE__ */ jsxs4(Text2, { type: "secondary", children: [
|
|
1689
|
+
"(",
|
|
1690
|
+
branches[0].code,
|
|
1691
|
+
")"
|
|
1692
|
+
] })
|
|
1693
|
+
] })
|
|
1694
|
+
}
|
|
1695
|
+
) : /* @__PURE__ */ jsx6(
|
|
1696
|
+
Alert,
|
|
1697
|
+
{
|
|
1698
|
+
type: "warning",
|
|
1699
|
+
message: "No branches available",
|
|
1700
|
+
description: "You don't have access to any branches in this organization."
|
|
1701
|
+
}
|
|
1702
|
+
)
|
|
1703
|
+
}
|
|
1704
|
+
),
|
|
1705
|
+
!needsSelection && selectedOrg && branches.length > 0 && /* @__PURE__ */ jsx6(
|
|
1706
|
+
Alert,
|
|
1707
|
+
{
|
|
1708
|
+
type: "info",
|
|
1709
|
+
message: "Auto-selected",
|
|
1710
|
+
description: `Using ${selectedOrg.name} / ${branches[0]?.name ?? "Default"}`,
|
|
1711
|
+
icon: /* @__PURE__ */ jsx6(CheckCircleFilled, {}),
|
|
1712
|
+
showIcon: true
|
|
1713
|
+
}
|
|
1714
|
+
)
|
|
1715
|
+
]
|
|
1716
|
+
}
|
|
1717
|
+
)
|
|
1718
|
+
}
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
// src/components/BranchGate.tsx
|
|
1723
|
+
import { BankOutlined as BankOutlined2, ApartmentOutlined as ApartmentOutlined2, CheckCircleFilled as CheckCircleFilled2 } from "@ant-design/icons";
|
|
1724
|
+
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
1725
|
+
import { Select as Select2, Space as Space3, Typography as Typography3, Badge as Badge3, Spin as Spin2, Button as Button2, Alert as Alert2 } from "antd";
|
|
1726
|
+
import React7, { useEffect as useEffect6, useState as useState5 } from "react";
|
|
1727
|
+
import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1728
|
+
var { Text: Text3, Title: Title2 } = Typography3;
|
|
1729
|
+
var DEFAULT_STORAGE_KEY2 = "omnify_branch_gate_selection";
|
|
1730
|
+
function BranchGate({
|
|
1731
|
+
children,
|
|
1732
|
+
onSelectionChange,
|
|
1733
|
+
storageKey = DEFAULT_STORAGE_KEY2,
|
|
1734
|
+
loadingComponent,
|
|
1735
|
+
title,
|
|
1736
|
+
description
|
|
1737
|
+
}) {
|
|
1738
|
+
const { config, isAuthenticated } = useSsoContext();
|
|
1739
|
+
const { organizations, currentOrg, hasMultipleOrgs } = useOrganization();
|
|
1740
|
+
const [storedSelection, setStoredSelection] = useState5(null);
|
|
1741
|
+
const [isInitialized, setIsInitialized] = useState5(false);
|
|
1742
|
+
const [tempOrgId, setTempOrgId] = useState5(null);
|
|
1743
|
+
const [tempBranchId, setTempBranchId] = useState5(null);
|
|
1744
|
+
const branchService = React7.useMemo(
|
|
1745
|
+
() => createBranchService({ apiUrl: config.apiUrl }),
|
|
1746
|
+
[config.apiUrl]
|
|
1747
|
+
);
|
|
1748
|
+
const activeOrgSlug = React7.useMemo(() => {
|
|
1749
|
+
if (tempOrgId) {
|
|
1750
|
+
return organizations.find((o) => String(o.id) === tempOrgId)?.slug;
|
|
1751
|
+
}
|
|
1752
|
+
return storedSelection?.orgSlug ?? currentOrg?.slug;
|
|
1753
|
+
}, [tempOrgId, organizations, storedSelection, currentOrg]);
|
|
1754
|
+
const { data: branchesData, isLoading: branchesLoading } = useQuery3({
|
|
1755
|
+
queryKey: ssoQueryKeys.branches.list(activeOrgSlug),
|
|
1756
|
+
queryFn: () => branchService.list(activeOrgSlug),
|
|
1757
|
+
enabled: isAuthenticated && !!activeOrgSlug
|
|
1758
|
+
});
|
|
1759
|
+
const branches = branchesData?.branches ?? [];
|
|
1760
|
+
const hasMultipleBranches = branches.length > 1;
|
|
1761
|
+
useEffect6(() => {
|
|
1762
|
+
if (typeof window === "undefined") return;
|
|
1763
|
+
const saved = localStorage.getItem(storageKey);
|
|
1764
|
+
if (saved) {
|
|
1765
|
+
try {
|
|
1766
|
+
const parsed = JSON.parse(saved);
|
|
1767
|
+
setStoredSelection(parsed);
|
|
1768
|
+
onSelectionChange?.(parsed);
|
|
1769
|
+
} catch {
|
|
1770
|
+
localStorage.removeItem(storageKey);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
setIsInitialized(true);
|
|
1774
|
+
}, [storageKey, onSelectionChange]);
|
|
1775
|
+
useEffect6(() => {
|
|
1776
|
+
if (!isAuthenticated || !isInitialized || storedSelection) return;
|
|
1777
|
+
if (organizations.length === 1 && !tempOrgId) {
|
|
1778
|
+
setTempOrgId(String(organizations[0].id));
|
|
1779
|
+
}
|
|
1780
|
+
}, [isAuthenticated, isInitialized, organizations, storedSelection, tempOrgId]);
|
|
1781
|
+
useEffect6(() => {
|
|
1782
|
+
if (!tempOrgId || branchesLoading || storedSelection) return;
|
|
1783
|
+
if (branches.length === 1 && !tempBranchId) {
|
|
1784
|
+
setTempBranchId(String(branches[0].id));
|
|
1785
|
+
} else if (branches.length > 0 && !tempBranchId) {
|
|
1786
|
+
const primaryId = branchesData?.primary_branch_id;
|
|
1787
|
+
if (primaryId) {
|
|
1788
|
+
setTempBranchId(String(primaryId));
|
|
1789
|
+
} else {
|
|
1790
|
+
const hq = branches.find((b) => b.is_headquarters);
|
|
1791
|
+
if (hq) {
|
|
1792
|
+
setTempBranchId(String(hq.id));
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
}, [tempOrgId, branches, branchesLoading, branchesData, storedSelection, tempBranchId]);
|
|
1797
|
+
useEffect6(() => {
|
|
1798
|
+
if (storedSelection || !isInitialized) return;
|
|
1799
|
+
if (!tempOrgId || !tempBranchId || branchesLoading) return;
|
|
1800
|
+
if (!hasMultipleOrgs && !hasMultipleBranches) {
|
|
1801
|
+
confirmSelection();
|
|
1802
|
+
}
|
|
1803
|
+
}, [tempOrgId, tempBranchId, branchesLoading, hasMultipleOrgs, hasMultipleBranches, storedSelection, isInitialized]);
|
|
1804
|
+
const confirmSelection = React7.useCallback(() => {
|
|
1805
|
+
if (!tempOrgId || !tempBranchId) return;
|
|
1806
|
+
const org = organizations.find((o) => String(o.id) === tempOrgId);
|
|
1807
|
+
const branch = branches.find((b) => String(b.id) === tempBranchId);
|
|
1808
|
+
if (!org || !branch) return;
|
|
1809
|
+
const selection = {
|
|
1810
|
+
orgId: String(org.id),
|
|
1811
|
+
orgSlug: org.slug,
|
|
1812
|
+
orgName: org.name,
|
|
1813
|
+
branchId: String(branch.id),
|
|
1814
|
+
branchName: branch.name,
|
|
1815
|
+
branchCode: branch.code
|
|
1816
|
+
};
|
|
1817
|
+
localStorage.setItem(storageKey, JSON.stringify(selection));
|
|
1818
|
+
setStoredSelection(selection);
|
|
1819
|
+
onSelectionChange?.(selection);
|
|
1820
|
+
setTempOrgId(null);
|
|
1821
|
+
setTempBranchId(null);
|
|
1822
|
+
}, [tempOrgId, tempBranchId, organizations, branches, storageKey, onSelectionChange]);
|
|
1823
|
+
const clearSelection = React7.useCallback(() => {
|
|
1824
|
+
localStorage.removeItem(storageKey);
|
|
1825
|
+
setStoredSelection(null);
|
|
1826
|
+
onSelectionChange?.(null);
|
|
1827
|
+
}, [storageKey, onSelectionChange]);
|
|
1828
|
+
const needsSelection = isAuthenticated && isInitialized && !storedSelection && (hasMultipleOrgs || hasMultipleBranches);
|
|
1829
|
+
const isLoading = !isAuthenticated || !isInitialized || !!activeOrgSlug && branchesLoading && !storedSelection;
|
|
1830
|
+
if (isLoading && !needsSelection) {
|
|
1831
|
+
if (loadingComponent) {
|
|
1832
|
+
return /* @__PURE__ */ jsx7(Fragment3, { children: loadingComponent });
|
|
1833
|
+
}
|
|
1834
|
+
return /* @__PURE__ */ jsx7("div", { style: {
|
|
1835
|
+
display: "flex",
|
|
1836
|
+
justifyContent: "center",
|
|
1837
|
+
alignItems: "center",
|
|
1838
|
+
minHeight: "100vh",
|
|
1839
|
+
background: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)"
|
|
1840
|
+
}, children: /* @__PURE__ */ jsx7(Spin2, { size: "large" }) });
|
|
1841
|
+
}
|
|
1842
|
+
if (needsSelection) {
|
|
1843
|
+
const canConfirm = tempOrgId && tempBranchId;
|
|
1844
|
+
return /* @__PURE__ */ jsx7("div", { style: {
|
|
1845
|
+
minHeight: "100vh",
|
|
1846
|
+
background: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
|
1847
|
+
display: "flex",
|
|
1848
|
+
alignItems: "center",
|
|
1849
|
+
justifyContent: "center",
|
|
1850
|
+
padding: 24
|
|
1851
|
+
}, children: /* @__PURE__ */ jsxs5("div", { style: {
|
|
1852
|
+
background: "#fff",
|
|
1853
|
+
borderRadius: 16,
|
|
1854
|
+
padding: 32,
|
|
1855
|
+
maxWidth: 480,
|
|
1856
|
+
width: "100%",
|
|
1857
|
+
boxShadow: "0 20px 60px rgba(0,0,0,0.3)"
|
|
1858
|
+
}, children: [
|
|
1859
|
+
/* @__PURE__ */ jsxs5("div", { style: { textAlign: "center", marginBottom: 24 }, children: [
|
|
1860
|
+
/* @__PURE__ */ jsx7("div", { style: {
|
|
1861
|
+
width: 64,
|
|
1862
|
+
height: 64,
|
|
1863
|
+
borderRadius: "50%",
|
|
1864
|
+
background: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
|
1865
|
+
display: "flex",
|
|
1866
|
+
alignItems: "center",
|
|
1867
|
+
justifyContent: "center",
|
|
1868
|
+
margin: "0 auto 16px"
|
|
1869
|
+
}, children: /* @__PURE__ */ jsx7(BankOutlined2, { style: { fontSize: 28, color: "#fff" } }) }),
|
|
1870
|
+
/* @__PURE__ */ jsx7(Title2, { level: 3, style: { margin: 0 }, children: title ?? "Select Organization" }),
|
|
1871
|
+
/* @__PURE__ */ jsx7(Text3, { type: "secondary", children: description ?? "Please select your organization and branch to continue" })
|
|
1872
|
+
] }),
|
|
1873
|
+
/* @__PURE__ */ jsxs5("div", { style: { marginBottom: 20 }, children: [
|
|
1874
|
+
/* @__PURE__ */ jsx7(Text3, { strong: true, style: { display: "block", marginBottom: 8 }, children: /* @__PURE__ */ jsxs5(Space3, { children: [
|
|
1875
|
+
/* @__PURE__ */ jsx7(BankOutlined2, {}),
|
|
1876
|
+
/* @__PURE__ */ jsx7("span", { children: "Organization" }),
|
|
1877
|
+
!hasMultipleOrgs && /* @__PURE__ */ jsx7(Badge3, { status: "success", text: "Auto-selected" })
|
|
1878
|
+
] }) }),
|
|
1879
|
+
hasMultipleOrgs ? /* @__PURE__ */ jsx7(
|
|
1880
|
+
Select2,
|
|
1881
|
+
{
|
|
1882
|
+
value: tempOrgId,
|
|
1883
|
+
onChange: (value) => {
|
|
1884
|
+
setTempOrgId(String(value));
|
|
1885
|
+
setTempBranchId(null);
|
|
1886
|
+
},
|
|
1887
|
+
placeholder: "Select organization",
|
|
1888
|
+
size: "large",
|
|
1889
|
+
style: { width: "100%" },
|
|
1890
|
+
optionLabelProp: "label",
|
|
1891
|
+
children: organizations.map((org) => /* @__PURE__ */ jsx7(Select2.Option, { value: String(org.id), label: org.name, children: /* @__PURE__ */ jsx7(Space3, { style: { width: "100%", justifyContent: "space-between" }, children: /* @__PURE__ */ jsxs5("div", { children: [
|
|
1892
|
+
/* @__PURE__ */ jsx7(Text3, { strong: true, children: org.name }),
|
|
1893
|
+
org.serviceRole && /* @__PURE__ */ jsxs5(Text3, { type: "secondary", style: { marginLeft: 8, fontSize: 12 }, children: [
|
|
1894
|
+
"(",
|
|
1895
|
+
org.serviceRole,
|
|
1896
|
+
")"
|
|
1897
|
+
] })
|
|
1898
|
+
] }) }) }, org.id))
|
|
1899
|
+
}
|
|
1900
|
+
) : /* @__PURE__ */ jsx7("div", { style: {
|
|
1901
|
+
padding: "8px 12px",
|
|
1902
|
+
background: "#f5f5f5",
|
|
1903
|
+
borderRadius: 6,
|
|
1904
|
+
border: "1px solid #d9d9d9"
|
|
1905
|
+
}, children: /* @__PURE__ */ jsxs5(Space3, { children: [
|
|
1906
|
+
/* @__PURE__ */ jsx7(BankOutlined2, { style: { color: "#1677ff" } }),
|
|
1907
|
+
/* @__PURE__ */ jsx7(Text3, { strong: true, children: organizations[0]?.name })
|
|
1908
|
+
] }) })
|
|
1909
|
+
] }),
|
|
1910
|
+
tempOrgId && /* @__PURE__ */ jsxs5("div", { style: { marginBottom: 24 }, children: [
|
|
1911
|
+
/* @__PURE__ */ jsx7(Text3, { strong: true, style: { display: "block", marginBottom: 8 }, children: /* @__PURE__ */ jsxs5(Space3, { children: [
|
|
1912
|
+
/* @__PURE__ */ jsx7(ApartmentOutlined2, {}),
|
|
1913
|
+
/* @__PURE__ */ jsx7("span", { children: "Branch" }),
|
|
1914
|
+
!hasMultipleBranches && branches.length === 1 && /* @__PURE__ */ jsx7(Badge3, { status: "success", text: "Auto-selected" })
|
|
1915
|
+
] }) }),
|
|
1916
|
+
branchesLoading ? /* @__PURE__ */ jsxs5("div", { style: { padding: "12px", textAlign: "center" }, children: [
|
|
1917
|
+
/* @__PURE__ */ jsx7(Spin2, { size: "small" }),
|
|
1918
|
+
/* @__PURE__ */ jsx7(Text3, { type: "secondary", style: { marginLeft: 8 }, children: "Loading..." })
|
|
1919
|
+
] }) : hasMultipleBranches ? /* @__PURE__ */ jsx7(
|
|
1920
|
+
Select2,
|
|
1921
|
+
{
|
|
1922
|
+
value: tempBranchId,
|
|
1923
|
+
onChange: (value) => setTempBranchId(String(value)),
|
|
1924
|
+
placeholder: "Select branch",
|
|
1925
|
+
size: "large",
|
|
1926
|
+
style: { width: "100%" },
|
|
1927
|
+
optionLabelProp: "label",
|
|
1928
|
+
children: branches.map((branch) => /* @__PURE__ */ jsx7(Select2.Option, { value: String(branch.id), label: branch.name, children: /* @__PURE__ */ jsxs5(Space3, { style: { width: "100%", justifyContent: "space-between" }, children: [
|
|
1929
|
+
/* @__PURE__ */ jsxs5("div", { children: [
|
|
1930
|
+
/* @__PURE__ */ jsx7(Text3, { strong: true, children: branch.name }),
|
|
1931
|
+
/* @__PURE__ */ jsx7(Text3, { type: "secondary", style: { marginLeft: 8, fontSize: 12 }, children: branch.code })
|
|
1932
|
+
] }),
|
|
1933
|
+
/* @__PURE__ */ jsxs5(Space3, { size: 4, children: [
|
|
1934
|
+
branch.is_headquarters && /* @__PURE__ */ jsx7(Badge3, { color: "blue", text: "HQ" }),
|
|
1935
|
+
branch.is_primary && /* @__PURE__ */ jsx7(Badge3, { color: "green", text: "Primary" })
|
|
1936
|
+
] })
|
|
1937
|
+
] }) }, branch.id))
|
|
1938
|
+
}
|
|
1939
|
+
) : branches.length === 1 ? /* @__PURE__ */ jsx7("div", { style: {
|
|
1940
|
+
padding: "8px 12px",
|
|
1941
|
+
background: "#f5f5f5",
|
|
1942
|
+
borderRadius: 6,
|
|
1943
|
+
border: "1px solid #d9d9d9"
|
|
1944
|
+
}, children: /* @__PURE__ */ jsxs5(Space3, { children: [
|
|
1945
|
+
/* @__PURE__ */ jsx7(ApartmentOutlined2, { style: { color: "#1677ff" } }),
|
|
1946
|
+
/* @__PURE__ */ jsx7(Text3, { strong: true, children: branches[0].name }),
|
|
1947
|
+
/* @__PURE__ */ jsxs5(Text3, { type: "secondary", children: [
|
|
1948
|
+
"(",
|
|
1949
|
+
branches[0].code,
|
|
1950
|
+
")"
|
|
1951
|
+
] })
|
|
1952
|
+
] }) }) : /* @__PURE__ */ jsx7(
|
|
1953
|
+
Alert2,
|
|
1954
|
+
{
|
|
1955
|
+
type: "warning",
|
|
1956
|
+
message: "No branches available",
|
|
1957
|
+
description: "You don't have access to any branches in this organization."
|
|
1958
|
+
}
|
|
1959
|
+
)
|
|
1960
|
+
] }),
|
|
1961
|
+
/* @__PURE__ */ jsx7(
|
|
1962
|
+
Button2,
|
|
1963
|
+
{
|
|
1964
|
+
type: "primary",
|
|
1965
|
+
size: "large",
|
|
1966
|
+
block: true,
|
|
1967
|
+
disabled: !canConfirm,
|
|
1968
|
+
onClick: confirmSelection,
|
|
1969
|
+
icon: /* @__PURE__ */ jsx7(CheckCircleFilled2, {}),
|
|
1970
|
+
style: {
|
|
1971
|
+
height: 48,
|
|
1972
|
+
fontSize: 16,
|
|
1973
|
+
background: canConfirm ? "linear-gradient(135deg, #667eea 0%, #764ba2 100%)" : void 0,
|
|
1974
|
+
border: "none"
|
|
1975
|
+
},
|
|
1976
|
+
children: "Confirm"
|
|
1977
|
+
}
|
|
1978
|
+
)
|
|
1979
|
+
] }) });
|
|
1980
|
+
}
|
|
1981
|
+
return /* @__PURE__ */ jsx7(Fragment3, { children });
|
|
1982
|
+
}
|
|
1983
|
+
function useBranchGate(storageKey = DEFAULT_STORAGE_KEY2) {
|
|
1984
|
+
const [selection, setSelection] = useState5(null);
|
|
1985
|
+
useEffect6(() => {
|
|
1986
|
+
if (typeof window === "undefined") return;
|
|
1987
|
+
const saved = localStorage.getItem(storageKey);
|
|
1988
|
+
if (saved) {
|
|
1989
|
+
try {
|
|
1990
|
+
setSelection(JSON.parse(saved));
|
|
1991
|
+
} catch {
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
const handleStorage = (e) => {
|
|
1995
|
+
if (e.key === storageKey) {
|
|
1996
|
+
if (e.newValue) {
|
|
1997
|
+
try {
|
|
1998
|
+
setSelection(JSON.parse(e.newValue));
|
|
1999
|
+
} catch {
|
|
2000
|
+
setSelection(null);
|
|
2001
|
+
}
|
|
2002
|
+
} else {
|
|
2003
|
+
setSelection(null);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
};
|
|
2007
|
+
window.addEventListener("storage", handleStorage);
|
|
2008
|
+
return () => window.removeEventListener("storage", handleStorage);
|
|
2009
|
+
}, [storageKey]);
|
|
2010
|
+
const clearSelection = React7.useCallback(() => {
|
|
2011
|
+
localStorage.removeItem(storageKey);
|
|
2012
|
+
setSelection(null);
|
|
2013
|
+
}, [storageKey]);
|
|
2014
|
+
return {
|
|
2015
|
+
selection,
|
|
2016
|
+
selectedOrg: selection ? { id: selection.orgId, slug: selection.orgSlug, name: selection.orgName } : null,
|
|
2017
|
+
selectedBranch: selection ? { id: selection.branchId, name: selection.branchName, code: selection.branchCode } : null,
|
|
2018
|
+
clearSelection
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
// src/components/admin/UserTable.tsx
|
|
2023
|
+
import { EditOutlined, DeleteOutlined, SearchOutlined } from "@ant-design/icons";
|
|
2024
|
+
import { Table, Space as Space4, Button as Button3, Popconfirm, Tag, Input } from "antd";
|
|
2025
|
+
|
|
2026
|
+
// src/i18n/translations.ts
|
|
2027
|
+
var ssoNamespace = "sso";
|
|
2028
|
+
var defaultTranslations = {
|
|
2029
|
+
en: {
|
|
2030
|
+
// Common
|
|
2031
|
+
actions: "Actions",
|
|
2032
|
+
save: "Save",
|
|
2033
|
+
cancel: "Cancel",
|
|
2034
|
+
delete: "Delete",
|
|
2035
|
+
edit: "Edit",
|
|
2036
|
+
search: "Search",
|
|
2037
|
+
loading: "Loading...",
|
|
2038
|
+
yes: "Yes",
|
|
2039
|
+
no: "No",
|
|
2040
|
+
confirmDelete: "Are you sure you want to delete?",
|
|
2041
|
+
// Users
|
|
2042
|
+
users: "Users",
|
|
2043
|
+
user: "User",
|
|
2044
|
+
name: "Name",
|
|
2045
|
+
email: "Email",
|
|
2046
|
+
ssoUser: "SSO User",
|
|
2047
|
+
localUser: "Local User",
|
|
2048
|
+
userList: "User List",
|
|
2049
|
+
userDetails: "User Details",
|
|
2050
|
+
editUser: "Edit User",
|
|
2051
|
+
deleteUser: "Delete User",
|
|
2052
|
+
searchUsers: "Search users...",
|
|
2053
|
+
noUsersFound: "No users found",
|
|
2054
|
+
userDeleted: "User deleted successfully",
|
|
2055
|
+
userUpdated: "User updated successfully",
|
|
2056
|
+
// Roles
|
|
2057
|
+
roles: "Roles",
|
|
2058
|
+
role: "Role",
|
|
2059
|
+
roleName: "Role Name",
|
|
2060
|
+
roleDescription: "Description",
|
|
2061
|
+
permissions: "Permissions",
|
|
2062
|
+
assignRole: "Assign Role",
|
|
2063
|
+
removeRole: "Remove Role",
|
|
2064
|
+
// Permissions
|
|
2065
|
+
permission: "Permission",
|
|
2066
|
+
permissionName: "Permission Name",
|
|
2067
|
+
permissionDescription: "Description",
|
|
2068
|
+
// Validation
|
|
2069
|
+
required: "{{field}} is required",
|
|
2070
|
+
maxLength: "{{field}} must be at most {{max}} characters",
|
|
2071
|
+
invalidEmail: "Please enter a valid email address",
|
|
2072
|
+
// Pagination
|
|
2073
|
+
total: "Total {{count}} items",
|
|
2074
|
+
page: "Page {{current}} of {{total}}"
|
|
2075
|
+
},
|
|
2076
|
+
ja: {
|
|
2077
|
+
// Common
|
|
2078
|
+
actions: "\u64CD\u4F5C",
|
|
2079
|
+
save: "\u4FDD\u5B58",
|
|
2080
|
+
cancel: "\u30AD\u30E3\u30F3\u30BB\u30EB",
|
|
2081
|
+
delete: "\u524A\u9664",
|
|
2082
|
+
edit: "\u7DE8\u96C6",
|
|
2083
|
+
search: "\u691C\u7D22",
|
|
2084
|
+
loading: "\u8AAD\u307F\u8FBC\u307F\u4E2D...",
|
|
2085
|
+
yes: "\u306F\u3044",
|
|
2086
|
+
no: "\u3044\u3044\u3048",
|
|
2087
|
+
confirmDelete: "\u672C\u5F53\u306B\u524A\u9664\u3057\u307E\u3059\u304B\uFF1F",
|
|
2088
|
+
// Users
|
|
2089
|
+
users: "\u30E6\u30FC\u30B6\u30FC",
|
|
2090
|
+
user: "\u30E6\u30FC\u30B6\u30FC",
|
|
2091
|
+
name: "\u540D\u524D",
|
|
2092
|
+
email: "\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9",
|
|
2093
|
+
ssoUser: "SSO\u30E6\u30FC\u30B6\u30FC",
|
|
2094
|
+
localUser: "\u30ED\u30FC\u30AB\u30EB\u30E6\u30FC\u30B6\u30FC",
|
|
2095
|
+
userList: "\u30E6\u30FC\u30B6\u30FC\u4E00\u89A7",
|
|
2096
|
+
userDetails: "\u30E6\u30FC\u30B6\u30FC\u8A73\u7D30",
|
|
2097
|
+
editUser: "\u30E6\u30FC\u30B6\u30FC\u7DE8\u96C6",
|
|
2098
|
+
deleteUser: "\u30E6\u30FC\u30B6\u30FC\u524A\u9664",
|
|
2099
|
+
searchUsers: "\u30E6\u30FC\u30B6\u30FC\u3092\u691C\u7D22...",
|
|
2100
|
+
noUsersFound: "\u30E6\u30FC\u30B6\u30FC\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093",
|
|
2101
|
+
userDeleted: "\u30E6\u30FC\u30B6\u30FC\u3092\u524A\u9664\u3057\u307E\u3057\u305F",
|
|
2102
|
+
userUpdated: "\u30E6\u30FC\u30B6\u30FC\u3092\u66F4\u65B0\u3057\u307E\u3057\u305F",
|
|
2103
|
+
// Roles
|
|
2104
|
+
roles: "\u30ED\u30FC\u30EB",
|
|
2105
|
+
role: "\u30ED\u30FC\u30EB",
|
|
2106
|
+
roleName: "\u30ED\u30FC\u30EB\u540D",
|
|
2107
|
+
roleDescription: "\u8AAC\u660E",
|
|
2108
|
+
permissions: "\u6A29\u9650",
|
|
2109
|
+
assignRole: "\u30ED\u30FC\u30EB\u3092\u5272\u308A\u5F53\u3066",
|
|
2110
|
+
removeRole: "\u30ED\u30FC\u30EB\u3092\u524A\u9664",
|
|
2111
|
+
// Permissions
|
|
2112
|
+
permission: "\u6A29\u9650",
|
|
2113
|
+
permissionName: "\u6A29\u9650\u540D",
|
|
2114
|
+
permissionDescription: "\u8AAC\u660E",
|
|
2115
|
+
// Validation
|
|
2116
|
+
required: "{{field}}\u306F\u5FC5\u9808\u3067\u3059",
|
|
2117
|
+
maxLength: "{{field}}\u306F{{max}}\u6587\u5B57\u4EE5\u5185\u3067\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
2118
|
+
invalidEmail: "\u6709\u52B9\u306A\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
2119
|
+
// Pagination
|
|
2120
|
+
total: "\u5168{{count}}\u4EF6",
|
|
2121
|
+
page: "{{total}}\u30DA\u30FC\u30B8\u4E2D{{current}}\u30DA\u30FC\u30B8"
|
|
2122
|
+
},
|
|
2123
|
+
vi: {
|
|
2124
|
+
// Common
|
|
2125
|
+
actions: "H\xE0nh \u0111\u1ED9ng",
|
|
2126
|
+
save: "L\u01B0u",
|
|
2127
|
+
cancel: "H\u1EE7y",
|
|
2128
|
+
delete: "X\xF3a",
|
|
2129
|
+
edit: "S\u1EEDa",
|
|
2130
|
+
search: "T\xECm ki\u1EBFm",
|
|
2131
|
+
loading: "\u0110ang t\u1EA3i...",
|
|
2132
|
+
yes: "C\xF3",
|
|
2133
|
+
no: "Kh\xF4ng",
|
|
2134
|
+
confirmDelete: "B\u1EA1n c\xF3 ch\u1EAFc mu\u1ED1n x\xF3a?",
|
|
2135
|
+
// Users
|
|
2136
|
+
users: "Ng\u01B0\u1EDDi d\xF9ng",
|
|
2137
|
+
user: "Ng\u01B0\u1EDDi d\xF9ng",
|
|
2138
|
+
name: "T\xEAn",
|
|
2139
|
+
email: "Email",
|
|
2140
|
+
ssoUser: "Ng\u01B0\u1EDDi d\xF9ng SSO",
|
|
2141
|
+
localUser: "Ng\u01B0\u1EDDi d\xF9ng n\u1ED9i b\u1ED9",
|
|
2142
|
+
userList: "Danh s\xE1ch ng\u01B0\u1EDDi d\xF9ng",
|
|
2143
|
+
userDetails: "Chi ti\u1EBFt ng\u01B0\u1EDDi d\xF9ng",
|
|
2144
|
+
editUser: "S\u1EEDa ng\u01B0\u1EDDi d\xF9ng",
|
|
2145
|
+
deleteUser: "X\xF3a ng\u01B0\u1EDDi d\xF9ng",
|
|
2146
|
+
searchUsers: "T\xECm ng\u01B0\u1EDDi d\xF9ng...",
|
|
2147
|
+
noUsersFound: "Kh\xF4ng t\xECm th\u1EA5y ng\u01B0\u1EDDi d\xF9ng",
|
|
2148
|
+
userDeleted: "\u0110\xE3 x\xF3a ng\u01B0\u1EDDi d\xF9ng",
|
|
2149
|
+
userUpdated: "\u0110\xE3 c\u1EADp nh\u1EADt ng\u01B0\u1EDDi d\xF9ng",
|
|
2150
|
+
// Roles
|
|
2151
|
+
roles: "Vai tr\xF2",
|
|
2152
|
+
role: "Vai tr\xF2",
|
|
2153
|
+
roleName: "T\xEAn vai tr\xF2",
|
|
2154
|
+
roleDescription: "M\xF4 t\u1EA3",
|
|
2155
|
+
permissions: "Quy\u1EC1n",
|
|
2156
|
+
assignRole: "G\xE1n vai tr\xF2",
|
|
2157
|
+
removeRole: "X\xF3a vai tr\xF2",
|
|
2158
|
+
// Permissions
|
|
2159
|
+
permission: "Quy\u1EC1n",
|
|
2160
|
+
permissionName: "T\xEAn quy\u1EC1n",
|
|
2161
|
+
permissionDescription: "M\xF4 t\u1EA3",
|
|
2162
|
+
// Validation
|
|
2163
|
+
required: "{{field}} l\xE0 b\u1EAFt bu\u1ED9c",
|
|
2164
|
+
maxLength: "{{field}} t\u1ED1i \u0111a {{max}} k\xFD t\u1EF1",
|
|
2165
|
+
invalidEmail: "Email kh\xF4ng h\u1EE3p l\u1EC7",
|
|
2166
|
+
// Pagination
|
|
2167
|
+
total: "T\u1ED5ng {{count}} m\u1EE5c",
|
|
2168
|
+
page: "Trang {{current}}/{{total}}"
|
|
2169
|
+
}
|
|
2170
|
+
};
|
|
2171
|
+
|
|
2172
|
+
// src/i18n/useSsoTranslation.ts
|
|
2173
|
+
import { useCallback as useCallback7 } from "react";
|
|
2174
|
+
function useSsoTranslation() {
|
|
2175
|
+
const t = useCallback7(
|
|
2176
|
+
(key, options) => {
|
|
2177
|
+
let value = defaultTranslations.en[key] || key;
|
|
2178
|
+
if (options) {
|
|
2179
|
+
Object.entries(options).forEach(([k, v]) => {
|
|
2180
|
+
value = value.replace(new RegExp(`{{${k}}}`, "g"), String(v));
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
return value;
|
|
2184
|
+
},
|
|
2185
|
+
[]
|
|
2186
|
+
);
|
|
2187
|
+
return { t };
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
// src/i18n/I18nProvider.tsx
|
|
2191
|
+
import i18n2 from "i18next";
|
|
2192
|
+
import LanguageDetector from "i18next-browser-languagedetector";
|
|
2193
|
+
import { useMemo as useMemo7 } from "react";
|
|
2194
|
+
import { I18nextProvider } from "react-i18next";
|
|
2195
|
+
import { initReactI18next } from "react-i18next";
|
|
2196
|
+
|
|
2197
|
+
// src/i18n/config.ts
|
|
2198
|
+
import i18n from "i18next";
|
|
2199
|
+
var locales = ["ja", "en", "vi"];
|
|
2200
|
+
var defaultLocale2 = "ja";
|
|
2201
|
+
var localeNames = {
|
|
2202
|
+
ja: "\u65E5\u672C\u8A9E",
|
|
2203
|
+
en: "English",
|
|
2204
|
+
vi: "Ti\u1EBFng Vi\u1EC7t"
|
|
2205
|
+
};
|
|
2206
|
+
var changeLanguage = (locale) => {
|
|
2207
|
+
if (typeof window === "undefined") return;
|
|
2208
|
+
i18n.changeLanguage(locale);
|
|
2209
|
+
document.cookie = `locale=${locale};path=/;max-age=31536000`;
|
|
2210
|
+
};
|
|
2211
|
+
var getCurrentLocale = () => {
|
|
2212
|
+
if (typeof window === "undefined") return defaultLocale2;
|
|
2213
|
+
return i18n.language || defaultLocale2;
|
|
2214
|
+
};
|
|
2215
|
+
|
|
2216
|
+
// src/i18n/I18nProvider.tsx
|
|
2217
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
2218
|
+
var initialized = false;
|
|
2219
|
+
function getOrCreateI18n(appTranslations, fallbackLocale2) {
|
|
2220
|
+
if (initialized) return i18n2;
|
|
2221
|
+
const resources = {
|
|
2222
|
+
en: {
|
|
2223
|
+
translation: appTranslations?.en || {},
|
|
2224
|
+
[ssoNamespace]: defaultTranslations.en
|
|
2225
|
+
},
|
|
2226
|
+
ja: {
|
|
2227
|
+
translation: appTranslations?.ja || {},
|
|
2228
|
+
[ssoNamespace]: defaultTranslations.ja
|
|
2229
|
+
},
|
|
2230
|
+
vi: {
|
|
2231
|
+
translation: appTranslations?.vi || {},
|
|
2232
|
+
[ssoNamespace]: defaultTranslations.vi
|
|
2233
|
+
}
|
|
2234
|
+
};
|
|
2235
|
+
i18n2.use(LanguageDetector).use(initReactI18next).init({
|
|
2236
|
+
resources,
|
|
2237
|
+
fallbackLng: fallbackLocale2 || defaultLocale2,
|
|
2238
|
+
supportedLngs: locales,
|
|
2239
|
+
detection: {
|
|
2240
|
+
order: ["cookie", "localStorage", "navigator"],
|
|
2241
|
+
caches: ["cookie", "localStorage"],
|
|
2242
|
+
lookupCookie: "locale",
|
|
2243
|
+
lookupLocalStorage: "locale"
|
|
2244
|
+
},
|
|
2245
|
+
interpolation: {
|
|
2246
|
+
escapeValue: false
|
|
2247
|
+
},
|
|
2248
|
+
defaultNS: "translation",
|
|
2249
|
+
ns: ["translation", ssoNamespace],
|
|
2250
|
+
react: {
|
|
2251
|
+
useSuspense: false
|
|
2252
|
+
}
|
|
2253
|
+
});
|
|
2254
|
+
initialized = true;
|
|
2255
|
+
return i18n2;
|
|
2256
|
+
}
|
|
2257
|
+
function I18nProvider({ children, translations, fallbackLocale: fallbackLocale2 }) {
|
|
2258
|
+
const i18nInstance = useMemo7(
|
|
2259
|
+
() => getOrCreateI18n(translations, fallbackLocale2),
|
|
2260
|
+
[translations, fallbackLocale2]
|
|
2261
|
+
);
|
|
2262
|
+
return /* @__PURE__ */ jsx8(I18nextProvider, { i18n: i18nInstance, children });
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
// src/i18n/useTranslations.ts
|
|
2266
|
+
import { useCallback as useCallback8 } from "react";
|
|
2267
|
+
import { useTranslation } from "react-i18next";
|
|
2268
|
+
function useTranslations(namespace) {
|
|
2269
|
+
const { t: i18nT } = useTranslation();
|
|
2270
|
+
const t = useCallback8(
|
|
2271
|
+
(key, values) => {
|
|
2272
|
+
const fullKey = namespace ? `${namespace}.${key}` : key;
|
|
2273
|
+
return i18nT(fullKey, values);
|
|
2274
|
+
},
|
|
2275
|
+
[i18nT, namespace]
|
|
2276
|
+
);
|
|
2277
|
+
return t;
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
// src/i18n/useLocale.ts
|
|
2281
|
+
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
2282
|
+
function useLocale() {
|
|
2283
|
+
const { i18n: i18n3 } = useTranslation2();
|
|
2284
|
+
return i18n3.language || defaultLocale2;
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
// src/components/admin/UserTable.tsx
|
|
2288
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2289
|
+
function UserTable({
|
|
2290
|
+
users,
|
|
2291
|
+
loading = false,
|
|
2292
|
+
pagination,
|
|
2293
|
+
sortField,
|
|
2294
|
+
sortOrder,
|
|
2295
|
+
onPageChange,
|
|
2296
|
+
onSortChange,
|
|
2297
|
+
onSearch,
|
|
2298
|
+
onEdit,
|
|
2299
|
+
onDelete,
|
|
2300
|
+
deleteLoading = false,
|
|
2301
|
+
showSearch = true,
|
|
2302
|
+
showActions = true
|
|
1001
2303
|
}) {
|
|
1002
|
-
const {
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
2304
|
+
const { t } = useSsoTranslation();
|
|
2305
|
+
const columns = [
|
|
2306
|
+
{
|
|
2307
|
+
title: t("email"),
|
|
2308
|
+
dataIndex: "email",
|
|
2309
|
+
key: "email",
|
|
2310
|
+
sorter: true,
|
|
2311
|
+
sortOrder: sortField === "email" ? sortOrder === "asc" ? "ascend" : "descend" : void 0
|
|
2312
|
+
},
|
|
2313
|
+
{
|
|
2314
|
+
title: t("name"),
|
|
2315
|
+
dataIndex: "name",
|
|
2316
|
+
key: "name",
|
|
2317
|
+
sorter: true,
|
|
2318
|
+
sortOrder: sortField === "name" ? sortOrder === "asc" ? "ascend" : "descend" : void 0
|
|
2319
|
+
},
|
|
2320
|
+
{
|
|
2321
|
+
title: "SSO",
|
|
2322
|
+
dataIndex: "console_user_id",
|
|
2323
|
+
key: "sso",
|
|
2324
|
+
width: 100,
|
|
2325
|
+
render: (value) => value ? /* @__PURE__ */ jsx9(Tag, { color: "green", children: t("ssoUser") }) : /* @__PURE__ */ jsx9(Tag, { color: "default", children: t("localUser") })
|
|
1010
2326
|
}
|
|
1011
|
-
|
|
1012
|
-
if (
|
|
1013
|
-
|
|
2327
|
+
];
|
|
2328
|
+
if (showActions && (onEdit || onDelete)) {
|
|
2329
|
+
columns.push({
|
|
2330
|
+
title: t("actions"),
|
|
2331
|
+
key: "actions",
|
|
2332
|
+
width: 120,
|
|
2333
|
+
render: (_, record) => /* @__PURE__ */ jsxs6(Space4, { children: [
|
|
2334
|
+
onEdit && /* @__PURE__ */ jsx9(
|
|
2335
|
+
Button3,
|
|
2336
|
+
{
|
|
2337
|
+
type: "text",
|
|
2338
|
+
icon: /* @__PURE__ */ jsx9(EditOutlined, {}),
|
|
2339
|
+
size: "small",
|
|
2340
|
+
onClick: () => onEdit(record)
|
|
2341
|
+
}
|
|
2342
|
+
),
|
|
2343
|
+
onDelete && /* @__PURE__ */ jsx9(
|
|
2344
|
+
Popconfirm,
|
|
2345
|
+
{
|
|
2346
|
+
title: t("confirmDelete"),
|
|
2347
|
+
onConfirm: () => onDelete(record),
|
|
2348
|
+
okText: t("yes"),
|
|
2349
|
+
cancelText: t("no"),
|
|
2350
|
+
children: /* @__PURE__ */ jsx9(
|
|
2351
|
+
Button3,
|
|
2352
|
+
{
|
|
2353
|
+
type: "text",
|
|
2354
|
+
danger: true,
|
|
2355
|
+
icon: /* @__PURE__ */ jsx9(DeleteOutlined, {}),
|
|
2356
|
+
size: "small",
|
|
2357
|
+
loading: deleteLoading
|
|
2358
|
+
}
|
|
2359
|
+
)
|
|
2360
|
+
}
|
|
2361
|
+
)
|
|
2362
|
+
] })
|
|
2363
|
+
});
|
|
1014
2364
|
}
|
|
1015
|
-
|
|
1016
|
-
if (
|
|
1017
|
-
|
|
2365
|
+
const handleTableChange = (paginationConfig, _filters, sorter) => {
|
|
2366
|
+
if (onPageChange && paginationConfig.current && paginationConfig.pageSize) {
|
|
2367
|
+
onPageChange(paginationConfig.current, paginationConfig.pageSize);
|
|
1018
2368
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
2369
|
+
if (onSortChange) {
|
|
2370
|
+
const singleSorter = Array.isArray(sorter) ? sorter[0] : sorter;
|
|
2371
|
+
if (singleSorter?.field) {
|
|
2372
|
+
onSortChange(
|
|
2373
|
+
singleSorter.field,
|
|
2374
|
+
singleSorter.order === "ascend" ? "asc" : "desc"
|
|
2375
|
+
);
|
|
2376
|
+
} else {
|
|
2377
|
+
onSortChange(void 0, void 0);
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
};
|
|
2381
|
+
return /* @__PURE__ */ jsxs6("div", { children: [
|
|
2382
|
+
showSearch && onSearch && /* @__PURE__ */ jsx9("div", { style: { marginBottom: 16 }, children: /* @__PURE__ */ jsx9(
|
|
2383
|
+
Input,
|
|
1024
2384
|
{
|
|
1025
|
-
|
|
2385
|
+
placeholder: t("searchUsers"),
|
|
2386
|
+
prefix: /* @__PURE__ */ jsx9(SearchOutlined, {}),
|
|
2387
|
+
onChange: (e) => onSearch(e.target.value),
|
|
2388
|
+
style: { width: 300 },
|
|
2389
|
+
allowClear: true
|
|
1026
2390
|
}
|
|
1027
|
-
)
|
|
1028
|
-
|
|
1029
|
-
|
|
2391
|
+
) }),
|
|
2392
|
+
/* @__PURE__ */ jsx9(
|
|
2393
|
+
Table,
|
|
2394
|
+
{
|
|
2395
|
+
columns,
|
|
2396
|
+
dataSource: users,
|
|
2397
|
+
loading,
|
|
2398
|
+
rowKey: "id",
|
|
2399
|
+
onChange: handleTableChange,
|
|
2400
|
+
pagination: pagination ? {
|
|
2401
|
+
current: pagination.current_page,
|
|
2402
|
+
pageSize: pagination.per_page,
|
|
2403
|
+
total: pagination.total,
|
|
2404
|
+
showSizeChanger: true,
|
|
2405
|
+
showTotal: (total) => t("total", { count: total })
|
|
2406
|
+
} : false
|
|
2407
|
+
}
|
|
2408
|
+
)
|
|
2409
|
+
] });
|
|
1030
2410
|
}
|
|
1031
2411
|
|
|
1032
|
-
// src/
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
2412
|
+
// src/components/admin/UserForm.tsx
|
|
2413
|
+
import { Form as Form2, Input as Input2, Button as Button4, Space as Space5 } from "antd";
|
|
2414
|
+
import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2415
|
+
function UserForm({
|
|
2416
|
+
initialValues,
|
|
2417
|
+
onSubmit,
|
|
2418
|
+
onCancel,
|
|
2419
|
+
loading = false,
|
|
2420
|
+
submitText
|
|
2421
|
+
}) {
|
|
2422
|
+
const { t } = useSsoTranslation();
|
|
2423
|
+
const [form] = Form2.useForm();
|
|
2424
|
+
const handleFinish = (values) => {
|
|
2425
|
+
onSubmit(values);
|
|
1041
2426
|
};
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
2427
|
+
return /* @__PURE__ */ jsxs7(
|
|
2428
|
+
Form2,
|
|
2429
|
+
{
|
|
2430
|
+
form,
|
|
2431
|
+
layout: "vertical",
|
|
2432
|
+
initialValues,
|
|
2433
|
+
onFinish: handleFinish,
|
|
2434
|
+
style: { maxWidth: 600 },
|
|
2435
|
+
children: [
|
|
2436
|
+
/* @__PURE__ */ jsx10(
|
|
2437
|
+
Form2.Item,
|
|
2438
|
+
{
|
|
2439
|
+
label: t("name"),
|
|
2440
|
+
name: "name",
|
|
2441
|
+
rules: [
|
|
2442
|
+
{ required: true, message: t("required", { field: t("name") }) },
|
|
2443
|
+
{ max: 255, message: t("maxLength", { field: t("name"), max: 255 }) }
|
|
2444
|
+
],
|
|
2445
|
+
children: /* @__PURE__ */ jsx10(Input2, {})
|
|
2446
|
+
}
|
|
2447
|
+
),
|
|
2448
|
+
/* @__PURE__ */ jsx10(
|
|
2449
|
+
Form2.Item,
|
|
2450
|
+
{
|
|
2451
|
+
label: t("email"),
|
|
2452
|
+
name: "email",
|
|
2453
|
+
rules: [
|
|
2454
|
+
{ required: true, message: t("required", { field: t("email") }) },
|
|
2455
|
+
{ type: "email", message: t("invalidEmail") }
|
|
2456
|
+
],
|
|
2457
|
+
children: /* @__PURE__ */ jsx10(Input2, { type: "email" })
|
|
2458
|
+
}
|
|
2459
|
+
),
|
|
2460
|
+
/* @__PURE__ */ jsx10(Form2.Item, { children: /* @__PURE__ */ jsxs7(Space5, { children: [
|
|
2461
|
+
/* @__PURE__ */ jsx10(Button4, { type: "primary", htmlType: "submit", loading, children: submitText || t("save") }),
|
|
2462
|
+
onCancel && /* @__PURE__ */ jsx10(Button4, { onClick: onCancel, children: t("cancel") })
|
|
2463
|
+
] }) })
|
|
2464
|
+
]
|
|
2465
|
+
}
|
|
2466
|
+
);
|
|
1050
2467
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
2468
|
+
|
|
2469
|
+
// src/utils/branchHeaders.ts
|
|
2470
|
+
var BRANCH_HEADERS = {
|
|
2471
|
+
BRANCH_ID: "X-Branch-Id",
|
|
2472
|
+
ORG_ID: "X-Org-Id",
|
|
2473
|
+
BRANCH_NAME: "X-Branch-Name",
|
|
2474
|
+
BRANCH_CODE: "X-Branch-Code"
|
|
2475
|
+
};
|
|
2476
|
+
function createBranchHeaderSetter(axiosInstance) {
|
|
2477
|
+
return (selection) => {
|
|
2478
|
+
if (selection) {
|
|
2479
|
+
axiosInstance.defaults.headers.common[BRANCH_HEADERS.BRANCH_ID] = selection.branchId;
|
|
2480
|
+
axiosInstance.defaults.headers.common[BRANCH_HEADERS.ORG_ID] = selection.orgId;
|
|
2481
|
+
if (selection.branchName) {
|
|
2482
|
+
axiosInstance.defaults.headers.common[BRANCH_HEADERS.BRANCH_NAME] = selection.branchName;
|
|
2483
|
+
}
|
|
2484
|
+
if (selection.branchCode) {
|
|
2485
|
+
axiosInstance.defaults.headers.common[BRANCH_HEADERS.BRANCH_CODE] = selection.branchCode;
|
|
2486
|
+
}
|
|
2487
|
+
} else {
|
|
2488
|
+
delete axiosInstance.defaults.headers.common[BRANCH_HEADERS.BRANCH_ID];
|
|
2489
|
+
delete axiosInstance.defaults.headers.common[BRANCH_HEADERS.ORG_ID];
|
|
2490
|
+
delete axiosInstance.defaults.headers.common[BRANCH_HEADERS.BRANCH_NAME];
|
|
2491
|
+
delete axiosInstance.defaults.headers.common[BRANCH_HEADERS.BRANCH_CODE];
|
|
2492
|
+
}
|
|
2493
|
+
};
|
|
1055
2494
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
...options,
|
|
1059
|
-
credentials: "include"
|
|
1060
|
-
});
|
|
1061
|
-
if (!response.ok) {
|
|
1062
|
-
const error = await response.json().catch(() => ({}));
|
|
1063
|
-
throw new Error(error.message || `HTTP ${response.status}`);
|
|
1064
|
-
}
|
|
1065
|
-
if (response.status === 204) {
|
|
1066
|
-
return void 0;
|
|
1067
|
-
}
|
|
1068
|
-
return response.json();
|
|
2495
|
+
function setBranchHeaders(axiosInstance, selection) {
|
|
2496
|
+
createBranchHeaderSetter(axiosInstance)(selection);
|
|
1069
2497
|
}
|
|
1070
2498
|
|
|
1071
2499
|
// src/services/authService.ts
|
|
@@ -1184,8 +2612,13 @@ function createRoleService(config) {
|
|
|
1184
2612
|
* List all roles (admin)
|
|
1185
2613
|
* GET /api/admin/sso/roles
|
|
1186
2614
|
*/
|
|
1187
|
-
adminList: async (orgSlug) => {
|
|
1188
|
-
|
|
2615
|
+
adminList: async (orgSlug, params) => {
|
|
2616
|
+
const searchParams = new URLSearchParams();
|
|
2617
|
+
if (params?.["filter[scope]"]) searchParams.set("filter[scope]", params["filter[scope]"]);
|
|
2618
|
+
if (params?.["filter[org_id]"]) searchParams.set("filter[org_id]", params["filter[org_id]"]);
|
|
2619
|
+
const query = searchParams.toString();
|
|
2620
|
+
const path = query ? `/api/admin/sso/roles?${query}` : "/api/admin/sso/roles";
|
|
2621
|
+
return request(apiUrl, path, {
|
|
1189
2622
|
headers: buildHeaders(orgSlug)
|
|
1190
2623
|
});
|
|
1191
2624
|
},
|
|
@@ -1539,66 +2972,87 @@ var getEffectivePermissions = (roleAssignments, allRoles, orgId, branchId) => {
|
|
|
1539
2972
|
return Array.from(permissions);
|
|
1540
2973
|
};
|
|
1541
2974
|
|
|
1542
|
-
// src/services/
|
|
1543
|
-
function
|
|
2975
|
+
// src/services/userService.ts
|
|
2976
|
+
function createUserService(config) {
|
|
1544
2977
|
const { apiUrl } = config;
|
|
2978
|
+
const basePath = "/api/admin/sso/users";
|
|
1545
2979
|
return {
|
|
1546
2980
|
/**
|
|
1547
|
-
*
|
|
1548
|
-
|
|
2981
|
+
* List users with pagination and filtering
|
|
2982
|
+
*/
|
|
2983
|
+
async list(params, orgSlug) {
|
|
2984
|
+
const searchParams = new URLSearchParams();
|
|
2985
|
+
if (params?.page) searchParams.set("page", String(params.page));
|
|
2986
|
+
if (params?.per_page) searchParams.set("per_page", String(params.per_page));
|
|
2987
|
+
if (params?.["filter[search]"]) searchParams.set("filter[search]", params["filter[search]"]);
|
|
2988
|
+
if (params?.["filter[org_id]"]) searchParams.set("filter[org_id]", params["filter[org_id]"]);
|
|
2989
|
+
if (params?.sort) searchParams.set("sort", params.sort);
|
|
2990
|
+
const query = searchParams.toString();
|
|
2991
|
+
const path = query ? `${basePath}?${query}` : basePath;
|
|
2992
|
+
return request(apiUrl, path, {
|
|
2993
|
+
method: "GET",
|
|
2994
|
+
headers: buildHeaders(orgSlug)
|
|
2995
|
+
});
|
|
2996
|
+
},
|
|
2997
|
+
/**
|
|
2998
|
+
* Get user by ID
|
|
1549
2999
|
*/
|
|
1550
|
-
|
|
1551
|
-
const
|
|
1552
|
-
|
|
1553
|
-
headers: buildHeaders()
|
|
3000
|
+
async get(id, orgSlug) {
|
|
3001
|
+
const response = await request(apiUrl, `${basePath}/${id}`, {
|
|
3002
|
+
method: "GET",
|
|
3003
|
+
headers: buildHeaders(orgSlug)
|
|
1554
3004
|
});
|
|
3005
|
+
return response.data;
|
|
1555
3006
|
},
|
|
1556
3007
|
/**
|
|
1557
|
-
*
|
|
1558
|
-
* GET /api/sso/branches/{id}
|
|
3008
|
+
* Update a user
|
|
1559
3009
|
*/
|
|
1560
|
-
|
|
1561
|
-
const response = await request(
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
);
|
|
1566
|
-
return
|
|
3010
|
+
async update(id, input, orgSlug) {
|
|
3011
|
+
const response = await request(apiUrl, `${basePath}/${id}`, {
|
|
3012
|
+
method: "PUT",
|
|
3013
|
+
headers: buildHeaders(orgSlug),
|
|
3014
|
+
body: JSON.stringify(input)
|
|
3015
|
+
});
|
|
3016
|
+
return response.data;
|
|
1567
3017
|
},
|
|
1568
3018
|
/**
|
|
1569
|
-
*
|
|
3019
|
+
* Delete a user
|
|
1570
3020
|
*/
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
`/api/sso/branches${params}`,
|
|
1577
|
-
{ headers: buildHeaders() }
|
|
1578
|
-
);
|
|
1579
|
-
return data.branches.find((b) => b.is_headquarters) ?? null;
|
|
1580
|
-
} catch {
|
|
1581
|
-
return null;
|
|
1582
|
-
}
|
|
3021
|
+
async delete(id, orgSlug) {
|
|
3022
|
+
await request(apiUrl, `${basePath}/${id}`, {
|
|
3023
|
+
method: "DELETE",
|
|
3024
|
+
headers: buildHeaders(orgSlug)
|
|
3025
|
+
});
|
|
1583
3026
|
},
|
|
1584
3027
|
/**
|
|
1585
|
-
*
|
|
3028
|
+
* Search users by email (autocomplete)
|
|
1586
3029
|
*/
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
if (data.primary_branch_id) {
|
|
1596
|
-
return data.branches.find((b) => b.id === data.primary_branch_id) ?? null;
|
|
3030
|
+
async search(email, orgSlug) {
|
|
3031
|
+
if (email.length < 2) return [];
|
|
3032
|
+
const response = await request(
|
|
3033
|
+
apiUrl,
|
|
3034
|
+
`${basePath}/search?email=${encodeURIComponent(email)}`,
|
|
3035
|
+
{
|
|
3036
|
+
method: "GET",
|
|
3037
|
+
headers: buildHeaders(orgSlug)
|
|
1597
3038
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
3039
|
+
);
|
|
3040
|
+
return response.data;
|
|
3041
|
+
},
|
|
3042
|
+
/**
|
|
3043
|
+
* Get user permissions breakdown
|
|
3044
|
+
* Shows roles, teams, and aggregated permissions for a user in context
|
|
3045
|
+
*/
|
|
3046
|
+
async getPermissions(userId, orgId, branchId, orgSlug) {
|
|
3047
|
+
const params = new URLSearchParams();
|
|
3048
|
+
if (orgId) params.set("org_id", orgId);
|
|
3049
|
+
if (branchId) params.set("branch_id", branchId);
|
|
3050
|
+
const query = params.toString();
|
|
3051
|
+
const path = query ? `${basePath}/${userId}/permissions?${query}` : `${basePath}/${userId}/permissions`;
|
|
3052
|
+
return request(apiUrl, path, {
|
|
3053
|
+
method: "GET",
|
|
3054
|
+
headers: buildHeaders(orgSlug)
|
|
3055
|
+
});
|
|
1602
3056
|
}
|
|
1603
3057
|
};
|
|
1604
3058
|
}
|
|
@@ -1618,7 +3072,7 @@ function buildHeaders2(orgSlug) {
|
|
|
1618
3072
|
headers["X-XSRF-TOKEN"] = decodeURIComponent(xsrfToken);
|
|
1619
3073
|
}
|
|
1620
3074
|
if (orgSlug) {
|
|
1621
|
-
headers["X-Org-
|
|
3075
|
+
headers["X-Org-Id"] = orgSlug;
|
|
1622
3076
|
}
|
|
1623
3077
|
return headers;
|
|
1624
3078
|
}
|
|
@@ -1980,110 +3434,27 @@ function createSsoService(config) {
|
|
|
1980
3434
|
}
|
|
1981
3435
|
};
|
|
1982
3436
|
}
|
|
1983
|
-
|
|
1984
|
-
// src/queryKeys.ts
|
|
1985
|
-
var ssoQueryKeys = {
|
|
1986
|
-
all: ["sso"],
|
|
1987
|
-
// =========================================================================
|
|
1988
|
-
// Auth (authService)
|
|
1989
|
-
// =========================================================================
|
|
1990
|
-
auth: {
|
|
1991
|
-
all: () => [...ssoQueryKeys.all, "auth"],
|
|
1992
|
-
user: () => [...ssoQueryKeys.auth.all(), "user"],
|
|
1993
|
-
globalLogoutUrl: (redirectUri) => [...ssoQueryKeys.auth.all(), "global-logout-url", redirectUri]
|
|
1994
|
-
},
|
|
1995
|
-
// =========================================================================
|
|
1996
|
-
// Tokens (tokenService)
|
|
1997
|
-
// =========================================================================
|
|
1998
|
-
tokens: {
|
|
1999
|
-
all: () => [...ssoQueryKeys.all, "tokens"],
|
|
2000
|
-
list: () => [...ssoQueryKeys.tokens.all(), "list"]
|
|
2001
|
-
},
|
|
2002
|
-
// =========================================================================
|
|
2003
|
-
// Roles (roleService)
|
|
2004
|
-
// =========================================================================
|
|
2005
|
-
roles: {
|
|
2006
|
-
all: () => [...ssoQueryKeys.all, "roles"],
|
|
2007
|
-
list: () => [...ssoQueryKeys.roles.all(), "list"],
|
|
2008
|
-
detail: (id) => [...ssoQueryKeys.roles.all(), "detail", id],
|
|
2009
|
-
permissions: (id) => [...ssoQueryKeys.roles.all(), id, "permissions"]
|
|
2010
|
-
},
|
|
2011
|
-
// =========================================================================
|
|
2012
|
-
// Permissions (permissionService)
|
|
2013
|
-
// =========================================================================
|
|
2014
|
-
permissions: {
|
|
2015
|
-
all: () => [...ssoQueryKeys.all, "permissions"],
|
|
2016
|
-
list: (params) => [...ssoQueryKeys.permissions.all(), "list", params],
|
|
2017
|
-
detail: (id) => [...ssoQueryKeys.permissions.all(), "detail", id],
|
|
2018
|
-
matrix: () => [...ssoQueryKeys.permissions.all(), "matrix"]
|
|
2019
|
-
},
|
|
2020
|
-
// =========================================================================
|
|
2021
|
-
// Teams (teamService)
|
|
2022
|
-
// =========================================================================
|
|
2023
|
-
teams: {
|
|
2024
|
-
all: () => [...ssoQueryKeys.all, "teams"],
|
|
2025
|
-
list: () => [...ssoQueryKeys.teams.all(), "list"],
|
|
2026
|
-
permissions: (teamId) => [...ssoQueryKeys.teams.all(), teamId, "permissions"],
|
|
2027
|
-
orphaned: () => [...ssoQueryKeys.teams.all(), "orphaned"]
|
|
2028
|
-
},
|
|
2029
|
-
// =========================================================================
|
|
2030
|
-
// User Roles (userRoleService) - Scoped Role Assignments
|
|
2031
|
-
// =========================================================================
|
|
2032
|
-
userRoles: {
|
|
2033
|
-
all: () => [...ssoQueryKeys.all, "user-roles"],
|
|
2034
|
-
list: (userId) => [...ssoQueryKeys.userRoles.all(), userId],
|
|
2035
|
-
byBranch: (userId, orgId, branchId) => [...ssoQueryKeys.userRoles.all(), userId, orgId, branchId]
|
|
2036
|
-
},
|
|
2037
|
-
// =========================================================================
|
|
2038
|
-
// Branches (branchService)
|
|
2039
|
-
// =========================================================================
|
|
2040
|
-
branches: {
|
|
2041
|
-
all: () => [...ssoQueryKeys.all, "branches"],
|
|
2042
|
-
list: (orgSlug) => [...ssoQueryKeys.branches.all(), "list", orgSlug],
|
|
2043
|
-
detail: (branchId) => [...ssoQueryKeys.branches.all(), "detail", branchId],
|
|
2044
|
-
headquarters: (orgSlug) => [...ssoQueryKeys.branches.all(), "headquarters", orgSlug],
|
|
2045
|
-
primary: (orgSlug) => [...ssoQueryKeys.branches.all(), "primary", orgSlug]
|
|
2046
|
-
},
|
|
2047
|
-
// =========================================================================
|
|
2048
|
-
// Admin variants (with org context)
|
|
2049
|
-
// =========================================================================
|
|
2050
|
-
admin: {
|
|
2051
|
-
roles: {
|
|
2052
|
-
all: (orgSlug) => [...ssoQueryKeys.all, "admin", orgSlug, "roles"],
|
|
2053
|
-
list: (orgSlug) => [...ssoQueryKeys.admin.roles.all(orgSlug), "list"],
|
|
2054
|
-
detail: (orgSlug, id) => [...ssoQueryKeys.admin.roles.all(orgSlug), "detail", id],
|
|
2055
|
-
permissions: (orgSlug, id) => [...ssoQueryKeys.admin.roles.all(orgSlug), id, "permissions"]
|
|
2056
|
-
},
|
|
2057
|
-
permissions: {
|
|
2058
|
-
all: (orgSlug) => [...ssoQueryKeys.all, "admin", orgSlug, "permissions"],
|
|
2059
|
-
list: (orgSlug, params) => [...ssoQueryKeys.admin.permissions.all(orgSlug), "list", params],
|
|
2060
|
-
detail: (orgSlug, id) => [...ssoQueryKeys.admin.permissions.all(orgSlug), "detail", id],
|
|
2061
|
-
matrix: (orgSlug) => [...ssoQueryKeys.admin.permissions.all(orgSlug), "matrix"]
|
|
2062
|
-
},
|
|
2063
|
-
teams: {
|
|
2064
|
-
all: (orgSlug) => [...ssoQueryKeys.all, "admin", orgSlug, "teams"],
|
|
2065
|
-
list: (orgSlug) => [...ssoQueryKeys.admin.teams.all(orgSlug), "list"],
|
|
2066
|
-
permissions: (orgSlug, teamId) => [...ssoQueryKeys.admin.teams.all(orgSlug), teamId, "permissions"],
|
|
2067
|
-
orphaned: (orgSlug) => [...ssoQueryKeys.admin.teams.all(orgSlug), "orphaned"]
|
|
2068
|
-
},
|
|
2069
|
-
userRoles: {
|
|
2070
|
-
all: (orgSlug) => [...ssoQueryKeys.all, "admin", orgSlug, "user-roles"],
|
|
2071
|
-
list: (orgSlug, userId) => [...ssoQueryKeys.admin.userRoles.all(orgSlug), userId],
|
|
2072
|
-
byBranch: (orgSlug, userId, orgId, branchId) => [...ssoQueryKeys.admin.userRoles.all(orgSlug), userId, orgId, branchId]
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
};
|
|
2076
3437
|
export {
|
|
3438
|
+
BRANCH_HEADERS,
|
|
3439
|
+
BranchContext,
|
|
3440
|
+
BranchGate,
|
|
3441
|
+
BranchProvider,
|
|
3442
|
+
I18nProvider,
|
|
3443
|
+
OrgBranchSelectorModal,
|
|
2077
3444
|
OrganizationSwitcher,
|
|
2078
3445
|
ProtectedRoute,
|
|
2079
3446
|
SsoCallback,
|
|
2080
3447
|
SsoContext,
|
|
2081
3448
|
SsoProvider,
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
3449
|
+
UserForm,
|
|
3450
|
+
UserTable,
|
|
3451
|
+
branchCacheCreateSchema,
|
|
3452
|
+
branchCacheI18n,
|
|
3453
|
+
branchCacheSchemas,
|
|
3454
|
+
branchCacheUpdateSchema,
|
|
3455
|
+
changeLanguage,
|
|
2086
3456
|
createAuthService,
|
|
3457
|
+
createBranchHeaderSetter,
|
|
2087
3458
|
createBranchService,
|
|
2088
3459
|
createPermissionService,
|
|
2089
3460
|
createRoleService,
|
|
@@ -2091,14 +3462,20 @@ export {
|
|
|
2091
3462
|
createTeamService,
|
|
2092
3463
|
createTokenService,
|
|
2093
3464
|
createUserRoleService,
|
|
2094
|
-
|
|
3465
|
+
createUserService,
|
|
3466
|
+
defaultLocale2 as defaultLocale,
|
|
3467
|
+
defaultTranslations,
|
|
2095
3468
|
fallbackLocale,
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
3469
|
+
getBranchCacheFieldLabel,
|
|
3470
|
+
getBranchCacheFieldPlaceholder,
|
|
3471
|
+
getBranchCacheLabel,
|
|
3472
|
+
getCurrentLocale,
|
|
2099
3473
|
getEffectivePermissions,
|
|
2100
3474
|
getMessage,
|
|
2101
3475
|
getMessages,
|
|
3476
|
+
getOrganizationCacheFieldLabel,
|
|
3477
|
+
getOrganizationCacheFieldPlaceholder,
|
|
3478
|
+
getOrganizationCacheLabel,
|
|
2102
3479
|
getPermissionFieldLabel,
|
|
2103
3480
|
getPermissionFieldPlaceholder,
|
|
2104
3481
|
getPermissionLabel,
|
|
@@ -2109,15 +3486,21 @@ export {
|
|
|
2109
3486
|
getRolePermissionFieldPlaceholder,
|
|
2110
3487
|
getRolePermissionLabel,
|
|
2111
3488
|
getScopeLabel,
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
3489
|
+
getTeamCacheFieldLabel,
|
|
3490
|
+
getTeamCacheFieldPlaceholder,
|
|
3491
|
+
getTeamCacheLabel,
|
|
2115
3492
|
getTeamPermissionFieldLabel,
|
|
2116
3493
|
getTeamPermissionFieldPlaceholder,
|
|
2117
3494
|
getTeamPermissionLabel,
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
3495
|
+
getUserCacheFieldLabel,
|
|
3496
|
+
getUserCacheFieldPlaceholder,
|
|
3497
|
+
getUserCacheLabel,
|
|
3498
|
+
localeNames,
|
|
3499
|
+
locales,
|
|
3500
|
+
organizationCacheCreateSchema,
|
|
3501
|
+
organizationCacheI18n,
|
|
3502
|
+
organizationCacheSchemas,
|
|
3503
|
+
organizationCacheUpdateSchema,
|
|
2121
3504
|
permissionCreateSchema,
|
|
2122
3505
|
permissionI18n,
|
|
2123
3506
|
permissionSchemas,
|
|
@@ -2130,23 +3513,30 @@ export {
|
|
|
2130
3513
|
rolePermissionUpdateSchema,
|
|
2131
3514
|
roleSchemas,
|
|
2132
3515
|
roleUpdateSchema,
|
|
3516
|
+
setBranchHeaders,
|
|
3517
|
+
ssoNamespace,
|
|
2133
3518
|
ssoQueryKeys,
|
|
2134
3519
|
supportedLocales,
|
|
2135
|
-
|
|
2136
|
-
|
|
3520
|
+
teamCacheCreateSchema,
|
|
3521
|
+
teamCacheI18n,
|
|
3522
|
+
teamCacheSchemas,
|
|
3523
|
+
teamCacheUpdateSchema,
|
|
2137
3524
|
teamPermissionCreateSchema,
|
|
2138
3525
|
teamPermissionI18n,
|
|
2139
3526
|
teamPermissionSchemas,
|
|
2140
3527
|
teamPermissionUpdateSchema,
|
|
2141
|
-
teamSchemas,
|
|
2142
|
-
teamUpdateSchema,
|
|
2143
3528
|
useAuth,
|
|
3529
|
+
useBranch,
|
|
3530
|
+
useBranchGate,
|
|
3531
|
+
useLocale,
|
|
2144
3532
|
useOrganization,
|
|
2145
3533
|
useSso,
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
3534
|
+
useSsoTranslation,
|
|
3535
|
+
useTranslations,
|
|
3536
|
+
userCacheCreateSchema,
|
|
3537
|
+
userCacheI18n,
|
|
3538
|
+
userCacheSchemas,
|
|
3539
|
+
userCacheUpdateSchema,
|
|
2150
3540
|
validationMessages
|
|
2151
3541
|
};
|
|
2152
3542
|
//# sourceMappingURL=index.js.map
|