@telamonjs/ui 1.2.1 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +1 -1
  3. package/dist/components/data/DataTableActions.js +1 -0
  4. package/dist/components/data/action-access.d.ts +9 -2
  5. package/dist/components/data/action-access.js +10 -3
  6. package/dist/components/dialog/CrudDialogShell.d.ts +2 -0
  7. package/dist/components/dialog/CrudDialogShell.js +9 -7
  8. package/dist/components/dialog/DialogLoadingState.d.ts +16 -0
  9. package/dist/components/dialog/DialogLoadingState.js +16 -0
  10. package/dist/components/dialog/confirm-action-dialog.d.ts +12 -4
  11. package/dist/components/dialog/confirm-action-dialog.js +156 -82
  12. package/dist/components/dialog/create-dialog.js +1 -12
  13. package/dist/components/dialog/edit-dialog.js +5 -4
  14. package/dist/components/dialog/index.d.ts +1 -1
  15. package/dist/components/dialog/index.js +1 -2
  16. package/dist/components/dialog/view-dialog.js +5 -4
  17. package/dist/components/utilities/QueryErrorState.d.ts +47 -0
  18. package/dist/components/utilities/QueryErrorState.js +85 -0
  19. package/dist/data/DataTable.d.ts +2 -2
  20. package/dist/data/DataTable.js +2 -0
  21. package/dist/data/ExportMenu.d.ts +30 -3
  22. package/dist/data/ExportMenu.js +69 -5
  23. package/dist/data/datatable/TableToolbar.d.ts +3 -2
  24. package/dist/data/datatable/TableToolbar.js +30 -13
  25. package/dist/data/datatable/types.d.ts +9 -0
  26. package/dist/data/fetch-all-pages.d.ts +30 -0
  27. package/dist/data/fetch-all-pages.js +44 -0
  28. package/dist/exports/data-crud.d.ts +7 -3
  29. package/dist/exports/data-crud.js +4 -0
  30. package/dist/exports/types-constants.d.ts +2 -2
  31. package/dist/exports/types-constants.js +1 -1
  32. package/dist/i18n/messages/en/data.d.ts +3 -0
  33. package/dist/i18n/messages/en/data.js +3 -0
  34. package/dist/i18n/messages/en/index.d.ts +5 -0
  35. package/dist/i18n/messages/en/validation.d.ts +2 -0
  36. package/dist/i18n/messages/en/validation.js +2 -0
  37. package/dist/i18n/messages/es/data.d.ts +3 -0
  38. package/dist/i18n/messages/es/data.js +3 -0
  39. package/dist/i18n/messages/es/index.d.ts +5 -0
  40. package/dist/i18n/messages/es/validation.d.ts +2 -0
  41. package/dist/i18n/messages/es/validation.js +2 -0
  42. package/dist/i18n/messages/pt-BR/data.d.ts +3 -0
  43. package/dist/i18n/messages/pt-BR/data.js +3 -0
  44. package/dist/i18n/messages/pt-BR/index.d.ts +5 -0
  45. package/dist/i18n/messages/pt-BR/validation.d.ts +2 -0
  46. package/dist/i18n/messages/pt-BR/validation.js +2 -0
  47. package/dist/i18n/use-t.d.ts +5 -0
  48. package/dist/pages/ListPage.js +9 -13
  49. package/dist/pages/list-page/ListPageTable.d.ts +4 -2
  50. package/dist/pages/list-page/ListPageTable.js +3 -3
  51. package/dist/pages/list-page/ListPageToolbar.d.ts +4 -1
  52. package/dist/pages/list-page/ListPageToolbar.js +10 -4
  53. package/dist/pages/list-page/apply-crud-permissions.d.ts +4 -1
  54. package/dist/pages/list-page/apply-crud-permissions.js +20 -3
  55. package/dist/pages/list-page/types.d.ts +2 -16
  56. package/dist/pages/list-page/useListPageExport.d.ts +24 -0
  57. package/dist/pages/list-page/useListPageExport.js +54 -0
  58. package/dist/types/actions.d.ts +43 -4
  59. package/dist/types/crud.d.ts +48 -2
  60. package/package.json +1 -1
  61. package/dist/components/dialog/DialogErrorState.d.ts +0 -44
  62. package/dist/components/dialog/DialogErrorState.js +0 -57
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 25f34e0: `ConfirmActionDialog` (and `confirmDialog.inputs` on row actions) focuses the first input on open,
8
+ so a reason can be typed right away. Without inputs, focus still starts on Cancel.
9
+
10
+ ## 1.3.0
11
+
12
+ ### Minor Changes
13
+
14
+ - 5a8b1b6: `ConfirmActionDialog` and `confirmDialog.inputs`: length, date and native field options, and an opt-in "disabled until valid" mode.
15
+
16
+ - `ConfirmDialogInput` gains `minLength`/`maxLength` (on the trimmed value; `minLength` checks an optional field only once it is filled), `min`/`max` for `date` (set on the native input and validated), `options` as `{ value, label }` (new `ConfirmDialogOption`; plain strings still work), `placeholder`, `description` (help text announced with the field), `rows` for `textarea`, `suggestions` for `text` (a native `<datalist>`) and the native `inputMode`/`autoComplete`.
17
+ - A `minLength`/`maxLength` input shows how many characters are missing or over as the user types, before any confirm attempt (new `validation.charactersMissing`/`charactersOver` messages in pt-BR, en and es).
18
+ - New `disableUntilValid` (on `ConfirmActionDialog` and on `ConfirmDialogConfig`): the confirm stays disabled while any input fails, and every failing field shows its message live — muted until edited, as an error once edited or after an attempt — so the reason is always visible. Without it, nothing changes: the confirm stays enabled and messages show from the first attempt, as in 1.2.
19
+
20
+ - 0429b6c: `CrudConfig.permissions` no longer fails open silently.
21
+
22
+ - In development, `ListPage` warns once per config when `permissions` declares operations but there is no way to check them (neither `permissions.can`, `actionsConfig.can` nor `actionsConfig.userPermissions`), which means every write button shows. Production behaviour is unchanged.
23
+ - New opt-in `permissions.failClosed` (same name and meaning as in `@telamonjs/permissions`): with no checker, every declared operation and every action `permission` is denied instead of allowed — useful while the session that feeds `can` is still loading. Default `false`.
24
+ - `applyCrudPermissions` now checks against the `actionsConfig` the list actually uses (it read `config.actionsConfig` for the dialogs only).
25
+
26
+ - 6349bde: `ListPage` export can cover every matching row, or hand the export to the app. The default is unchanged: "All" exports the rows already loaded.
27
+
28
+ - `list.exportAll: true | { pageSize?, maxRows? }`: "All" fetches every row matching the current search, filters and sort through `query.queryFn`, page by page and sequentially, honoring `totalPages`. A progress toast offers Cancel. Rows are capped at `maxRows` (default 10 000), with a warning when the file holds fewer rows than the server total. Requests use `exportAll.pageSize`, else `defaultPageSize` (50).
29
+ - `list.onExport(state: ListQueryState, format)`: an app-side export (e.g. a server-generated file). The menu lists the formats only and calls it with the same query `toolbarContent` receives. It wins over `exportAll`, shows the menu without `enableExport`, and errors show the export error toast.
30
+ - `list.exportFormats` picks the formats offered.
31
+ - `ExportMenu` gains `loadAll` (+ `allCount`) and `onServerExport`, and `DataTable` gains `exportMenuProps` to pass them through. New public `fetchAllPages()` helper and `ExportFormat`, `ExportLoadAllContext`, `ExportAllOptions`, `FetchAllPagesOptions`, `DataTableExportMenuProps` types.
32
+
33
+ Fix: the paginated `ListPage` (`infiniteScroll: false`) no longer exports through a raw `Object.values` CSV without headers. It uses the same Excel/CSV/PDF menu as the infinite list, with the list's columns and filename, now also available below `lg` through a compact trigger.
34
+
35
+ - df92415: New public `QueryErrorState`: the error state for screens that run their own `useQuery`, so apps stop keeping a local `QueryErrorAlert`.
36
+
37
+ - `error` (an `Error`, a string or any object with a string `message`) becomes the description; `title` and `description` take `I18nText`, with a localized "Failed to load data" default.
38
+ - `onRetry` shows a "Try again" button, called with no arguments (`onRetry={refetch}` is safe), pending (disabled, spinner, `aria-busy`) while the promise it returns runs; `retrying` drives the same state from the caller. The button is `type="button"`.
39
+ - It is now the single implementation behind the CRUD view/edit dialogs' load error, which gain a working "Try again" (they had none). The internal `DialogErrorState` is gone, and so is the never-set error branch of `CreateDialog`.
40
+
41
+ Migrating a local `QueryErrorAlert({ message, onRetry })`: `message` → `title` (or `description`), `onRetry={() => refetch()}` → `onRetry={refetch}`, and add `className='mb-4'` where the layout relied on the local copy's margin.
42
+
3
43
  ## 1.2.1
