@agent-native/core 0.123.0 → 0.123.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.
- package/corpus/README.md +1 -1
- package/corpus/core/CHANGELOG.md +16 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/cli/templates-meta.ts +12 -0
- package/corpus/templates/crm/.agents/skills/agent-native-docs/SKILL.md +115 -0
- package/corpus/templates/crm/.agents/skills/agent-native-toolkit/SKILL.md +177 -0
- package/corpus/templates/crm/.agents/skills/crm/SKILL.md +205 -0
- package/corpus/templates/crm/.agents/skills/customizing-agent-native/SKILL.md +220 -0
- package/corpus/templates/crm/.agents/skills/feature-flags/SKILL.md +169 -0
- package/corpus/templates/crm/.agents/skills/sharing/SKILL.md +228 -0
- package/corpus/templates/crm/.agents/skills/storing-data/SKILL.md +178 -0
- package/corpus/templates/crm/.agents/skills/upgrade-agent-native/SKILL.md +122 -0
- package/corpus/templates/crm/.env.example +5 -0
- package/corpus/templates/crm/AGENTS.md +82 -0
- package/corpus/templates/crm/CHANGELOG.md +25 -0
- package/corpus/templates/crm/DEVELOPING.md +66 -0
- package/corpus/templates/crm/README.md +122 -0
- package/corpus/templates/crm/_gitignore +12 -0
- package/corpus/templates/crm/actions/_crm-action-utils.ts +98 -0
- package/corpus/templates/crm/actions/_crm-attribute-utils.ts +219 -0
- package/corpus/templates/crm/actions/_crm-dashboard.ts +69 -0
- package/corpus/templates/crm/actions/_crm-data-program-actions.ts +15 -0
- package/corpus/templates/crm/actions/_crm-list-utils.ts +775 -0
- package/corpus/templates/crm/actions/_crm-signal-utils.ts +79 -0
- package/corpus/templates/crm/actions/add-crm-record-to-list.ts +164 -0
- package/corpus/templates/crm/actions/apply-crm-proposals.ts +291 -0
- package/corpus/templates/crm/actions/archive-crm-attribute.ts +69 -0
- package/corpus/templates/crm/actions/attach-call-evidence.ts +170 -0
- package/corpus/templates/crm/actions/configure-crm-connection.ts +126 -0
- package/corpus/templates/crm/actions/configure-native-crm.ts +44 -0
- package/corpus/templates/crm/actions/create-crm-attribute.ts +350 -0
- package/corpus/templates/crm/actions/create-crm-list.ts +194 -0
- package/corpus/templates/crm/actions/create-crm-record.ts +148 -0
- package/corpus/templates/crm/actions/create-crm-signal-tracker.ts +58 -0
- package/corpus/templates/crm/actions/delete-crm-saved-view.ts +68 -0
- package/corpus/templates/crm/actions/delete-staged-dataset.ts +14 -0
- package/corpus/templates/crm/actions/estimate-crm-enrichment.ts +229 -0
- package/corpus/templates/crm/actions/find-crm-duplicates.ts +87 -0
- package/corpus/templates/crm/actions/get-crm-automation-recipe.ts +36 -0
- package/corpus/templates/crm/actions/get-crm-dashboard-panel.ts +35 -0
- package/corpus/templates/crm/actions/get-crm-dashboard.ts +14 -0
- package/corpus/templates/crm/actions/get-crm-overview.ts +13 -0
- package/corpus/templates/crm/actions/get-crm-pipeline-data.ts +61 -0
- package/corpus/templates/crm/actions/get-crm-record-page.ts +287 -0
- package/corpus/templates/crm/actions/get-crm-record.ts +75 -0
- package/corpus/templates/crm/actions/get-crm-workspace.ts +364 -0
- package/corpus/templates/crm/actions/install-crm-pipeline-dashboard.ts +81 -0
- package/corpus/templates/crm/actions/list-crm-attributes.ts +71 -0
- package/corpus/templates/crm/actions/list-crm-connections.ts +68 -0
- package/corpus/templates/crm/actions/list-crm-dashboard-revisions.ts +15 -0
- package/corpus/templates/crm/actions/list-crm-dashboards.ts +15 -0
- package/corpus/templates/crm/actions/list-crm-enrichment-slots.ts +28 -0
- package/corpus/templates/crm/actions/list-crm-list-entries.ts +192 -0
- package/corpus/templates/crm/actions/list-crm-lists.ts +80 -0
- package/corpus/templates/crm/actions/list-crm-proposals.ts +55 -0
- package/corpus/templates/crm/actions/list-crm-record-field-history.ts +201 -0
- package/corpus/templates/crm/actions/list-crm-record-values.ts +200 -0
- package/corpus/templates/crm/actions/list-crm-records.ts +103 -0
- package/corpus/templates/crm/actions/list-crm-saved-views.ts +66 -0
- package/corpus/templates/crm/actions/list-crm-signal-hits.ts +43 -0
- package/corpus/templates/crm/actions/list-crm-signal-trackers.ts +32 -0
- package/corpus/templates/crm/actions/list-crm-tasks.ts +22 -0
- package/corpus/templates/crm/actions/list-staged-datasets.ts +14 -0
- package/corpus/templates/crm/actions/list-workspace-connections.ts +47 -0
- package/corpus/templates/crm/actions/manage-crm-attribute-option.ts +272 -0
- package/corpus/templates/crm/actions/manage-crm-signal-tracker.ts +87 -0
- package/corpus/templates/crm/actions/manage-crm-task.ts +132 -0
- package/corpus/templates/crm/actions/merge-crm-records.ts +691 -0
- package/corpus/templates/crm/actions/navigate.ts +54 -0
- package/corpus/templates/crm/actions/provider-api-catalog.ts +22 -0
- package/corpus/templates/crm/actions/provider-api-docs.ts +54 -0
- package/corpus/templates/crm/actions/provider-api-request.ts +92 -0
- package/corpus/templates/crm/actions/query-staged-dataset.ts +44 -0
- package/corpus/templates/crm/actions/record-crm-call-insight.ts +160 -0
- package/corpus/templates/crm/actions/record-crm-smart-signal.ts +150 -0
- package/corpus/templates/crm/actions/remove-crm-list-entry.ts +79 -0
- package/corpus/templates/crm/actions/restore-crm-dashboard-revision.ts +23 -0
- package/corpus/templates/crm/actions/review-crm-signal.ts +31 -0
- package/corpus/templates/crm/actions/run-crm-attribute-fill.ts +443 -0
- package/corpus/templates/crm/actions/run-crm-enrichment.ts +647 -0
- package/corpus/templates/crm/actions/run-crm-saved-view-program.ts +103 -0
- package/corpus/templates/crm/actions/run-crm-signal-trackers.ts +265 -0
- package/corpus/templates/crm/actions/run.ts +7 -0
- package/corpus/templates/crm/actions/save-crm-dashboard.ts +51 -0
- package/corpus/templates/crm/actions/save-crm-saved-view.ts +296 -0
- package/corpus/templates/crm/actions/sync-crm.ts +146 -0
- package/corpus/templates/crm/actions/update-crm-attribute.ts +111 -0
- package/corpus/templates/crm/actions/update-crm-list-entry.ts +102 -0
- package/corpus/templates/crm/actions/update-crm-list.ts +97 -0
- package/corpus/templates/crm/actions/update-crm-record.ts +543 -0
- package/corpus/templates/crm/actions/view-screen.ts +324 -0
- package/corpus/templates/crm/agent-native.app-skill.json +69 -0
- package/corpus/templates/crm/app/components/crm/CreateCrmRecordDialog.tsx +158 -0
- package/corpus/templates/crm/app/components/crm/CrmDashboardPanel.tsx +78 -0
- package/corpus/templates/crm/app/components/crm/CrmSignalsPanel.tsx +220 -0
- package/corpus/templates/crm/app/components/crm/IntelligenceSettings.tsx +414 -0
- package/corpus/templates/crm/app/components/crm/RecordActions.tsx +648 -0
- package/corpus/templates/crm/app/components/crm/RecordGrid.tsx +488 -0
- package/corpus/templates/crm/app/components/crm/RecordWorkspace.tsx +232 -0
- package/corpus/templates/crm/app/components/crm/SavedViewDataProgram.tsx +93 -0
- package/corpus/templates/crm/app/components/crm/Surface.tsx +97 -0
- package/corpus/templates/crm/app/components/crm/WorkOverview.tsx +180 -0
- package/corpus/templates/crm/app/components/crm/board/CrmBoard.tsx +988 -0
- package/corpus/templates/crm/app/components/crm/board/board-model.ts +399 -0
- package/corpus/templates/crm/app/components/crm/board/entry-filter.ts +150 -0
- package/corpus/templates/crm/app/components/crm/board/view-draft.ts +227 -0
- package/corpus/templates/crm/app/components/crm/grid/CrmGrid.tsx +1033 -0
- package/corpus/templates/crm/app/components/crm/grid/GridCell.tsx +620 -0
- package/corpus/templates/crm/app/components/crm/grid/clipboard.ts +84 -0
- package/corpus/templates/crm/app/components/crm/grid/model.ts +304 -0
- package/corpus/templates/crm/app/components/crm/grid/navigation.ts +220 -0
- package/corpus/templates/crm/app/components/crm/grid/query.ts +214 -0
- package/corpus/templates/crm/app/components/crm/record/AttributePanel.tsx +192 -0
- package/corpus/templates/crm/app/components/crm/record/FieldHistory.tsx +179 -0
- package/corpus/templates/crm/app/components/crm/record/RecordHeader.tsx +103 -0
- package/corpus/templates/crm/app/components/crm/record/RecordLists.tsx +235 -0
- package/corpus/templates/crm/app/components/crm/record/RecordTabs.tsx +206 -0
- package/corpus/templates/crm/app/components/crm/record/field-editors.tsx +245 -0
- package/corpus/templates/crm/app/components/crm/record/record-data.ts +603 -0
- package/corpus/templates/crm/app/components/crm/settings/AdvancedSettings.tsx +49 -0
- package/corpus/templates/crm/app/components/crm/settings/AttributeOptionsEditor.tsx +441 -0
- package/corpus/templates/crm/app/components/crm/settings/ConnectionSettings.tsx +169 -0
- package/corpus/templates/crm/app/components/crm/settings/FieldsSettings.tsx +935 -0
- package/corpus/templates/crm/app/components/crm/settings/ListsSettings.tsx +339 -0
- package/corpus/templates/crm/app/components/crm/settings/settings-admin.ts +377 -0
- package/corpus/templates/crm/app/components/crm/shared/AttributeValueParts.tsx +69 -0
- package/corpus/templates/crm/app/components/crm/shared/attribute-value.ts +591 -0
- package/corpus/templates/crm/app/components/layout/CrmCommandMenu.tsx +556 -0
- package/corpus/templates/crm/app/components/layout/CrmLayout.tsx +130 -0
- package/corpus/templates/crm/app/components/layout/CrmSidebar.tsx +407 -0
- package/corpus/templates/crm/app/components/layout/command-palette-search.ts +126 -0
- package/corpus/templates/crm/app/components/layout/crm-ui-intents.ts +41 -0
- package/corpus/templates/crm/app/components/layout/sidebar-collapse.ts +40 -0
- package/corpus/templates/crm/app/components/layout/sidebar-lists.ts +109 -0
- package/corpus/templates/crm/app/components/ui/alert-dialog.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/badge.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/button.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/card.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/checkbox.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/dialog.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/dropdown-menu.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/hover-card.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/input.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/label.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/popover.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/select.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/sheet.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/skeleton.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/switch.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/table.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/tabs.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/textarea.tsx +1 -0
- package/corpus/templates/crm/app/components/ui/toolkit-provider.tsx +17 -0
- package/corpus/templates/crm/app/components/ui/tooltip.tsx +1 -0
- package/corpus/templates/crm/app/design-system.ts +3 -0
- package/corpus/templates/crm/app/entry.client.tsx +19 -0
- package/corpus/templates/crm/app/entry.server.tsx +10 -0
- package/corpus/templates/crm/app/global.css +167 -0
- package/corpus/templates/crm/app/hooks/use-keyboard-shortcuts.ts +206 -0
- package/corpus/templates/crm/app/hooks/use-navigation-state.ts +48 -0
- package/corpus/templates/crm/app/i18n/en-US.ts +684 -0
- package/corpus/templates/crm/app/i18n/index.ts +34 -0
- package/corpus/templates/crm/app/lib/dashboard.ts +13 -0
- package/corpus/templates/crm/app/lib/navigation.ts +17 -0
- package/corpus/templates/crm/app/lib/tab-id.ts +1 -0
- package/corpus/templates/crm/app/lib/types.ts +172 -0
- package/corpus/templates/crm/app/lib/utils.ts +1 -0
- package/corpus/templates/crm/app/root.tsx +93 -0
- package/corpus/templates/crm/app/routes/_index.tsx +26 -0
- package/corpus/templates/crm/app/routes/accounts.tsx +41 -0
- package/corpus/templates/crm/app/routes/agent.tsx +5 -0
- package/corpus/templates/crm/app/routes/ask.tsx +53 -0
- package/corpus/templates/crm/app/routes/dashboard.tsx +118 -0
- package/corpus/templates/crm/app/routes/lists.tsx +228 -0
- package/corpus/templates/crm/app/routes/opportunities.tsx +41 -0
- package/corpus/templates/crm/app/routes/people.tsx +41 -0
- package/corpus/templates/crm/app/routes/proposals.tsx +388 -0
- package/corpus/templates/crm/app/routes/records.$recordId.tsx +53 -0
- package/corpus/templates/crm/app/routes/records.tsx +64 -0
- package/corpus/templates/crm/app/routes/settings.tsx +118 -0
- package/corpus/templates/crm/app/routes/setup.tsx +308 -0
- package/corpus/templates/crm/app/routes/tasks.tsx +252 -0
- package/corpus/templates/crm/app/routes/views.tsx +683 -0
- package/corpus/templates/crm/app/routes.ts +19 -0
- package/corpus/templates/crm/app/vite-env.d.ts +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-any-list-or-view-can-be-shown-as-a-board-grouped-by-stage-so.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-crm-now-finds-likely-duplicate-records-and-tells-you-exactly.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-enrichment-now-shows-what-a-run-will-cost-before-it-starts-g.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-lists-turn-any-set-of-records-into-a-pipeline-with-its-own-s.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-moving-a-record-or-list-entry-into-a-stage-that-was-retired-.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-opening-a-record-now-shows-one-page-with-its-fields-the-list.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-press-cmd-k-to-jump-to-any-record-list-view-or-setting-and-u.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-provider-record-edits-now-show-an-exact-before-after-diff-an.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-record-page-attribute-labels-now-read-in-full-instead-of-bei.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-records-now-use-typed-fields-currency-dates-ratings-status-s.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-retyping-a-value-on-the-record-page-now-replaces-it-instead-.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-settings-now-has-fields-and-lists-tabs-for-adding-fields-edi.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-the-proposal-review-now-shows-the-field-that-actually-change.md +6 -0
- package/corpus/templates/crm/changelog/2026-07-26-the-record-grid-is-now-a-real-spreadsheet-filter-sort-and-pa.md +6 -0
- package/corpus/templates/crm/components.json +20 -0
- package/corpus/templates/crm/docs/architecture/crm-contract.md +214 -0
- package/corpus/templates/crm/docs/features/README.md +55 -0
- package/corpus/templates/crm/docs/features/f1-records-and-fields.mdx +52 -0
- package/corpus/templates/crm/docs/features/f2-lists-pipelines-and-views.mdx +48 -0
- package/corpus/templates/crm/docs/features/f3-work-and-record-quality.mdx +40 -0
- package/corpus/templates/crm/docs/features/f4-evidence-and-chat.mdx +47 -0
- package/corpus/templates/crm/learnings.defaults.md +5 -0
- package/corpus/templates/crm/netlify.toml +11 -0
- package/corpus/templates/crm/package.json +61 -0
- package/corpus/templates/crm/public/favicon.svg +1 -0
- package/corpus/templates/crm/public/icon-180.svg +1 -0
- package/corpus/templates/crm/public/manifest.json +11 -0
- package/corpus/templates/crm/react-router.config.ts +7 -0
- package/corpus/templates/crm/server/crm/adapter.ts +32 -0
- package/corpus/templates/crm/server/crm/crm-field-firewall.ts +64 -0
- package/corpus/templates/crm/server/crm/crm-mirror.ts +721 -0
- package/corpus/templates/crm/server/crm/field-policy-attributes.ts +48 -0
- package/corpus/templates/crm/server/crm/hubspot-adapter.ts +1146 -0
- package/corpus/templates/crm/server/crm/native-adapter.ts +1810 -0
- package/corpus/templates/crm/server/crm/provider-record-link.ts +264 -0
- package/corpus/templates/crm/server/crm/read-through.ts +207 -0
- package/corpus/templates/crm/server/crm/salesforce-adapter.ts +1255 -0
- package/corpus/templates/crm/server/db/crm-store.ts +1112 -0
- package/corpus/templates/crm/server/db/index.ts +191 -0
- package/corpus/templates/crm/server/db/schema.ts +647 -0
- package/corpus/templates/crm/server/lib/crm-query.ts +1558 -0
- package/corpus/templates/crm/server/lib/dedupe.ts +714 -0
- package/corpus/templates/crm/server/lib/enrichment-cost.ts +381 -0
- package/corpus/templates/crm/server/lib/enrichment-slots.ts +519 -0
- package/corpus/templates/crm/server/lib/intelligence/default-detectors.ts +65 -0
- package/corpus/templates/crm/server/lib/intelligence/evidence.ts +105 -0
- package/corpus/templates/crm/server/lib/intelligence/keyword-detector.ts +94 -0
- package/corpus/templates/crm/server/lib/intelligence/smart-detector.ts +39 -0
- package/corpus/templates/crm/server/lib/intelligence/summary.ts +19 -0
- package/corpus/templates/crm/server/lib/lifecycle.ts +634 -0
- package/corpus/templates/crm/server/lib/provider-api.ts +64 -0
- package/corpus/templates/crm/server/middleware/auth.ts +4 -0
- package/corpus/templates/crm/server/plugins/agent-chat.ts +65 -0
- package/corpus/templates/crm/server/plugins/auth.ts +14 -0
- package/corpus/templates/crm/server/plugins/core-routes.ts +17 -0
- package/corpus/templates/crm/server/plugins/db.ts +738 -0
- package/corpus/templates/crm/server/routes/[...page].get.ts +5 -0
- package/corpus/templates/crm/shared/crm-attributes.ts +469 -0
- package/corpus/templates/crm/shared/crm-automation-recipes.ts +132 -0
- package/corpus/templates/crm/shared/crm-contract.ts +417 -0
- package/corpus/templates/crm/shared/crm-navigation.ts +190 -0
- package/corpus/templates/crm/shared/crm-sales-config.ts +63 -0
- package/corpus/templates/crm/ssr-entry.ts +11 -0
- package/corpus/templates/crm/tsconfig.json +24 -0
- package/corpus/templates/crm/vite.config.ts +15 -0
- package/corpus/templates/crm/vitest.config.ts +5 -0
- package/corpus/templates/design/app/i18n-data.ts +12 -12
- package/corpus/templates/design/changelog/2026-07-26-apply-design-updates-from-a-centered-top-toolbar-without-cov.md +6 -0
- package/dist/cli/templates-meta.d.ts.map +1 -1
- package/dist/cli/templates-meta.js +12 -0
- package/dist/cli/templates-meta.js.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/observability/routes.d.ts +3 -3
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/server/realtime-token.d.ts +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/package.json +1 -1
- package/src/cli/templates-meta.ts +12 -0
|
@@ -0,0 +1,935 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useActionMutation,
|
|
3
|
+
useActionQuery,
|
|
4
|
+
} from "@agent-native/core/client/hooks";
|
|
5
|
+
import { useT } from "@agent-native/core/client/i18n";
|
|
6
|
+
import {
|
|
7
|
+
IconAlertTriangle,
|
|
8
|
+
IconArchive,
|
|
9
|
+
IconArrowBackUp,
|
|
10
|
+
IconLock,
|
|
11
|
+
IconPencil,
|
|
12
|
+
IconPlus,
|
|
13
|
+
IconTags,
|
|
14
|
+
} from "@tabler/icons-react";
|
|
15
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
16
|
+
import { useMemo, useState } from "react";
|
|
17
|
+
import { toast } from "sonner";
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
AlertDialog,
|
|
21
|
+
AlertDialogAction,
|
|
22
|
+
AlertDialogCancel,
|
|
23
|
+
AlertDialogContent,
|
|
24
|
+
AlertDialogDescription,
|
|
25
|
+
AlertDialogFooter,
|
|
26
|
+
AlertDialogHeader,
|
|
27
|
+
AlertDialogTitle,
|
|
28
|
+
AlertDialogTrigger,
|
|
29
|
+
} from "@/components/ui/alert-dialog";
|
|
30
|
+
import { Badge } from "@/components/ui/badge";
|
|
31
|
+
import { Button } from "@/components/ui/button";
|
|
32
|
+
import {
|
|
33
|
+
Dialog,
|
|
34
|
+
DialogContent,
|
|
35
|
+
DialogDescription,
|
|
36
|
+
DialogFooter,
|
|
37
|
+
DialogHeader,
|
|
38
|
+
DialogTitle,
|
|
39
|
+
DialogTrigger,
|
|
40
|
+
} from "@/components/ui/dialog";
|
|
41
|
+
import { Input } from "@/components/ui/input";
|
|
42
|
+
import { Label } from "@/components/ui/label";
|
|
43
|
+
import {
|
|
44
|
+
Select,
|
|
45
|
+
SelectContent,
|
|
46
|
+
SelectGroup,
|
|
47
|
+
SelectItem,
|
|
48
|
+
SelectLabel,
|
|
49
|
+
SelectTrigger,
|
|
50
|
+
SelectValue,
|
|
51
|
+
} from "@/components/ui/select";
|
|
52
|
+
import { Switch } from "@/components/ui/switch";
|
|
53
|
+
import {
|
|
54
|
+
Table,
|
|
55
|
+
TableBody,
|
|
56
|
+
TableCell,
|
|
57
|
+
TableHead,
|
|
58
|
+
TableHeader,
|
|
59
|
+
TableRow,
|
|
60
|
+
} from "@/components/ui/table";
|
|
61
|
+
import { Textarea } from "@/components/ui/textarea";
|
|
62
|
+
import {
|
|
63
|
+
Tooltip,
|
|
64
|
+
TooltipContent,
|
|
65
|
+
TooltipProvider,
|
|
66
|
+
TooltipTrigger,
|
|
67
|
+
} from "@/components/ui/tooltip";
|
|
68
|
+
|
|
69
|
+
import type {
|
|
70
|
+
CrmAttributeDefinition,
|
|
71
|
+
CrmAttributeType,
|
|
72
|
+
} from "../../../../shared/crm-contract";
|
|
73
|
+
import { AttributeOptionsEditor } from "./AttributeOptionsEditor";
|
|
74
|
+
import {
|
|
75
|
+
applyAttributePatch,
|
|
76
|
+
attributeEditDraft,
|
|
77
|
+
attributeTypeCapabilities,
|
|
78
|
+
ATTRIBUTE_AUTHORITY_INFO,
|
|
79
|
+
AUTHORED_ATTRIBUTE_TYPES,
|
|
80
|
+
buildCreateAttributeInput,
|
|
81
|
+
buildUpdateAttributeInput,
|
|
82
|
+
emptyAttributeDraft,
|
|
83
|
+
emptyAttributeOptionDraft,
|
|
84
|
+
hasAttributeEdits,
|
|
85
|
+
type AttributeDraft,
|
|
86
|
+
type AttributeEditDraft,
|
|
87
|
+
type CrmAttributeListResult,
|
|
88
|
+
type UpdateAttributeInput,
|
|
89
|
+
} from "./settings-admin";
|
|
90
|
+
|
|
91
|
+
interface CrmConnectionSummary {
|
|
92
|
+
id: string;
|
|
93
|
+
provider: string;
|
|
94
|
+
label: string;
|
|
95
|
+
mode: string;
|
|
96
|
+
objectTypes: string[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface CrmListSummary {
|
|
100
|
+
id: string;
|
|
101
|
+
connectionId: string;
|
|
102
|
+
name: string;
|
|
103
|
+
parentObjectType: string;
|
|
104
|
+
archived: boolean;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface FieldsTarget {
|
|
108
|
+
key: string;
|
|
109
|
+
target: "object" | "list";
|
|
110
|
+
targetId: string;
|
|
111
|
+
connectionId: string;
|
|
112
|
+
label: string;
|
|
113
|
+
group: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function FieldsSettings() {
|
|
117
|
+
const t = useT();
|
|
118
|
+
const queryClient = useQueryClient();
|
|
119
|
+
const connectionsQuery = useActionQuery<{
|
|
120
|
+
connections: CrmConnectionSummary[];
|
|
121
|
+
}>("list-crm-connections" as never, {} as never);
|
|
122
|
+
const listsQuery = useActionQuery<{ lists: CrmListSummary[] }>(
|
|
123
|
+
"list-crm-lists" as never,
|
|
124
|
+
{ limit: 100 } as never,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const targets = useMemo<FieldsTarget[]>(() => {
|
|
128
|
+
const connections = connectionsQuery.data?.connections ?? [];
|
|
129
|
+
const objectTargets = connections.flatMap((connection) =>
|
|
130
|
+
connection.objectTypes.map((objectType) => ({
|
|
131
|
+
key: `object:${connection.id}:${objectType}`,
|
|
132
|
+
target: "object" as const,
|
|
133
|
+
targetId: objectType,
|
|
134
|
+
connectionId: connection.id,
|
|
135
|
+
label: objectType,
|
|
136
|
+
group: connection.label,
|
|
137
|
+
})),
|
|
138
|
+
);
|
|
139
|
+
const listTargets = (listsQuery.data?.lists ?? [])
|
|
140
|
+
.filter((list) => !list.archived)
|
|
141
|
+
.map((list) => ({
|
|
142
|
+
key: `list:${list.id}`,
|
|
143
|
+
target: "list" as const,
|
|
144
|
+
targetId: list.id,
|
|
145
|
+
connectionId: list.connectionId,
|
|
146
|
+
label: list.name,
|
|
147
|
+
group: t("fields.listsGroup"),
|
|
148
|
+
}));
|
|
149
|
+
return [...objectTargets, ...listTargets];
|
|
150
|
+
}, [connectionsQuery.data, listsQuery.data, t]);
|
|
151
|
+
|
|
152
|
+
const [targetKey, setTargetKey] = useState("");
|
|
153
|
+
const [includeArchived, setIncludeArchived] = useState(false);
|
|
154
|
+
const activeTarget =
|
|
155
|
+
targets.find((target) => target.key === targetKey) ?? targets[0];
|
|
156
|
+
|
|
157
|
+
const attributeParams = activeTarget
|
|
158
|
+
? {
|
|
159
|
+
target: activeTarget.target,
|
|
160
|
+
targetId: activeTarget.targetId,
|
|
161
|
+
connectionId: activeTarget.connectionId,
|
|
162
|
+
includeArchived,
|
|
163
|
+
}
|
|
164
|
+
: undefined;
|
|
165
|
+
const attributesKey = ["action", "list-crm-attributes", attributeParams];
|
|
166
|
+
const attributesQuery = useActionQuery<CrmAttributeListResult>(
|
|
167
|
+
"list-crm-attributes" as never,
|
|
168
|
+
attributeParams as never,
|
|
169
|
+
{ enabled: Boolean(activeTarget) } as never,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Writes the optimistic state and hands back the undo. An error path that
|
|
174
|
+
* cannot restore the previous rows would leave the table asserting a change
|
|
175
|
+
* the server refused.
|
|
176
|
+
*/
|
|
177
|
+
function patchAttribute(
|
|
178
|
+
attributeId: string,
|
|
179
|
+
patch: Partial<CrmAttributeDefinition>,
|
|
180
|
+
) {
|
|
181
|
+
void queryClient.cancelQueries({ queryKey: attributesKey });
|
|
182
|
+
const previous =
|
|
183
|
+
queryClient.getQueryData<CrmAttributeListResult>(attributesKey);
|
|
184
|
+
queryClient.setQueryData(
|
|
185
|
+
attributesKey,
|
|
186
|
+
applyAttributePatch(previous, attributeId, patch),
|
|
187
|
+
);
|
|
188
|
+
return () => queryClient.setQueryData(attributesKey, previous);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const attributes = attributesQuery.data?.attributes ?? [];
|
|
192
|
+
const loadFailed = connectionsQuery.isError || listsQuery.isError;
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<TooltipProvider>
|
|
196
|
+
<div className="mx-auto w-full max-w-4xl">
|
|
197
|
+
<div className="flex flex-wrap items-start justify-between gap-4">
|
|
198
|
+
<div className="min-w-0">
|
|
199
|
+
<h1 className="text-xl font-semibold tracking-tight">
|
|
200
|
+
{t("fields.title")}
|
|
201
|
+
</h1>
|
|
202
|
+
<p className="mt-1 max-w-2xl text-sm leading-6 text-muted-foreground">
|
|
203
|
+
{t("fields.description")}
|
|
204
|
+
</p>
|
|
205
|
+
</div>
|
|
206
|
+
{activeTarget ? (
|
|
207
|
+
<CreateAttributeDialog
|
|
208
|
+
target={activeTarget}
|
|
209
|
+
onCreated={() =>
|
|
210
|
+
void queryClient.invalidateQueries({
|
|
211
|
+
queryKey: ["action", "list-crm-attributes"],
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
/>
|
|
215
|
+
) : null}
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
<AuthorityLegend />
|
|
219
|
+
|
|
220
|
+
{loadFailed ? (
|
|
221
|
+
<div className="mt-6 flex items-center gap-3 rounded-lg border border-destructive/40 bg-destructive/5 px-4 py-3">
|
|
222
|
+
<IconAlertTriangle className="size-4 shrink-0 text-destructive" />
|
|
223
|
+
<p className="flex-1 text-sm">{t("fields.targetsLoadFailed")}</p>
|
|
224
|
+
<Button
|
|
225
|
+
variant="outline"
|
|
226
|
+
size="sm"
|
|
227
|
+
onClick={() => {
|
|
228
|
+
void connectionsQuery.refetch();
|
|
229
|
+
void listsQuery.refetch();
|
|
230
|
+
}}
|
|
231
|
+
>
|
|
232
|
+
{t("fields.retry")}
|
|
233
|
+
</Button>
|
|
234
|
+
</div>
|
|
235
|
+
) : null}
|
|
236
|
+
|
|
237
|
+
<div className="mt-6 flex flex-wrap items-end gap-4">
|
|
238
|
+
<div className="grid min-w-56 gap-2">
|
|
239
|
+
<Label htmlFor="fields-target">{t("fields.target")}</Label>
|
|
240
|
+
<Select
|
|
241
|
+
value={activeTarget?.key ?? ""}
|
|
242
|
+
onValueChange={setTargetKey}
|
|
243
|
+
disabled={!targets.length}
|
|
244
|
+
>
|
|
245
|
+
<SelectTrigger id="fields-target">
|
|
246
|
+
<SelectValue placeholder={t("fields.targetPlaceholder")} />
|
|
247
|
+
</SelectTrigger>
|
|
248
|
+
<SelectContent>
|
|
249
|
+
{groupTargets(targets).map(([group, groupTargetList]) => (
|
|
250
|
+
<SelectGroup key={group}>
|
|
251
|
+
<SelectLabel>{group}</SelectLabel>
|
|
252
|
+
{groupTargetList.map((target) => (
|
|
253
|
+
<SelectItem key={target.key} value={target.key}>
|
|
254
|
+
{target.label}
|
|
255
|
+
</SelectItem>
|
|
256
|
+
))}
|
|
257
|
+
</SelectGroup>
|
|
258
|
+
))}
|
|
259
|
+
</SelectContent>
|
|
260
|
+
</Select>
|
|
261
|
+
</div>
|
|
262
|
+
<label className="flex items-center gap-2 pb-2 text-sm text-muted-foreground">
|
|
263
|
+
<Switch
|
|
264
|
+
checked={includeArchived}
|
|
265
|
+
onCheckedChange={setIncludeArchived}
|
|
266
|
+
aria-label={t("fields.showArchived")}
|
|
267
|
+
/>
|
|
268
|
+
{t("fields.showArchived")}
|
|
269
|
+
</label>
|
|
270
|
+
</div>
|
|
271
|
+
|
|
272
|
+
{attributesQuery.isError ? (
|
|
273
|
+
<div className="mt-6 flex items-center gap-3 rounded-lg border border-destructive/40 bg-destructive/5 px-4 py-3">
|
|
274
|
+
<IconAlertTriangle className="size-4 shrink-0 text-destructive" />
|
|
275
|
+
<p className="flex-1 text-sm">
|
|
276
|
+
{attributesQuery.error instanceof Error
|
|
277
|
+
? attributesQuery.error.message
|
|
278
|
+
: t("fields.attributesLoadFailed")}
|
|
279
|
+
</p>
|
|
280
|
+
<Button
|
|
281
|
+
variant="outline"
|
|
282
|
+
size="sm"
|
|
283
|
+
onClick={() => void attributesQuery.refetch()}
|
|
284
|
+
>
|
|
285
|
+
{t("fields.retry")}
|
|
286
|
+
</Button>
|
|
287
|
+
</div>
|
|
288
|
+
) : attributes.length ? (
|
|
289
|
+
<div className="mt-4 overflow-x-auto rounded-lg border border-border/70">
|
|
290
|
+
<Table>
|
|
291
|
+
<TableHeader>
|
|
292
|
+
<TableRow>
|
|
293
|
+
<TableHead>{t("fields.columnName")}</TableHead>
|
|
294
|
+
<TableHead>{t("fields.columnSlug")}</TableHead>
|
|
295
|
+
<TableHead>{t("fields.columnType")}</TableHead>
|
|
296
|
+
<TableHead>{t("fields.columnAuthority")}</TableHead>
|
|
297
|
+
<TableHead>{t("fields.columnRules")}</TableHead>
|
|
298
|
+
<TableHead className="text-end">
|
|
299
|
+
{t("fields.columnActions")}
|
|
300
|
+
</TableHead>
|
|
301
|
+
</TableRow>
|
|
302
|
+
</TableHeader>
|
|
303
|
+
<TableBody>
|
|
304
|
+
{attributes.map((attribute) => (
|
|
305
|
+
<AttributeRow
|
|
306
|
+
key={attribute.id}
|
|
307
|
+
attribute={attribute}
|
|
308
|
+
patchAttribute={patchAttribute}
|
|
309
|
+
/>
|
|
310
|
+
))}
|
|
311
|
+
</TableBody>
|
|
312
|
+
</Table>
|
|
313
|
+
</div>
|
|
314
|
+
) : (
|
|
315
|
+
<div className="mt-4 rounded-lg border border-dashed border-border px-4 py-10 text-center">
|
|
316
|
+
<p className="text-sm font-medium">
|
|
317
|
+
{attributesQuery.isLoading
|
|
318
|
+
? t("fields.loading")
|
|
319
|
+
: t("fields.emptyTitle")}
|
|
320
|
+
</p>
|
|
321
|
+
<p className="mt-1 text-sm text-muted-foreground">
|
|
322
|
+
{t("fields.emptyDescription")}
|
|
323
|
+
</p>
|
|
324
|
+
</div>
|
|
325
|
+
)}
|
|
326
|
+
</div>
|
|
327
|
+
</TooltipProvider>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function groupTargets(
|
|
332
|
+
targets: FieldsTarget[],
|
|
333
|
+
): Array<[string, FieldsTarget[]]> {
|
|
334
|
+
const groups = new Map<string, FieldsTarget[]>();
|
|
335
|
+
for (const target of targets) {
|
|
336
|
+
groups.set(target.group, [...(groups.get(target.group) ?? []), target]);
|
|
337
|
+
}
|
|
338
|
+
return [...groups.entries()];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function AuthorityLegend() {
|
|
342
|
+
const t = useT();
|
|
343
|
+
return (
|
|
344
|
+
<div className="mt-5 grid gap-3 rounded-lg border border-border/70 bg-card p-4 sm:grid-cols-3">
|
|
345
|
+
{(["local-authoritative", "derived-local", "provider"] as const).map(
|
|
346
|
+
(authority) => {
|
|
347
|
+
const info = ATTRIBUTE_AUTHORITY_INFO[authority];
|
|
348
|
+
return (
|
|
349
|
+
<div key={authority} className="grid gap-1">
|
|
350
|
+
<Badge variant={info.badge} className="w-fit font-normal">
|
|
351
|
+
{t(info.labelKey)}
|
|
352
|
+
</Badge>
|
|
353
|
+
<p className="text-xs leading-5 text-muted-foreground">
|
|
354
|
+
{t(info.descriptionKey)}
|
|
355
|
+
</p>
|
|
356
|
+
</div>
|
|
357
|
+
);
|
|
358
|
+
},
|
|
359
|
+
)}
|
|
360
|
+
</div>
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function AttributeRow({
|
|
365
|
+
attribute,
|
|
366
|
+
patchAttribute,
|
|
367
|
+
}: {
|
|
368
|
+
attribute: CrmAttributeDefinition;
|
|
369
|
+
patchAttribute: (
|
|
370
|
+
attributeId: string,
|
|
371
|
+
patch: Partial<CrmAttributeDefinition>,
|
|
372
|
+
) => () => void;
|
|
373
|
+
}) {
|
|
374
|
+
const t = useT();
|
|
375
|
+
const authority = ATTRIBUTE_AUTHORITY_INFO[attribute.authority];
|
|
376
|
+
const capabilities = attributeTypeCapabilities(attribute.attributeType);
|
|
377
|
+
const rules = [
|
|
378
|
+
attribute.required ? t("fields.ruleRequired") : null,
|
|
379
|
+
attribute.uniqueValue ? t("fields.ruleUnique") : null,
|
|
380
|
+
attribute.historyTracked ? t("fields.ruleHistory") : null,
|
|
381
|
+
attribute.multi ? t("fields.ruleMulti") : null,
|
|
382
|
+
].filter(Boolean) as string[];
|
|
383
|
+
|
|
384
|
+
return (
|
|
385
|
+
<TableRow className={attribute.archived ? "opacity-60" : undefined}>
|
|
386
|
+
<TableCell className="font-medium">
|
|
387
|
+
<span className="flex flex-wrap items-center gap-2">
|
|
388
|
+
{attribute.label}
|
|
389
|
+
{attribute.archived ? (
|
|
390
|
+
<Badge variant="outline" className="font-normal">
|
|
391
|
+
{t("fields.archived")}
|
|
392
|
+
</Badge>
|
|
393
|
+
) : null}
|
|
394
|
+
</span>
|
|
395
|
+
{attribute.description ? (
|
|
396
|
+
<p className="mt-1 text-xs text-muted-foreground">
|
|
397
|
+
{attribute.description}
|
|
398
|
+
</p>
|
|
399
|
+
) : null}
|
|
400
|
+
</TableCell>
|
|
401
|
+
<TableCell>
|
|
402
|
+
<code className="rounded bg-muted px-1.5 py-0.5 text-xs">
|
|
403
|
+
{attribute.apiSlug}
|
|
404
|
+
</code>
|
|
405
|
+
</TableCell>
|
|
406
|
+
<TableCell className="text-sm text-muted-foreground">
|
|
407
|
+
{attribute.attributeType}
|
|
408
|
+
</TableCell>
|
|
409
|
+
<TableCell>
|
|
410
|
+
<Tooltip delayDuration={0}>
|
|
411
|
+
<TooltipTrigger asChild>
|
|
412
|
+
<Badge variant={authority.badge} className="font-normal">
|
|
413
|
+
{t(authority.labelKey)}
|
|
414
|
+
</Badge>
|
|
415
|
+
</TooltipTrigger>
|
|
416
|
+
<TooltipContent side="top" className="max-w-64">
|
|
417
|
+
{t(authority.descriptionKey)}
|
|
418
|
+
</TooltipContent>
|
|
419
|
+
</Tooltip>
|
|
420
|
+
</TableCell>
|
|
421
|
+
<TableCell className="text-xs text-muted-foreground">
|
|
422
|
+
{rules.length ? rules.join(" · ") : t("fields.ruleNone")}
|
|
423
|
+
</TableCell>
|
|
424
|
+
<TableCell>
|
|
425
|
+
<div className="flex items-center justify-end gap-1">
|
|
426
|
+
{capabilities.usesOptions ? (
|
|
427
|
+
<AttributeOptionsEditor
|
|
428
|
+
attribute={attribute}
|
|
429
|
+
patchAttribute={patchAttribute}
|
|
430
|
+
trigger={
|
|
431
|
+
<Button
|
|
432
|
+
variant="ghost"
|
|
433
|
+
size="icon"
|
|
434
|
+
aria-label={t("fields.editOptionsAria", {
|
|
435
|
+
name: attribute.label,
|
|
436
|
+
})}
|
|
437
|
+
>
|
|
438
|
+
<IconTags className="size-4" />
|
|
439
|
+
</Button>
|
|
440
|
+
}
|
|
441
|
+
/>
|
|
442
|
+
) : null}
|
|
443
|
+
<EditAttributeDialog
|
|
444
|
+
attribute={attribute}
|
|
445
|
+
patchAttribute={patchAttribute}
|
|
446
|
+
/>
|
|
447
|
+
<ArchiveAttributeButton
|
|
448
|
+
attribute={attribute}
|
|
449
|
+
patchAttribute={patchAttribute}
|
|
450
|
+
/>
|
|
451
|
+
</div>
|
|
452
|
+
</TableCell>
|
|
453
|
+
</TableRow>
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* `api_slug` and the attribute type are shown, never offered: the actions
|
|
459
|
+
* reject a change to either because stored value rows are keyed by the slug and
|
|
460
|
+
* typed by the type.
|
|
461
|
+
*/
|
|
462
|
+
function ImmutableField({
|
|
463
|
+
label,
|
|
464
|
+
value,
|
|
465
|
+
explanation,
|
|
466
|
+
}: {
|
|
467
|
+
label: string;
|
|
468
|
+
value: string;
|
|
469
|
+
explanation: string;
|
|
470
|
+
}) {
|
|
471
|
+
return (
|
|
472
|
+
<div className="grid gap-2">
|
|
473
|
+
<Label>{label}</Label>
|
|
474
|
+
<Tooltip delayDuration={0}>
|
|
475
|
+
<TooltipTrigger asChild>
|
|
476
|
+
<div className="flex cursor-help items-center gap-2 rounded-md border border-border bg-muted/40 px-3 py-2 text-sm text-muted-foreground">
|
|
477
|
+
<IconLock className="size-3.5 shrink-0" />
|
|
478
|
+
<code className="truncate">{value}</code>
|
|
479
|
+
</div>
|
|
480
|
+
</TooltipTrigger>
|
|
481
|
+
<TooltipContent side="top" className="max-w-72">
|
|
482
|
+
{explanation}
|
|
483
|
+
</TooltipContent>
|
|
484
|
+
</Tooltip>
|
|
485
|
+
</div>
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function EditAttributeDialog({
|
|
490
|
+
attribute,
|
|
491
|
+
patchAttribute,
|
|
492
|
+
}: {
|
|
493
|
+
attribute: CrmAttributeDefinition;
|
|
494
|
+
patchAttribute: (
|
|
495
|
+
attributeId: string,
|
|
496
|
+
patch: Partial<CrmAttributeDefinition>,
|
|
497
|
+
) => () => void;
|
|
498
|
+
}) {
|
|
499
|
+
const t = useT();
|
|
500
|
+
const [open, setOpen] = useState(false);
|
|
501
|
+
const [draft, setDraft] = useState<AttributeEditDraft>(() =>
|
|
502
|
+
attributeEditDraft(attribute),
|
|
503
|
+
);
|
|
504
|
+
const update = useActionMutation<unknown, UpdateAttributeInput>(
|
|
505
|
+
"update-crm-attribute" as never,
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
function openChange(next: boolean) {
|
|
509
|
+
if (next) setDraft(attributeEditDraft(attribute));
|
|
510
|
+
setOpen(next);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
async function save() {
|
|
514
|
+
const input = buildUpdateAttributeInput(attribute, draft);
|
|
515
|
+
if (!hasAttributeEdits(input)) {
|
|
516
|
+
setOpen(false);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
setOpen(false);
|
|
520
|
+
const rollback = patchAttribute(attribute.id, {
|
|
521
|
+
label: draft.title.trim() || attribute.label,
|
|
522
|
+
description: draft.description.trim() || undefined,
|
|
523
|
+
required: draft.required,
|
|
524
|
+
historyTracked: draft.historyTracked,
|
|
525
|
+
});
|
|
526
|
+
try {
|
|
527
|
+
await update.mutateAsync(input);
|
|
528
|
+
} catch (error) {
|
|
529
|
+
rollback();
|
|
530
|
+
toast.error(
|
|
531
|
+
error instanceof Error ? error.message : t("fields.updateFailed"),
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return (
|
|
537
|
+
<Dialog open={open} onOpenChange={openChange}>
|
|
538
|
+
<DialogTrigger asChild>
|
|
539
|
+
<Button
|
|
540
|
+
variant="ghost"
|
|
541
|
+
size="icon"
|
|
542
|
+
aria-label={t("fields.editAria", { name: attribute.label })}
|
|
543
|
+
>
|
|
544
|
+
<IconPencil className="size-4" />
|
|
545
|
+
</Button>
|
|
546
|
+
</DialogTrigger>
|
|
547
|
+
<DialogContent className="sm:max-w-lg">
|
|
548
|
+
<DialogHeader>
|
|
549
|
+
<DialogTitle>{t("fields.editTitle")}</DialogTitle>
|
|
550
|
+
<DialogDescription>{t("fields.editDescription")}</DialogDescription>
|
|
551
|
+
</DialogHeader>
|
|
552
|
+
<div className="grid gap-4 py-2">
|
|
553
|
+
<div className="grid gap-2">
|
|
554
|
+
<Label htmlFor="attribute-title">{t("fields.name")}</Label>
|
|
555
|
+
<Input
|
|
556
|
+
id="attribute-title"
|
|
557
|
+
value={draft.title}
|
|
558
|
+
maxLength={200}
|
|
559
|
+
onChange={(event) =>
|
|
560
|
+
setDraft({ ...draft, title: event.target.value })
|
|
561
|
+
}
|
|
562
|
+
/>
|
|
563
|
+
</div>
|
|
564
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
565
|
+
<ImmutableField
|
|
566
|
+
label={t("fields.columnSlug")}
|
|
567
|
+
value={attribute.apiSlug}
|
|
568
|
+
explanation={t("fields.slugImmutable")}
|
|
569
|
+
/>
|
|
570
|
+
<ImmutableField
|
|
571
|
+
label={t("fields.columnType")}
|
|
572
|
+
value={attribute.attributeType}
|
|
573
|
+
explanation={t("fields.typeImmutable")}
|
|
574
|
+
/>
|
|
575
|
+
</div>
|
|
576
|
+
<div className="grid gap-2">
|
|
577
|
+
<Label htmlFor="attribute-description">
|
|
578
|
+
{t("fields.attributeDescription")}
|
|
579
|
+
</Label>
|
|
580
|
+
<Textarea
|
|
581
|
+
id="attribute-description"
|
|
582
|
+
value={draft.description}
|
|
583
|
+
maxLength={2000}
|
|
584
|
+
onChange={(event) =>
|
|
585
|
+
setDraft({ ...draft, description: event.target.value })
|
|
586
|
+
}
|
|
587
|
+
/>
|
|
588
|
+
</div>
|
|
589
|
+
<label className="flex items-center justify-between gap-4 text-sm">
|
|
590
|
+
<span>
|
|
591
|
+
{t("fields.required")}
|
|
592
|
+
<span className="mt-0.5 block text-xs text-muted-foreground">
|
|
593
|
+
{t("fields.requiredHelp")}
|
|
594
|
+
</span>
|
|
595
|
+
</span>
|
|
596
|
+
<Switch
|
|
597
|
+
checked={draft.required}
|
|
598
|
+
onCheckedChange={(required) => setDraft({ ...draft, required })}
|
|
599
|
+
/>
|
|
600
|
+
</label>
|
|
601
|
+
<label className="flex items-center justify-between gap-4 text-sm">
|
|
602
|
+
<span>
|
|
603
|
+
{t("fields.historyTracked")}
|
|
604
|
+
<span className="mt-0.5 block text-xs text-muted-foreground">
|
|
605
|
+
{t("fields.historyTrackedHelp")}
|
|
606
|
+
</span>
|
|
607
|
+
</span>
|
|
608
|
+
<Switch
|
|
609
|
+
checked={draft.historyTracked}
|
|
610
|
+
onCheckedChange={(historyTracked) =>
|
|
611
|
+
setDraft({ ...draft, historyTracked })
|
|
612
|
+
}
|
|
613
|
+
/>
|
|
614
|
+
</label>
|
|
615
|
+
{ATTRIBUTE_AUTHORITY_INFO[attribute.authority]
|
|
616
|
+
.editsBecomeProposals ? (
|
|
617
|
+
<p className="rounded-md border border-border/70 bg-muted/40 px-3 py-2 text-xs leading-5 text-muted-foreground">
|
|
618
|
+
{t("fields.providerEditNote")}
|
|
619
|
+
</p>
|
|
620
|
+
) : null}
|
|
621
|
+
</div>
|
|
622
|
+
<DialogFooter>
|
|
623
|
+
<Button onClick={() => void save()}>{t("fields.save")}</Button>
|
|
624
|
+
</DialogFooter>
|
|
625
|
+
</DialogContent>
|
|
626
|
+
</Dialog>
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function ArchiveAttributeButton({
|
|
631
|
+
attribute,
|
|
632
|
+
patchAttribute,
|
|
633
|
+
}: {
|
|
634
|
+
attribute: CrmAttributeDefinition;
|
|
635
|
+
patchAttribute: (
|
|
636
|
+
attributeId: string,
|
|
637
|
+
patch: Partial<CrmAttributeDefinition>,
|
|
638
|
+
) => () => void;
|
|
639
|
+
}) {
|
|
640
|
+
const t = useT();
|
|
641
|
+
const archive = useActionMutation<unknown, { attributeId: string }>(
|
|
642
|
+
"archive-crm-attribute" as never,
|
|
643
|
+
);
|
|
644
|
+
const update = useActionMutation<
|
|
645
|
+
unknown,
|
|
646
|
+
{ attributeId: string; archived: boolean }
|
|
647
|
+
>("update-crm-attribute" as never);
|
|
648
|
+
|
|
649
|
+
async function restore() {
|
|
650
|
+
const rollback = patchAttribute(attribute.id, { archived: false });
|
|
651
|
+
try {
|
|
652
|
+
await update.mutateAsync({
|
|
653
|
+
attributeId: attribute.id,
|
|
654
|
+
archived: false,
|
|
655
|
+
});
|
|
656
|
+
} catch (error) {
|
|
657
|
+
rollback();
|
|
658
|
+
toast.error(
|
|
659
|
+
error instanceof Error ? error.message : t("fields.updateFailed"),
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
async function run() {
|
|
665
|
+
const rollback = patchAttribute(attribute.id, { archived: true });
|
|
666
|
+
try {
|
|
667
|
+
await archive.mutateAsync({ attributeId: attribute.id });
|
|
668
|
+
} catch (error) {
|
|
669
|
+
rollback();
|
|
670
|
+
toast.error(
|
|
671
|
+
error instanceof Error ? error.message : t("fields.archiveFailed"),
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
if (attribute.archived) {
|
|
677
|
+
return (
|
|
678
|
+
<Button
|
|
679
|
+
variant="ghost"
|
|
680
|
+
size="icon"
|
|
681
|
+
aria-label={t("fields.restoreAria", { name: attribute.label })}
|
|
682
|
+
onClick={() => void restore()}
|
|
683
|
+
>
|
|
684
|
+
<IconArrowBackUp className="size-4" />
|
|
685
|
+
</Button>
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
return (
|
|
690
|
+
<AlertDialog>
|
|
691
|
+
<AlertDialogTrigger asChild>
|
|
692
|
+
<Button
|
|
693
|
+
variant="ghost"
|
|
694
|
+
size="icon"
|
|
695
|
+
aria-label={t("fields.archiveAria", { name: attribute.label })}
|
|
696
|
+
>
|
|
697
|
+
<IconArchive className="size-4" />
|
|
698
|
+
</Button>
|
|
699
|
+
</AlertDialogTrigger>
|
|
700
|
+
<AlertDialogContent>
|
|
701
|
+
<AlertDialogHeader>
|
|
702
|
+
<AlertDialogTitle>
|
|
703
|
+
{t("fields.archiveTitle", { name: attribute.label })}
|
|
704
|
+
</AlertDialogTitle>
|
|
705
|
+
<AlertDialogDescription>
|
|
706
|
+
{t("fields.archiveDescription")}
|
|
707
|
+
</AlertDialogDescription>
|
|
708
|
+
</AlertDialogHeader>
|
|
709
|
+
<AlertDialogFooter>
|
|
710
|
+
<AlertDialogCancel>{t("fields.cancel")}</AlertDialogCancel>
|
|
711
|
+
<AlertDialogAction onClick={() => void run()}>
|
|
712
|
+
{t("fields.archive")}
|
|
713
|
+
</AlertDialogAction>
|
|
714
|
+
</AlertDialogFooter>
|
|
715
|
+
</AlertDialogContent>
|
|
716
|
+
</AlertDialog>
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
function CreateAttributeDialog({
|
|
721
|
+
target,
|
|
722
|
+
onCreated,
|
|
723
|
+
}: {
|
|
724
|
+
target: FieldsTarget;
|
|
725
|
+
onCreated: () => void;
|
|
726
|
+
}) {
|
|
727
|
+
const t = useT();
|
|
728
|
+
const [open, setOpen] = useState(false);
|
|
729
|
+
const [draft, setDraft] = useState<AttributeDraft>(emptyAttributeDraft);
|
|
730
|
+
const create = useActionMutation<unknown, Record<string, unknown>>(
|
|
731
|
+
"create-crm-attribute" as never,
|
|
732
|
+
);
|
|
733
|
+
const capabilities = attributeTypeCapabilities(draft.type);
|
|
734
|
+
|
|
735
|
+
function openChange(next: boolean) {
|
|
736
|
+
if (!next) setDraft(emptyAttributeDraft());
|
|
737
|
+
setOpen(next);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
async function submit() {
|
|
741
|
+
try {
|
|
742
|
+
await create.mutateAsync(
|
|
743
|
+
buildCreateAttributeInput(draft, {
|
|
744
|
+
target: target.target,
|
|
745
|
+
targetId: target.targetId,
|
|
746
|
+
connectionId: target.connectionId,
|
|
747
|
+
}) as unknown as Record<string, unknown>,
|
|
748
|
+
);
|
|
749
|
+
openChange(false);
|
|
750
|
+
onCreated();
|
|
751
|
+
toast.success(t("fields.created"));
|
|
752
|
+
} catch (error) {
|
|
753
|
+
toast.error(
|
|
754
|
+
error instanceof Error ? error.message : t("fields.createFailed"),
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
return (
|
|
760
|
+
<Dialog open={open} onOpenChange={openChange}>
|
|
761
|
+
<DialogTrigger asChild>
|
|
762
|
+
<Button size="sm" className="gap-1.5">
|
|
763
|
+
<IconPlus className="size-4" /> {t("fields.newAttribute")}
|
|
764
|
+
</Button>
|
|
765
|
+
</DialogTrigger>
|
|
766
|
+
<DialogContent className="sm:max-w-lg">
|
|
767
|
+
<DialogHeader>
|
|
768
|
+
<DialogTitle>{t("fields.createTitle")}</DialogTitle>
|
|
769
|
+
<DialogDescription>
|
|
770
|
+
{t("fields.createDescription", { target: target.label })}
|
|
771
|
+
</DialogDescription>
|
|
772
|
+
</DialogHeader>
|
|
773
|
+
<div className="grid gap-4 py-2">
|
|
774
|
+
<div className="grid gap-2">
|
|
775
|
+
<Label htmlFor="new-attribute-title">{t("fields.name")}</Label>
|
|
776
|
+
<Input
|
|
777
|
+
id="new-attribute-title"
|
|
778
|
+
value={draft.title}
|
|
779
|
+
maxLength={200}
|
|
780
|
+
onChange={(event) =>
|
|
781
|
+
setDraft({ ...draft, title: event.target.value })
|
|
782
|
+
}
|
|
783
|
+
/>
|
|
784
|
+
<p className="text-xs text-muted-foreground">
|
|
785
|
+
{t("fields.slugDerivedHelp")}
|
|
786
|
+
</p>
|
|
787
|
+
</div>
|
|
788
|
+
<div className="grid gap-2">
|
|
789
|
+
<Label htmlFor="new-attribute-type">{t("fields.columnType")}</Label>
|
|
790
|
+
<Select
|
|
791
|
+
value={draft.type}
|
|
792
|
+
onValueChange={(value) =>
|
|
793
|
+
setDraft({ ...draft, type: value as CrmAttributeType })
|
|
794
|
+
}
|
|
795
|
+
>
|
|
796
|
+
<SelectTrigger id="new-attribute-type">
|
|
797
|
+
<SelectValue />
|
|
798
|
+
</SelectTrigger>
|
|
799
|
+
<SelectContent>
|
|
800
|
+
{AUTHORED_ATTRIBUTE_TYPES.map((type) => (
|
|
801
|
+
<SelectItem key={type} value={type}>
|
|
802
|
+
{type}
|
|
803
|
+
</SelectItem>
|
|
804
|
+
))}
|
|
805
|
+
</SelectContent>
|
|
806
|
+
</Select>
|
|
807
|
+
<p className="text-xs text-muted-foreground">
|
|
808
|
+
{t("fields.typeImmutable")}
|
|
809
|
+
</p>
|
|
810
|
+
</div>
|
|
811
|
+
{capabilities.supportsMulti ? (
|
|
812
|
+
<label className="flex items-center justify-between gap-4 text-sm">
|
|
813
|
+
<span>{t("fields.multi")}</span>
|
|
814
|
+
<Switch
|
|
815
|
+
checked={draft.multi}
|
|
816
|
+
onCheckedChange={(multi) => setDraft({ ...draft, multi })}
|
|
817
|
+
/>
|
|
818
|
+
</label>
|
|
819
|
+
) : null}
|
|
820
|
+
{capabilities.usesOptions ? (
|
|
821
|
+
<NewOptionsField
|
|
822
|
+
draft={draft}
|
|
823
|
+
showStageFields={capabilities.showsStageFields}
|
|
824
|
+
onChange={(options) => setDraft({ ...draft, options })}
|
|
825
|
+
/>
|
|
826
|
+
) : null}
|
|
827
|
+
<label className="flex items-center justify-between gap-4 text-sm">
|
|
828
|
+
<span>{t("fields.required")}</span>
|
|
829
|
+
<Switch
|
|
830
|
+
checked={draft.required}
|
|
831
|
+
onCheckedChange={(required) => setDraft({ ...draft, required })}
|
|
832
|
+
/>
|
|
833
|
+
</label>
|
|
834
|
+
<label className="flex items-center justify-between gap-4 text-sm">
|
|
835
|
+
<span>{t("fields.uniqueValue")}</span>
|
|
836
|
+
<Switch
|
|
837
|
+
checked={draft.uniqueValue}
|
|
838
|
+
onCheckedChange={(uniqueValue) =>
|
|
839
|
+
setDraft({ ...draft, uniqueValue })
|
|
840
|
+
}
|
|
841
|
+
/>
|
|
842
|
+
</label>
|
|
843
|
+
</div>
|
|
844
|
+
<DialogFooter>
|
|
845
|
+
<Button
|
|
846
|
+
disabled={!draft.title.trim() || create.isPending}
|
|
847
|
+
onClick={() => void submit()}
|
|
848
|
+
>
|
|
849
|
+
{t("fields.create")}
|
|
850
|
+
</Button>
|
|
851
|
+
</DialogFooter>
|
|
852
|
+
</DialogContent>
|
|
853
|
+
</Dialog>
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function NewOptionsField({
|
|
858
|
+
draft,
|
|
859
|
+
showStageFields,
|
|
860
|
+
onChange,
|
|
861
|
+
}: {
|
|
862
|
+
draft: AttributeDraft;
|
|
863
|
+
showStageFields: boolean;
|
|
864
|
+
onChange: (options: AttributeDraft["options"]) => void;
|
|
865
|
+
}) {
|
|
866
|
+
const t = useT();
|
|
867
|
+
return (
|
|
868
|
+
<div className="grid gap-2">
|
|
869
|
+
<Label>{t("fields.options")}</Label>
|
|
870
|
+
{draft.options.map((option, index) => (
|
|
871
|
+
<div key={index} className="flex flex-wrap items-center gap-2">
|
|
872
|
+
<Input
|
|
873
|
+
className="flex-1"
|
|
874
|
+
value={option.value}
|
|
875
|
+
maxLength={200}
|
|
876
|
+
placeholder={t("fields.optionValuePlaceholder")}
|
|
877
|
+
onChange={(event) =>
|
|
878
|
+
onChange(
|
|
879
|
+
draft.options.map((current, position) =>
|
|
880
|
+
position === index
|
|
881
|
+
? { ...current, value: event.target.value }
|
|
882
|
+
: current,
|
|
883
|
+
),
|
|
884
|
+
)
|
|
885
|
+
}
|
|
886
|
+
/>
|
|
887
|
+
{showStageFields ? (
|
|
888
|
+
<Input
|
|
889
|
+
className="w-28"
|
|
890
|
+
type="number"
|
|
891
|
+
min={0}
|
|
892
|
+
value={option.targetDays ?? ""}
|
|
893
|
+
placeholder={t("fields.targetDays")}
|
|
894
|
+
onChange={(event) =>
|
|
895
|
+
onChange(
|
|
896
|
+
draft.options.map((current, position) =>
|
|
897
|
+
position === index
|
|
898
|
+
? {
|
|
899
|
+
...current,
|
|
900
|
+
targetDays: event.target.value
|
|
901
|
+
? Number(event.target.value)
|
|
902
|
+
: null,
|
|
903
|
+
}
|
|
904
|
+
: current,
|
|
905
|
+
),
|
|
906
|
+
)
|
|
907
|
+
}
|
|
908
|
+
/>
|
|
909
|
+
) : null}
|
|
910
|
+
<Button
|
|
911
|
+
variant="ghost"
|
|
912
|
+
size="sm"
|
|
913
|
+
onClick={() =>
|
|
914
|
+
onChange(
|
|
915
|
+
draft.options.filter((_, position) => position !== index),
|
|
916
|
+
)
|
|
917
|
+
}
|
|
918
|
+
>
|
|
919
|
+
{t("fields.remove")}
|
|
920
|
+
</Button>
|
|
921
|
+
</div>
|
|
922
|
+
))}
|
|
923
|
+
<Button
|
|
924
|
+
variant="outline"
|
|
925
|
+
size="sm"
|
|
926
|
+
className="w-fit gap-1.5"
|
|
927
|
+
onClick={() =>
|
|
928
|
+
onChange([...draft.options, emptyAttributeOptionDraft()])
|
|
929
|
+
}
|
|
930
|
+
>
|
|
931
|
+
<IconPlus className="size-4" /> {t("fields.addOption")}
|
|
932
|
+
</Button>
|
|
933
|
+
</div>
|
|
934
|
+
);
|
|
935
|
+
}
|