@middag-io/react 0.45.0 → 0.45.2
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/docs/public/schemas/ai-contract-manifest.json +1820 -0
- package/docs/public/schemas/blocks.json +445 -0
- package/docs/public/schemas/components.json +166 -0
- package/docs/public/schemas/connectors.json +97 -0
- package/docs/public/schemas/fragment.json +2329 -0
- package/docs/public/schemas/manifest.json +119 -0
- package/docs/public/schemas/navigation.json +72 -0
- package/docs/public/schemas/page-contract.json +2329 -0
- package/docs/public/schemas/shared-props.json +118 -0
- package/docs/public/schemas/theme-defaults.json +253 -0
- package/docs/public/schemas/theme.json +401 -0
- package/package.json +109 -3
- package/src/assets/lottie/calendar/schedule-1.json +1 -0
- package/src/assets/lottie/calendar/schedule-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-1.json +1 -0
- package/src/assets/lottie/celebration/confetti-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-3.json +1 -0
- package/src/assets/lottie/cloud/cloud-1.json +1 -0
- package/src/assets/lottie/cloud/cloud-2.json +1 -0
- package/src/assets/lottie/connection/network-1.json +1 -0
- package/src/assets/lottie/connection/network-2.json +1 -0
- package/src/assets/lottie/connection/network-3.json +1 -0
- package/src/assets/lottie/dashboard/analytics-1.json +1 -0
- package/src/assets/lottie/dashboard/analytics-2.json +1 -0
- package/src/assets/lottie/dashboard/analytics-3.json +1 -0
- package/src/assets/lottie/email/mail-1.json +1 -0
- package/src/assets/lottie/email/mail-2.json +1 -0
- package/src/assets/lottie/email/mail-3.json +1 -0
- package/src/assets/lottie/empty-state/empty-1.json +1 -0
- package/src/assets/lottie/empty-state/empty-2.json +1 -0
- package/src/assets/lottie/empty-state/empty-3.json +1 -0
- package/src/assets/lottie/error/warning-1.json +1 -0
- package/src/assets/lottie/error/warning-2.json +1 -0
- package/src/assets/lottie/error/warning-3.json +1 -0
- package/src/assets/lottie/index.ts +49 -0
- package/src/assets/lottie/loading/spinner-1.json +1 -0
- package/src/assets/lottie/loading/spinner-2.json +1 -0
- package/src/assets/lottie/loading/spinner-3.json +1 -0
- package/src/assets/lottie/maintenance/construction-1.json +1 -0
- package/src/assets/lottie/maintenance/construction-2.json +1 -0
- package/src/assets/lottie/maintenance/construction-3.json +1 -0
- package/src/assets/lottie/not-found/404-1.json +1 -0
- package/src/assets/lottie/not-found/404-2.json +1 -0
- package/src/assets/lottie/not-found/404-3.json +1 -0
- package/src/assets/lottie/notification/bell-1.json +1 -0
- package/src/assets/lottie/notification/bell-2.json +1 -0
- package/src/assets/lottie/notification/bell-3.json +1 -0
- package/src/assets/lottie/onboarding/welcome-1.json +1 -0
- package/src/assets/lottie/onboarding/welcome-2.json +1 -0
- package/src/assets/lottie/onboarding/welcome-3.json +1 -0
- package/src/assets/lottie/payment/wallet-1.json +1 -0
- package/src/assets/lottie/payment/wallet-2.json +1 -0
- package/src/assets/lottie/payment/wallet-3.json +1 -0
- package/src/assets/lottie/search/search-1.json +1 -0
- package/src/assets/lottie/search/search-2.json +1 -0
- package/src/assets/lottie/search/search-3.json +1 -0
- package/src/assets/lottie/security/lock-1.json +1 -0
- package/src/assets/lottie/security/lock-2.json +1 -0
- package/src/assets/lottie/security/lock-3.json +1 -0
- package/src/assets/lottie/settings/gear-1.json +1 -0
- package/src/assets/lottie/settings/gear-2.json +1 -0
- package/src/assets/lottie/settings/gear-3.json +1 -0
- package/src/assets/lottie/success/check-1.json +1 -0
- package/src/assets/lottie/success/check-2.json +1 -0
- package/src/assets/lottie/success/check-3.json +1 -0
- package/src/assets/lottie/upload/upload-1.json +1 -0
- package/src/assets/lottie/upload/upload-2.json +1 -0
- package/src/assets/lottie/upload/upload-3.json +1 -0
- package/src/assets/lottie/user/profile-1.json +1 -0
- package/src/assets/lottie/user/profile-2.json +1 -0
- package/src/assets/lottie/user/profile-3.json +1 -0
- package/src/base/blocks/ActionGridBlock.tsx +151 -0
- package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
- package/src/base/blocks/CardGridBlock.tsx +384 -0
- package/src/base/blocks/ChartBlock.tsx +81 -0
- package/src/base/blocks/DenseTableBlock.tsx +403 -0
- package/src/base/blocks/DetailPanelBlock.tsx +189 -0
- package/src/base/blocks/EmptyStateBlock.tsx +46 -0
- package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
- package/src/base/blocks/FormPanelBlock.tsx +480 -0
- package/src/base/blocks/LinkListBlock.tsx +94 -0
- package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
- package/src/base/blocks/MetricCardBlock.tsx +128 -0
- package/src/base/blocks/StatusStripBlock.tsx +43 -0
- package/src/base/blocks/TabsBlock.tsx +94 -0
- package/src/base/form/FormField.tsx +607 -0
- package/src/base/form/fields/CheckboxField.tsx +56 -0
- package/src/base/form/fields/ColorField.tsx +76 -0
- package/src/base/form/fields/CurrencyField.tsx +126 -0
- package/src/base/form/fields/DateField.tsx +168 -0
- package/src/base/form/fields/DateRangeField.tsx +66 -0
- package/src/base/form/fields/DocumentField.tsx +222 -0
- package/src/base/form/fields/EntityPickerField.tsx +244 -0
- package/src/base/form/fields/FileUploadField.tsx +253 -0
- package/src/base/form/fields/MultiSelectField.tsx +286 -0
- package/src/base/form/fields/NativeSelectField.tsx +67 -0
- package/src/base/form/fields/NumberField.tsx +67 -0
- package/src/base/form/fields/OtpField.tsx +88 -0
- package/src/base/form/fields/PasswordField.tsx +69 -0
- package/src/base/form/fields/PhoneField.tsx +64 -0
- package/src/base/form/fields/RadioField.tsx +66 -0
- package/src/base/form/fields/RatingField.tsx +52 -0
- package/src/base/form/fields/SelectField.tsx +76 -0
- package/src/base/form/fields/SliderField.tsx +77 -0
- package/src/base/form/fields/SlugField.tsx +114 -0
- package/src/base/form/fields/StaticField.tsx +25 -0
- package/src/base/form/fields/SwitchField.tsx +56 -0
- package/src/base/form/fields/TagsField.tsx +128 -0
- package/src/base/form/fields/TextField.tsx +55 -0
- package/src/base/form/fields/TextareaField.tsx +55 -0
- package/src/base/form/fields/document-validation.ts +126 -0
- package/src/base/form/fields/field-registry.ts +53 -0
- package/src/base/form/fields/register-default-fields.ts +86 -0
- package/src/base/form/form-schema-builder.ts +192 -0
- package/src/base/form/form-utils.ts +71 -0
- package/src/base/hooks/useIsDark.ts +50 -0
- package/src/base/hooks/useLazyTabs.ts +98 -0
- package/src/base/hooks/usePolling.ts +43 -0
- package/src/base/hooks/useRemember.ts +58 -0
- package/src/base/hooks/useToast.ts +27 -0
- package/src/base/layout/BlockRegion.tsx +39 -0
- package/src/base/layout/DashboardLayout.tsx +110 -0
- package/src/base/layout/SidebarLayout.tsx +38 -0
- package/src/base/layout/StackLayout.tsx +32 -0
- package/src/base/layout/WizardLayout.tsx +49 -0
- package/src/base/partials/ActionBar/index.tsx +115 -0
- package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
- package/src/base/partials/DataTable/cell-registry.ts +50 -0
- package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
- package/src/base/partials/DataTable/index.tsx +1282 -0
- package/src/base/partials/DataTable/register-default-cells.ts +37 -0
- package/src/base/partials/DataTable/sanitize-html.ts +45 -0
- package/src/base/partials/DataTable/types.ts +229 -0
- package/src/base/partials/DetailSection/index.tsx +316 -0
- package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
- package/src/base/partials/EntityItem/index.tsx +154 -0
- package/src/base/partials/FilterBar/index.tsx +256 -0
- package/src/base/partials/FormSection/index.tsx +87 -0
- package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
- package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
- package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
- package/src/base/partials/LogViewer/index.tsx +110 -0
- package/src/base/partials/LogViewer/types.ts +28 -0
- package/src/base/partials/MarkdownContent/index.tsx +307 -0
- package/src/base/partials/MenuBar/index.tsx +80 -0
- package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
- package/src/base/partials/ResizableSidebar/index.tsx +70 -0
- package/src/base/partials/StatRow/index.tsx +28 -0
- package/src/base/partials/StatusBar/index.tsx +126 -0
- package/src/base/partials/StatusIndicator/index.tsx +61 -0
- package/src/base/partials/StepIndicator/index.tsx +63 -0
- package/src/base/partials/TableOfContents/index.tsx +78 -0
- package/src/base/partials/TimelineList/index.tsx +273 -0
- package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
- package/src/base/partials/TreeView/index.tsx +75 -0
- package/src/base/partials/index.ts +23 -0
- package/src/base/shell/AuthShell.tsx +54 -0
- package/src/base/shell/BasicShell.tsx +286 -0
- package/src/base/shell/ImmersiveShell.tsx +85 -0
- package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
- package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
- package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
- package/src/base/shell/partials/InspectorContext.tsx +173 -0
- package/src/base/shell/partials/InspectorPanel.tsx +65 -0
- package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
- package/src/base/shell/partials/OverlayScreen.tsx +67 -0
- package/src/base/shell/partials/PageActionButton.tsx +203 -0
- package/src/base/theme/appearance.ts +133 -0
- package/src/base/theme/host-layout-detector.ts +119 -0
- package/src/base/theme/host-theme-detector.ts +146 -0
- package/src/base/theme/sidebar-safelist.txt +20 -0
- package/src/base/theme/tailwind-theme.css +136 -0
- package/src/base/theme/theme-bridge.css +164 -0
- package/src/base/theme/theme-context.tsx +142 -0
- package/src/base/theme/themes/classic.css +174 -0
- package/src/base/theme/tokens.css +290 -0
- package/src/base/theme/useHostTheme.ts +95 -0
- package/src/base/utils/clipboard.ts +39 -0
- package/src/base/utils/conditions.ts +27 -0
- package/src/base/utils/icon-registry.ts +78 -0
- package/src/base/utils/icons.ts +31 -0
- package/src/base/utils/interpolate.ts +9 -0
- package/src/base/utils/register-default-icons.ts +163 -0
- package/src/base/utils/storage.ts +65 -0
- package/src/base/utils/time.ts +139 -0
- package/src/contracts/block-data/actions.ts +73 -0
- package/src/contracts/block-data/data-display.ts +343 -0
- package/src/contracts/block-data/form.ts +164 -0
- package/src/contracts/block-data/index.ts +15 -0
- package/src/contracts/block-data/interactive.ts +34 -0
- package/src/contracts/block-data/shared.ts +44 -0
- package/src/contracts/connectors.ts +60 -0
- package/src/contracts/generated/contract-schema.ts +1237 -0
- package/src/contracts/generated/contract-types.ts +675 -0
- package/src/contracts/generated/index.ts +15 -0
- package/src/contracts/navigation.ts +59 -0
- package/src/contracts/page-contract-schema.ts +40 -0
- package/src/contracts/page-contract.ts +79 -0
- package/src/contracts/shared-props.ts +92 -0
- package/src/engine/ContractPage.tsx +178 -0
- package/src/engine/EntityRoutes.tsx +72 -0
- package/src/engine/HostSlot.tsx +126 -0
- package/src/engine/LazyBlock.tsx +92 -0
- package/src/engine/bootstrap.tsx +20 -0
- package/src/engine/providers/auth.tsx +87 -0
- package/src/engine/providers/error-reporter.tsx +89 -0
- package/src/engine/providers/flash.tsx +44 -0
- package/src/engine/providers/index.ts +18 -0
- package/src/engine/providers/inertia-error-reporter.tsx +61 -0
- package/src/engine/providers/progress.tsx +56 -0
- package/src/engine/providers/scope.tsx +51 -0
- package/src/engine/register-defaults.ts +88 -0
- package/src/engine/registries.ts +96 -0
- package/src/i18n/I18nProvider.tsx +53 -0
- package/src/i18n/MANIFEST.md +101 -0
- package/src/i18n/host-resolver.ts +18 -0
- package/src/i18n/instance.ts +69 -0
- package/src/i18n/locales/en/ui.json +277 -0
- package/src/i18n/locales/en/validators.json +13 -0
- package/src/i18n/locales/pt-BR/ui.json +277 -0
- package/src/i18n/locales/pt-BR/validators.json +13 -0
- package/src/i18n/register-strings.ts +10 -0
- package/src/i18n/render-label.ts +33 -0
- package/src/i18n/resolve-field-error.ts +29 -0
- package/src/i18n/useHostString.ts +50 -0
- package/src/i18n/useTranslation.ts +83 -0
- package/src/lib/actions/resolve-action-target.ts +151 -0
- package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
- package/src/lib/hooks/use-file-upload.ts +406 -0
- package/src/lib/hooks/use-mobile.ts +21 -0
- package/src/lib/host-pending.ts +76 -0
- package/src/lib/portal-container.ts +16 -0
- package/src/lib/test-ids.ts +40 -0
- package/src/lib/utils.ts +6 -0
- package/src/primitives/reui/MANIFEST.md +97 -0
- package/src/primitives/reui/accordion.tsx +64 -0
- package/src/primitives/reui/alert-dialog.tsx +196 -0
- package/src/primitives/reui/alert.tsx +92 -0
- package/src/primitives/reui/aspect-ratio.tsx +9 -0
- package/src/primitives/reui/autocomplete.tsx +343 -0
- package/src/primitives/reui/avatar.tsx +109 -0
- package/src/primitives/reui/badge.tsx +94 -0
- package/src/primitives/reui/breadcrumb.tsx +109 -0
- package/src/primitives/reui/button-group.tsx +83 -0
- package/src/primitives/reui/button.tsx +64 -0
- package/src/primitives/reui/calendar.tsx +220 -0
- package/src/primitives/reui/card.tsx +92 -0
- package/src/primitives/reui/carousel.tsx +239 -0
- package/src/primitives/reui/chart.tsx +388 -0
- package/src/primitives/reui/checkbox.tsx +30 -0
- package/src/primitives/reui/collapsible.tsx +31 -0
- package/src/primitives/reui/combobox.tsx +308 -0
- package/src/primitives/reui/command.tsx +182 -0
- package/src/primitives/reui/context-menu.tsx +250 -0
- package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
- package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
- package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
- package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
- package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
- package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
- package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
- package/src/primitives/reui/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/date-selector.tsx +1353 -0
- package/src/primitives/reui/dialog.tsx +158 -0
- package/src/primitives/reui/drawer.tsx +133 -0
- package/src/primitives/reui/dropdown-menu.tsx +257 -0
- package/src/primitives/reui/empty.tsx +104 -0
- package/src/primitives/reui/field.tsx +246 -0
- package/src/primitives/reui/filters.tsx +1891 -0
- package/src/primitives/reui/frame.tsx +170 -0
- package/src/primitives/reui/hover-card.tsx +42 -0
- package/src/primitives/reui/icon-placeholder.tsx +39 -0
- package/src/primitives/reui/index.ts +98 -0
- package/src/primitives/reui/input-group.tsx +170 -0
- package/src/primitives/reui/input-otp.tsx +75 -0
- package/src/primitives/reui/input.tsx +21 -0
- package/src/primitives/reui/item.tsx +193 -0
- package/src/primitives/reui/kanban.tsx +743 -0
- package/src/primitives/reui/kbd.tsx +28 -0
- package/src/primitives/reui/label.tsx +22 -0
- package/src/primitives/reui/menubar.tsx +274 -0
- package/src/primitives/reui/native-select.tsx +62 -0
- package/src/primitives/reui/navigation-menu.tsx +168 -0
- package/src/primitives/reui/number-field.tsx +250 -0
- package/src/primitives/reui/pagination.tsx +127 -0
- package/src/primitives/reui/phone-input.tsx +231 -0
- package/src/primitives/reui/popover.tsx +87 -0
- package/src/primitives/reui/progress.tsx +31 -0
- package/src/primitives/reui/radio-group.tsx +43 -0
- package/src/primitives/reui/rating.tsx +177 -0
- package/src/primitives/reui/resizable.tsx +51 -0
- package/src/primitives/reui/scroll-area.tsx +58 -0
- package/src/primitives/reui/scrollspy.tsx +240 -0
- package/src/primitives/reui/select.tsx +188 -0
- package/src/primitives/reui/separator.tsx +28 -0
- package/src/primitives/reui/sheet.tsx +141 -0
- package/src/primitives/reui/sidebar.tsx +732 -0
- package/src/primitives/reui/skeleton.tsx +13 -0
- package/src/primitives/reui/slider.tsx +61 -0
- package/src/primitives/reui/sonner.tsx +47 -0
- package/src/primitives/reui/sortable.tsx +414 -0
- package/src/primitives/reui/spinner.tsx +16 -0
- package/src/primitives/reui/stepper.tsx +484 -0
- package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
- package/src/primitives/reui/svgs/gemini.tsx +171 -0
- package/src/primitives/reui/svgs/openai.tsx +9 -0
- package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
- package/src/primitives/reui/switch.tsx +33 -0
- package/src/primitives/reui/table.tsx +114 -0
- package/src/primitives/reui/tabs.tsx +91 -0
- package/src/primitives/reui/textarea.tsx +18 -0
- package/src/primitives/reui/timeline.tsx +219 -0
- package/src/primitives/reui/toggle-group.tsx +83 -0
- package/src/primitives/reui/toggle.tsx +45 -0
- package/src/primitives/reui/tooltip.tsx +55 -0
- package/src/primitives/reui/tree.tsx +247 -0
- package/src/theme.css +71 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ActionGridBlock — grid of action cards with confirmation dialog.
|
|
3
|
+
*
|
|
4
|
+
* Each card displays an icon, title, description, and an action button.
|
|
5
|
+
* When confirmText is present, an AlertDialog gates the action.
|
|
6
|
+
* Actions execute via Inertia router.post/delete.
|
|
7
|
+
*
|
|
8
|
+
* @see ADR-807
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
"use client";
|
|
12
|
+
|
|
13
|
+
import { useCallback, useState, type ReactElement } from "react";
|
|
14
|
+
import { AlertCircleIcon, CheckmarkCircle01Icon } from "@hugeicons/core-free-icons";
|
|
15
|
+
import { HugeiconsIcon } from "@hugeicons/react";
|
|
16
|
+
import { router } from "@inertiajs/core";
|
|
17
|
+
|
|
18
|
+
import { ConfirmationDialog } from "@/base/partials/ConfirmationDialog";
|
|
19
|
+
import { getIcon } from "@/base/utils/icons";
|
|
20
|
+
import type { ActionGridBlockData } from "@/contracts/block-data";
|
|
21
|
+
import type { BlockProps } from "@/engine/registries";
|
|
22
|
+
import { renderLabel } from "@/i18n/render-label";
|
|
23
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
24
|
+
import { resolveActionTarget } from "@/lib/actions/resolve-action-target";
|
|
25
|
+
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/primitives/reui/alert";
|
|
26
|
+
import { Badge } from "@/primitives/reui/badge";
|
|
27
|
+
import { Button } from "@/primitives/reui/button";
|
|
28
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/primitives/reui/card";
|
|
29
|
+
import { Spinner } from "@/primitives/reui/spinner";
|
|
30
|
+
|
|
31
|
+
export function ActionGridBlock({ block }: BlockProps<ActionGridBlockData>): ReactElement {
|
|
32
|
+
const { t } = useTranslation();
|
|
33
|
+
const { data } = block;
|
|
34
|
+
// Tie dismissal to the specific flash, so a new server message re-shows the
|
|
35
|
+
// alert instead of staying suppressed after a previous dismissal.
|
|
36
|
+
const flashKey = data.flash ? `${data.flash.success}:${data.flash.message}` : null;
|
|
37
|
+
const [dismissedKey, setDismissedKey] = useState<string | null>(null);
|
|
38
|
+
const isDismissed = dismissedKey !== null && dismissedKey === flashKey;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className="space-y-6">
|
|
42
|
+
{data.flash && !isDismissed && (
|
|
43
|
+
<Alert variant={data.flash.success ? "success" : "destructive"}>
|
|
44
|
+
<HugeiconsIcon
|
|
45
|
+
icon={data.flash.success ? CheckmarkCircle01Icon : AlertCircleIcon}
|
|
46
|
+
size={16}
|
|
47
|
+
/>
|
|
48
|
+
<AlertTitle>
|
|
49
|
+
{data.flash.success
|
|
50
|
+
? t("middag.ui.action_grid.success")
|
|
51
|
+
: t("middag.ui.action_grid.error")}
|
|
52
|
+
</AlertTitle>
|
|
53
|
+
<AlertDescription>{data.flash.message}</AlertDescription>
|
|
54
|
+
<AlertAction>
|
|
55
|
+
<Button variant="ghost" size="xs" onClick={() => setDismissedKey(flashKey)}>
|
|
56
|
+
{t("middag.ui.dismiss")}
|
|
57
|
+
</Button>
|
|
58
|
+
</AlertAction>
|
|
59
|
+
</Alert>
|
|
60
|
+
)}
|
|
61
|
+
|
|
62
|
+
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
|
63
|
+
{data.items.map((item) => (
|
|
64
|
+
<ActionCard key={item.id} item={item} />
|
|
65
|
+
))}
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function ActionCard({ item }: { item: ActionGridBlockData["items"][number] }): ReactElement {
|
|
72
|
+
const { t } = useTranslation();
|
|
73
|
+
const Icon = getIcon(item.icon ?? "");
|
|
74
|
+
const [showConfirm, setShowConfirm] = useState(false);
|
|
75
|
+
|
|
76
|
+
const executeAction = useCallback(() => {
|
|
77
|
+
const target = resolveActionTarget(item);
|
|
78
|
+
if (target.kind === "link") {
|
|
79
|
+
router.visit(target.url);
|
|
80
|
+
} else if (target.method === "delete") {
|
|
81
|
+
router.delete(target.url);
|
|
82
|
+
} else {
|
|
83
|
+
const method = target.method as "post" | "put" | "patch";
|
|
84
|
+
router[method](target.url);
|
|
85
|
+
}
|
|
86
|
+
}, [item]);
|
|
87
|
+
|
|
88
|
+
const handleClick = useCallback(() => {
|
|
89
|
+
if (item.confirmation) {
|
|
90
|
+
setShowConfirm(true);
|
|
91
|
+
} else {
|
|
92
|
+
executeAction();
|
|
93
|
+
}
|
|
94
|
+
}, [item.confirmation, executeAction]);
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Card>
|
|
98
|
+
<CardHeader>
|
|
99
|
+
<div className="flex items-start gap-3">
|
|
100
|
+
<Badge variant="secondary" size="xl" radius="full" className="shrink-0">
|
|
101
|
+
<HugeiconsIcon icon={Icon} size={16} />
|
|
102
|
+
</Badge>
|
|
103
|
+
<div className="min-w-0">
|
|
104
|
+
<CardTitle className="text-sm">{item.title}</CardTitle>
|
|
105
|
+
<CardDescription className="mt-1">{item.description}</CardDescription>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
</CardHeader>
|
|
109
|
+
<CardContent>
|
|
110
|
+
{/* `loading`/`disabled` já fazem parte do contrato Action (gerado de
|
|
111
|
+
Middag\Ui) mas eram ignorados aqui: o servidor podia sinalizar uma
|
|
112
|
+
ação em andamento e o botão seguia inerte e clicável. `loading`
|
|
113
|
+
implica desabilitado — reenviar durante o processamento é o que a
|
|
114
|
+
sinalização existe para evitar. */}
|
|
115
|
+
<Button
|
|
116
|
+
variant="outline"
|
|
117
|
+
size="sm"
|
|
118
|
+
className="w-full"
|
|
119
|
+
onClick={handleClick}
|
|
120
|
+
disabled={item.disabled === true || item.loading === true}
|
|
121
|
+
>
|
|
122
|
+
{item.loading === true && <Spinner className="mr-2 size-4" />}
|
|
123
|
+
{renderLabel(item.label, t)}
|
|
124
|
+
</Button>
|
|
125
|
+
{item.confirmation && (
|
|
126
|
+
<ConfirmationDialog
|
|
127
|
+
open={showConfirm}
|
|
128
|
+
onClose={() => setShowConfirm(false)}
|
|
129
|
+
onConfirm={() => {
|
|
130
|
+
executeAction();
|
|
131
|
+
setShowConfirm(false);
|
|
132
|
+
}}
|
|
133
|
+
title={renderLabel(item.confirmation.title, t)}
|
|
134
|
+
message={renderLabel(item.confirmation.message, t)}
|
|
135
|
+
intent={item.confirmation.intent}
|
|
136
|
+
confirmLabel={
|
|
137
|
+
item.confirmation.confirmLabel
|
|
138
|
+
? renderLabel(item.confirmation.confirmLabel, t)
|
|
139
|
+
: undefined
|
|
140
|
+
}
|
|
141
|
+
cancelLabel={
|
|
142
|
+
item.confirmation.cancelLabel
|
|
143
|
+
? renderLabel(item.confirmation.cancelLabel, t)
|
|
144
|
+
: undefined
|
|
145
|
+
}
|
|
146
|
+
/>
|
|
147
|
+
)}
|
|
148
|
+
</CardContent>
|
|
149
|
+
</Card>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ActivityTimelineBlock — grouped activity timeline.
|
|
3
|
+
*
|
|
4
|
+
* Renders timeline entries grouped by date. Supports load more via Inertia partial reload.
|
|
5
|
+
* Stub implementation until TimelineList partial is available.
|
|
6
|
+
*
|
|
7
|
+
* @see NV-05-ux-blocks.md §6
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { useState, type ReactElement } from "react";
|
|
11
|
+
import { HugeiconsIcon } from "@hugeicons/react";
|
|
12
|
+
import { router } from "@inertiajs/core";
|
|
13
|
+
import { usePage } from "@inertiajs/react";
|
|
14
|
+
|
|
15
|
+
import { EmptyPlaceholder } from "@/base/partials/EmptyPlaceholder";
|
|
16
|
+
import { getIcon } from "@/base/utils/icons";
|
|
17
|
+
import { formatISO, formatRelativeTime } from "@/base/utils/time";
|
|
18
|
+
import type { ActivityTimelineBlockData } from "@/contracts/block-data";
|
|
19
|
+
import type { BlockProps } from "@/engine/registries";
|
|
20
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
21
|
+
import { cn } from "@/lib/utils";
|
|
22
|
+
import { Button } from "@/primitives/reui/button";
|
|
23
|
+
import { Skeleton } from "@/primitives/reui/skeleton";
|
|
24
|
+
|
|
25
|
+
const COLOR_MAP: Record<string, string> = {
|
|
26
|
+
success: "bg-success",
|
|
27
|
+
info: "bg-info",
|
|
28
|
+
warning: "bg-warning",
|
|
29
|
+
destructive: "bg-destructive",
|
|
30
|
+
neutral: "bg-muted",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function ActivityTimelineBlock({
|
|
34
|
+
block,
|
|
35
|
+
}: BlockProps<ActivityTimelineBlockData>): ReactElement {
|
|
36
|
+
const { t, locale } = useTranslation();
|
|
37
|
+
const { meta, key } = block;
|
|
38
|
+
// Honor Inertia v3 prop merging. Load-more reloads the top-level prop named
|
|
39
|
+
// `key` (see handleLoadMore `only: [key]`); when the backend marks it with
|
|
40
|
+
// `mergeProps`/`prependProps`/`deepMergeProps`, Inertia core accumulates the
|
|
41
|
+
// entries onto the live page prop before render. Read that merged value when
|
|
42
|
+
// present, falling back to the contract-embedded data on initial render (or
|
|
43
|
+
// when the host keeps the timeline payload inside the PageContract).
|
|
44
|
+
const pageProps = usePage().props as Record<string, unknown>;
|
|
45
|
+
const data = (pageProps[key] as ActivityTimelineBlockData | undefined) ?? block.data;
|
|
46
|
+
const isLoading = meta?.loading === true;
|
|
47
|
+
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
48
|
+
|
|
49
|
+
// Optimistic read state. Clicking "mark as read" acknowledges the entry
|
|
50
|
+
// locally (so the action flips to a "Read" marker immediately) and POSTs to the
|
|
51
|
+
// entry's markReadHref to persist. Server-confirmed entries arrive with read=true.
|
|
52
|
+
const [ackedIds, setAckedIds] = useState<Set<string>>(new Set());
|
|
53
|
+
|
|
54
|
+
const handleMarkRead = (href: string, id: string) => {
|
|
55
|
+
setAckedIds((prev) => new Set(prev).add(id));
|
|
56
|
+
router.post(href, {}, { preserveState: true, preserveScroll: true, only: [key] });
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const handleLoadMore = () => {
|
|
60
|
+
if (!data.loadMoreHref) return;
|
|
61
|
+
setIsLoadingMore(true);
|
|
62
|
+
router.get(
|
|
63
|
+
data.loadMoreHref,
|
|
64
|
+
{},
|
|
65
|
+
{
|
|
66
|
+
preserveState: true,
|
|
67
|
+
preserveScroll: true,
|
|
68
|
+
only: [key],
|
|
69
|
+
onFinish: () => setIsLoadingMore(false),
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (isLoading) {
|
|
75
|
+
return (
|
|
76
|
+
<div className="space-y-4">
|
|
77
|
+
{[1, 2, 3].map((i) => (
|
|
78
|
+
<div key={i} className="flex gap-3">
|
|
79
|
+
<Skeleton className="h-6 w-6 shrink-0 rounded-full" />
|
|
80
|
+
<div className="flex-1 space-y-2">
|
|
81
|
+
<Skeleton className="h-4 w-48" />
|
|
82
|
+
<Skeleton className="h-3 w-32" />
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
))}
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const allEntries = data.groups.flatMap((g) => g.entries);
|
|
91
|
+
if (allEntries.length === 0) {
|
|
92
|
+
return (
|
|
93
|
+
<EmptyPlaceholder variant="inline" icon="clock" title={t("middag.ui.activity.no_activity")} />
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<ol role="list" aria-label={t("middag.ui.activity.timeline_label")} className="space-y-6">
|
|
99
|
+
{data.groups.map((group) => (
|
|
100
|
+
<li key={group.label}>
|
|
101
|
+
<h3 className="text-muted-foreground mb-3 text-xs font-semibold tracking-wide uppercase">
|
|
102
|
+
{group.label}
|
|
103
|
+
</h3>
|
|
104
|
+
<ol className="space-y-3">
|
|
105
|
+
{group.entries.map((entry) => (
|
|
106
|
+
<li
|
|
107
|
+
key={entry.id}
|
|
108
|
+
className="hover:bg-accent/50 flex gap-3 rounded-md p-2 transition-colors"
|
|
109
|
+
>
|
|
110
|
+
<span
|
|
111
|
+
className={cn(
|
|
112
|
+
"flex h-6 w-6 shrink-0 items-center justify-center rounded-full",
|
|
113
|
+
COLOR_MAP[entry.color] ?? "bg-muted",
|
|
114
|
+
)}
|
|
115
|
+
>
|
|
116
|
+
<HugeiconsIcon icon={getIcon(entry.icon)} size={14} className="text-white" />
|
|
117
|
+
</span>
|
|
118
|
+
<div className="min-w-0 flex-1">
|
|
119
|
+
<div className="flex items-baseline justify-between gap-2">
|
|
120
|
+
<p className="text-sm">
|
|
121
|
+
{entry.actorHref ? (
|
|
122
|
+
<a
|
|
123
|
+
href={entry.actorHref}
|
|
124
|
+
className="text-primary font-semibold hover:underline"
|
|
125
|
+
>
|
|
126
|
+
{entry.actor || t("middag.ui.activity.system_actor")}
|
|
127
|
+
</a>
|
|
128
|
+
) : (
|
|
129
|
+
<span className="font-semibold">
|
|
130
|
+
{entry.actor || t("middag.ui.activity.system_actor")}
|
|
131
|
+
</span>
|
|
132
|
+
)}{" "}
|
|
133
|
+
{entry.action}
|
|
134
|
+
</p>
|
|
135
|
+
<time
|
|
136
|
+
dateTime={formatISO(entry.timestamp)}
|
|
137
|
+
className="text-muted-foreground shrink-0 text-xs"
|
|
138
|
+
title={formatISO(entry.timestamp)}
|
|
139
|
+
>
|
|
140
|
+
{formatRelativeTime(entry.timestamp, locale)}
|
|
141
|
+
</time>
|
|
142
|
+
</div>
|
|
143
|
+
{entry.markReadHref &&
|
|
144
|
+
(entry.read || ackedIds.has(entry.id) ? (
|
|
145
|
+
<span className="text-muted-foreground mt-1 inline-block text-xs">
|
|
146
|
+
{t("middag.ui.activity.read")}
|
|
147
|
+
</span>
|
|
148
|
+
) : (
|
|
149
|
+
<Button
|
|
150
|
+
variant="ghost"
|
|
151
|
+
size="sm"
|
|
152
|
+
className="mt-1 h-auto px-2 py-0.5 text-xs"
|
|
153
|
+
onClick={() => handleMarkRead(entry.markReadHref!, entry.id)}
|
|
154
|
+
>
|
|
155
|
+
{t("middag.ui.activity.mark_read")}
|
|
156
|
+
</Button>
|
|
157
|
+
))}
|
|
158
|
+
</div>
|
|
159
|
+
</li>
|
|
160
|
+
))}
|
|
161
|
+
</ol>
|
|
162
|
+
</li>
|
|
163
|
+
))}
|
|
164
|
+
|
|
165
|
+
{data.hasMore && (
|
|
166
|
+
<li className="flex justify-center pt-2">
|
|
167
|
+
<Button
|
|
168
|
+
variant="ghost"
|
|
169
|
+
size="sm"
|
|
170
|
+
onClick={handleLoadMore}
|
|
171
|
+
disabled={isLoadingMore}
|
|
172
|
+
aria-label={t("middag.ui.activity.load_more_label")}
|
|
173
|
+
>
|
|
174
|
+
{isLoadingMore ? t("middag.ui.loading") : t("middag.ui.load_more")}
|
|
175
|
+
</Button>
|
|
176
|
+
</li>
|
|
177
|
+
)}
|
|
178
|
+
</ol>
|
|
179
|
+
);
|
|
180
|
+
}
|