4
44
 
5
45
  ### Patch Changes
package/README.md CHANGED
@@ -89,7 +89,7 @@ async `loadField`), `'multiselect'`, `'richtext'` and 31 more; there is no
89
89
  | Forms | `AdminForm`, `CreateForm`, `EditForm`, `Stepper`, `FileUpload`, `useUnsavedChangesGuard` |
90
90
  | Field system | 36 field types; `registerFieldRenderer` adds your own |
91
91
  | Shell | `AdminShell` (sidebar, breadcrumb, header, Cmd+K palette fed from your menu), `ShellPage`, `AdminTabs`, `ImpersonationBanner` |
92
- | Data | `DataTable`, `VirtualDataTable`, `InfiniteList`, bulk actions, Excel/CSV/PDF export |
92
+ | Data | `DataTable`, `VirtualDataTable`, `InfiniteList`, bulk actions, Excel/CSV/PDF export, `QueryErrorState` (error + pending "Try again" for your own `useQuery`) |
93
93
  | Dashboards and charts | `DashboardGrid`, `DashboardShell`, `StatCard`, `ChartWidget`, `LineChart`, `BarChart`, `PieChart`, `AreaChart`, `KPICard` |
94
94
  | Queue UI | `@telamonjs/ui/queue`: `QueueTabbedDashboard`, `QueueApiProvider`, `createNestJSAdapter`, a frontend for `@telamonjs/queue` |
