@eintrek/erp-shell 0.1.11 → 0.1.12
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/dist/auth/permission-provider.d.ts +1 -1
- package/dist/index.esm.js +16 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -41,4 +41,4 @@ export interface PermissionProviderProps {
|
|
|
41
41
|
* The host wraps `<PermissionProvider>` around its page chrome (typically
|
|
42
42
|
* via `AppLayoutShell`'s `permissionProvider` slot).
|
|
43
43
|
*/
|
|
44
|
-
export declare function PermissionProvider({ children, usePermission, fallbackRulesMap, }: PermissionProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
44
|
+
export declare function PermissionProvider({ children, usePermission, fallbackRulesMap, }: PermissionProviderProps): import("react/jsx-runtime").JSX.Element | null;
|
package/dist/index.esm.js
CHANGED
|
@@ -1189,12 +1189,27 @@ function PermissionProvider({ children, usePermission, fallbackRulesMap, }) {
|
|
|
1189
1189
|
return { ...fallbackRulesMap, ...rulesMap };
|
|
1190
1190
|
}, [rulesMap, fallbackRulesMap]);
|
|
1191
1191
|
const requiredRoles = useMemo(() => getRequiredChildGroups(pathname, mergedMap), [pathname, mergedMap]);
|
|
1192
|
+
// Hook must run unconditionally (rules of hooks); we just ignore the
|
|
1193
|
+
// result on the fast path below.
|
|
1192
1194
|
const { hasPermission, isLoading, userRoles } = usePermission({
|
|
1193
1195
|
requiredRoles,
|
|
1194
1196
|
});
|
|
1197
|
+
// Fast path — no rule covers this pathname, anyone can see it. Skip the
|
|
1198
|
+
// probe UI entirely; flashing "checking permission" or "no access" on an
|
|
1199
|
+
// unrestricted page is pure noise.
|
|
1200
|
+
if (requiredRoles.length === 0) {
|
|
1201
|
+
return jsx(Fragment$1, { children: children });
|
|
1202
|
+
}
|
|
1203
|
+
// While the answer hasn't settled, render nothing and let the surrounding
|
|
1204
|
+
// Next.js loading.tsx / Suspense fallback show. The old behaviour wrapped
|
|
1205
|
+
// a big "กำลังตรวจสอบสิทธิ์..." card over the top, which both duplicated
|
|
1206
|
+
// the app's own loader and — worse — caused a "ไม่มีสิทธิ์" flash on
|
|
1207
|
+
// fast loads because the probe transiently returned `hasPermission:false,
|
|
1208
|
+
// isLoading:false` before its dependencies (org context, role-segments)
|
|
1209
|
+
// arrived.
|
|
1195
1210
|
const isLoadingCombined = rulesLoading || isLoading;
|
|
1196
1211
|
if (isLoadingCombined) {
|
|
1197
|
-
return
|
|
1212
|
+
return null;
|
|
1198
1213
|
}
|
|
1199
1214
|
if (!hasPermission) {
|
|
1200
1215
|
return (jsx(Card, { className: "p-6", children: jsxs("div", { className: "flex flex-col items-center justify-center gap-3 text-center", children: [jsx(AlertCircle, { className: "h-8 w-8 text-destructive" }), jsxs("div", { className: "space-y-1", children: [jsx("h3", { className: "text-lg font-semibold text-destructive", children: "\u0E44\u0E21\u0E48\u0E21\u0E35\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E40\u0E02\u0E49\u0E32\u0E16\u0E36\u0E07" }), jsx("p", { className: "text-sm text-muted-foreground", children: "\u0E04\u0E38\u0E13\u0E44\u0E21\u0E48\u0E21\u0E35\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E43\u0E19\u0E01\u0E32\u0E23\u0E40\u0E02\u0E49\u0E32\u0E16\u0E36\u0E07\u0E2B\u0E19\u0E49\u0E32\u0E19\u0E35\u0E49" }), requiredRoles.length > 0 && (jsxs("div", { className: "mt-3 space-y-1", children: [jsx("p", { className: "text-xs text-muted-foreground", children: "\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E17\u0E35\u0E48\u0E15\u0E49\u0E2D\u0E07\u0E01\u0E32\u0E23:" }), jsx("div", { className: "flex flex-wrap gap-1 justify-center", children: requiredRoles.map((role, idx) => (jsx("span", { className: "rounded bg-muted px-2 py-0.5 text-xs font-mono", children: role }, idx))) })] })), userRoles.length > 0 && (jsxs("div", { className: "mt-3 space-y-1", children: [jsx("p", { className: "text-xs text-muted-foreground", children: "\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13:" }), jsx("div", { className: "flex flex-wrap gap-1 justify-center", children: userRoles.map((role, idx) => (jsx("span", { className: "rounded bg-primary/10 px-2 py-0.5 text-xs font-mono text-primary", children: role }, idx))) })] }))] })] }) }));
|