@open-mercato/core 0.8.1-develop.7228.1.b7ea09d2d3 → 0.8.1-develop.7238.1.3abe669ea5
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 +2 -2
- package/dist/generated/entities/availability_policy/index.js +41 -0
- package/dist/generated/entities/availability_policy/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +4 -0
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +21 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/attachments/data/entities.js +3 -3
- package/dist/modules/attachments/data/entities.js.map +2 -2
- package/dist/modules/availability/acl.js +16 -0
- package/dist/modules/availability/acl.js.map +7 -0
- package/dist/modules/availability/api/check/route.js +95 -0
- package/dist/modules/availability/api/check/route.js.map +7 -0
- package/dist/modules/availability/api/openapi.js +27 -0
- package/dist/modules/availability/api/openapi.js.map +7 -0
- package/dist/modules/availability/api/policies/resolve-preview/route.js +58 -0
- package/dist/modules/availability/api/policies/resolve-preview/route.js.map +7 -0
- package/dist/modules/availability/api/policies/route.js +188 -0
- package/dist/modules/availability/api/policies/route.js.map +7 -0
- package/dist/modules/availability/backend/availability/check/page.js +185 -0
- package/dist/modules/availability/backend/availability/check/page.js.map +7 -0
- package/dist/modules/availability/backend/availability/check/page.meta.js +16 -0
- package/dist/modules/availability/backend/availability/check/page.meta.js.map +7 -0
- package/dist/modules/availability/backend/availability/policies/ResolutionPreviewPanel.js +79 -0
- package/dist/modules/availability/backend/availability/policies/ResolutionPreviewPanel.js.map +7 -0
- package/dist/modules/availability/backend/availability/policies/ScopeFields.js +53 -0
- package/dist/modules/availability/backend/availability/policies/ScopeFields.js.map +7 -0
- package/dist/modules/availability/backend/availability/policies/[id]/page.js +152 -0
- package/dist/modules/availability/backend/availability/policies/[id]/page.js.map +7 -0
- package/dist/modules/availability/backend/availability/policies/[id]/page.meta.js +12 -0
- package/dist/modules/availability/backend/availability/policies/[id]/page.meta.js.map +7 -0
- package/dist/modules/availability/backend/availability/policies/create/page.js +94 -0
- package/dist/modules/availability/backend/availability/policies/create/page.js.map +7 -0
- package/dist/modules/availability/backend/availability/policies/create/page.meta.js +12 -0
- package/dist/modules/availability/backend/availability/policies/create/page.meta.js.map +7 -0
- package/dist/modules/availability/backend/availability/policies/formGroups.js +75 -0
- package/dist/modules/availability/backend/availability/policies/formGroups.js.map +7 -0
- package/dist/modules/availability/backend/availability/policies/page.js +176 -0
- package/dist/modules/availability/backend/availability/policies/page.js.map +7 -0
- package/dist/modules/availability/backend/availability/policies/page.meta.js +16 -0
- package/dist/modules/availability/backend/availability/policies/page.meta.js.map +7 -0
- package/dist/modules/availability/commands/policies.js +312 -0
- package/dist/modules/availability/commands/policies.js.map +7 -0
- package/dist/modules/availability/commands/scope.js +19 -0
- package/dist/modules/availability/commands/scope.js.map +7 -0
- package/dist/modules/availability/data/entities.js +95 -0
- package/dist/modules/availability/data/entities.js.map +7 -0
- package/dist/modules/availability/data/validators.js +53 -0
- package/dist/modules/availability/data/validators.js.map +7 -0
- package/dist/modules/availability/di.js +41 -0
- package/dist/modules/availability/di.js.map +7 -0
- package/dist/modules/availability/events.js +18 -0
- package/dist/modules/availability/events.js.map +7 -0
- package/dist/modules/availability/index.js +15 -0
- package/dist/modules/availability/index.js.map +7 -0
- package/dist/modules/availability/lib/policyResolution.js +155 -0
- package/dist/modules/availability/lib/policyResolution.js.map +7 -0
- package/dist/modules/availability/lib/tryResolve.js +11 -0
- package/dist/modules/availability/lib/tryResolve.js.map +7 -0
- package/dist/modules/availability/migrations/Migration20260922095844_availability.js +16 -0
- package/dist/modules/availability/migrations/Migration20260922095844_availability.js.map +7 -0
- package/dist/modules/availability/setup.js +12 -0
- package/dist/modules/availability/setup.js.map +7 -0
- package/dist/modules/entities/cli.js +33 -12
- package/dist/modules/entities/cli.js.map +2 -2
- package/dist/modules/inbox_ops/api/settings/route.js +7 -32
- package/dist/modules/inbox_ops/api/settings/route.js.map +2 -2
- package/dist/modules/inbox_ops/backend/inbox-ops/settings/page.js +2 -2
- package/dist/modules/inbox_ops/backend/inbox-ops/settings/page.js.map +2 -2
- package/dist/modules/inbox_ops/components/proposals/ActionCard.js +1 -1
- package/dist/modules/inbox_ops/components/proposals/ActionCard.js.map +2 -2
- package/dist/modules/inbox_ops/lib/ensure-settings.js +47 -0
- package/dist/modules/inbox_ops/lib/ensure-settings.js.map +7 -0
- package/dist/modules/inbox_ops/lib/executionEngine.js.map +1 -1
- package/dist/modules/inbox_ops/lib/executionHelpers.js +0 -23
- package/dist/modules/inbox_ops/lib/executionHelpers.js.map +2 -2
- package/dist/modules/inbox_ops/lib/payloadEnrichment.js +0 -3
- package/dist/modules/inbox_ops/lib/payloadEnrichment.js.map +2 -2
- package/dist/modules/inbox_ops/setup.js +2 -21
- package/dist/modules/inbox_ops/setup.js.map +2 -2
- package/dist/modules/inbox_ops/subscribers/extractionWorker.js.map +1 -1
- package/dist/modules/sales/components/documents/SalesDocumentForm.js +7 -0
- package/dist/modules/sales/components/documents/SalesDocumentForm.js.map +2 -2
- package/dist/modules/sales/data/entities.js +3 -1
- package/dist/modules/sales/data/entities.js.map +2 -2
- package/dist/modules/sales/inbox-actions.js +0 -12
- package/dist/modules/sales/inbox-actions.js.map +2 -2
- package/dist/modules/sales/migrations/Migration20260916120000_sales_payment_allocation_order_idx.js +20 -0
- package/dist/modules/sales/migrations/Migration20260916120000_sales_payment_allocation_order_idx.js.map +7 -0
- package/dist/modules/wms/di.js +3 -0
- package/dist/modules/wms/di.js.map +2 -2
- package/dist/modules/wms/lib/availabilityCache.js +85 -0
- package/dist/modules/wms/lib/availabilityCache.js.map +7 -0
- package/dist/modules/wms/lib/availabilityCalculation.js +178 -0
- package/dist/modules/wms/lib/availabilityCalculation.js.map +7 -0
- package/dist/modules/wms/lib/availabilityProvider.js +14 -0
- package/dist/modules/wms/lib/availabilityProvider.js.map +7 -0
- package/dist/modules/wms/lib/sqlInClause.js +9 -0
- package/dist/modules/wms/lib/sqlInClause.js.map +7 -0
- package/dist/modules/wms/lib/tryResolve.js +11 -0
- package/dist/modules/wms/lib/tryResolve.js.map +7 -0
- package/dist/modules/wms/subscribers/invalidate-availability-cache.js +16 -0
- package/dist/modules/wms/subscribers/invalidate-availability-cache.js.map +7 -0
- package/generated/entities/availability_policy/index.ts +19 -0
- package/generated/entities.ids.generated.ts +4 -0
- package/generated/entity-fields-registry.ts +21 -0
- package/package.json +7 -7
- package/src/modules/attachments/data/entities.ts +5 -3
- package/src/modules/auth/i18n/de.json +3 -0
- package/src/modules/auth/i18n/en.json +3 -0
- package/src/modules/auth/i18n/es.json +3 -0
- package/src/modules/auth/i18n/ko.json +3 -0
- package/src/modules/auth/i18n/pl.json +3 -0
- package/src/modules/availability/acl.ts +12 -0
- package/src/modules/availability/api/check/route.ts +114 -0
- package/src/modules/availability/api/openapi.ts +28 -0
- package/src/modules/availability/api/policies/resolve-preview/route.ts +67 -0
- package/src/modules/availability/api/policies/route.ts +224 -0
- package/src/modules/availability/backend/availability/check/page.meta.ts +12 -0
- package/src/modules/availability/backend/availability/check/page.tsx +223 -0
- package/src/modules/availability/backend/availability/policies/ResolutionPreviewPanel.tsx +106 -0
- package/src/modules/availability/backend/availability/policies/ScopeFields.tsx +55 -0
- package/src/modules/availability/backend/availability/policies/[id]/page.meta.ts +8 -0
- package/src/modules/availability/backend/availability/policies/[id]/page.tsx +182 -0
- package/src/modules/availability/backend/availability/policies/create/page.meta.ts +8 -0
- package/src/modules/availability/backend/availability/policies/create/page.tsx +105 -0
- package/src/modules/availability/backend/availability/policies/formGroups.ts +77 -0
- package/src/modules/availability/backend/availability/policies/page.meta.ts +12 -0
- package/src/modules/availability/backend/availability/policies/page.tsx +196 -0
- package/src/modules/availability/commands/policies.ts +358 -0
- package/src/modules/availability/commands/scope.ts +26 -0
- package/src/modules/availability/data/entities.ts +92 -0
- package/src/modules/availability/data/validators.ts +70 -0
- package/src/modules/availability/di.ts +54 -0
- package/src/modules/availability/events.ts +17 -0
- package/src/modules/availability/i18n/de.json +81 -0
- package/src/modules/availability/i18n/en.json +81 -0
- package/src/modules/availability/i18n/es.json +81 -0
- package/src/modules/availability/i18n/ko.json +81 -0
- package/src/modules/availability/i18n/pl.json +81 -0
- package/src/modules/availability/index.ts +13 -0
- package/src/modules/availability/lib/policyResolution.ts +264 -0
- package/src/modules/availability/lib/tryResolve.ts +8 -0
- package/src/modules/availability/migrations/.snapshot-open-mercato.json +375 -0
- package/src/modules/availability/migrations/Migration20260922095844_availability.ts +13 -0
- package/src/modules/availability/setup.ts +10 -0
- package/src/modules/entities/cli.ts +53 -13
- package/src/modules/inbox_ops/api/settings/route.ts +9 -32
- package/src/modules/inbox_ops/backend/inbox-ops/settings/page.tsx +2 -2
- package/src/modules/inbox_ops/components/proposals/ActionCard.tsx +1 -1
- package/src/modules/inbox_ops/i18n/de.json +1 -1
- package/src/modules/inbox_ops/i18n/en.json +1 -1
- package/src/modules/inbox_ops/i18n/es.json +1 -1
- package/src/modules/inbox_ops/i18n/ko.json +1 -1
- package/src/modules/inbox_ops/i18n/pl.json +1 -1
- package/src/modules/inbox_ops/lib/ensure-settings.ts +77 -0
- package/src/modules/inbox_ops/lib/executionEngine.ts +1 -1
- package/src/modules/inbox_ops/lib/executionHelpers.ts +0 -27
- package/src/modules/inbox_ops/lib/payloadEnrichment.ts +1 -5
- package/src/modules/inbox_ops/setup.ts +2 -21
- package/src/modules/inbox_ops/subscribers/extractionWorker.ts +1 -1
- package/src/modules/sales/components/documents/SalesDocumentForm.tsx +13 -0
- package/src/modules/sales/data/entities.ts +2 -0
- package/src/modules/sales/inbox-actions.ts +0 -20
- package/src/modules/sales/migrations/.snapshot-open-mercato.json +20 -0
- package/src/modules/sales/migrations/Migration20260916120000_sales_payment_allocation_order_idx.ts +74 -0
- package/src/modules/wms/di.ts +6 -0
- package/src/modules/wms/lib/availabilityCache.ts +136 -0
- package/src/modules/wms/lib/availabilityCalculation.ts +289 -0
- package/src/modules/wms/lib/availabilityProvider.ts +29 -0
- package/src/modules/wms/lib/sqlInClause.ts +21 -0
- package/src/modules/wms/lib/tryResolve.ts +8 -0
- package/src/modules/wms/subscribers/invalidate-availability-cache.ts +30 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useRouter } from "next/navigation";
|
|
5
|
+
import { CrudForm } from "@open-mercato/ui/backend/CrudForm";
|
|
6
|
+
import { createCrud } from "@open-mercato/ui/backend/utils/crud";
|
|
7
|
+
import { createCrudFormError } from "@open-mercato/ui/backend/utils/serverErrors";
|
|
8
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
9
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
10
|
+
import { useOrganizationScopeDetail } from "@open-mercato/shared/lib/frontend/useOrganizationScope";
|
|
11
|
+
import { ScopeFields } from "../ScopeFields.js";
|
|
12
|
+
import { ResolutionPreviewPanel } from "../ResolutionPreviewPanel.js";
|
|
13
|
+
import { buildPolicyFieldGroups } from "../formGroups.js";
|
|
14
|
+
function toNullableInt(value) {
|
|
15
|
+
if (value === null || value === void 0 || value === "") return null;
|
|
16
|
+
const parsed = typeof value === "number" ? value : parseInt(value, 10);
|
|
17
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
18
|
+
}
|
|
19
|
+
function AvailabilityPolicyCreatePage() {
|
|
20
|
+
const t = useT();
|
|
21
|
+
const router = useRouter();
|
|
22
|
+
const { organizationId, tenantId } = useOrganizationScopeDetail();
|
|
23
|
+
const [scope, setScope] = React.useState({ productId: "", variantId: "", storeId: "" });
|
|
24
|
+
const groups = React.useMemo(() => buildPolicyFieldGroups(t), [t]);
|
|
25
|
+
return /* @__PURE__ */ jsx(
|
|
26
|
+
CrudForm,
|
|
27
|
+
{
|
|
28
|
+
title: t("availability.policies.create.title"),
|
|
29
|
+
titleHeadingLevel: 1,
|
|
30
|
+
backHref: "/backend/availability/policies",
|
|
31
|
+
fields: [],
|
|
32
|
+
groups,
|
|
33
|
+
submitLabel: t("availability.policies.form.action.create"),
|
|
34
|
+
cancelHref: "/backend/availability/policies",
|
|
35
|
+
contentHeader: /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
36
|
+
/* @__PURE__ */ jsx(ScopeFields, { value: scope, onChange: setScope }),
|
|
37
|
+
/* @__PURE__ */ jsx(
|
|
38
|
+
ResolutionPreviewPanel,
|
|
39
|
+
{
|
|
40
|
+
productId: scope.productId,
|
|
41
|
+
variantId: scope.variantId || null,
|
|
42
|
+
storeId: scope.storeId || null
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
] }),
|
|
46
|
+
onSubmit: async (values) => {
|
|
47
|
+
if (scope.variantId && !scope.productId) {
|
|
48
|
+
throw createCrudFormError(
|
|
49
|
+
t("availability.policies.errors.variantRequiresProduct"),
|
|
50
|
+
{ productId: t("availability.policies.errors.variantRequiresProduct") }
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (values.allowBackorder && toNullableInt(values.backorderLeadTimeDays) == null) {
|
|
54
|
+
throw createCrudFormError(
|
|
55
|
+
t("availability.policies.errors.backorderRequiresLeadTime"),
|
|
56
|
+
{ backorderLeadTimeDays: t("availability.policies.errors.backorderRequiresLeadTime") }
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
const min = toNullableInt(values.minOrderQuantity);
|
|
60
|
+
const max = toNullableInt(values.maxOrderQuantity);
|
|
61
|
+
if (min != null && max != null && max < min) {
|
|
62
|
+
throw createCrudFormError(
|
|
63
|
+
t("availability.policies.errors.maxBelowMin"),
|
|
64
|
+
{ maxOrderQuantity: t("availability.policies.errors.maxBelowMin") }
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const payload = {
|
|
68
|
+
organizationId,
|
|
69
|
+
tenantId,
|
|
70
|
+
productId: scope.productId || null,
|
|
71
|
+
variantId: scope.variantId || null,
|
|
72
|
+
storeId: scope.storeId || null,
|
|
73
|
+
isStockManaged: !!values.isStockManaged,
|
|
74
|
+
allowBackorder: !!values.allowBackorder,
|
|
75
|
+
backorderLeadTimeDays: toNullableInt(values.backorderLeadTimeDays),
|
|
76
|
+
preorderReleaseAt: values.preorderReleaseAt || null,
|
|
77
|
+
lowStockThreshold: toNullableInt(values.lowStockThreshold),
|
|
78
|
+
minOrderQuantity: min,
|
|
79
|
+
maxOrderQuantity: max,
|
|
80
|
+
quantityIncrement: toNullableInt(values.quantityIncrement),
|
|
81
|
+
hideWhenOutOfStock: !!values.hideWhenOutOfStock,
|
|
82
|
+
isActive: values.isActive !== false
|
|
83
|
+
};
|
|
84
|
+
await createCrud("availability/policies", payload);
|
|
85
|
+
flash(t("availability.policies.flash.created"), "success");
|
|
86
|
+
router.push("/backend/availability/policies");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
AvailabilityPolicyCreatePage as default
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/availability/backend/availability/policies/create/page.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { useRouter } from 'next/navigation'\nimport { CrudForm } from '@open-mercato/ui/backend/CrudForm'\nimport { createCrud } 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 { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { useOrganizationScopeDetail } from '@open-mercato/shared/lib/frontend/useOrganizationScope'\nimport { ScopeFields, type PolicyScope } from '../ScopeFields'\nimport { ResolutionPreviewPanel } from '../ResolutionPreviewPanel'\nimport { buildPolicyFieldGroups } from '../formGroups'\n\ntype FormValues = {\n isStockManaged?: boolean\n allowBackorder?: boolean\n backorderLeadTimeDays?: number | string | null\n preorderReleaseAt?: string | null\n lowStockThreshold?: number | string | null\n minOrderQuantity?: number | string | null\n maxOrderQuantity?: number | string | null\n quantityIncrement?: number | string | null\n hideWhenOutOfStock?: boolean\n isActive?: boolean\n}\n\nfunction toNullableInt(value: number | string | null | undefined): number | null {\n if (value === null || value === undefined || value === '') return null\n const parsed = typeof value === 'number' ? value : parseInt(value, 10)\n return Number.isFinite(parsed) ? parsed : null\n}\n\nexport default function AvailabilityPolicyCreatePage() {\n const t = useT()\n const router = useRouter()\n const { organizationId, tenantId } = useOrganizationScopeDetail()\n const [scope, setScope] = React.useState<PolicyScope>({ productId: '', variantId: '', storeId: '' })\n\n const groups = React.useMemo(() => buildPolicyFieldGroups(t), [t])\n\n return (\n <CrudForm<FormValues>\n title={t('availability.policies.create.title')}\n titleHeadingLevel={1}\n backHref=\"/backend/availability/policies\"\n fields={[]}\n groups={groups}\n submitLabel={t('availability.policies.form.action.create')}\n cancelHref=\"/backend/availability/policies\"\n contentHeader={(\n <div className=\"space-y-4\">\n <ScopeFields value={scope} onChange={setScope} />\n <ResolutionPreviewPanel\n productId={scope.productId}\n variantId={scope.variantId || null}\n storeId={scope.storeId || null}\n />\n </div>\n )}\n onSubmit={async (values) => {\n if (scope.variantId && !scope.productId) {\n throw createCrudFormError(\n t('availability.policies.errors.variantRequiresProduct'),\n { productId: t('availability.policies.errors.variantRequiresProduct') },\n )\n }\n if (values.allowBackorder && toNullableInt(values.backorderLeadTimeDays) == null) {\n throw createCrudFormError(\n t('availability.policies.errors.backorderRequiresLeadTime'),\n { backorderLeadTimeDays: t('availability.policies.errors.backorderRequiresLeadTime') },\n )\n }\n const min = toNullableInt(values.minOrderQuantity)\n const max = toNullableInt(values.maxOrderQuantity)\n if (min != null && max != null && max < min) {\n throw createCrudFormError(\n t('availability.policies.errors.maxBelowMin'),\n { maxOrderQuantity: t('availability.policies.errors.maxBelowMin') },\n )\n }\n\n const payload = {\n organizationId,\n tenantId,\n productId: scope.productId || null,\n variantId: scope.variantId || null,\n storeId: scope.storeId || null,\n isStockManaged: !!values.isStockManaged,\n allowBackorder: !!values.allowBackorder,\n backorderLeadTimeDays: toNullableInt(values.backorderLeadTimeDays),\n preorderReleaseAt: values.preorderReleaseAt || null,\n lowStockThreshold: toNullableInt(values.lowStockThreshold),\n minOrderQuantity: min,\n maxOrderQuantity: max,\n quantityIncrement: toNullableInt(values.quantityIncrement),\n hideWhenOutOfStock: !!values.hideWhenOutOfStock,\n isActive: values.isActive !== false,\n }\n await createCrud('availability/policies', payload)\n flash(t('availability.policies.flash.created'), 'success')\n router.push('/backend/availability/policies')\n }}\n />\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAkDQ,SACE,KADF;AAjDR,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,aAAa;AACtB,SAAS,YAAY;AACrB,SAAS,kCAAkC;AAC3C,SAAS,mBAAqC;AAC9C,SAAS,8BAA8B;AACvC,SAAS,8BAA8B;AAevC,SAAS,cAAc,OAA0D;AAC/E,MAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,GAAI,QAAO;AAClE,QAAM,SAAS,OAAO,UAAU,WAAW,QAAQ,SAAS,OAAO,EAAE;AACrE,SAAO,OAAO,SAAS,MAAM,IAAI,SAAS;AAC5C;AAEe,SAAR,+BAAgD;AACrD,QAAM,IAAI,KAAK;AACf,QAAM,SAAS,UAAU;AACzB,QAAM,EAAE,gBAAgB,SAAS,IAAI,2BAA2B;AAChE,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAsB,EAAE,WAAW,IAAI,WAAW,IAAI,SAAS,GAAG,CAAC;AAEnG,QAAM,SAAS,MAAM,QAAQ,MAAM,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC;AAEjE,SACE;AA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AqB;AAAA,UACjE,mBAAmB,OAAO,qBAAqB;AAAA,UAC/C,mBAAmB,cAAc,OAAO,iBAAiB;AAAA,UACzD,kBAAkB;AAAA,UAClB,kBAAkB;AAAA,UAClB,mBAAmB,cAAc,OAAO,iBAAiB;AAAA,UACzD,oBAAoB,CAAC,CAAC,OAAO;AAAA,UAC7B,UAAU,OAAO,aAAa;AAAA,QAChC;AACA,cAAM,WAAW,yBAAyB,OAAO;AACjD,cAAM,EAAE,qCAAqC,GAAG,SAAS;AACzD,eAAO,KAAK,gCAAgC;AAAA,MAC9C;AAAA;AAAA,EACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const metadata = {
|
|
2
|
+
requireAuth: true,
|
|
3
|
+
requireFeatures: ["availability.policies.manage"],
|
|
4
|
+
breadcrumb: [
|
|
5
|
+
{ label: "Availability Policies", labelKey: "availability.policies.nav.title", href: "/backend/availability/policies" },
|
|
6
|
+
{ label: "Create", labelKey: "availability.policies.create.title" }
|
|
7
|
+
]
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
metadata
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=page.meta.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/availability/backend/availability/policies/create/page.meta.ts"],
|
|
4
|
+
"sourcesContent": ["export const metadata = {\n requireAuth: true,\n requireFeatures: ['availability.policies.manage'],\n breadcrumb: [\n { label: 'Availability Policies', labelKey: 'availability.policies.nav.title', href: '/backend/availability/policies' },\n { label: 'Create', labelKey: 'availability.policies.create.title' },\n ],\n}\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,WAAW;AAAA,EACtB,aAAa;AAAA,EACb,iBAAiB,CAAC,8BAA8B;AAAA,EAChD,YAAY;AAAA,IACV,EAAE,OAAO,yBAAyB,UAAU,mCAAmC,MAAM,iCAAiC;AAAA,IACtH,EAAE,OAAO,UAAU,UAAU,qCAAqC;AAAA,EACpE;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
function buildPolicyFieldGroups(t) {
|
|
2
|
+
return [
|
|
3
|
+
{
|
|
4
|
+
id: "sell-policy",
|
|
5
|
+
column: 1,
|
|
6
|
+
title: t("availability.policies.form.group.sellPolicy"),
|
|
7
|
+
fields: [
|
|
8
|
+
{
|
|
9
|
+
id: "isStockManaged",
|
|
10
|
+
type: "checkbox",
|
|
11
|
+
label: t("availability.policies.form.field.isStockManaged"),
|
|
12
|
+
description: t("availability.policies.form.field.isStockManaged.help")
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "allowBackorder",
|
|
16
|
+
type: "checkbox",
|
|
17
|
+
label: t("availability.policies.form.field.allowBackorder")
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "backorderLeadTimeDays",
|
|
21
|
+
type: "number",
|
|
22
|
+
label: t("availability.policies.form.field.backorderLeadTimeDays"),
|
|
23
|
+
description: t("availability.policies.form.field.backorderLeadTimeDays.help")
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "preorderReleaseAt",
|
|
27
|
+
type: "datetime-local",
|
|
28
|
+
label: t("availability.policies.form.field.preorderReleaseAt")
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "thresholds",
|
|
34
|
+
column: 2,
|
|
35
|
+
title: t("availability.policies.form.group.thresholds"),
|
|
36
|
+
fields: [
|
|
37
|
+
{
|
|
38
|
+
id: "lowStockThreshold",
|
|
39
|
+
type: "number",
|
|
40
|
+
label: t("availability.policies.form.field.lowStockThreshold")
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "minOrderQuantity",
|
|
44
|
+
type: "number",
|
|
45
|
+
label: t("availability.policies.form.field.minOrderQuantity")
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "maxOrderQuantity",
|
|
49
|
+
type: "number",
|
|
50
|
+
label: t("availability.policies.form.field.maxOrderQuantity")
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "quantityIncrement",
|
|
54
|
+
type: "number",
|
|
55
|
+
label: t("availability.policies.form.field.quantityIncrement")
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "hideWhenOutOfStock",
|
|
59
|
+
type: "checkbox",
|
|
60
|
+
label: t("availability.policies.form.field.hideWhenOutOfStock")
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: "isActive",
|
|
64
|
+
type: "checkbox",
|
|
65
|
+
label: t("availability.policies.form.field.isActive"),
|
|
66
|
+
defaultValue: true
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
buildPolicyFieldGroups
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=formGroups.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/availability/backend/availability/policies/formGroups.ts"],
|
|
4
|
+
"sourcesContent": ["import type { CrudFormGroup } from '@open-mercato/ui/backend/CrudForm'\n\n/**\n * Shared field groups for the create and edit policy forms. Scope fields\n * (productId/variantId/storeId) live outside this list \u2014 see `ScopeFields`.\n */\nexport function buildPolicyFieldGroups(t: (key: string) => string): CrudFormGroup[] {\n return [\n {\n id: 'sell-policy',\n column: 1,\n title: t('availability.policies.form.group.sellPolicy'),\n fields: [\n {\n id: 'isStockManaged',\n type: 'checkbox',\n label: t('availability.policies.form.field.isStockManaged'),\n description: t('availability.policies.form.field.isStockManaged.help'),\n },\n {\n id: 'allowBackorder',\n type: 'checkbox',\n label: t('availability.policies.form.field.allowBackorder'),\n },\n {\n id: 'backorderLeadTimeDays',\n type: 'number',\n label: t('availability.policies.form.field.backorderLeadTimeDays'),\n description: t('availability.policies.form.field.backorderLeadTimeDays.help'),\n },\n {\n id: 'preorderReleaseAt',\n type: 'datetime-local',\n label: t('availability.policies.form.field.preorderReleaseAt'),\n },\n ],\n },\n {\n id: 'thresholds',\n column: 2,\n title: t('availability.policies.form.group.thresholds'),\n fields: [\n {\n id: 'lowStockThreshold',\n type: 'number',\n label: t('availability.policies.form.field.lowStockThreshold'),\n },\n {\n id: 'minOrderQuantity',\n type: 'number',\n label: t('availability.policies.form.field.minOrderQuantity'),\n },\n {\n id: 'maxOrderQuantity',\n type: 'number',\n label: t('availability.policies.form.field.maxOrderQuantity'),\n },\n {\n id: 'quantityIncrement',\n type: 'number',\n label: t('availability.policies.form.field.quantityIncrement'),\n },\n {\n id: 'hideWhenOutOfStock',\n type: 'checkbox',\n label: t('availability.policies.form.field.hideWhenOutOfStock'),\n },\n {\n id: 'isActive',\n type: 'checkbox',\n label: t('availability.policies.form.field.isActive'),\n defaultValue: true,\n },\n ],\n },\n ]\n}\n"],
|
|
5
|
+
"mappings": "AAMO,SAAS,uBAAuB,GAA6C;AAClF,SAAO;AAAA,IACL;AAAA,MACE,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,OAAO,EAAE,6CAA6C;AAAA,MACtD,QAAQ;AAAA,QACN;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,iDAAiD;AAAA,UAC1D,aAAa,EAAE,sDAAsD;AAAA,QACvE;AAAA,QACA;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,iDAAiD;AAAA,QAC5D;AAAA,QACA;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,wDAAwD;AAAA,UACjE,aAAa,EAAE,6DAA6D;AAAA,QAC9E;AAAA,QACA;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,oDAAoD;AAAA,QAC/D;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,OAAO,EAAE,6CAA6C;AAAA,MACtD,QAAQ;AAAA,QACN;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,oDAAoD;AAAA,QAC/D;AAAA,QACA;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,mDAAmD;AAAA,QAC9D;AAAA,QACA;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,mDAAmD;AAAA,QAC9D;AAAA,QACA;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,oDAAoD;AAAA,QAC/D;AAAA,QACA;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,qDAAqD;AAAA,QAChE;AAAA,QACA;AAAA,UACE,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,OAAO,EAAE,2CAA2C;AAAA,UACpD,cAAc;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import { Page, PageBody } from "@open-mercato/ui/backend/Page";
|
|
6
|
+
import { DataTable } from "@open-mercato/ui/backend/DataTable";
|
|
7
|
+
import { Button } from "@open-mercato/ui/primitives/button";
|
|
8
|
+
import { RowActions } from "@open-mercato/ui/backend/RowActions";
|
|
9
|
+
import { apiCall, withScopedApiRequestHeaders } from "@open-mercato/ui/backend/utils/apiCall";
|
|
10
|
+
import { buildOptimisticLockHeader } from "@open-mercato/ui/backend/utils/optimisticLock";
|
|
11
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
12
|
+
import { useOrganizationScopeVersion } from "@open-mercato/shared/lib/frontend/useOrganizationScope";
|
|
13
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
14
|
+
import { useConfirmDialog } from "@open-mercato/ui/backend/confirm-dialog";
|
|
15
|
+
function ScopeCell({ value, allLabel }) {
|
|
16
|
+
if (!value) return /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: allLabel });
|
|
17
|
+
return /* @__PURE__ */ jsx("code", { className: "text-xs", children: value });
|
|
18
|
+
}
|
|
19
|
+
function AvailabilityPoliciesListPage() {
|
|
20
|
+
const [rows, setRows] = React.useState([]);
|
|
21
|
+
const [page, setPage] = React.useState(1);
|
|
22
|
+
const [total, setTotal] = React.useState(0);
|
|
23
|
+
const [totalPages, setTotalPages] = React.useState(1);
|
|
24
|
+
const [totalIsCapped, setTotalIsCapped] = React.useState(false);
|
|
25
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
26
|
+
const [reloadToken, setReloadToken] = React.useState(0);
|
|
27
|
+
const scopeVersion = useOrganizationScopeVersion();
|
|
28
|
+
const t = useT();
|
|
29
|
+
const { confirm, ConfirmDialogElement } = useConfirmDialog();
|
|
30
|
+
const [filterValues, setFilterValues] = React.useState({});
|
|
31
|
+
const filters = React.useMemo(() => [
|
|
32
|
+
{ id: "productId", label: t("availability.policies.list.columns.product"), type: "text" },
|
|
33
|
+
{ id: "storeId", label: t("availability.policies.list.columns.store"), type: "text" },
|
|
34
|
+
{
|
|
35
|
+
id: "isActive",
|
|
36
|
+
label: t("availability.policies.list.columns.active"),
|
|
37
|
+
type: "select",
|
|
38
|
+
options: [
|
|
39
|
+
{ value: "true", label: t("common.yes") },
|
|
40
|
+
{ value: "false", label: t("common.no") }
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
], [t]);
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
let cancelled = false;
|
|
46
|
+
async function load() {
|
|
47
|
+
setIsLoading(true);
|
|
48
|
+
try {
|
|
49
|
+
const params = new URLSearchParams();
|
|
50
|
+
params.set("page", String(page));
|
|
51
|
+
params.set("pageSize", "50");
|
|
52
|
+
const productId = typeof filterValues.productId === "string" ? filterValues.productId.trim() : "";
|
|
53
|
+
const storeId = typeof filterValues.storeId === "string" ? filterValues.storeId.trim() : "";
|
|
54
|
+
const isActive = typeof filterValues.isActive === "string" ? filterValues.isActive : "";
|
|
55
|
+
if (productId) params.set("productId", productId);
|
|
56
|
+
if (storeId) params.set("storeId", storeId);
|
|
57
|
+
if (isActive) params.set("isActive", isActive);
|
|
58
|
+
const fallback = { items: [], total: 0, page, totalPages: 1 };
|
|
59
|
+
const call = await apiCall(`/api/availability/policies?${params.toString()}`, void 0, { fallback });
|
|
60
|
+
if (!call.ok) {
|
|
61
|
+
const errorPayload = call.result;
|
|
62
|
+
const message = typeof errorPayload?.error === "string" ? errorPayload.error : t("availability.policies.list.error.loadFailed");
|
|
63
|
+
flash(message, "error");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const payload = call.result ?? fallback;
|
|
67
|
+
if (!cancelled) {
|
|
68
|
+
setRows(Array.isArray(payload.items) ? payload.items : []);
|
|
69
|
+
setTotal(payload.total || 0);
|
|
70
|
+
setTotalPages(payload.totalPages || 1);
|
|
71
|
+
setTotalIsCapped(payload?.totalIsCapped === true);
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (!cancelled) {
|
|
75
|
+
const message = error instanceof Error ? error.message : t("availability.policies.list.error.loadFailed");
|
|
76
|
+
flash(message, "error");
|
|
77
|
+
}
|
|
78
|
+
} finally {
|
|
79
|
+
if (!cancelled) setIsLoading(false);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
load();
|
|
83
|
+
return () => {
|
|
84
|
+
cancelled = true;
|
|
85
|
+
};
|
|
86
|
+
}, [page, reloadToken, scopeVersion, filterValues, t]);
|
|
87
|
+
const handleDelete = React.useCallback(async (row) => {
|
|
88
|
+
const confirmed = await confirm({ title: t("availability.policies.list.confirmDelete"), variant: "destructive" });
|
|
89
|
+
if (!confirmed) return;
|
|
90
|
+
try {
|
|
91
|
+
const call = await withScopedApiRequestHeaders(
|
|
92
|
+
buildOptimisticLockHeader(row.updatedAt),
|
|
93
|
+
() => apiCall(`/api/availability/policies?id=${encodeURIComponent(row.id)}`, { method: "DELETE" }, { fallback: null })
|
|
94
|
+
);
|
|
95
|
+
if (!call.ok) {
|
|
96
|
+
const errorPayload = call.result;
|
|
97
|
+
const message = typeof errorPayload?.error === "string" ? errorPayload.error : t("availability.policies.list.error.deleteFailed");
|
|
98
|
+
flash(message, "error");
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
flash(t("availability.policies.list.success.deleted"), "success");
|
|
102
|
+
setReloadToken((token) => token + 1);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
const message = error instanceof Error ? error.message : t("availability.policies.list.error.deleteFailed");
|
|
105
|
+
flash(message, "error");
|
|
106
|
+
}
|
|
107
|
+
}, [confirm, t]);
|
|
108
|
+
const columns = React.useMemo(() => [
|
|
109
|
+
{
|
|
110
|
+
accessorKey: "productId",
|
|
111
|
+
header: t("availability.policies.list.columns.product"),
|
|
112
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(ScopeCell, { value: row.original.productId, allLabel: t("availability.policies.list.storeDefault") })
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
accessorKey: "variantId",
|
|
116
|
+
header: t("availability.policies.list.columns.variant"),
|
|
117
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(ScopeCell, { value: row.original.variantId, allLabel: t("availability.policies.list.allVariants") })
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
accessorKey: "storeId",
|
|
121
|
+
header: t("availability.policies.list.columns.store"),
|
|
122
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(ScopeCell, { value: row.original.storeId, allLabel: t("availability.policies.list.allStores") })
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
accessorKey: "isStockManaged",
|
|
126
|
+
header: t("availability.policies.list.columns.stockManaged"),
|
|
127
|
+
cell: ({ row }) => row.original.isStockManaged ? t("common.yes") : t("common.no")
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
accessorKey: "allowBackorder",
|
|
131
|
+
header: t("availability.policies.list.columns.backorder"),
|
|
132
|
+
cell: ({ row }) => row.original.allowBackorder ? t("common.yes") : t("common.no")
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
accessorKey: "isActive",
|
|
136
|
+
header: t("availability.policies.list.columns.active"),
|
|
137
|
+
cell: ({ row }) => row.original.isActive ? t("common.yes") : t("common.no")
|
|
138
|
+
}
|
|
139
|
+
], [t]);
|
|
140
|
+
return /* @__PURE__ */ jsxs(Page, { children: [
|
|
141
|
+
/* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
|
|
142
|
+
DataTable,
|
|
143
|
+
{
|
|
144
|
+
title: t("availability.policies.list.title"),
|
|
145
|
+
titleHeadingLevel: 1,
|
|
146
|
+
actions: /* @__PURE__ */ jsx(Button, { asChild: true, children: /* @__PURE__ */ jsx(Link, { href: "/backend/availability/policies/create", children: t("availability.policies.list.actions.create") }) }),
|
|
147
|
+
columns,
|
|
148
|
+
data: rows,
|
|
149
|
+
filters,
|
|
150
|
+
filterValues,
|
|
151
|
+
onFiltersApply: (values) => {
|
|
152
|
+
setFilterValues(values);
|
|
153
|
+
setPage(1);
|
|
154
|
+
},
|
|
155
|
+
onFiltersClear: () => {
|
|
156
|
+
setFilterValues({});
|
|
157
|
+
setPage(1);
|
|
158
|
+
},
|
|
159
|
+
perspective: { tableId: "availability.policies.list" },
|
|
160
|
+
rowActions: (row) => /* @__PURE__ */ jsx(RowActions, { items: [
|
|
161
|
+
{ id: "edit", label: t("common.edit"), href: `/backend/availability/policies/${row.id}` },
|
|
162
|
+
{ id: "delete", label: t("common.delete"), destructive: true, onSelect: () => {
|
|
163
|
+
void handleDelete(row);
|
|
164
|
+
} }
|
|
165
|
+
] }),
|
|
166
|
+
pagination: { page, pageSize: 50, total, totalPages, totalIsCapped, onPageChange: setPage },
|
|
167
|
+
isLoading
|
|
168
|
+
}
|
|
169
|
+
) }),
|
|
170
|
+
ConfirmDialogElement
|
|
171
|
+
] });
|
|
172
|
+
}
|
|
173
|
+
export {
|
|
174
|
+
AvailabilityPoliciesListPage as default
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/availability/backend/availability/policies/page.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { RowActions } from '@open-mercato/ui/backend/RowActions'\nimport { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useOrganizationScopeVersion } from '@open-mercato/shared/lib/frontend/useOrganizationScope'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'\n\ntype Row = {\n id: string\n storeId: string | null\n productId: string | null\n variantId: string | null\n isStockManaged: boolean\n allowBackorder: boolean\n isActive: boolean\n updatedAt: string | null\n}\n\ntype ResponsePayload = {\n items: Row[]\n total: number\n page?: number\n pageSize?: number\n totalPages: number\n totalIsCapped?: boolean\n}\n\nfunction ScopeCell({ value, allLabel }: { value: string | null; allLabel: string }) {\n if (!value) return <span className=\"text-muted-foreground\">{allLabel}</span>\n return <code className=\"text-xs\">{value}</code>\n}\n\nexport default function AvailabilityPoliciesListPage() {\n const [rows, setRows] = React.useState<Row[]>([])\n const [page, setPage] = React.useState(1)\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [totalIsCapped, setTotalIsCapped] = React.useState(false)\n const [isLoading, setIsLoading] = React.useState(true)\n const [reloadToken, setReloadToken] = React.useState(0)\n const scopeVersion = useOrganizationScopeVersion()\n const t = useT()\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n const [filterValues, setFilterValues] = React.useState<FilterValues>({})\n\n const filters = React.useMemo<FilterDef[]>(() => [\n { id: 'productId', label: t('availability.policies.list.columns.product'), type: 'text' },\n { id: 'storeId', label: t('availability.policies.list.columns.store'), type: 'text' },\n {\n id: 'isActive',\n label: t('availability.policies.list.columns.active'),\n type: 'select',\n options: [\n { value: 'true', label: t('common.yes') },\n { value: 'false', label: t('common.no') },\n ],\n },\n ], [t])\n\n React.useEffect(() => {\n let cancelled = false\n async function load() {\n setIsLoading(true)\n try {\n const params = new URLSearchParams()\n params.set('page', String(page))\n params.set('pageSize', '50')\n const productId = typeof filterValues.productId === 'string' ? filterValues.productId.trim() : ''\n const storeId = typeof filterValues.storeId === 'string' ? filterValues.storeId.trim() : ''\n const isActive = typeof filterValues.isActive === 'string' ? filterValues.isActive : ''\n if (productId) params.set('productId', productId)\n if (storeId) params.set('storeId', storeId)\n if (isActive) params.set('isActive', isActive)\n const fallback: ResponsePayload = { items: [], total: 0, page, totalPages: 1 }\n const call = await apiCall<ResponsePayload>(`/api/availability/policies?${params.toString()}`, undefined, { fallback })\n if (!call.ok) {\n const errorPayload = call.result as { error?: string } | undefined\n const message = typeof errorPayload?.error === 'string' ? errorPayload.error : t('availability.policies.list.error.loadFailed')\n flash(message, 'error')\n return\n }\n const payload = call.result ?? fallback\n if (!cancelled) {\n setRows(Array.isArray(payload.items) ? payload.items : [])\n setTotal(payload.total || 0)\n setTotalPages(payload.totalPages || 1)\n setTotalIsCapped(payload?.totalIsCapped === true)\n }\n } catch (error) {\n if (!cancelled) {\n const message = error instanceof Error ? error.message : t('availability.policies.list.error.loadFailed')\n flash(message, 'error')\n }\n } finally {\n if (!cancelled) setIsLoading(false)\n }\n }\n load()\n return () => { cancelled = true }\n }, [page, reloadToken, scopeVersion, filterValues, t])\n\n const handleDelete = React.useCallback(async (row: Row) => {\n const confirmed = await confirm({ title: t('availability.policies.list.confirmDelete'), variant: 'destructive' })\n if (!confirmed) return\n try {\n const call = await withScopedApiRequestHeaders(buildOptimisticLockHeader(row.updatedAt), () =>\n apiCall<{ error?: string }>(`/api/availability/policies?id=${encodeURIComponent(row.id)}`, { method: 'DELETE' }, { fallback: null }),\n )\n if (!call.ok) {\n const errorPayload = call.result as { error?: string } | undefined\n const message = typeof errorPayload?.error === 'string' ? errorPayload.error : t('availability.policies.list.error.deleteFailed')\n flash(message, 'error')\n return\n }\n flash(t('availability.policies.list.success.deleted'), 'success')\n setReloadToken((token) => token + 1)\n } catch (error) {\n const message = error instanceof Error ? error.message : t('availability.policies.list.error.deleteFailed')\n flash(message, 'error')\n }\n }, [confirm, t])\n\n const columns = React.useMemo<ColumnDef<Row>[]>(() => [\n {\n accessorKey: 'productId',\n header: t('availability.policies.list.columns.product'),\n cell: ({ row }) => <ScopeCell value={row.original.productId} allLabel={t('availability.policies.list.storeDefault')} />,\n },\n {\n accessorKey: 'variantId',\n header: t('availability.policies.list.columns.variant'),\n cell: ({ row }) => <ScopeCell value={row.original.variantId} allLabel={t('availability.policies.list.allVariants')} />,\n },\n {\n accessorKey: 'storeId',\n header: t('availability.policies.list.columns.store'),\n cell: ({ row }) => <ScopeCell value={row.original.storeId} allLabel={t('availability.policies.list.allStores')} />,\n },\n {\n accessorKey: 'isStockManaged',\n header: t('availability.policies.list.columns.stockManaged'),\n cell: ({ row }) => (row.original.isStockManaged ? t('common.yes') : t('common.no')),\n },\n {\n accessorKey: 'allowBackorder',\n header: t('availability.policies.list.columns.backorder'),\n cell: ({ row }) => (row.original.allowBackorder ? t('common.yes') : t('common.no')),\n },\n {\n accessorKey: 'isActive',\n header: t('availability.policies.list.columns.active'),\n cell: ({ row }) => (row.original.isActive ? t('common.yes') : t('common.no')),\n },\n ], [t])\n\n return (\n <Page>\n <PageBody>\n <DataTable\n title={t('availability.policies.list.title')}\n titleHeadingLevel={1}\n actions={(\n <Button asChild>\n <Link href=\"/backend/availability/policies/create\">{t('availability.policies.list.actions.create')}</Link>\n </Button>\n )}\n columns={columns}\n data={rows}\n filters={filters}\n filterValues={filterValues}\n onFiltersApply={(values) => { setFilterValues(values); setPage(1) }}\n onFiltersClear={() => { setFilterValues({}); setPage(1) }}\n perspective={{ tableId: 'availability.policies.list' }}\n rowActions={(row) => (\n <RowActions items={[\n { id: 'edit', label: t('common.edit'), href: `/backend/availability/policies/${row.id}` },\n { id: 'delete', label: t('common.delete'), destructive: true, onSelect: () => { void handleDelete(row) } },\n ]} />\n )}\n pagination={{ page, pageSize: 50, total, totalPages, totalIsCapped, onPageChange: setPage }}\n isLoading={isLoading}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAqCqB,cAgIjB,YAhIiB;AApCrB,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,iBAAiB;AAE1B,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,SAAS,mCAAmC;AACrD,SAAS,iCAAiC;AAC1C,SAAS,aAAa;AACtB,SAAS,mCAAmC;AAC5C,SAAS,YAAY;AACrB,SAAS,wBAAwB;AAuBjC,SAAS,UAAU,EAAE,OAAO,SAAS,GAA+C;AAClF,MAAI,CAAC,MAAO,QAAO,oBAAC,UAAK,WAAU,yBAAyB,oBAAS;AACrE,SAAO,oBAAC,UAAK,WAAU,WAAW,iBAAM;AAC1C;AAEe,SAAR,+BAAgD;AACrD,QAAM,CAAC,MAAM,OAA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AAa,GAAG;AAAA,UAAE,EAAE;AAAA,QAC3G,GAAG;AAAA,QAEL,YAAY,EAAE,MAAM,UAAU,IAAI,OAAO,YAAY,eAAe,cAAc,QAAQ;AAAA,QAC1F;AAAA;AAAA,IACF,GACF;AAAA,IACC;AAAA,KACH;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const metadata = {
|
|
2
|
+
requireAuth: true,
|
|
3
|
+
requireFeatures: ["availability.policies.view"],
|
|
4
|
+
pageTitle: "Availability Policies",
|
|
5
|
+
pageTitleKey: "availability.policies.nav.title",
|
|
6
|
+
pageGroup: "Availability",
|
|
7
|
+
pageGroupKey: "availability.nav.group",
|
|
8
|
+
pageOrder: 10,
|
|
9
|
+
pageContext: "settings",
|
|
10
|
+
icon: "boxes",
|
|
11
|
+
breadcrumb: [{ label: "Availability Policies", labelKey: "availability.policies.nav.title" }]
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
metadata
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=page.meta.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/availability/backend/availability/policies/page.meta.ts"],
|
|
4
|
+
"sourcesContent": ["export const metadata = {\n requireAuth: true,\n requireFeatures: ['availability.policies.view'],\n pageTitle: 'Availability Policies',\n pageTitleKey: 'availability.policies.nav.title',\n pageGroup: 'Availability',\n pageGroupKey: 'availability.nav.group',\n pageOrder: 10,\n pageContext: 'settings' as const,\n icon: 'boxes',\n breadcrumb: [{ label: 'Availability Policies', labelKey: 'availability.policies.nav.title' }],\n}\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,WAAW;AAAA,EACtB,aAAa;AAAA,EACb,iBAAiB,CAAC,4BAA4B;AAAA,EAC9C,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,aAAa;AAAA,EACb,MAAM;AAAA,EACN,YAAY,CAAC,EAAE,OAAO,yBAAyB,UAAU,kCAAkC,CAAC;AAC9F;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|