95
95
  | Server | `@telamonjs/ui/server`: `createPaginationContext`, `buildPrismaOrderBy`, `createPaginatedResponse`, `revalidatePathAction` |
@@ -97,6 +97,7 @@ function RowConfirmDialog({
97
97
  cancelText: config?.cancelText,
98
98
  variant: config?.variant,
99
99
  inputs,
100
+ disableUntilValid: config?.disableUntilValid,
100
101
  onConfirm: (values) => onRun(inputs ? { inputs: values } : void 0),
101
102
  children
102
103
  }
@@ -10,12 +10,19 @@ import type { CrudConfig, CrudPermissions } from '../../types/crud';
10
10
  * `userPermissions`. Neither = everything allowed.
11
11
  */
12
12
  export declare function actionGranted(permission: ActionConfig['permission'], userPermissions: readonly string[] | ReadonlySet<string> | undefined, can?: (permission: string) => boolean): boolean;
13
+ /**
14
+ * The permission checker a CrudConfig resolves to: `actionsConfig.can`, else
15
+ * `permissions.can`. With neither and no `actionsConfig.userPermissions`, it is
16
+ * `undefined` (everything allowed) — or a checker that denies everything when
17
+ * `permissions.failClosed` is set.
18
+ */
19
+ export declare function crudChecker(config: Pick<CrudConfig, 'permissions' | 'actionsConfig'>): ((permission: string) => boolean) | undefined;
13
20
  /**
14
21
  * A CrudConfig operation (`permissions.create`, …) against the same checker the
15
22
  * row actions use: `permissions.can` or `actionsConfig.can`, else
16
- * `actionsConfig.userPermissions`.
23
+ * `actionsConfig.userPermissions` (see `crudChecker` for `failClosed`).
17
24
  */
18
- export declare function crudGranted(config: Pick<CrudConfig, 'permissions' | 'actionsConfig'>, operation: keyof Omit<CrudPermissions, 'can'>): boolean;
25
+ export declare function crudGranted(config: Pick<CrudConfig, 'permissions' | 'actionsConfig'>, operation: Exclude<keyof CrudPermissions, 'can' | 'failClosed'>): boolean;
19
26
  /** `visible` for this row (`undefined` = visible). */
20
27
  export declare function actionVisible<TData>(action: Pick<ActionConfig<TData>, 'visible'>, row: TData): boolean;
21
28
  /** `enabled` for this row (`undefined` = enabled). */
@@ -7,12 +7,18 @@ function actionGranted(permission, userPermissions, can) {
7
7
  const granted = userPermissions instanceof Set ? userPermissions : new Set(userPermissions);
8
8
  return required.some((perm) => granted.has(perm));
9
9
  }
10
- function crudGranted(config, operation) {
10
+ var denyAll = () => false;
11
+ function crudChecker(config) {
11
12
  const actions = config.actionsConfig || void 0;
13
+ const can = actions?.can ?? config.permissions?.can;
14
+ if (can || actions?.userPermissions) return can;
15
+ return config.permissions?.failClosed ? denyAll : void 0;
16
+ }
17
+ function crudGranted(config, operation) {
12
18
  return actionGranted(
13
19
  config.permissions?.[operation],
14
- actions?.userPermissions,
15
- actions?.can ?? config.permissions?.can
20
+ (config.actionsConfig || void 0)?.userPermissions,
21
+ crudChecker(config)
16
22
  );
17
23
  }
18
24
  function actionVisible(action, row) {
@@ -29,5 +35,6 @@ export {
29
35
  actionEnabled,
30
36
  actionGranted,
31
37
  actionVisible,
38
+ crudChecker,
32
39
  crudGranted
33
40
  };
@@ -11,6 +11,8 @@ export interface CrudDialogDesktopStatus {
11
11
  isLoading: boolean;
12
12
  /** Error message, if any */
13
13
  error: string | null;
14
+ /** "Try again" on the error state */
15
+ onRetry?: () => void;
14
16
  }
15
17
  /**
16
18
  * Props for the internal CrudDialogShell component.
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
 
3
3
  // src/components/dialog/CrudDialogShell.tsx
4
- import { AlertCircle } from "lucide-react";
5
4
  import { useIsMobile } from "../../hooks/use-mobile.js";
6
5
  import {
7
6
  Dialog,
@@ -18,8 +17,8 @@ import {
18
17
  SheetTitle
19
18
  } from "../../ui/sheet.js";
20
19
  import { cn } from "../../utils/index.js";
21
- import { Alert, AlertDescription } from "../../ui/alert.js";
22
- import { DialogLoadingState } from "./DialogErrorState.js";
20
+ import { DialogLoadingState } from "./DialogLoadingState.js";
21
+ import { QueryErrorState } from "../utilities/QueryErrorState.js";
23
22
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
24
23
  function CrudDialogShell({
25
24
  open,
@@ -69,10 +68,13 @@ function CrudDialogShell({
69
68
  children: [
70
69
  /* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: title }),
71
70
  desktopStatus.isLoading && /* @__PURE__ */ jsx(DialogLoadingState, {}),
72
- desktopStatus.error && /* @__PURE__ */ jsx("div", { className: "py-8 w-full px-6", children: /* @__PURE__ */ jsxs(Alert, { variant: "destructive", children: [
73
- /* @__PURE__ */ jsx(AlertCircle, { className: "h-4 w-4" }),
74
- /* @__PURE__ */ jsx(AlertDescription, { children: desktopStatus.error })
75
- ] }) })
71
+ desktopStatus.error && /* @__PURE__ */ jsx("div", { className: "py-8 w-full px-6", children: /* @__PURE__ */ jsx(
72
+ QueryErrorState,
73
+ {
74
+ error: desktopStatus.error,
75
+ onRetry: desktopStatus.onRetry
76
+ }
77
+ ) })
76
78
  ]
77
79
  }
78
80
  ) });
