@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/index.js CHANGED
@@ -1208,12 +1208,27 @@ function PermissionProvider({ children, usePermission, fallbackRulesMap, }) {
1208
1208
  return { ...fallbackRulesMap, ...rulesMap };
1209
1209
  }, [rulesMap, fallbackRulesMap]);
1210
1210
  const requiredRoles = React.useMemo(() => getRequiredChildGroups(pathname, mergedMap), [pathname, mergedMap]);
1211
+ // Hook must run unconditionally (rules of hooks); we just ignore the
1212
+ // result on the fast path below.
1211
1213
  const { hasPermission, isLoading, userRoles } = usePermission({
1212
1214
  requiredRoles,
1213
1215
  });
1216
+ // Fast path — no rule covers this pathname, anyone can see it. Skip the
1217
+ // probe UI entirely; flashing "checking permission" or "no access" on an
1218
+ // unrestricted page is pure noise.
1219
+ if (requiredRoles.length === 0) {
1220
+ return jsxRuntime.jsx(jsxRuntime.Fragment, { children: children });
1221
+ }
1222
+ // While the answer hasn't settled, render nothing and let the surrounding
1223
+ // Next.js loading.tsx / Suspense fallback show. The old behaviour wrapped
1224
+ // a big "กำลังตรวจสอบสิทธิ์..." card over the top, which both duplicated
1225
+ // the app's own loader and — worse — caused a "ไม่มีสิทธิ์" flash on
1226
+ // fast loads because the probe transiently returned `hasPermission:false,
1227
+ // isLoading:false` before its dependencies (org context, role-segments)
1228
+ // arrived.
1214
1229
  const isLoadingCombined = rulesLoading || isLoading;
1215
1230
  if (isLoadingCombined) {
1216
- return (jsxRuntime.jsx(erpTheme.Card, { className: "p-6", children: jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-3", children: [jsxRuntime.jsx(lucideReact.Loader2, { className: "h-5 w-5 animate-spin text-muted-foreground" }), jsxRuntime.jsx("span", { className: "text-sm text-muted-foreground", children: "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E15\u0E23\u0E27\u0E08\u0E2A\u0E2D\u0E1A\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E01\u0E32\u0E23\u0E40\u0E02\u0E49\u0E32\u0E16\u0E36\u0E07..." })] }) }));
1231
+ return null;
1217
1232
  }
1218
1233
  if (!hasPermission) {
1219
1234
  return (jsxRuntime.jsx(erpTheme.Card, { className: "p-6", children: jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center gap-3 text-center", children: [jsxRuntime.jsx(lucideReact.AlertCircle, { className: "h-8 w-8 text-destructive" }), jsxRuntime.jsxs("div", { className: "space-y-1", children: [jsxRuntime.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" }), jsxRuntime.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 && (jsxRuntime.jsxs("div", { className: "mt-3 space-y-1", children: [jsxRuntime.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:" }), jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1 justify-center", children: requiredRoles.map((role, idx) => (jsxRuntime.jsx("span", { className: "rounded bg-muted px-2 py-0.5 text-xs font-mono", children: role }, idx))) })] })), userRoles.length > 0 && (jsxRuntime.jsxs("div", { className: "mt-3 space-y-1", children: [jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13:" }), jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1 justify-center", children: userRoles.map((role, idx) => (jsxRuntime.jsx("span", { className: "rounded bg-primary/10 px-2 py-0.5 text-xs font-mono text-primary", children: role }, idx))) })] }))] })] }) }));