@open-mercato/core 0.7.1-develop.7106.1.53fe9dd1b1 → 0.7.1-develop.7111.1.c0d5d7286f
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/.turbo/turbo-build.log +1 -1
- package/dist/modules/business_rules/backend/logs/[id]/page.js +3 -9
- package/dist/modules/business_rules/backend/logs/[id]/page.js.map +2 -2
- package/dist/modules/business_rules/backend/rules/[id]/page.js +3 -9
- package/dist/modules/business_rules/backend/rules/[id]/page.js.map +2 -2
- package/dist/modules/business_rules/backend/sets/[id]/page.js +3 -9
- package/dist/modules/business_rules/backend/sets/[id]/page.js.map +2 -2
- package/dist/modules/communication_channels/backend/communication_channels/channels/[id]/page.js +6 -4
- package/dist/modules/communication_channels/backend/communication_channels/channels/[id]/page.js.map +2 -2
- package/dist/modules/currencies/backend/currencies/[id]/page.js.map +2 -2
- package/dist/modules/customers/components/detail/ActivitiesSection.js +4 -12
- package/dist/modules/customers/components/detail/ActivitiesSection.js.map +2 -2
- package/dist/modules/customers/components/detail/authorUserLookup.js +46 -0
- package/dist/modules/customers/components/detail/authorUserLookup.js.map +7 -0
- package/dist/modules/query_index/lib/engine.js +2 -1
- package/dist/modules/query_index/lib/engine.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/[id]/page.js +3 -9
- package/dist/modules/workflows/backend/definitions/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.js +3 -9
- package/dist/modules/workflows/backend/events/[id]/page.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/business_rules/backend/logs/[id]/page.tsx +3 -11
- package/src/modules/business_rules/backend/rules/[id]/page.tsx +3 -11
- package/src/modules/business_rules/backend/sets/[id]/page.tsx +3 -11
- package/src/modules/communication_channels/backend/communication_channels/channels/[id]/page.tsx +7 -5
- package/src/modules/communication_channels/i18n/de.json +1 -0
- package/src/modules/communication_channels/i18n/en.json +1 -0
- package/src/modules/communication_channels/i18n/es.json +1 -0
- package/src/modules/communication_channels/i18n/ko.json +1 -0
- package/src/modules/communication_channels/i18n/pl.json +1 -0
- package/src/modules/currencies/backend/currencies/[id]/page.tsx +1 -1
- package/src/modules/customers/components/detail/ActivitiesSection.tsx +8 -18
- package/src/modules/customers/components/detail/authorUserLookup.ts +85 -0
- package/src/modules/query_index/lib/engine.ts +9 -0
- package/src/modules/workflows/backend/definitions/[id]/page.tsx +3 -11
- package/src/modules/workflows/backend/events/[id]/page.tsx +3 -12
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import Link from "next/link";
|
|
4
|
-
import {
|
|
4
|
+
import { useRouter } from "next/navigation";
|
|
5
5
|
import { useQuery } from "@tanstack/react-query";
|
|
6
6
|
import { apiFetch } from "@open-mercato/ui/backend/utils/api";
|
|
7
7
|
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
@@ -10,15 +10,9 @@ import { Button } from "@open-mercato/ui/primitives/button";
|
|
|
10
10
|
import { Spinner } from "@open-mercato/ui/primitives/spinner";
|
|
11
11
|
import { JsonDisplay } from "@open-mercato/ui/backend/JsonDisplay";
|
|
12
12
|
import { RecordNotFoundState, ErrorMessage } from "@open-mercato/ui/backend/detail";
|
|
13
|
-
function ExecutionLogDetailPage() {
|
|
13
|
+
function ExecutionLogDetailPage({ params }) {
|
|
14
14
|
const router = useRouter();
|
|
15
|
-
const
|
|
16
|
-
let logId;
|
|
17
|
-
if (params?.slug && Array.isArray(params.slug)) {
|
|
18
|
-
logId = params.slug[1];
|
|
19
|
-
} else if (params?.id) {
|
|
20
|
-
logId = Array.isArray(params.id) ? params.id[0] : params.id;
|
|
21
|
-
}
|
|
15
|
+
const logId = params?.id;
|
|
22
16
|
const t = useT();
|
|
23
17
|
const { data: log, isLoading, error } = useQuery({
|
|
24
18
|
queryKey: ["business-rules", "logs", logId],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/business_rules/backend/logs/%5Bid%5D/page.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useParams, useRouter } from 'next/navigation'\nimport { useQuery } from '@tanstack/react-query'\nimport { apiFetch } from '@open-mercato/ui/backend/utils/api'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\nimport { JsonDisplay } from '@open-mercato/ui/backend/JsonDisplay'\nimport { RecordNotFoundState, ErrorMessage } from '@open-mercato/ui/backend/detail'\n\ntype RuleExecutionLog = {\n id: string\n ruleId: string\n rule?: {\n id: string\n ruleId: string\n ruleName: string\n ruleType: string\n } | null\n entityType: string\n entityId: string | null\n eventType: string | null\n executedAt: string\n executionTimeMs: number\n executionResult: 'SUCCESS' | 'FAILURE' | 'ERROR'\n resultValue: any | null\n errorMessage: string | null\n inputContext: any | null\n outputContext: any | null\n executedBy: string | null\n tenantId: string | null\n organizationId: string | null\n}\n\nexport default function ExecutionLogDetailPage() {\n const router = useRouter()\n const params = useParams()\n\n // Handle catch-all route: params.slug = ['logs', 'id']\n let logId: string | undefined\n if (params?.slug && Array.isArray(params.slug)) {\n logId = params.slug[1] // Second element is the ID\n } else if (params?.id) {\n logId = Array.isArray(params.id) ? params.id[0] : params.id\n }\n\n const t = useT()\n\n const { data: log, isLoading, error } = useQuery({\n queryKey: ['business-rules', 'logs', logId],\n queryFn: async () => {\n const response = await apiFetch(`/api/business_rules/logs/${logId}`)\n if (!response.ok) {\n const httpErr = new Error(\n response.status === 404\n ? t('business_rules.logs.errors.notFound', 'Execution log not found.')\n : t('business_rules.logs.errors.fetchFailed')\n ) as Error & { status: number }\n httpErr.status = response.status\n throw httpErr\n }\n const result = await response.json()\n return result as RuleExecutionLog\n },\n enabled: !!logId,\n })\n\n if (isLoading) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground\">\n <Spinner className=\"h-6 w-6\" />\n <span>{t('business_rules.logs.detail.loading')}</span>\n </div>\n </PageBody>\n </Page>\n )\n }\n\n const isNotFound = !isLoading && (error as (Error & { status?: number }) | null)?.status === 404\n\n if (isNotFound) {\n return (\n <Page>\n <PageBody>\n <RecordNotFoundState\n label={t('business_rules.logs.errors.notFound', 'Execution log not found.')}\n backHref=\"/backend/logs\"\n backLabel={t('business_rules.logs.backToList', 'Back to logs')}\n />\n </PageBody>\n </Page>\n )\n }\n\n if (error || !log) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage\n label={(error as Error | null)?.message ?? t('business_rules.logs.errors.loadFailed')}\n action={\n <Button asChild variant=\"outline\" size=\"sm\">\n <Link href=\"/backend/logs\">{t('business_rules.logs.backToList', 'Back to logs')}</Link>\n </Button>\n }\n />\n </PageBody>\n </Page>\n )\n }\n\n const getResultBadgeClass = (result: string) => {\n switch (result) {\n case 'SUCCESS':\n return 'bg-green-100 text-green-800'\n case 'FAILURE':\n return 'bg-yellow-100 text-yellow-800'\n case 'ERROR':\n return 'bg-red-100 text-red-800'\n default:\n return 'bg-muted text-foreground'\n }\n }\n\n return (\n <Page>\n <PageBody>\n <div className=\"space-y-6\">\n {/* Header */}\n <div className=\"flex items-center justify-between\">\n <div>\n <h1 className=\"text-2xl font-bold text-foreground\">\n {t('business_rules.logs.detail.title')}\n </h1>\n <p className=\"text-sm text-muted-foreground mt-1\">\n {t('business_rules.logs.detail.logId')}: {log.id}\n </p>\n </div>\n <Button onClick={() => router.push('/backend/logs')} variant=\"outline\">\n {t('business_rules.logs.backToList')}\n </Button>\n </div>\n\n {/* Execution Summary */}\n <div className=\"rounded-lg border bg-card p-6\">\n <h2 className=\"text-lg font-semibold mb-4\">\n {t('business_rules.logs.detail.summary')}\n </h2>\n <dl className=\"grid grid-cols-1 md:grid-cols-2 gap-4\">\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.executedAt')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">\n {new Date(log.executedAt).toLocaleString()}\n </dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.result')}\n </dt>\n <dd className=\"mt-1\">\n <span\n className={`inline-flex items-center px-2 py-1 rounded text-xs font-medium ${getResultBadgeClass(\n log.executionResult\n )}`}\n >\n {t(`business_rules.logs.result.${log.executionResult.toLowerCase()}`)}\n </span>\n </dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.executionTime')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">{log.executionTimeMs}ms</dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.executedBy')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">\n {log.executedBy || t('common.unknown')}\n </dd>\n </div>\n </dl>\n </div>\n\n {/* Rule Information */}\n <div className=\"rounded-lg border bg-card p-6\">\n <h2 className=\"text-lg font-semibold mb-4\">\n {t('business_rules.logs.detail.ruleInfo')}\n </h2>\n {log.rule ? (\n <dl className=\"grid grid-cols-1 md:grid-cols-2 gap-4\">\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.ruleName')}\n </dt>\n <dd className=\"mt-1\">\n <Link\n href={`/backend/rules/${log.rule.id}`}\n className=\"text-sm text-primary hover:underline\"\n >\n {log.rule.ruleName}\n </Link>\n </dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.ruleType')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">{log.rule.ruleType}</dd>\n </div>\n <div className=\"md:col-span-2\">\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.ruleId')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground font-mono\">{log.rule.ruleId}</dd>\n </div>\n </dl>\n ) : (\n <p className=\"text-sm text-muted-foreground\">{t('business_rules.logs.ruleDeleted')}</p>\n )}\n </div>\n\n {/* Entity Information */}\n <div className=\"rounded-lg border bg-card p-6\">\n <h2 className=\"text-lg font-semibold mb-4\">\n {t('business_rules.logs.detail.entityInfo')}\n </h2>\n <dl className=\"grid grid-cols-1 md:grid-cols-2 gap-4\">\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.entityType')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">{log.entityType}</dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.eventType')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">\n {log.eventType || t('common.none')}\n </dd>\n </div>\n {log.entityId && (\n <div className=\"md:col-span-2\">\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.entityId')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground font-mono break-all\">\n {log.entityId}\n </dd>\n </div>\n )}\n </dl>\n </div>\n\n {/* Error Message (if present) */}\n {log.errorMessage && (\n <div className=\"rounded-lg border border-destructive bg-destructive/5 p-6\">\n <h2 className=\"text-lg font-semibold mb-4 text-destructive\">\n {t('business_rules.logs.detail.errorMessage')}\n </h2>\n <pre className=\"text-sm text-destructive whitespace-pre-wrap font-mono\">\n {log.errorMessage}\n </pre>\n </div>\n )}\n\n {/* Input Context */}\n {log.inputContext && (\n <JsonDisplay\n data={log.inputContext}\n title={t('business_rules.logs.detail.inputContext')}\n />\n )}\n\n {/* Output Context */}\n {log.outputContext && (\n <JsonDisplay\n data={log.outputContext}\n title={t('business_rules.logs.detail.outputContext')}\n />\n )}\n\n {/* Result Value */}\n {log.resultValue && (\n <JsonDisplay\n data={log.resultValue}\n title={t('business_rules.logs.detail.resultValue')}\n />\n )}\n </div>\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useRouter } from 'next/navigation'\nimport { useQuery } from '@tanstack/react-query'\nimport { apiFetch } from '@open-mercato/ui/backend/utils/api'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\nimport { JsonDisplay } from '@open-mercato/ui/backend/JsonDisplay'\nimport { RecordNotFoundState, ErrorMessage } from '@open-mercato/ui/backend/detail'\n\ntype RuleExecutionLog = {\n id: string\n ruleId: string\n rule?: {\n id: string\n ruleId: string\n ruleName: string\n ruleType: string\n } | null\n entityType: string\n entityId: string | null\n eventType: string | null\n executedAt: string\n executionTimeMs: number\n executionResult: 'SUCCESS' | 'FAILURE' | 'ERROR'\n resultValue: any | null\n errorMessage: string | null\n inputContext: any | null\n outputContext: any | null\n executedBy: string | null\n tenantId: string | null\n organizationId: string | null\n}\n\nexport default function ExecutionLogDetailPage({ params }: { params?: { id?: string } }) {\n const router = useRouter()\n const logId = params?.id\n\n const t = useT()\n\n const { data: log, isLoading, error } = useQuery({\n queryKey: ['business-rules', 'logs', logId],\n queryFn: async () => {\n const response = await apiFetch(`/api/business_rules/logs/${logId}`)\n if (!response.ok) {\n const httpErr = new Error(\n response.status === 404\n ? t('business_rules.logs.errors.notFound', 'Execution log not found.')\n : t('business_rules.logs.errors.fetchFailed')\n ) as Error & { status: number }\n httpErr.status = response.status\n throw httpErr\n }\n const result = await response.json()\n return result as RuleExecutionLog\n },\n enabled: !!logId,\n })\n\n if (isLoading) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground\">\n <Spinner className=\"h-6 w-6\" />\n <span>{t('business_rules.logs.detail.loading')}</span>\n </div>\n </PageBody>\n </Page>\n )\n }\n\n const isNotFound = !isLoading && (error as (Error & { status?: number }) | null)?.status === 404\n\n if (isNotFound) {\n return (\n <Page>\n <PageBody>\n <RecordNotFoundState\n label={t('business_rules.logs.errors.notFound', 'Execution log not found.')}\n backHref=\"/backend/logs\"\n backLabel={t('business_rules.logs.backToList', 'Back to logs')}\n />\n </PageBody>\n </Page>\n )\n }\n\n if (error || !log) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage\n label={(error as Error | null)?.message ?? t('business_rules.logs.errors.loadFailed')}\n action={\n <Button asChild variant=\"outline\" size=\"sm\">\n <Link href=\"/backend/logs\">{t('business_rules.logs.backToList', 'Back to logs')}</Link>\n </Button>\n }\n />\n </PageBody>\n </Page>\n )\n }\n\n const getResultBadgeClass = (result: string) => {\n switch (result) {\n case 'SUCCESS':\n return 'bg-green-100 text-green-800'\n case 'FAILURE':\n return 'bg-yellow-100 text-yellow-800'\n case 'ERROR':\n return 'bg-red-100 text-red-800'\n default:\n return 'bg-muted text-foreground'\n }\n }\n\n return (\n <Page>\n <PageBody>\n <div className=\"space-y-6\">\n {/* Header */}\n <div className=\"flex items-center justify-between\">\n <div>\n <h1 className=\"text-2xl font-bold text-foreground\">\n {t('business_rules.logs.detail.title')}\n </h1>\n <p className=\"text-sm text-muted-foreground mt-1\">\n {t('business_rules.logs.detail.logId')}: {log.id}\n </p>\n </div>\n <Button onClick={() => router.push('/backend/logs')} variant=\"outline\">\n {t('business_rules.logs.backToList')}\n </Button>\n </div>\n\n {/* Execution Summary */}\n <div className=\"rounded-lg border bg-card p-6\">\n <h2 className=\"text-lg font-semibold mb-4\">\n {t('business_rules.logs.detail.summary')}\n </h2>\n <dl className=\"grid grid-cols-1 md:grid-cols-2 gap-4\">\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.executedAt')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">\n {new Date(log.executedAt).toLocaleString()}\n </dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.result')}\n </dt>\n <dd className=\"mt-1\">\n <span\n className={`inline-flex items-center px-2 py-1 rounded text-xs font-medium ${getResultBadgeClass(\n log.executionResult\n )}`}\n >\n {t(`business_rules.logs.result.${log.executionResult.toLowerCase()}`)}\n </span>\n </dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.executionTime')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">{log.executionTimeMs}ms</dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.executedBy')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">\n {log.executedBy || t('common.unknown')}\n </dd>\n </div>\n </dl>\n </div>\n\n {/* Rule Information */}\n <div className=\"rounded-lg border bg-card p-6\">\n <h2 className=\"text-lg font-semibold mb-4\">\n {t('business_rules.logs.detail.ruleInfo')}\n </h2>\n {log.rule ? (\n <dl className=\"grid grid-cols-1 md:grid-cols-2 gap-4\">\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.ruleName')}\n </dt>\n <dd className=\"mt-1\">\n <Link\n href={`/backend/rules/${log.rule.id}`}\n className=\"text-sm text-primary hover:underline\"\n >\n {log.rule.ruleName}\n </Link>\n </dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.ruleType')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">{log.rule.ruleType}</dd>\n </div>\n <div className=\"md:col-span-2\">\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.ruleId')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground font-mono\">{log.rule.ruleId}</dd>\n </div>\n </dl>\n ) : (\n <p className=\"text-sm text-muted-foreground\">{t('business_rules.logs.ruleDeleted')}</p>\n )}\n </div>\n\n {/* Entity Information */}\n <div className=\"rounded-lg border bg-card p-6\">\n <h2 className=\"text-lg font-semibold mb-4\">\n {t('business_rules.logs.detail.entityInfo')}\n </h2>\n <dl className=\"grid grid-cols-1 md:grid-cols-2 gap-4\">\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.entityType')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">{log.entityType}</dd>\n </div>\n <div>\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.eventType')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground\">\n {log.eventType || t('common.none')}\n </dd>\n </div>\n {log.entityId && (\n <div className=\"md:col-span-2\">\n <dt className=\"text-sm font-medium text-muted-foreground\">\n {t('business_rules.logs.fields.entityId')}\n </dt>\n <dd className=\"mt-1 text-sm text-foreground font-mono break-all\">\n {log.entityId}\n </dd>\n </div>\n )}\n </dl>\n </div>\n\n {/* Error Message (if present) */}\n {log.errorMessage && (\n <div className=\"rounded-lg border border-destructive bg-destructive/5 p-6\">\n <h2 className=\"text-lg font-semibold mb-4 text-destructive\">\n {t('business_rules.logs.detail.errorMessage')}\n </h2>\n <pre className=\"text-sm text-destructive whitespace-pre-wrap font-mono\">\n {log.errorMessage}\n </pre>\n </div>\n )}\n\n {/* Input Context */}\n {log.inputContext && (\n <JsonDisplay\n data={log.inputContext}\n title={t('business_rules.logs.detail.inputContext')}\n />\n )}\n\n {/* Output Context */}\n {log.outputContext && (\n <JsonDisplay\n data={log.outputContext}\n title={t('business_rules.logs.detail.outputContext')}\n />\n )}\n\n {/* Result Value */}\n {log.resultValue && (\n <JsonDisplay\n data={log.resultValue}\n title={t('business_rules.logs.detail.resultValue')}\n />\n )}\n </div>\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAmEU,SACE,KADF;AAhEV,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS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from "react";
|
|
4
4
|
import Link from "next/link";
|
|
5
|
-
import { useRouter,
|
|
5
|
+
import { useRouter, usePathname } from "next/navigation";
|
|
6
6
|
import { useQuery } from "@tanstack/react-query";
|
|
7
7
|
import { Page, PageBody } from "@open-mercato/ui/backend/Page";
|
|
8
8
|
import { CrudForm } from "@open-mercato/ui/backend/CrudForm";
|
|
@@ -23,16 +23,10 @@ import {
|
|
|
23
23
|
import { ConditionBuilder } from "../../../components/ConditionBuilder.js";
|
|
24
24
|
import { ActionBuilder } from "../../../components/ActionBuilder.js";
|
|
25
25
|
import { buildRulePayload, parseRuleToFormValues } from "../../../components/utils/formHelpers.js";
|
|
26
|
-
function EditBusinessRulePage() {
|
|
26
|
+
function EditBusinessRulePage({ params }) {
|
|
27
27
|
const router = useRouter();
|
|
28
|
-
const params = useParams();
|
|
29
28
|
const pathname = usePathname();
|
|
30
|
-
|
|
31
|
-
if (params?.slug && Array.isArray(params.slug)) {
|
|
32
|
-
ruleId = params.slug[1];
|
|
33
|
-
} else if (params?.id) {
|
|
34
|
-
ruleId = Array.isArray(params.id) ? params.id[0] : params.id;
|
|
35
|
-
}
|
|
29
|
+
const ruleId = params?.id;
|
|
36
30
|
const t = useT();
|
|
37
31
|
const { organizationId, tenantId } = useOrganizationScopeDetail();
|
|
38
32
|
const { data: rule, isLoading, error } = useQuery({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/business_rules/backend/rules/%5Bid%5D/page.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useRouter,
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useRouter, usePathname } from 'next/navigation'\nimport { useQuery } from '@tanstack/react-query'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm } from '@open-mercato/ui/backend/CrudForm'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { apiFetch, withScopedApiHeaders } from '@open-mercato/ui/backend/utils/api'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { buildRecordInjectionContext, useSetCurrentRecordInjectionContext } from '@open-mercato/ui/backend/injection/recordContext'\nimport { readJsonSafe } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { useOrganizationScopeDetail } from '@open-mercato/shared/lib/frontend/useOrganizationScope'\nimport {\n businessRuleFormSchema,\n createFormGroups,\n createFieldDefinitions,\n type BusinessRuleFormValues,\n} from '../../../components/formConfig'\nimport { ConditionBuilder } from '../../../components/ConditionBuilder'\nimport { ActionBuilder } from '../../../components/ActionBuilder'\nimport { buildRulePayload, parseRuleToFormValues } from '../../../components/utils/formHelpers'\n\nexport default function EditBusinessRulePage({ params }: { params?: { id?: string } }) {\n const router = useRouter()\n const pathname = usePathname()\n const ruleId = params?.id\n\n const t = useT()\n const { organizationId, tenantId } = useOrganizationScopeDetail()\n\n const { data: rule, isLoading, error } = useQuery({\n queryKey: ['business_rule', ruleId],\n queryFn: async () => {\n const response = await apiFetch(`/api/business_rules/rules/${ruleId}`)\n if (!response.ok) {\n throw new Error(t('business_rules.errors.fetchFailed'))\n }\n const result = await response.json()\n return result\n },\n enabled: !!ruleId,\n })\n\n const initialValues = React.useMemo(() => {\n if (rule) {\n return parseRuleToFormValues(rule)\n }\n return null\n }, [rule])\n\n const handleSubmit = async (values: BusinessRuleFormValues) => {\n // Use tenant/org from the loaded rule if available, otherwise from context\n const effectiveTenantId = rule?.tenantId || tenantId\n const effectiveOrgId = rule?.organizationId || organizationId\n\n if (!effectiveTenantId || !effectiveOrgId) {\n throw new Error(t('business_rules.errors.missingTenantOrOrg'))\n }\n\n const payload = buildRulePayload(values, effectiveTenantId, effectiveOrgId, undefined)\n\n const updateRule = () => apiFetch('/api/business_rules/rules', {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n ...payload,\n id: ruleId,\n }),\n })\n const headers = buildOptimisticLockHeader(rule?.updatedAt ?? rule?.updated_at ?? null)\n const response = Object.keys(headers).length\n ? await withScopedApiHeaders(headers, updateRule)\n : await updateRule()\n\n if (!response.ok) {\n const body = (await readJsonSafe<Record<string, unknown>>(response)) ?? {}\n const message =\n (typeof body.error === 'string' && body.error) ||\n (typeof body.message === 'string' && body.message) ||\n t('business_rules.errors.updateFailed')\n throw new CrudHttpError(response.status, { ...body, error: message })\n }\n\n router.push('/backend/rules')\n router.refresh()\n }\n\n const fields = React.useMemo(() => createFieldDefinitions(t), [t])\n\n const formGroups = React.useMemo(\n () => createFormGroups(t, ConditionBuilder, ActionBuilder),\n [t]\n )\n\n // Publish page-load record context to the AppShell-owned `backend:record:current`\n // mount so the enterprise record_locks widget resolves `business_rules.rule` + id\n // explicitly. The resourceKind mirrors the route's `enforceCommandOptimisticLock`\n // call so the held lock matches the save-time conflict surface for the same rule.\n useSetCurrentRecordInjectionContext(\n buildRecordInjectionContext({\n resourceKind: 'business_rules.rule',\n resourceId: ruleId ?? null,\n updatedAt: rule?.updatedAt ?? rule?.updated_at ?? null,\n data: (rule ?? null) as Record<string, unknown> | null,\n path: pathname,\n }),\n )\n\n if (isLoading) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground\">\n <Spinner className=\"h-6 w-6\" />\n <span>{t('business_rules.rules.edit.loading')}</span>\n </div>\n </PageBody>\n </Page>\n )\n }\n\n if (error || !rule) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground\">\n <p>{t('business_rules.errors.loadFailed')}</p>\n <Button asChild variant=\"outline\">\n <Link href=\"/backend/rules\">{t('business_rules.rules.backToList')}</Link>\n </Button>\n </div>\n </PageBody>\n </Page>\n )\n }\n\n if (!initialValues) {\n return null\n }\n\n return (\n <Page>\n <PageBody>\n <CrudForm\n key={ruleId}\n title={t('business_rules.rules.edit.title')}\n backHref=\"/backend/rules\"\n schema={businessRuleFormSchema}\n fields={fields}\n initialValues={initialValues}\n optimisticLockUpdatedAt={rule?.updatedAt ?? rule?.updated_at ?? null}\n onSubmit={handleSubmit}\n cancelHref=\"/backend/rules\"\n groups={formGroups}\n submitLabel={t('business_rules.rules.form.update')}\n />\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAqHU,SACE,KADF;AAnHV,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,WAAW,mBAAmB;AACvC,SAAS,gBAAgB;AACzB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,UAAU,4BAA4B;AAC/C,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B,2CAA2C;AACjF,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,YAAY;AACrB,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB,6BAA6B;AAEzC,SAAR,qBAAsC,EAAE,OAAO,GAAiC;AACrF,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,YAAY;AAC7B,QAAM,SAAS,QAAQ;AAEvB,QAAM,IAAI,KAAK;AACf,QAAM,EAAE,gBAAgB,SAAS,IAAI,2BAA2B;AAEhE,QAAM,EAAE,MAAM,MAAM,WAAW,MAAM,IAAI,SAAS;AAAA,IAChD,UAAU,CAAC,iBAAiB,MAAM;AAAA,IAClC,SAAS,YAAY;AACnB,YAAM,WAAW,MAAM,SAAS,6BAA6B,MAAM,EAAE;AACrE,UAAI,C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|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import Link from "next/link";
|
|
5
|
-
import { useRouter,
|
|
5
|
+
import { useRouter, usePathname } from "next/navigation";
|
|
6
6
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
7
7
|
import { Page, PageBody } from "@open-mercato/ui/backend/Page";
|
|
8
8
|
import { CrudForm } from "@open-mercato/ui/backend/CrudForm";
|
|
@@ -26,16 +26,10 @@ const ruleSetFormSchema = z.object({
|
|
|
26
26
|
description: z.string().max(5e3).optional().nullable(),
|
|
27
27
|
enabled: z.boolean().optional()
|
|
28
28
|
});
|
|
29
|
-
function EditRuleSetPage() {
|
|
29
|
+
function EditRuleSetPage({ params }) {
|
|
30
30
|
const router = useRouter();
|
|
31
|
-
const params = useParams();
|
|
32
31
|
const pathname = usePathname();
|
|
33
|
-
|
|
34
|
-
if (params?.slug && Array.isArray(params.slug)) {
|
|
35
|
-
setId = params.slug[1];
|
|
36
|
-
} else if (params?.id) {
|
|
37
|
-
setId = Array.isArray(params.id) ? params.id[0] : params.id;
|
|
38
|
-
}
|
|
32
|
+
const setId = params?.id;
|
|
39
33
|
const t = useT();
|
|
40
34
|
const { organizationId, tenantId } = useOrganizationScopeDetail();
|
|
41
35
|
const queryClient = useQueryClient();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/business_rules/backend/sets/%5Bid%5D/page.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useRouter, useParams, usePathname } from 'next/navigation'\nimport { useQuery, useQueryClient } from '@tanstack/react-query'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm } from '@open-mercato/ui/backend/CrudForm'\nimport type { CrudField } from '@open-mercato/ui/backend/CrudForm'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { apiFetch, withScopedApiHeaders } from '@open-mercato/ui/backend/utils/api'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { buildRecordInjectionContext, useSetCurrentRecordInjectionContext } from '@open-mercato/ui/backend/injection/recordContext'\nimport { readJsonSafe } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { useOrganizationScopeDetail } from '@open-mercato/shared/lib/frontend/useOrganizationScope'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { z } from 'zod'\nimport { RuleSetMembers } from '@open-mercato/core/modules/business_rules/components/RuleSetMembers'\n\nconst ruleSetFormSchema = z.object({\n setId: z.string().min(1).max(50),\n setName: z.string().min(1).max(200),\n description: z.string().max(5000).optional().nullable(),\n enabled: z.boolean().optional(),\n})\n\ntype RuleSetFormValues = z.infer<typeof ruleSetFormSchema>\n\ntype RuleSetDetail = {\n id: string\n setId: string\n setName: string\n description: string | null\n enabled: boolean\n tenantId: string\n organizationId: string\n createdBy: string | null\n updatedBy: string | null\n createdAt: string\n updatedAt: string\n members: Array<{\n id: string\n ruleId: string\n ruleName: string\n ruleType: string\n sequence: number\n enabled: boolean\n }>\n}\n\nexport default function EditRuleSetPage() {\n const router = useRouter()\n const params = useParams()\n const pathname = usePathname()\n\n // Handle catch-all route: params.slug = ['sets', 'uuid']\n let setId: string | undefined\n if (params?.slug && Array.isArray(params.slug)) {\n setId = params.slug[1] // Second element is the ID\n } else if (params?.id) {\n setId = Array.isArray(params.id) ? params.id[0] : params.id\n }\n\n const t = useT()\n const { organizationId, tenantId } = useOrganizationScopeDetail()\n const queryClient = useQueryClient()\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n\n const { data: ruleSet, isLoading, error } = useQuery({\n queryKey: ['business-rules', 'sets', setId],\n queryFn: async () => {\n const response = await apiFetch(`/api/business_rules/sets/${setId}`)\n if (!response.ok) {\n throw new Error(t('business_rules.sets.errors.fetchFailed'))\n }\n const result = await response.json()\n return result as RuleSetDetail\n },\n enabled: !!setId,\n })\n\n const handleSubmit = async (values: RuleSetFormValues) => {\n const payload = {\n id: setId,\n ...values,\n }\n\n const updateSet = () => apiFetch('/api/business_rules/sets', {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(payload),\n })\n const headers = buildOptimisticLockHeader(ruleSet?.updatedAt ?? null)\n const response = Object.keys(headers).length\n ? await withScopedApiHeaders(headers, updateSet)\n : await updateSet()\n\n if (!response.ok) {\n const body = (await readJsonSafe<Record<string, unknown>>(response)) ?? {}\n const message =\n (typeof body.error === 'string' && body.error) ||\n (typeof body.message === 'string' && body.message) ||\n t('business_rules.sets.errors.updateFailed')\n throw new CrudHttpError(response.status, { ...body, error: message })\n }\n\n flash(t('business_rules.sets.messages.updated'), 'success')\n queryClient.invalidateQueries({ queryKey: ['business-rules', 'sets', setId] })\n }\n\n const handleAddMember = async (ruleId: string, sequence: number) => {\n const result = await apiCall(`/api/business_rules/sets/${setId}/members`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n ruleId,\n sequence,\n enabled: true,\n }),\n })\n\n if (result.ok) {\n flash(t('business_rules.sets.members.messages.added'), 'success')\n queryClient.invalidateQueries({ queryKey: ['business-rules', 'sets', setId] })\n } else {\n const error = result.result as { error?: string; message?: string } | null\n if (error?.error?.includes('duplicate') || error?.message?.includes('exists')) {\n flash(t('business_rules.sets.members.messages.alreadyExists'), 'error')\n } else {\n flash(t('business_rules.sets.members.messages.addFailed'), 'error')\n }\n }\n }\n\n const handleUpdateMember = async (memberId: string, updates: { sequence?: number; enabled?: boolean }) => {\n const result = await apiCall(`/api/business_rules/sets/${setId}/members`, {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n memberId,\n ...updates,\n }),\n })\n\n if (result.ok) {\n flash(t('business_rules.sets.members.messages.updated'), 'success')\n queryClient.invalidateQueries({ queryKey: ['business-rules', 'sets', setId] })\n } else {\n flash(t('business_rules.sets.members.messages.updateFailed'), 'error')\n }\n }\n\n const handleRemoveMember = async (memberId: string, ruleName: string) => {\n const confirmed = await confirm({\n title: t('business_rules.sets.members.confirm.remove', { name: ruleName }),\n variant: 'destructive',\n })\n if (!confirmed) return\n\n const result = await apiCall(`/api/business_rules/sets/${setId}/members?memberId=${memberId}`, {\n method: 'DELETE',\n })\n\n if (result.ok) {\n flash(t('business_rules.sets.members.messages.removed'), 'success')\n queryClient.invalidateQueries({ queryKey: ['business-rules', 'sets', setId] })\n } else {\n flash(t('business_rules.sets.members.messages.removeFailed'), 'error')\n }\n }\n\n const fields: CrudField[] = React.useMemo(() => [\n {\n id: 'setId',\n label: t('business_rules.sets.form.setId'),\n type: 'text',\n required: true,\n placeholder: t('business_rules.sets.form.placeholders.setId'),\n description: t('business_rules.sets.form.descriptions.setId'),\n },\n {\n id: 'setName',\n label: t('business_rules.sets.form.setName'),\n type: 'text',\n required: true,\n placeholder: t('business_rules.sets.form.placeholders.setName'),\n },\n {\n id: 'description',\n label: t('business_rules.sets.form.description'),\n type: 'textarea',\n placeholder: t('business_rules.sets.form.placeholders.description'),\n },\n {\n id: 'enabled',\n label: t('business_rules.sets.form.enabled'),\n type: 'checkbox',\n description: t('business_rules.sets.form.descriptions.enabled'),\n },\n ], [t])\n\n const initialValues: Partial<RuleSetFormValues> = React.useMemo(() => {\n if (!ruleSet) return {}\n return {\n setId: ruleSet.setId,\n setName: ruleSet.setName,\n description: ruleSet.description,\n enabled: ruleSet.enabled,\n }\n }, [ruleSet])\n\n const formGroups = React.useMemo(() => {\n if (!ruleSet) return []\n return [\n {\n id: 'details',\n title: t('business_rules.sets.edit.detailsSection'),\n column: 1 as const,\n fields: ['setId', 'setName', 'description', 'enabled'],\n },\n {\n id: 'members',\n title: t('business_rules.sets.edit.membersSection'),\n column: 1 as const,\n component: () => (\n <RuleSetMembers\n members={ruleSet.members}\n onAdd={handleAddMember}\n onUpdate={handleUpdateMember}\n onRemove={handleRemoveMember}\n />\n ),\n },\n ]\n }, [t, ruleSet, handleAddMember, handleUpdateMember, handleRemoveMember])\n\n // Publish page-load record context to the AppShell-owned `backend:record:current`\n // mount so the enterprise record_locks widget resolves the rule set + id\n // explicitly. The resourceKind mirrors the route's `enforceCommandOptimisticLock`\n // call (`business_rules.ruleSet`) so the held lock matches the save-time conflict\n // surface for the same rule set.\n useSetCurrentRecordInjectionContext(\n buildRecordInjectionContext({\n resourceKind: 'business_rules.ruleSet',\n resourceId: setId ?? null,\n updatedAt: ruleSet?.updatedAt ?? null,\n data: (ruleSet ?? null) as Record<string, unknown> | null,\n path: pathname,\n }),\n )\n\n if (isLoading) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground\">\n <Spinner className=\"h-6 w-6\" />\n <span>{t('business_rules.sets.edit.loading')}</span>\n </div>\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n if (error || !ruleSet) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground\">\n <p>{t('business_rules.sets.messages.loadFailed')}</p>\n <Button asChild variant=\"outline\">\n <Link href=\"/backend/sets\">{t('business_rules.sets.backToList')}</Link>\n </Button>\n </div>\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n return (\n <Page>\n <PageBody>\n <CrudForm\n title={t('business_rules.sets.edit.title')}\n backHref=\"/backend/sets\"\n schema={ruleSetFormSchema}\n fields={fields}\n initialValues={initialValues}\n optimisticLockUpdatedAt={ruleSet.updatedAt}\n onSubmit={handleSubmit}\n cancelHref=\"/backend/sets\"\n submitLabel={t('business_rules.sets.form.update')}\n groups={formGroups}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useRouter, usePathname } from 'next/navigation'\nimport { useQuery, useQueryClient } from '@tanstack/react-query'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm } from '@open-mercato/ui/backend/CrudForm'\nimport type { CrudField } from '@open-mercato/ui/backend/CrudForm'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { apiFetch, withScopedApiHeaders } from '@open-mercato/ui/backend/utils/api'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { buildRecordInjectionContext, useSetCurrentRecordInjectionContext } from '@open-mercato/ui/backend/injection/recordContext'\nimport { readJsonSafe } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { useOrganizationScopeDetail } from '@open-mercato/shared/lib/frontend/useOrganizationScope'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { z } from 'zod'\nimport { RuleSetMembers } from '@open-mercato/core/modules/business_rules/components/RuleSetMembers'\n\nconst ruleSetFormSchema = z.object({\n setId: z.string().min(1).max(50),\n setName: z.string().min(1).max(200),\n description: z.string().max(5000).optional().nullable(),\n enabled: z.boolean().optional(),\n})\n\ntype RuleSetFormValues = z.infer<typeof ruleSetFormSchema>\n\ntype RuleSetDetail = {\n id: string\n setId: string\n setName: string\n description: string | null\n enabled: boolean\n tenantId: string\n organizationId: string\n createdBy: string | null\n updatedBy: string | null\n createdAt: string\n updatedAt: string\n members: Array<{\n id: string\n ruleId: string\n ruleName: string\n ruleType: string\n sequence: number\n enabled: boolean\n }>\n}\n\nexport default function EditRuleSetPage({ params }: { params?: { id?: string } }) {\n const router = useRouter()\n const pathname = usePathname()\n const setId = params?.id\n\n const t = useT()\n const { organizationId, tenantId } = useOrganizationScopeDetail()\n const queryClient = useQueryClient()\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n\n const { data: ruleSet, isLoading, error } = useQuery({\n queryKey: ['business-rules', 'sets', setId],\n queryFn: async () => {\n const response = await apiFetch(`/api/business_rules/sets/${setId}`)\n if (!response.ok) {\n throw new Error(t('business_rules.sets.errors.fetchFailed'))\n }\n const result = await response.json()\n return result as RuleSetDetail\n },\n enabled: !!setId,\n })\n\n const handleSubmit = async (values: RuleSetFormValues) => {\n const payload = {\n id: setId,\n ...values,\n }\n\n const updateSet = () => apiFetch('/api/business_rules/sets', {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(payload),\n })\n const headers = buildOptimisticLockHeader(ruleSet?.updatedAt ?? null)\n const response = Object.keys(headers).length\n ? await withScopedApiHeaders(headers, updateSet)\n : await updateSet()\n\n if (!response.ok) {\n const body = (await readJsonSafe<Record<string, unknown>>(response)) ?? {}\n const message =\n (typeof body.error === 'string' && body.error) ||\n (typeof body.message === 'string' && body.message) ||\n t('business_rules.sets.errors.updateFailed')\n throw new CrudHttpError(response.status, { ...body, error: message })\n }\n\n flash(t('business_rules.sets.messages.updated'), 'success')\n queryClient.invalidateQueries({ queryKey: ['business-rules', 'sets', setId] })\n }\n\n const handleAddMember = async (ruleId: string, sequence: number) => {\n const result = await apiCall(`/api/business_rules/sets/${setId}/members`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n ruleId,\n sequence,\n enabled: true,\n }),\n })\n\n if (result.ok) {\n flash(t('business_rules.sets.members.messages.added'), 'success')\n queryClient.invalidateQueries({ queryKey: ['business-rules', 'sets', setId] })\n } else {\n const error = result.result as { error?: string; message?: string } | null\n if (error?.error?.includes('duplicate') || error?.message?.includes('exists')) {\n flash(t('business_rules.sets.members.messages.alreadyExists'), 'error')\n } else {\n flash(t('business_rules.sets.members.messages.addFailed'), 'error')\n }\n }\n }\n\n const handleUpdateMember = async (memberId: string, updates: { sequence?: number; enabled?: boolean }) => {\n const result = await apiCall(`/api/business_rules/sets/${setId}/members`, {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n memberId,\n ...updates,\n }),\n })\n\n if (result.ok) {\n flash(t('business_rules.sets.members.messages.updated'), 'success')\n queryClient.invalidateQueries({ queryKey: ['business-rules', 'sets', setId] })\n } else {\n flash(t('business_rules.sets.members.messages.updateFailed'), 'error')\n }\n }\n\n const handleRemoveMember = async (memberId: string, ruleName: string) => {\n const confirmed = await confirm({\n title: t('business_rules.sets.members.confirm.remove', { name: ruleName }),\n variant: 'destructive',\n })\n if (!confirmed) return\n\n const result = await apiCall(`/api/business_rules/sets/${setId}/members?memberId=${memberId}`, {\n method: 'DELETE',\n })\n\n if (result.ok) {\n flash(t('business_rules.sets.members.messages.removed'), 'success')\n queryClient.invalidateQueries({ queryKey: ['business-rules', 'sets', setId] })\n } else {\n flash(t('business_rules.sets.members.messages.removeFailed'), 'error')\n }\n }\n\n const fields: CrudField[] = React.useMemo(() => [\n {\n id: 'setId',\n label: t('business_rules.sets.form.setId'),\n type: 'text',\n required: true,\n placeholder: t('business_rules.sets.form.placeholders.setId'),\n description: t('business_rules.sets.form.descriptions.setId'),\n },\n {\n id: 'setName',\n label: t('business_rules.sets.form.setName'),\n type: 'text',\n required: true,\n placeholder: t('business_rules.sets.form.placeholders.setName'),\n },\n {\n id: 'description',\n label: t('business_rules.sets.form.description'),\n type: 'textarea',\n placeholder: t('business_rules.sets.form.placeholders.description'),\n },\n {\n id: 'enabled',\n label: t('business_rules.sets.form.enabled'),\n type: 'checkbox',\n description: t('business_rules.sets.form.descriptions.enabled'),\n },\n ], [t])\n\n const initialValues: Partial<RuleSetFormValues> = React.useMemo(() => {\n if (!ruleSet) return {}\n return {\n setId: ruleSet.setId,\n setName: ruleSet.setName,\n description: ruleSet.description,\n enabled: ruleSet.enabled,\n }\n }, [ruleSet])\n\n const formGroups = React.useMemo(() => {\n if (!ruleSet) return []\n return [\n {\n id: 'details',\n title: t('business_rules.sets.edit.detailsSection'),\n column: 1 as const,\n fields: ['setId', 'setName', 'description', 'enabled'],\n },\n {\n id: 'members',\n title: t('business_rules.sets.edit.membersSection'),\n column: 1 as const,\n component: () => (\n <RuleSetMembers\n members={ruleSet.members}\n onAdd={handleAddMember}\n onUpdate={handleUpdateMember}\n onRemove={handleRemoveMember}\n />\n ),\n },\n ]\n }, [t, ruleSet, handleAddMember, handleUpdateMember, handleRemoveMember])\n\n // Publish page-load record context to the AppShell-owned `backend:record:current`\n // mount so the enterprise record_locks widget resolves the rule set + id\n // explicitly. The resourceKind mirrors the route's `enforceCommandOptimisticLock`\n // call (`business_rules.ruleSet`) so the held lock matches the save-time conflict\n // surface for the same rule set.\n useSetCurrentRecordInjectionContext(\n buildRecordInjectionContext({\n resourceKind: 'business_rules.ruleSet',\n resourceId: setId ?? null,\n updatedAt: ruleSet?.updatedAt ?? null,\n data: (ruleSet ?? null) as Record<string, unknown> | null,\n path: pathname,\n }),\n )\n\n if (isLoading) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground\">\n <Spinner className=\"h-6 w-6\" />\n <span>{t('business_rules.sets.edit.loading')}</span>\n </div>\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n if (error || !ruleSet) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex h-[50vh] flex-col items-center justify-center gap-2 text-muted-foreground\">\n <p>{t('business_rules.sets.messages.loadFailed')}</p>\n <Button asChild variant=\"outline\">\n <Link href=\"/backend/sets\">{t('business_rules.sets.backToList')}</Link>\n </Button>\n </div>\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n return (\n <Page>\n <PageBody>\n <CrudForm\n title={t('business_rules.sets.edit.title')}\n backHref=\"/backend/sets\"\n schema={ruleSetFormSchema}\n fields={fields}\n initialValues={initialValues}\n optimisticLockUpdatedAt={ruleSet.updatedAt}\n onSubmit={handleSubmit}\n cancelHref=\"/backend/sets\"\n submitLabel={t('business_rules.sets.form.update')}\n groups={formGroups}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AA8NU,cA8BA,YA9BA;AA5NV,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,WAAW,mBAAmB;AACvC,SAAS,UAAU,sBAAsB;AACzC,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAAgB;AAEzB,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,UAAU,4BAA4B;AAC/C,SAAS,eAAe;AACxB,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B,2CAA2C;AACjF,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,aAAa;AACtB,SAAS,YAAY;AACrB,SAAS,kCAAkC;AAC3C,SAAS,wBAAwB;AACjC,SAAS,SAAS;AAClB,SAAS,sBAAsB;AAE/B,MAAM,oBAAoB,EAAE,OAAO;AAAA,EACjC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE;AAAA,EAC/B,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG;AAAA,EAClC,aAAa,EAAE,OAAO,EAAE,IAAI,GAAI,EAAE,SAAS,EAAE,SAAS;AAAA,EACtD,SAAS,EAAE,QAAQ,EAAE,SAAS;AAChC,CAAC;AA0Bc,SAAR,gBAAiC,EAAE,OAAO,GAAiC;AAChF,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,YAAY;AAC7B,QAAM,QAAQ,QAAQ;AAEtB,QAAM,IAAI,KAAK;AACf,QAAM,E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,EAEJ;AAEA,SACE,qBAAC,QACC;AAAA,wBAAC,YACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,EAAE,gCAAgC;AAAA,QACzC,UAAS;AAAA,QACT,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,QACA,yBAAyB,QAAQ;AAAA,QACjC,UAAU;AAAA,QACV,YAAW;AAAA,QACX,aAAa,EAAE,iCAAiC;AAAA,QAChD,QAAQ;AAAA;AAAA,IACV,GACF;AAAA,IACC;AAAA,KACH;AAEJ;",
|
|
6
6
|
"names": ["error"]
|
|
7
7
|
}
|
package/dist/modules/communication_channels/backend/communication_channels/channels/[id]/page.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import { useParams } from "next/navigation";
|
|
5
4
|
import { Page, PageBody } from "@open-mercato/ui/backend/Page";
|
|
6
5
|
import { LoadingMessage, ErrorMessage, RecordNotFoundState } from "@open-mercato/ui/backend/detail";
|
|
7
6
|
import { Tag } from "@open-mercato/ui/primitives/tag";
|
|
8
7
|
import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
|
|
9
8
|
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
10
|
-
function ChannelDetailPage() {
|
|
9
|
+
function ChannelDetailPage({ params }) {
|
|
11
10
|
const t = useT();
|
|
12
|
-
const params = useParams();
|
|
13
11
|
const id = params?.id ?? "";
|
|
14
12
|
const [detail, setDetail] = React.useState(null);
|
|
15
13
|
const [health, setHealth] = React.useState(null);
|
|
@@ -17,7 +15,11 @@ function ChannelDetailPage() {
|
|
|
17
15
|
const [errorMessage, setErrorMessage] = React.useState(null);
|
|
18
16
|
const [notFound, setNotFound] = React.useState(false);
|
|
19
17
|
React.useEffect(() => {
|
|
20
|
-
if (!id)
|
|
18
|
+
if (!id) {
|
|
19
|
+
setIsLoading(false);
|
|
20
|
+
setErrorMessage(t("communication_channels.errors.missingChannelId", "No channel selected."));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
21
23
|
let cancelled = false;
|
|
22
24
|
async function load() {
|
|
23
25
|
setIsLoading(true);
|
package/dist/modules/communication_channels/backend/communication_channels/channels/[id]/page.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/modules/communication_channels/backend/communication_channels/channels/%5Bid%5D/page.tsx"],
|
|
4
|
-
"sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport {
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { LoadingMessage, ErrorMessage, RecordNotFoundState } from '@open-mercato/ui/backend/detail'\nimport { Tag } from '@open-mercato/ui/primitives/tag'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\n\ntype ChannelDetail = {\n id: string\n providerKey: string\n channelType: string\n displayName: string\n externalIdentifier: string | null\n capabilities: Record<string, unknown> | null\n isActive: boolean\n}\n\ntype ChannelHealth = {\n channelId: string\n providerKey: string\n channelType: string\n windowHours: number\n totalsLast24h: number\n counts: Record<string, number>\n recentFailures: Array<{\n id: string\n messageId: string\n direction: string\n createdAt: string | null\n lastError: string | null\n transient: boolean | null\n }>\n}\n\nexport default function ChannelDetailPage({ params }: { params?: { id?: string } }) {\n const t = useT()\n const id = params?.id ?? ''\n\n const [detail, setDetail] = React.useState<ChannelDetail | null>(null)\n const [health, setHealth] = React.useState<ChannelHealth | null>(null)\n const [isLoading, setIsLoading] = React.useState(true)\n const [errorMessage, setErrorMessage] = React.useState<string | null>(null)\n const [notFound, setNotFound] = React.useState(false)\n\n React.useEffect(() => {\n if (!id) {\n setIsLoading(false)\n setErrorMessage(t('communication_channels.errors.missingChannelId', 'No channel selected.'))\n return\n }\n let cancelled = false\n async function load() {\n setIsLoading(true)\n setErrorMessage(null)\n setNotFound(false)\n const [detailRes, healthRes] = await Promise.all([\n apiCall<ChannelDetail>(`/api/communication_channels/channels/${encodeURIComponent(id)}`),\n apiCall<ChannelHealth>(`/api/communication_channels/channels/${encodeURIComponent(id)}/health`),\n ]).catch((err: unknown) => {\n return [\n { ok: false, result: { error: err instanceof Error ? err.message : 'load failed' } },\n { ok: false, result: { error: err instanceof Error ? err.message : 'load failed' } },\n ] as const\n })\n if (cancelled) return\n if (!detailRes.ok) {\n const status = (detailRes as { status?: number }).status\n if (status === 404) {\n setNotFound(true)\n } else {\n const body = detailRes.result as { error?: string } | undefined\n setErrorMessage(\n body?.error ?? t('communication_channels.errors.loadDetail', 'Failed to load channel'),\n )\n }\n setDetail(null)\n setHealth(null)\n } else {\n setDetail(detailRes.result ?? null)\n setHealth(healthRes.ok ? (healthRes.result ?? null) : null)\n }\n setIsLoading(false)\n }\n void load()\n return () => {\n cancelled = true\n }\n }, [id, t])\n\n if (isLoading) {\n return (\n <Page>\n <PageBody>\n <LoadingMessage label={t('communication_channels.detail.loading', 'Loading channel...')} />\n </PageBody>\n </Page>\n )\n }\n if (notFound) {\n return (\n <Page>\n <PageBody>\n <RecordNotFoundState\n label={t('communication_channels.detail.notFound', 'Channel not found')}\n backHref=\"/backend/communication_channels/channels\"\n />\n </PageBody>\n </Page>\n )\n }\n if (errorMessage || !detail) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage\n label={errorMessage ?? t('communication_channels.errors.loadDetail', 'Failed to load channel')}\n />\n </PageBody>\n </Page>\n )\n }\n\n const capabilities = (detail.capabilities ?? {}) as Record<string, unknown>\n const capabilityKeys = Object.keys(capabilities)\n\n return (\n <Page>\n <PageBody>\n <header className=\"mb-4 flex flex-wrap items-baseline justify-between gap-4\">\n <div>\n <h2 className=\"text-2xl font-semibold\">{detail.displayName}</h2>\n <p className=\"text-sm text-muted-foreground\">\n {detail.providerKey} \u00B7 {detail.channelType}\n {detail.externalIdentifier ? ` \u00B7 ${detail.externalIdentifier}` : ''}\n </p>\n </div>\n {detail.isActive ? (\n <Tag variant=\"success\" dot>\n {t('communication_channels.status.active', 'Active')}\n </Tag>\n ) : (\n <Tag variant=\"neutral\">{t('communication_channels.status.inactive', 'Inactive')}</Tag>\n )}\n </header>\n\n <section\n className=\"mb-4 rounded-md border bg-card p-4\"\n aria-label={t('communication_channels.detail.capabilities', 'Capabilities')}\n >\n <header className=\"mb-2 text-overline text-muted-foreground\">\n {t('communication_channels.detail.capabilities', 'Capabilities')}\n </header>\n {capabilityKeys.length === 0 ? (\n <p className=\"text-sm text-muted-foreground\">\n {t(\n 'communication_channels.detail.noCapabilities',\n 'No capabilities snapshot recorded for this channel yet.',\n )}\n </p>\n ) : (\n <dl className=\"grid grid-cols-2 gap-x-6 gap-y-1 text-sm md:grid-cols-3\">\n {capabilityKeys.sort((a, b) => a.localeCompare(b)).map((key) => (\n <React.Fragment key={key}>\n <dt className=\"text-muted-foreground\">{key}</dt>\n <dd className=\"md:col-span-2\">{renderCapabilityValue(capabilities[key])}</dd>\n </React.Fragment>\n ))}\n </dl>\n )}\n </section>\n\n <section\n className=\"rounded-md border bg-card p-4\"\n aria-label={t('communication_channels.detail.health', 'Delivery health (last 24h)')}\n >\n <header className=\"mb-2 flex items-baseline justify-between text-overline text-muted-foreground\">\n <span>{t('communication_channels.detail.health', 'Delivery health (last 24h)')}</span>\n {health ? (\n <span className=\"text-xs\">\n {health.totalsLast24h}{' '}\n {t('communication_channels.detail.messages', 'messages')}\n </span>\n ) : null}\n </header>\n {health ? (\n <>\n <ul className=\"mb-3 flex flex-wrap gap-2 text-xs\">\n {Object.entries(health.counts).map(([status, count]) => (\n <li key={status}>\n <Tag variant={tagVariantForStatus(status)}>\n {status}: {count}\n </Tag>\n </li>\n ))}\n </ul>\n {health.recentFailures.length > 0 ? (\n <details>\n <summary className=\"cursor-pointer text-sm text-muted-foreground\">\n {t('communication_channels.detail.recentFailures', 'Recent failures')} (\n {health.recentFailures.length})\n </summary>\n <ul className=\"mt-2 space-y-1 text-xs\">\n {health.recentFailures.map((failure) => (\n <li key={failure.id} className=\"rounded border bg-muted p-2\">\n <div className=\"font-mono text-xs text-muted-foreground\">\n {failure.messageId} \u00B7 {failure.direction} \u00B7{' '}\n {failure.createdAt ?? '\u2014'}\n </div>\n {failure.lastError ? (\n <div className=\"mt-1\">{failure.lastError}</div>\n ) : null}\n </li>\n ))}\n </ul>\n </details>\n ) : null}\n </>\n ) : (\n <p className=\"text-sm text-muted-foreground\">\n {t('communication_channels.detail.noHealth', 'No health data available.')}\n </p>\n )}\n </section>\n </PageBody>\n </Page>\n )\n}\n\nfunction renderCapabilityValue(value: unknown): string {\n if (value === null || value === undefined) return '\u2014'\n if (Array.isArray(value)) return value.join(', ')\n if (typeof value === 'object') return JSON.stringify(value)\n return String(value)\n}\n\nfunction tagVariantForStatus(status: string): 'success' | 'warning' | 'error' | 'info' | 'neutral' {\n switch (status) {\n case 'sent':\n case 'delivered':\n case 'read':\n return 'success'\n case 'failed':\n return 'error'\n case 'pending':\n case 'queued':\n return 'warning'\n default:\n return 'neutral'\n }\n}\n"],
|
|
5
|
+
"mappings": ";AA+FU,SA4FE,UA5FF,KAsCE,YAtCF;AA7FV,YAAY,WAAW;AACvB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAAgB,cAAc,2BAA2B;AAClE,SAAS,WAAW;AACpB,SAAS,eAAe;AACxB,SAAS,YAAY;AA6BN,SAAR,kBAAmC,EAAE,OAAO,GAAiC;AAClF,QAAM,IAAI,KAAK;AACf,QAAM,KAAK,QAAQ,MAAM;AAEzB,QAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,SAA+B,IAAI;AACrE,QAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,SAA+B,IAAI;AACrE,QAAM,CAAC,WAAW,YAAY,IAAI,MAAM,SAAS,IAAI;AACrD,QAAM,CAAC,cAAc,eAAe,IAAI,MAAM,SAAwB,IA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AC3C,QAAQ,aAAa;AAAA,mBACxB;AAAA,gBACC,QAAQ,YACP,oBAAC,SAAI,WAAU,QAAQ,kBAAQ,WAAU,IACvC;AAAA,mBAPG,QAAQ,EAQjB,CACD,GACH;AAAA,eACF,IACE;AAAA,aACN,IAEA,oBAAC,OAAE,WAAU,iCACV,YAAE,0CAA0C,2BAA2B,GAC1E;AAAA;AAAA;AAAA,IAEJ;AAAA,KACF,GACF;AAEJ;AAEA,SAAS,sBAAsB,OAAwB;AACrD,MAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,KAAK,IAAI;AAChD,MAAI,OAAO,UAAU,SAAU,QAAO,KAAK,UAAU,KAAK;AAC1D,SAAO,OAAO,KAAK;AACrB;AAEA,SAAS,oBAAoB,QAAsE;AACjG,UAAQ,QAAQ;AAAA,IACd,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/currencies/backend/currencies/%5Bid%5D/page.tsx"],
|
|
4
|
-
"sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { useRouter, useParams, usePathname } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm, type CrudFormGroup } from '@open-mercato/ui/backend/CrudForm'\nimport { updateCrud, deleteCrud } from '@open-mercato/ui/backend/utils/crud'\nimport { createCrudFormError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { surfaceRecordConflict } from '@open-mercato/ui/backend/conflicts'\nimport { buildRecordInjectionContext, useSetCurrentRecordInjectionContext } from '@open-mercato/ui/backend/injection/recordContext'\nimport { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { SendObjectMessageDialog } from '@open-mercato/ui/backend/messages'\nimport { DataLoader } from '@open-mercato/ui/primitives/DataLoader'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { RecordNotFoundState, ErrorMessage } from '@open-mercato/ui/backend/detail'\n\ntype CurrencyData = {\n id: string\n code: string\n name: string\n symbol: string | null\n decimalPlaces: number\n thousandsSeparator: string | null\n decimalSeparator: string | null\n isBase: boolean\n isActive: boolean\n organizationId: string\n tenantId: string\n updatedAt?: string | null\n updated_at?: string | null\n}\n\nexport default function EditCurrencyPage({ params }: { params?: { id?: string } }) {\n const t = useT()\n const router = useRouter()\n const pathname = usePathname()\n const { confirm: confirmDialog, ConfirmDialogElement } = useConfirmDialog()\n const mutationContextId = 'currencies-edit:delete'\n const { runMutation, retryLastMutation } = useGuardedMutation<{\n formId: string\n resourceKind: string\n resourceId: string\n retryLastMutation: () => Promise<boolean>\n }>({\n contextId: mutationContextId,\n blockedMessage: t('ui.forms.flash.saveBlocked', 'Save blocked by validation'),\n })\n\n const [currency, setCurrency] = React.useState<CurrencyData | null>(null)\n const [loading, setLoading] = React.useState(true)\n const [error, setError] = React.useState<string | null>(null)\n const [isNotFound, setIsNotFound] = React.useState(false)\n\n React.useEffect(() => {\n async function loadCurrency() {\n try {\n const response = await apiCall<{ items: CurrencyData[] }>(`/api/currencies/currencies?id=${params?.id}`)\n if (response.ok && response.result && response.result.items.length > 0) {\n setCurrency(response.result.items[0])\n } else if (!response.ok) {\n setError(t('currencies.form.errors.load'))\n } else {\n setIsNotFound(true)\n }\n } catch (err) {\n setError(t('currencies.form.errors.load'))\n } finally {\n setLoading(false)\n }\n }\n loadCurrency()\n }, [params, t])\n\n const groups = React.useMemo<CrudFormGroup[]>(\n () => [\n {\n id: 'basic',\n column: 1,\n title: t('currencies.form.group.details'),\n fields: [\n {\n id: 'code',\n type: 'text',\n label: t('currencies.form.field.code'),\n placeholder: t('currencies.form.field.codePlaceholder'),\n required: true,\n maxLength: 3,\n helpText: t('currencies.form.field.codeHelp'),\n },\n {\n id: 'name',\n type: 'text',\n label: t('currencies.form.field.name'),\n placeholder: t('currencies.form.field.namePlaceholder'),\n required: true,\n },\n {\n id: 'symbol',\n type: 'text',\n label: t('currencies.form.field.symbol'),\n placeholder: t('currencies.form.field.symbolPlaceholder'),\n },\n ],\n },\n {\n id: 'formatting',\n column: 2,\n title: t('currencies.form.group.formatting'),\n fields: [\n {\n id: 'decimalPlaces',\n type: 'number',\n label: t('currencies.form.field.decimalPlaces'),\n min: 0,\n max: 8,\n },\n {\n id: 'thousandsSeparator',\n type: 'text',\n label: t('currencies.form.field.thousandsSeparator'),\n placeholder: ',',\n maxLength: 5,\n },\n {\n id: 'decimalSeparator',\n type: 'text',\n label: t('currencies.form.field.decimalSeparator'),\n placeholder: '.',\n maxLength: 5,\n },\n {\n id: 'isBase',\n type: 'checkbox',\n label: t('currencies.form.field.isBase'),\n },\n {\n id: 'isActive',\n type: 'checkbox',\n label: t('currencies.form.field.isActive'),\n },\n ],\n },\n ],\n [t]\n )\n\n const handleDelete = React.useCallback(async () => {\n if (!currency) return\n\n const confirmed = await confirmDialog({\n title: t('currencies.list.confirmDelete', { code: currency.code }),\n variant: 'destructive',\n })\n if (!confirmed) return\n\n try {\n await runMutation({\n operation: async () => {\n const headers = buildOptimisticLockHeader(currency.updatedAt ?? currency.updated_at ?? null)\n const call = await withScopedApiRequestHeaders(headers, () => (\n apiCall('/api/currencies/currencies', {\n method: 'DELETE',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ id: currency.id, organizationId: currency.organizationId, tenantId: currency.tenantId }),\n })\n ))\n if (!call.ok) {\n throw Object.assign(new Error('[internal] currencies.delete failed'), {\n status: call.status,\n ...((call.result as Record<string, unknown> | null) ?? {}),\n })\n }\n return call\n },\n context: {\n formId: mutationContextId,\n resourceKind: 'currencies.currency',\n resourceId: currency.id,\n retryLastMutation,\n },\n mutationPayload: { id: currency.id },\n })\n\n flash(t('currencies.flash.deleted'), 'success')\n router.push('/backend/currencies')\n } catch (error) {\n if (surfaceRecordConflict(error, t)) return\n flash(t('currencies.flash.deleteError'), 'error')\n }\n }, [currency, t, router, confirmDialog, mutationContextId, retryLastMutation, runMutation])\n\n // Publish page-load record context to the AppShell-owned `backend:record:current`\n // mount so the enterprise record_locks widget resolves `currencies.currency` + id\n // explicitly. The resourceKind mirrors the CrudForm `versionHistory` so the held\n // lock matches the save-time conflict surface for the same currency.\n useSetCurrentRecordInjectionContext(\n buildRecordInjectionContext({\n resourceKind: 'currencies.currency',\n resourceId: currency?.id ?? null,\n updatedAt: currency?.updatedAt ?? currency?.updated_at ?? null,\n data: currency as Record<string, unknown> | null,\n path: pathname,\n }),\n )\n\n if (loading) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex items-center justify-center p-8\">\n <div className=\"text-muted-foreground\">{t('currencies.form.loading')}</div>\n </div>\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n if (isNotFound) {\n return (\n <Page>\n <PageBody>\n <RecordNotFoundState\n label={t('currencies.form.errors.notFound', 'Currency not found.')}\n backHref=\"/backend/currencies\"\n backLabel={t('currencies.form.actions.backToList', 'Back to currencies')}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n if (error || !currency) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage label={error ?? t('currencies.form.errors.notFound', 'Currency not found.')} />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n return (\n <Page>\n <PageBody>\n <CrudForm\n title={t('currencies.edit.title')}\n backHref=\"/backend/currencies\"\n versionHistory={{ resourceKind: 'currencies.currency', resourceId: currency.id }}\n extraActions={(\n <SendObjectMessageDialog\n object={{\n entityModule: 'currencies',\n entityType: 'currency',\n entityId: currency.id,\n previewData: {\n title: currency.name,\n subtitle: currency.code,\n metadata: {\n [t('currencies.form.field.code')]: currency.code,\n [t('currencies.form.field.name')]: currency.name,\n [t('currencies.form.field.symbol')]: currency.symbol || '-',\n },\n },\n }}\n viewHref={`/backend/currencies/${currency.id}`}\n />\n )}\n fields={[]}\n groups={groups}\n optimisticLockUpdatedAt={currency.updatedAt ?? currency.updated_at ?? null}\n initialValues={{\n code: currency.code,\n name: currency.name,\n symbol: currency.symbol || '',\n decimalPlaces: currency.decimalPlaces,\n thousandsSeparator: currency.thousandsSeparator || '',\n decimalSeparator: currency.decimalSeparator || '',\n isBase: currency.isBase,\n isActive: currency.isActive,\n }}\n submitLabel={t('currencies.form.action.save')}\n cancelHref=\"/backend/currencies\"\n onSubmit={async (values) => {\n // Validate currency code\n const code = String(values.code || '').trim().toUpperCase()\n if (!/^[A-Z]{3}$/.test(code)) {\n throw createCrudFormError(t('currencies.form.errors.codeFormat'), {\n code: t('currencies.form.errors.codeFormat'),\n })\n }\n\n const payload = {\n id: currency.id,\n code,\n name: String(values.name || '').trim(),\n symbol: values.symbol ? String(values.symbol).trim() : null,\n decimalPlaces: values.decimalPlaces ? parseInt(String(values.decimalPlaces)) : 2,\n thousandsSeparator: values.thousandsSeparator ? String(values.thousandsSeparator) : null,\n decimalSeparator: values.decimalSeparator ? String(values.decimalSeparator) : null,\n isBase: !!values.isBase,\n isActive: values.isActive !== false,\n }\n\n await updateCrud('currencies/currencies', payload)\n\n flash(t('currencies.flash.updated'), 'success')\n router.push('/backend/currencies')\n }}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n}\n"],
|
|
5
|
-
"mappings": ";AAmNM,SAGM,KAHN;AAjNN,YAAY,WAAW;AACvB,SAAS,
|
|
4
|
+
"sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { useRouter, usePathname } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm, type CrudFormGroup } from '@open-mercato/ui/backend/CrudForm'\nimport { updateCrud, deleteCrud } from '@open-mercato/ui/backend/utils/crud'\nimport { createCrudFormError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { surfaceRecordConflict } from '@open-mercato/ui/backend/conflicts'\nimport { buildRecordInjectionContext, useSetCurrentRecordInjectionContext } from '@open-mercato/ui/backend/injection/recordContext'\nimport { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { SendObjectMessageDialog } from '@open-mercato/ui/backend/messages'\nimport { DataLoader } from '@open-mercato/ui/primitives/DataLoader'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { RecordNotFoundState, ErrorMessage } from '@open-mercato/ui/backend/detail'\n\ntype CurrencyData = {\n id: string\n code: string\n name: string\n symbol: string | null\n decimalPlaces: number\n thousandsSeparator: string | null\n decimalSeparator: string | null\n isBase: boolean\n isActive: boolean\n organizationId: string\n tenantId: string\n updatedAt?: string | null\n updated_at?: string | null\n}\n\nexport default function EditCurrencyPage({ params }: { params?: { id?: string } }) {\n const t = useT()\n const router = useRouter()\n const pathname = usePathname()\n const { confirm: confirmDialog, ConfirmDialogElement } = useConfirmDialog()\n const mutationContextId = 'currencies-edit:delete'\n const { runMutation, retryLastMutation } = useGuardedMutation<{\n formId: string\n resourceKind: string\n resourceId: string\n retryLastMutation: () => Promise<boolean>\n }>({\n contextId: mutationContextId,\n blockedMessage: t('ui.forms.flash.saveBlocked', 'Save blocked by validation'),\n })\n\n const [currency, setCurrency] = React.useState<CurrencyData | null>(null)\n const [loading, setLoading] = React.useState(true)\n const [error, setError] = React.useState<string | null>(null)\n const [isNotFound, setIsNotFound] = React.useState(false)\n\n React.useEffect(() => {\n async function loadCurrency() {\n try {\n const response = await apiCall<{ items: CurrencyData[] }>(`/api/currencies/currencies?id=${params?.id}`)\n if (response.ok && response.result && response.result.items.length > 0) {\n setCurrency(response.result.items[0])\n } else if (!response.ok) {\n setError(t('currencies.form.errors.load'))\n } else {\n setIsNotFound(true)\n }\n } catch (err) {\n setError(t('currencies.form.errors.load'))\n } finally {\n setLoading(false)\n }\n }\n loadCurrency()\n }, [params, t])\n\n const groups = React.useMemo<CrudFormGroup[]>(\n () => [\n {\n id: 'basic',\n column: 1,\n title: t('currencies.form.group.details'),\n fields: [\n {\n id: 'code',\n type: 'text',\n label: t('currencies.form.field.code'),\n placeholder: t('currencies.form.field.codePlaceholder'),\n required: true,\n maxLength: 3,\n helpText: t('currencies.form.field.codeHelp'),\n },\n {\n id: 'name',\n type: 'text',\n label: t('currencies.form.field.name'),\n placeholder: t('currencies.form.field.namePlaceholder'),\n required: true,\n },\n {\n id: 'symbol',\n type: 'text',\n label: t('currencies.form.field.symbol'),\n placeholder: t('currencies.form.field.symbolPlaceholder'),\n },\n ],\n },\n {\n id: 'formatting',\n column: 2,\n title: t('currencies.form.group.formatting'),\n fields: [\n {\n id: 'decimalPlaces',\n type: 'number',\n label: t('currencies.form.field.decimalPlaces'),\n min: 0,\n max: 8,\n },\n {\n id: 'thousandsSeparator',\n type: 'text',\n label: t('currencies.form.field.thousandsSeparator'),\n placeholder: ',',\n maxLength: 5,\n },\n {\n id: 'decimalSeparator',\n type: 'text',\n label: t('currencies.form.field.decimalSeparator'),\n placeholder: '.',\n maxLength: 5,\n },\n {\n id: 'isBase',\n type: 'checkbox',\n label: t('currencies.form.field.isBase'),\n },\n {\n id: 'isActive',\n type: 'checkbox',\n label: t('currencies.form.field.isActive'),\n },\n ],\n },\n ],\n [t]\n )\n\n const handleDelete = React.useCallback(async () => {\n if (!currency) return\n\n const confirmed = await confirmDialog({\n title: t('currencies.list.confirmDelete', { code: currency.code }),\n variant: 'destructive',\n })\n if (!confirmed) return\n\n try {\n await runMutation({\n operation: async () => {\n const headers = buildOptimisticLockHeader(currency.updatedAt ?? currency.updated_at ?? null)\n const call = await withScopedApiRequestHeaders(headers, () => (\n apiCall('/api/currencies/currencies', {\n method: 'DELETE',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ id: currency.id, organizationId: currency.organizationId, tenantId: currency.tenantId }),\n })\n ))\n if (!call.ok) {\n throw Object.assign(new Error('[internal] currencies.delete failed'), {\n status: call.status,\n ...((call.result as Record<string, unknown> | null) ?? {}),\n })\n }\n return call\n },\n context: {\n formId: mutationContextId,\n resourceKind: 'currencies.currency',\n resourceId: currency.id,\n retryLastMutation,\n },\n mutationPayload: { id: currency.id },\n })\n\n flash(t('currencies.flash.deleted'), 'success')\n router.push('/backend/currencies')\n } catch (error) {\n if (surfaceRecordConflict(error, t)) return\n flash(t('currencies.flash.deleteError'), 'error')\n }\n }, [currency, t, router, confirmDialog, mutationContextId, retryLastMutation, runMutation])\n\n // Publish page-load record context to the AppShell-owned `backend:record:current`\n // mount so the enterprise record_locks widget resolves `currencies.currency` + id\n // explicitly. The resourceKind mirrors the CrudForm `versionHistory` so the held\n // lock matches the save-time conflict surface for the same currency.\n useSetCurrentRecordInjectionContext(\n buildRecordInjectionContext({\n resourceKind: 'currencies.currency',\n resourceId: currency?.id ?? null,\n updatedAt: currency?.updatedAt ?? currency?.updated_at ?? null,\n data: currency as Record<string, unknown> | null,\n path: pathname,\n }),\n )\n\n if (loading) {\n return (\n <Page>\n <PageBody>\n <div className=\"flex items-center justify-center p-8\">\n <div className=\"text-muted-foreground\">{t('currencies.form.loading')}</div>\n </div>\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n if (isNotFound) {\n return (\n <Page>\n <PageBody>\n <RecordNotFoundState\n label={t('currencies.form.errors.notFound', 'Currency not found.')}\n backHref=\"/backend/currencies\"\n backLabel={t('currencies.form.actions.backToList', 'Back to currencies')}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n if (error || !currency) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage label={error ?? t('currencies.form.errors.notFound', 'Currency not found.')} />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n }\n\n return (\n <Page>\n <PageBody>\n <CrudForm\n title={t('currencies.edit.title')}\n backHref=\"/backend/currencies\"\n versionHistory={{ resourceKind: 'currencies.currency', resourceId: currency.id }}\n extraActions={(\n <SendObjectMessageDialog\n object={{\n entityModule: 'currencies',\n entityType: 'currency',\n entityId: currency.id,\n previewData: {\n title: currency.name,\n subtitle: currency.code,\n metadata: {\n [t('currencies.form.field.code')]: currency.code,\n [t('currencies.form.field.name')]: currency.name,\n [t('currencies.form.field.symbol')]: currency.symbol || '-',\n },\n },\n }}\n viewHref={`/backend/currencies/${currency.id}`}\n />\n )}\n fields={[]}\n groups={groups}\n optimisticLockUpdatedAt={currency.updatedAt ?? currency.updated_at ?? null}\n initialValues={{\n code: currency.code,\n name: currency.name,\n symbol: currency.symbol || '',\n decimalPlaces: currency.decimalPlaces,\n thousandsSeparator: currency.thousandsSeparator || '',\n decimalSeparator: currency.decimalSeparator || '',\n isBase: currency.isBase,\n isActive: currency.isActive,\n }}\n submitLabel={t('currencies.form.action.save')}\n cancelHref=\"/backend/currencies\"\n onSubmit={async (values) => {\n // Validate currency code\n const code = String(values.code || '').trim().toUpperCase()\n if (!/^[A-Z]{3}$/.test(code)) {\n throw createCrudFormError(t('currencies.form.errors.codeFormat'), {\n code: t('currencies.form.errors.codeFormat'),\n })\n }\n\n const payload = {\n id: currency.id,\n code,\n name: String(values.name || '').trim(),\n symbol: values.symbol ? String(values.symbol).trim() : null,\n decimalPlaces: values.decimalPlaces ? parseInt(String(values.decimalPlaces)) : 2,\n thousandsSeparator: values.thousandsSeparator ? String(values.thousandsSeparator) : null,\n decimalSeparator: values.decimalSeparator ? String(values.decimalSeparator) : null,\n isBase: !!values.isBase,\n isActive: values.isActive !== false,\n }\n\n await updateCrud('currencies/currencies', payload)\n\n flash(t('currencies.flash.updated'), 'success')\n router.push('/backend/currencies')\n }}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAmNM,SAGM,KAHN;AAjNN,YAAY,WAAW;AACvB,SAAS,WAAW,mBAAmB;AACvC,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAAoC;AAC7C,SAAS,kBAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,aAAa;AACtB,SAAS,SAAS,mCAAmC;AACrD,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AACtC,SAAS,6BAA6B,2CAA2C;AACjF,SAAS,0BAA0B;AACnC,SAAS,YAAY;AACrB,SAAS,+BAA+B;AAExC,SAAS,wBAAwB;AACjC,SAAS,qBAAqB,oBAAoB;AAkBnC,SAAR,iBAAkC,EAAE,OAAO,GAAiC;AACjF,QAAM,IAAI,KAAK;AACf,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,YAAY;AAC7B,QAAM,EAAE,SAAS,eAAe,qBAAqB,IAAI,iBAAiB;AAC1E,QAAM,oBAAoB;AAC1B,QAAM,EAAE,aAAa,kBAAkB,IAAI,mBAKxC;AAAA,IACD,WAAW;AAAA,IACX,gBAAgB,EAAE,8BAA8B,4BAA4B;AAAA,EAC9E,CAAC;AAED,QAAM,CAAC,UAAU,WAAW,IAAI,MAAM,SAA8B,IAAI;AACxE,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM,SAAS,IAAI;AACjD,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAwB,IAAI;AAC5D,QAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAS,KAAK;AAExD,QAAM,UAAU,MAAM;AACpB,mBAAe,eAAe;AAC5B,UAAI;AACF,cAAM,WAAW,MAAM,QAAmC,iCAAiC,QAAQ,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A,gBAAM,UAAU;AAAA,YACd,IAAI,SAAS;AAAA,YACb;AAAA,YACA,MAAM,OAAO,OAAO,QAAQ,EAAE,EAAE,KAAK;AAAA,YACrC,QAAQ,OAAO,SAAS,OAAO,OAAO,MAAM,EAAE,KAAK,IAAI;AAAA,YACvD,eAAe,OAAO,gBAAgB,SAAS,OAAO,OAAO,aAAa,CAAC,IAAI;AAAA,YAC/E,oBAAoB,OAAO,qBAAqB,OAAO,OAAO,kBAAkB,IAAI;AAAA,YACpF,kBAAkB,OAAO,mBAAmB,OAAO,OAAO,gBAAgB,IAAI;AAAA,YAC9E,QAAQ,CAAC,CAAC,OAAO;AAAA,YACjB,UAAU,OAAO,aAAa;AAAA,UAChC;AAEA,gBAAM,WAAW,yBAAyB,OAAO;AAEjD,gBAAM,EAAE,0BAA0B,GAAG,SAAS;AAC9C,iBAAO,KAAK,qBAAqB;AAAA,QACnC;AAAA;AAAA,IACF,GACF;AAAA,IACC;AAAA,KACH;AAEJ;",
|
|
6
6
|
"names": ["error"]
|
|
7
7
|
}
|
|
@@ -9,6 +9,7 @@ import { Button } from "@open-mercato/ui/primitives/button";
|
|
|
9
9
|
import { Kbd } from "@open-mercato/ui/primitives/kbd";
|
|
10
10
|
import { ActivityTimelineFilters } from "./ActivityTimelineFilters.js";
|
|
11
11
|
import { ActivityTimeline } from "./ActivityTimeline.js";
|
|
12
|
+
import { resolveAuthorUserNames } from "./authorUserLookup.js";
|
|
12
13
|
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
13
14
|
const logger = createLogger("customers");
|
|
14
15
|
function toDateOnly(value) {
|
|
@@ -247,19 +248,10 @@ function ActivitiesSection({
|
|
|
247
248
|
}
|
|
248
249
|
}
|
|
249
250
|
if (unresolvedIds.size === 0) return;
|
|
250
|
-
for (const uid of unresolvedIds) resolvedUserIdsRef.current.add(uid);
|
|
251
251
|
const controller = new AbortController();
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
).then((data) => {
|
|
256
|
-
const users = Array.isArray(data?.items) ? data.items : [];
|
|
257
|
-
const nameMap = /* @__PURE__ */ new Map();
|
|
258
|
-
for (const user of users) {
|
|
259
|
-
const userId = typeof user.id === "string" ? user.id : null;
|
|
260
|
-
const name = typeof user.display_name === "string" && user.display_name.trim() ? user.display_name.trim() : typeof user.email === "string" ? user.email : null;
|
|
261
|
-
if (userId && name) nameMap.set(userId, name);
|
|
262
|
-
}
|
|
252
|
+
resolveAuthorUserNames([...unresolvedIds], controller.signal).then(({ names: nameMap, resolvedIds }) => {
|
|
253
|
+
if (controller.signal.aborted) return;
|
|
254
|
+
for (const uid of resolvedIds) resolvedUserIdsRef.current.add(uid);
|
|
263
255
|
if (nameMap.size > 0) {
|
|
264
256
|
setActivities(
|
|
265
257
|
(prev) => prev.map((a) => {
|