@@ -0,0 +1,16 @@
1
+ export interface DialogLoadingStateProps {
2
+ /** Loading message */
3
+ message?: string;
4
+ }
5
+ /**
6
+ * DialogLoadingState - Renders loading spinner with optional message.
7
+ *
8
+ * Consolidates the duplicated loading spinner rendering from EditDialog and ViewDialog.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * {isLoading && <DialogLoadingState />}
13
+ * {isLoading && <DialogLoadingState message="Buscando dados..." />}
14
+ * ```
15
+ */
16
+ export declare function DialogLoadingState({ message }: DialogLoadingStateProps): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ "use client";
2
+
3
+ // src/components/dialog/DialogLoadingState.tsx
4
+ import { Loader2 } from "lucide-react";
5
+ import { useTelamonjsT } from "../../i18n/use-t.js";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ function DialogLoadingState({ message }) {
8
+ const t = useTelamonjsT();
9
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center py-12 space-y-4", children: [
10
+ /* @__PURE__ */ jsx(Loader2, { className: "h-8 w-8 animate-spin text-primary" }),
11
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: message ?? t("dialog.loadingData") })
12
+ ] });
13
+ }
14
+ export {
15
+ DialogLoadingState
16
+ };
@@ -32,10 +32,17 @@ export interface ConfirmActionDialogProps {
32
32
  */
33
33
  pending?: boolean;
34
34
  /**
35
- * Fields asked before confirming; `required` and `validate` block the
36
- * confirm while they fail
35
+ * Fields asked before confirming; `required`, `minLength`, `maxLength`,
36
+ * `min`/`max` and `validate` block the confirm while they fail
37
37
  */
38
38
  inputs?: ConfirmDialogInput[];
39
+ /**
40
+ * Keep the confirm disabled while any input fails, each failing field
41
+ * showing its message live (muted until edited), so the reason is always
42
+ * visible. Default: the confirm stays enabled and messages show from the
43
+ * first attempt (`minLength`/`maxLength` counts show live in both modes).
44
+ */
45
+ disableUntilValid?: boolean;
39
46
  /**
40
47
  * Runs on confirm with the `inputs` values (`{}` without inputs). Without
41
48
  * `pending`, the dialog stays open, buttons disabled, while the returned
@@ -55,7 +62,8 @@ export interface ConfirmActionDialogProps {
55
62
  * @description
56
63
  * The dialog behind `confirmDialog` on row and menu actions, public for any
57
64
  * other button. Optional `inputs` (text, textarea, select, date) are validated
58
- * (`required`, `validate`) and handed to `onConfirm`; `body` adds free
65
+ * (`required`, `minLength`/`maxLength`, `min`/`max`, `validate`) and handed to
66
+ * `onConfirm`; `disableUntilValid` keeps the confirm off until they pass; `body` adds free
59
67
  * content. Two pending modes: by default the dialog awaits `onConfirm`
60
68
  * (spinner, closes on success, shows the error on failure); with a `pending`
61
69
  * prop the caller runs the action and closes the dialog itself.
@@ -83,4 +91,4 @@ export interface ConfirmActionDialogProps {
83
91
  * />
84
92
  * ```
85
93
  */
86
- export declare function ConfirmActionDialog({ open: openProp, onOpenChange, children, title, description, body, confirmText, pendingText, cancelText, variant, confirmDisabled, pending: pendingProp, inputs, onConfirm, }: ConfirmActionDialogProps): import("react").JSX.Element;
94
+ export declare function ConfirmActionDialog({ open: openProp, onOpenChange, children, title, description, body, confirmText, pendingText, cancelText, variant, confirmDisabled, pending: pendingProp, inputs, disableUntilValid, onConfirm, }: ConfirmActionDialogProps): import("react").JSX.Element;
@@ -26,8 +26,13 @@ import {
26
26
  import { Textarea } from "../../ui/textarea.js";
27
27
  import { useTelamonjsT, useText } from "../../i18n/use-t.js";
28
28
  import { isMessageRef } from "../../i18n/msg.js";
29
- import { jsx, jsxs } from "react/jsx-runtime";
29
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
30
30
  var initialValues = (inputs = []) => Object.fromEntries(inputs.map((i) => [i.name, i.defaultValue ?? ""]));
31
+ var asOption = (o) => typeof o === "string" ? { value: o, label: o } : o;
32
+ var calendarDate = (iso) => {
33
+ const [y, m, d] = iso.split("-").map(Number);
34
+ return new Date(Date.UTC(y, m - 1, d, 12));
35
+ };
31
36
  function ConfirmActionDialog({
32
37
  open: openProp,
33
38
  onOpenChange,
@@ -42,6 +47,7 @@ function ConfirmActionDialog({
42
47
  confirmDisabled = false,
43
48
  pending: pendingProp,
44
49
  inputs,
50
+ disableUntilValid = false,
45
51
  onConfirm
46
52
  }) {
47
53
  const t = useTelamonjsT();
@@ -51,6 +57,7 @@ function ConfirmActionDialog({
51
57
  const open = openProp ?? innerOpen;
52
58
  const [values, setValues] = useState(() => initialValues(inputs));
53
59
  const [attempted, setAttempted] = useState(false);
60
+ const [touched, setTouched] = useState({});
54
61
  const [error, setError] = useState(null);
55
62
  const [innerPending, setInnerPending] = useState(false);
56
63
  const callerOwnsPending = pendingProp !== void 0;
@@ -61,15 +68,33 @@ function ConfirmActionDialog({
61
68
  if (open) {
62
69
  setValues(initialValues(inputs));
63
70
  setAttempted(false);
71
+ setTouched({});
64
72
  setError(null);
65
73
  }
66
74
  }
67
75
  const node = (value) => isMessageRef(value) ? text(value) : value;
76
+ const lengthMessage = (input) => {
77
+ const length = (values[input.name] ?? "").trim().length;
78
+ if (input.minLength && length < input.minLength && (length > 0 || input.required))
79
+ return t("validation.charactersMissing", { count: input.minLength - length });
80
+ if (input.maxLength && length > input.maxLength)
81
+ return t("validation.charactersOver", { count: length - input.maxLength });
82
+ return void 0;
83
+ };
68
84
  const fieldError = (input) => {
69
85
  const value = values[input.name] ?? "";
86
+ const length = lengthMessage(input);
87
+ if (length) return length;
70
88
  if (input.required && !value.trim()) return t("validation.required");
89
+ if (input.type === "date" && value) {
90
+ if (input.min && value < input.min)
91
+ return t("validation.tooSmallDate", { min: calendarDate(input.min) });
92
+ if (input.max && value > input.max)
93
+ return t("validation.tooBigDate", { max: calendarDate(input.max) });
94
+ }
71
95
  return input.validate?.(value, values);
72
96
  };
97
+ const invalid = (inputs ?? []).some((input) => fieldError(input));
73
98
  const setOpen = (next) => {
74
99
  if (openProp === void 0) setInnerOpen(next);
75
100
  onOpenChange?.(next);
@@ -81,7 +106,7 @@ function ConfirmActionDialog({
81
106
  const handleConfirm = async (event) => {
82
107
  event.preventDefault();
83
108
  setAttempted(true);
84
- if ((inputs ?? []).some((input) => fieldError(input))) return;
109
+ if (invalid) return;
85
110
  setError(null);
86
111
  if (!callerOwnsPending) setInnerPending(true);
87
112
  try {
@@ -96,97 +121,146 @@ function ConfirmActionDialog({
96
121
  );
97
122
  }
98
123
  };
99
- const setValue = (name, value) => setValues((prev) => ({ ...prev, [name]: value }));
124
+ const setValue = (name, value) => {
125
+ setValues((prev) => ({ ...prev, [name]: value }));
126
+ setTouched((prev) => prev[name] ? prev : { ...prev, [name]: true });
127
+ };
100
128
  return /* @__PURE__ */ jsxs(AlertDialog, { open, onOpenChange: handleOpenChange, children: [
101
129
  children && /* @__PURE__ */ jsx(AlertDialogTrigger, { asChild: true, children }),
102
- /* @__PURE__ */ jsxs(AlertDialogContent, { children: [
103
- /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
104
- /* @__PURE__ */ jsx(AlertDialogTitle, { children: node(title) || t("dialog.confirmActionTitle") }),
105
- description && /* @__PURE__ */ jsx(AlertDialogDescription, { children: node(description) })
106
- ] }),
107
- body,
108
- inputs && inputs.length > 0 && /* @__PURE__ */ jsx("div", { className: "grid gap-4", children: inputs.map((input) => {
109
- const id = `${idPrefix}-${input.name}`;
110
- const errorId = `${id}-error`;
111
- const message = attempted ? fieldError(input) : void 0;
112
- const common = {
113
- id,
114
- name: input.name,
115
- required: input.required,
116
- disabled: pending,
117
- "aria-invalid": message ? true : void 0,
118
- "aria-describedby": message ? errorId : void 0
119
- };
120
- return /* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", children: [
121
- /* @__PURE__ */ jsxs(Label, { htmlFor: id, children: [
122
- text(input.label),
123
- input.required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-destructive", children: " *" })
130
+ /* @__PURE__ */ jsxs(
131
+ AlertDialogContent,
132
+ {
133
+ onOpenAutoFocus: (event) => {
134
+ const first = inputs?.[0];
135
+ if (!first) return;
136
+ const field = document.getElementById(`${idPrefix}-${first.name}`);
137
+ if (!field) return;
138
+ event.preventDefault();
139
+ field.focus();
140
+ },
141
+ children: [
142
+ /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
143
+ /* @__PURE__ */ jsx(AlertDialogTitle, { children: node(title) || t("dialog.confirmActionTitle") }),
144
+ description && /* @__PURE__ */ jsx(AlertDialogDescription, { children: node(description) })
124
145
  ] }),
125
- input.type === "textarea" ? /* @__PURE__ */ jsx(
126
- Textarea,
127
- {
128
- ...common,
129
- value: values[input.name] ?? "",
130
- onChange: (e) => setValue(input.name, e.target.value)
131
- }
132
- ) : input.type === "select" ? /* @__PURE__ */ jsxs(
133
- Select,
134
- {
135
- value: values[input.name] ?? "",
136
- onValueChange: (v) => setValue(input.name, v),
146
+ body,
147
+ inputs && inputs.length > 0 && /* @__PURE__ */ jsx("div", { className: "grid gap-4", children: inputs.map((input) => {
148
+ const id = `${idPrefix}-${input.name}`;
149
+ const errorId = `${id}-error`;
150
+ const helpId = `${id}-help`;
151
+ const listId = `${id}-suggestions`;
152
+ const message = fieldError(input);
153
+ const asError = !!message && (attempted || disableUntilValid && !!touched[input.name]);
154
+ const shown = asError || !!message && (disableUntilValid || !!lengthMessage(input));
155
+ const describedBy = [input.description && helpId, shown && errorId].filter(Boolean).join(" ") || void 0;
156
+ const placeholder = text(input.placeholder);
157
+ const common = {
158
+ id,
159
+ name: input.name,
160
+ required: input.required,
137
161
  disabled: pending,
138
- children: [
162
+ placeholder,
163
+ inputMode: input.inputMode,
164
+ autoComplete: input.autoComplete,
165
+ "aria-invalid": asError ? true : void 0,
166
+ "aria-describedby": describedBy
167
+ };
168
+ return /* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", children: [
169
+ /* @__PURE__ */ jsxs(Label, { htmlFor: id, children: [
170
+ text(input.label),
171
+ input.required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-destructive", children: " *" })
172
+ ] }),
173
+ input.type === "textarea" ? /* @__PURE__ */ jsx(
174
+ Textarea,
175
+ {
176
+ ...common,
177
+ rows: input.rows,
178
+ value: values[input.name] ?? "",
179
+ onChange: (e) => setValue(input.name, e.target.value)
180
+ }
181
+ ) : input.type === "select" ? /* @__PURE__ */ jsxs(
182
+ Select,
183
+ {
184
+ value: values[input.name] ?? "",
185
+ onValueChange: (v) => setValue(input.name, v),
186
+ disabled: pending,
187
+ children: [
188
+ /* @__PURE__ */ jsx(
189
+ SelectTrigger,
190
+ {
191
+ id,
192
+ "aria-invalid": common["aria-invalid"],
193
+ "aria-describedby": describedBy,
194
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: placeholder || t("common.select") })
195
+ }
196
+ ),
197
+ /* @__PURE__ */ jsx(SelectContent, { children: (input.options ?? []).map(asOption).map((option) => /* @__PURE__ */ jsx(SelectItem, { value: option.value, children: text(option.label) }, option.value)) })
198
+ ]
199
+ }
200
+ ) : input.type === "date" ? /* @__PURE__ */ jsx(
201
+ Input,
202
+ {
203
+ ...common,
204
+ type: "date",
205
+ min: input.min,
206
+ max: input.max,
207
+ value: values[input.name] ?? "",
208
+ onChange: (e) => setValue(input.name, e.target.value)
209
+ }
210
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
139
211
  /* @__PURE__ */ jsx(
140
- SelectTrigger,
212
+ Input,
141
213
  {
142
- id,
143
- "aria-invalid": common["aria-invalid"],
144
- "aria-describedby": common["aria-describedby"],
145
- children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("common.select") })
214
+ ...common,
215
+ type: "text",
216
+ list: input.suggestions?.length ? listId : void 0,
217
+ value: values[input.name] ?? "",
218
+ onChange: (e) => setValue(input.name, e.target.value)
146
219
  }
147
220
  ),
148
- /* @__PURE__ */ jsx(SelectContent, { children: (input.options ?? []).map((option) => /* @__PURE__ */ jsx(SelectItem, { value: option, children: option }, option)) })
149
- ]
150
- }
151
- ) : /* @__PURE__ */ jsx(
152
- Input,
221
+ input.suggestions?.length ? /* @__PURE__ */ jsx("datalist", { id: listId, children: input.suggestions.map((s) => /* @__PURE__ */ jsx("option", { value: s }, s)) }) : null
222
+ ] }),
223
+ input.description && /* @__PURE__ */ jsx("p", { id: helpId, className: "text-xs text-muted-foreground", children: text(input.description) }),
224
+ shown && message && /* @__PURE__ */ jsx(
225
+ "p",
226
+ {
227
+ id: errorId,
228
+ "data-state": asError ? "error" : "hint",
229
+ className: asError ? "text-sm text-destructive" : "text-sm text-muted-foreground",
230
+ children: text(message)
231
+ }
232
+ )
233
+ ] }, input.name);
234
+ }) }),
235
+ error && /* @__PURE__ */ jsx(
236
+ "p",
153
237
  {
154
- ...common,
155
- type: input.type === "date" ? "date" : "text",
156
- value: values[input.name] ?? "",
157
- onChange: (e) => setValue(input.name, e.target.value)
238
+ role: "alert",
239
+ "data-testid": "confirm-action-error",
240
+ className: "text-sm text-destructive",
241
+ children: error
158
242
  }
159
243
  ),
160
- message && /* @__PURE__ */ jsx("p", { id: errorId, className: "text-sm text-destructive", children: text(message) })
161
- ] }, input.name);
162
- }) }),
163
- error && /* @__PURE__ */ jsx(
164
- "p",
165
- {
166
- role: "alert",
167
- "data-testid": "confirm-action-error",
168
- className: "text-sm text-destructive",
169
- children: error
170
- }
171
- ),
172
- /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
173
- /* @__PURE__ */ jsx(AlertDialogCancel, { "data-testid": "modal-cancel", disabled: pending, children: text(cancelText) || t("common.cancel") }),
174
- /* @__PURE__ */ jsxs(
175
- AlertDialogAction,
176
- {
177
- "data-testid": "modal-confirm",
178
- disabled: pending || confirmDisabled,
179
- "aria-busy": pending || void 0,
180
- className: variant === "destructive" ? "bg-red-500 text-white hover:bg-red-600" : "",
181
- onClick: handleConfirm,
182
- children: [
183
- pending && /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin", "aria-hidden": "true" }),
184
- pending && text(pendingText) || text(confirmText) || t("common.confirm")
185
- ]
186
- }
187
- )
188
- ] })
189
- ] })
244
+ /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
245
+ /* @__PURE__ */ jsx(AlertDialogCancel, { "data-testid": "modal-cancel", disabled: pending, children: text(cancelText) || t("common.cancel") }),
246
+ /* @__PURE__ */ jsxs(
247
+ AlertDialogAction,
248
+ {
249
+ "data-testid": "modal-confirm",
250
+ disabled: pending || confirmDisabled || disableUntilValid && invalid,
251
+ "aria-busy": pending || void 0,
252
+ className: variant === "destructive" ? "bg-red-500 text-white hover:bg-red-600" : "",
253
+ onClick: handleConfirm,
254
+ children: [
255
+ pending && /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin", "aria-hidden": "true" }),
256
+ pending && text(pendingText) || text(confirmText) || t("common.confirm")
257
+ ]
258
+ }
259
+ )
260
+ ] })
261
+ ]
262
+ }
263
+ )
190
264
  ] });
191
265
  }
192
266
  export {
@@ -16,7 +16,6 @@ import {
16
16
  } from "../../utils/spacing.js";
17
17
  import { createCreateHeaderRenderer } from "./DialogHeaderContent.js";
18
18
  import { formHeaderConfig } from "./form-header-config.js";
19
- import { DialogErrorState } from "./DialogErrorState.js";
20
19
  import { CrudDialogShell } from "./CrudDialogShell.js";
21
20
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
22
21
  function CreateDialog({
@@ -42,7 +41,6 @@ function CreateDialog({
42
41
  const t = useTelamonjsT();
43
42
  const resolvedSubmitText = submitText ?? t("dialog.createSubmit");
44
43
  const renderHeader = renderHeaderProp || (headerConfig ? createCreateHeaderRenderer(formHeaderConfig(headerConfig)) : void 0);
45
- const [error, setError] = React.useState(null);
46
44
  const guard = useUnsavedChangesGuard();
47
45
  const resolvedTitle = typeof title === "string" ? title : t("common.create");
48
46
  const hasCustomHeader = Boolean(renderHeader);
@@ -73,15 +71,6 @@ function CreateDialog({
73
71
  onOpenChange(false);
74
72
  }
75
73
  }, [onSuccess, onOpenChange, guard]);
76
- React.useEffect(() => {
77
- if (!open) {
78
- const timer = setTimeout(() => {
79
- setError(null);
80
- }, 200);
81
- return () => clearTimeout(timer);
82
- }
83
- return void 0;
84
- }, [open]);
85
74
  const handleCancel = React.useCallback(() => {
86
75
  guard.guard(() => onOpenChange(false));
87
76
  }, [guard, onOpenChange]);
@@ -128,7 +117,7 @@ function CreateDialog({
128
117
  !hasCustomHeader && "overflow-y-auto -mx-6 px-6 mt-4"
129
118
  ),
130
119
  wrapDesktopCustomHeader: true,
131
- children: error ? /* @__PURE__ */ jsx(DialogErrorState, { error }) : /* @__PURE__ */ jsx(
120
+ children: /* @__PURE__ */ jsx(
132
121
  CreateForm,
133
122
  {
134
123
  sections: formSections,
@@ -17,7 +17,8 @@ import {
17
17
  resolveDialogSize,
18
18
  withWideFormGrid
19
19
  } from "../../utils/spacing.js";
20
- import { DialogErrorState, DialogLoadingState } from "./DialogErrorState.js";
20
+ import { DialogLoadingState } from "./DialogLoadingState.js";
21
+ import { QueryErrorState } from "../utilities/QueryErrorState.js";
21
22
  import { createHeaderRenderer } from "./DialogHeaderContent.js";
22
23
  import { formHeaderConfig } from "./form-header-config.js";
23
24
  import { lockSectionFields } from "./lock-section-fields.js";
@@ -60,7 +61,7 @@ function EditDialog({
60
61
  const renderHeader = renderHeaderProp || (headerConfig ? createHeaderRenderer(formHeaderConfig(headerConfig), "edit") : void 0);
61
62
  const router = useRouter();
62
63
  const guard = useUnsavedChangesGuard();
63
- const { data, isLoading, error, refetchSilent } = useDialogData(
64
+ const { data, isLoading, error, refetch, refetchSilent } = useDialogData(
64
65
  id,
65
66
  fetchAction,
66
67
  open
@@ -123,7 +124,7 @@ function EditDialog({
123
124
  return /* @__PURE__ */ jsx(DialogLoadingState, {});
124
125
  }
125
126
  if (error) {
126
- return /* @__PURE__ */ jsx(DialogErrorState, { error });
127
+ return /* @__PURE__ */ jsx(QueryErrorState, { error, onRetry: refetch, className: "my-8" });
127
128
  }
128
129
  if (!data || !id) {
129
130
  return null;
@@ -155,7 +156,7 @@ function EditDialog({
155
156
  hasMultipleSections: effectiveUseTabs,
156
157
  sections
157
158
  });
158
- const desktopStatus = isLoading || error || !data ? { sizeClass, isLoading, error } : void 0;
159
+ const desktopStatus = isLoading || error || !data ? { sizeClass, isLoading, error, onRetry: refetch } : void 0;
159
160
  return /* @__PURE__ */ jsxs(Fragment, { children: [
160
161
  /* @__PURE__ */ jsx(
161
162
  CrudDialogShell,
@@ -7,4 +7,4 @@ export { DialogHeaderContent, createHeaderRenderer, createCreateHeaderRenderer }
7
7
  export { StatsGrid } from './StatsGrid';
8
8
  export { DialogFrame } from './DialogFrame';
9
9
  export { SplitDialogFrame } from './SplitDialogFrame';
10
- export { DialogErrorState, DialogLoadingState } from './DialogErrorState';
10
+ export { DialogLoadingState } from './DialogLoadingState';
@@ -3,9 +3,8 @@ import { DialogHeaderContent, createHeaderRenderer, createCreateHeaderRenderer }
3
3
  import { StatsGrid } from "./StatsGrid.js";
4
4
  import { DialogFrame } from "./DialogFrame.js";
5
5
  import { SplitDialogFrame } from "./SplitDialogFrame.js";
6
- import { DialogErrorState, DialogLoadingState } from "./DialogErrorState.js";
6
+ import { DialogLoadingState } from "./DialogLoadingState.js";
7
7
  export {
8
- DialogErrorState,
9
8
  DialogFrame,
10
9
  DialogHeaderContent,
11
10
  DialogLoadingState,