@open-mercato/core 0.4.6-develop-9ff1d4a9a2 → 0.4.6-develop-219dae16c5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/modules/currencies/backend/exchange-rates/[id]/page.js +17 -154
  2. package/dist/modules/currencies/backend/exchange-rates/[id]/page.js.map +3 -3
  3. package/dist/modules/currencies/backend/exchange-rates/create/page.js +14 -152
  4. package/dist/modules/currencies/backend/exchange-rates/create/page.js.map +2 -2
  5. package/dist/modules/currencies/lib/exchangeRateFormConfig.js +167 -0
  6. package/dist/modules/currencies/lib/exchangeRateFormConfig.js.map +7 -0
  7. package/dist/modules/customers/api/dashboard/widgets/utils.js +1 -34
  8. package/dist/modules/customers/api/dashboard/widgets/utils.js.map +2 -2
  9. package/dist/modules/customers/commands/activities.js +3 -8
  10. package/dist/modules/customers/commands/activities.js.map +2 -2
  11. package/dist/modules/customers/commands/comments.js +2 -8
  12. package/dist/modules/customers/commands/comments.js.map +2 -2
  13. package/dist/modules/dashboards/lib/widgetScope.js +38 -0
  14. package/dist/modules/dashboards/lib/widgetScope.js.map +7 -0
  15. package/dist/modules/entities/lib/makeActivityRoute.js +265 -0
  16. package/dist/modules/entities/lib/makeActivityRoute.js.map +7 -0
  17. package/dist/modules/resources/api/activities.js +24 -232
  18. package/dist/modules/resources/api/activities.js.map +2 -2
  19. package/dist/modules/resources/commands/activities.js +3 -8
  20. package/dist/modules/resources/commands/activities.js.map +2 -2
  21. package/dist/modules/resources/commands/comments.js +2 -8
  22. package/dist/modules/resources/commands/comments.js.map +2 -2
  23. package/dist/modules/sales/api/dashboard/widgets/new-orders/route.js +27 -182
  24. package/dist/modules/sales/api/dashboard/widgets/new-orders/route.js.map +2 -2
  25. package/dist/modules/sales/api/dashboard/widgets/new-quotes/route.js +28 -183
  26. package/dist/modules/sales/api/dashboard/widgets/new-quotes/route.js.map +2 -2
  27. package/dist/modules/sales/api/order-line-statuses/route.js +15 -194
  28. package/dist/modules/sales/api/order-line-statuses/route.js.map +2 -2
  29. package/dist/modules/sales/api/order-lines/route.js +15 -281
  30. package/dist/modules/sales/api/order-lines/route.js.map +2 -2
  31. package/dist/modules/sales/api/order-statuses/route.js +15 -194
  32. package/dist/modules/sales/api/order-statuses/route.js.map +2 -2
  33. package/dist/modules/sales/api/payment-statuses/route.js +15 -194
  34. package/dist/modules/sales/api/payment-statuses/route.js.map +2 -2
  35. package/dist/modules/sales/api/quote-lines/route.js +15 -279
  36. package/dist/modules/sales/api/quote-lines/route.js.map +2 -2
  37. package/dist/modules/sales/api/shipment-statuses/route.js +15 -194
  38. package/dist/modules/sales/api/shipment-statuses/route.js.map +2 -2
  39. package/dist/modules/sales/components/PaymentMethodsSettings.js +3 -84
  40. package/dist/modules/sales/components/PaymentMethodsSettings.js.map +2 -2
  41. package/dist/modules/sales/components/ProviderFieldInput.js +86 -0
  42. package/dist/modules/sales/components/ProviderFieldInput.js.map +7 -0
  43. package/dist/modules/sales/components/ShippingMethodsSettings.js +3 -82
  44. package/dist/modules/sales/components/ShippingMethodsSettings.js.map +2 -2
  45. package/dist/modules/sales/lib/makeSalesLineRoute.js +308 -0
  46. package/dist/modules/sales/lib/makeSalesLineRoute.js.map +7 -0
  47. package/dist/modules/sales/lib/makeStatusDictionaryRoute.js +206 -0
  48. package/dist/modules/sales/lib/makeStatusDictionaryRoute.js.map +7 -0
  49. package/dist/modules/sales/widgets/dashboard/makeDashboardWidgetRoute.js +178 -0
  50. package/dist/modules/sales/widgets/dashboard/makeDashboardWidgetRoute.js.map +7 -0
  51. package/dist/modules/sales/widgets/dashboard/new-orders/widget.client.js +1 -39
  52. package/dist/modules/sales/widgets/dashboard/new-orders/widget.client.js.map +2 -2
  53. package/dist/modules/sales/widgets/dashboard/new-quotes/widget.client.js +1 -39
  54. package/dist/modules/sales/widgets/dashboard/new-quotes/widget.client.js.map +2 -2
  55. package/dist/modules/sales/widgets/dashboard/shared.js +46 -0
  56. package/dist/modules/sales/widgets/dashboard/shared.js.map +7 -0
  57. package/dist/modules/staff/api/activities.js +24 -232
  58. package/dist/modules/staff/api/activities.js.map +2 -2
  59. package/dist/modules/staff/backend/staff/leave-requests/[id]/page.js +14 -34
  60. package/dist/modules/staff/backend/staff/leave-requests/[id]/page.js.map +2 -2
  61. package/dist/modules/staff/backend/staff/my-leave-requests/[id]/page.js +15 -34
  62. package/dist/modules/staff/backend/staff/my-leave-requests/[id]/page.js.map +2 -2
  63. package/dist/modules/staff/commands/activities.js +3 -8
  64. package/dist/modules/staff/commands/activities.js.map +2 -2
  65. package/dist/modules/staff/commands/comments.js +2 -8
  66. package/dist/modules/staff/commands/comments.js.map +2 -2
  67. package/dist/modules/staff/lib/leaveRequestHelpers.js +41 -0
  68. package/dist/modules/staff/lib/leaveRequestHelpers.js.map +7 -0
  69. package/package.json +2 -2
  70. package/src/modules/currencies/backend/exchange-rates/[id]/page.tsx +20 -180
  71. package/src/modules/currencies/backend/exchange-rates/create/page.tsx +16 -175
  72. package/src/modules/currencies/lib/exchangeRateFormConfig.ts +200 -0
  73. package/src/modules/customers/api/dashboard/widgets/utils.ts +1 -53
  74. package/src/modules/customers/commands/activities.ts +2 -8
  75. package/src/modules/customers/commands/comments.ts +2 -8
  76. package/src/modules/dashboards/i18n/de.json +3 -0
  77. package/src/modules/dashboards/i18n/en.json +3 -0
  78. package/src/modules/dashboards/i18n/es.json +3 -0
  79. package/src/modules/dashboards/i18n/pl.json +3 -0
  80. package/src/modules/dashboards/lib/widgetScope.ts +53 -0
  81. package/src/modules/entities/lib/makeActivityRoute.ts +327 -0
  82. package/src/modules/resources/api/activities.ts +25 -269
  83. package/src/modules/resources/commands/activities.ts +2 -7
  84. package/src/modules/resources/commands/comments.ts +2 -8
  85. package/src/modules/sales/api/dashboard/widgets/new-orders/route.ts +29 -244
  86. package/src/modules/sales/api/dashboard/widgets/new-quotes/route.ts +30 -245
  87. package/src/modules/sales/api/order-line-statuses/route.ts +16 -209
  88. package/src/modules/sales/api/order-lines/route.ts +16 -300
  89. package/src/modules/sales/api/order-statuses/route.ts +16 -209
  90. package/src/modules/sales/api/payment-statuses/route.ts +16 -209
  91. package/src/modules/sales/api/quote-lines/route.ts +16 -298
  92. package/src/modules/sales/api/shipment-statuses/route.ts +16 -209
  93. package/src/modules/sales/components/PaymentMethodsSettings.tsx +3 -88
  94. package/src/modules/sales/components/ProviderFieldInput.tsx +85 -0
  95. package/src/modules/sales/components/ShippingMethodsSettings.tsx +3 -86
  96. package/src/modules/sales/lib/makeSalesLineRoute.ts +345 -0
  97. package/src/modules/sales/lib/makeStatusDictionaryRoute.ts +229 -0
  98. package/src/modules/sales/widgets/dashboard/makeDashboardWidgetRoute.ts +247 -0
  99. package/src/modules/sales/widgets/dashboard/new-orders/widget.client.tsx +7 -50
  100. package/src/modules/sales/widgets/dashboard/new-quotes/widget.client.tsx +7 -49
  101. package/src/modules/sales/widgets/dashboard/shared.ts +44 -0
  102. package/src/modules/staff/api/activities.ts +25 -269
  103. package/src/modules/staff/backend/staff/leave-requests/[id]/page.tsx +15 -69
  104. package/src/modules/staff/backend/staff/my-leave-requests/[id]/page.tsx +16 -65
  105. package/src/modules/staff/commands/activities.ts +2 -7
  106. package/src/modules/staff/commands/comments.ts +2 -8
  107. package/src/modules/staff/lib/leaveRequestHelpers.ts +78 -0
@@ -3,12 +3,18 @@ import { jsx } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import { useRouter } from "next/navigation";
5
5
  import { Page, PageBody } from "@open-mercato/ui/backend/Page";
6
+ import { LoadingMessage, ErrorMessage } from "@open-mercato/ui/backend/detail";
6
7
  import { CrudForm } from "@open-mercato/ui/backend/CrudForm";
7
8
  import { updateCrud } from "@open-mercato/ui/backend/utils/crud";
8
- import { createCrudFormError } from "@open-mercato/ui/backend/utils/serverErrors";
9
9
  import { flash } from "@open-mercato/ui/backend/FlashMessages";
10
10
  import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
11
11
  import { useT } from "@open-mercato/shared/lib/i18n/context";
12
+ import {
13
+ loadCurrencyOptions,
14
+ exchangeRateGroups,
15
+ validateExchangeRateForm,
16
+ buildExchangeRatePayload
17
+ } from "../../../lib/exchangeRateFormConfig.js";
12
18
  function formatDateTimeLocal(date) {
13
19
  const year = date.getFullYear();
14
20
  const month = String(date.getMonth() + 1).padStart(2, "0");
@@ -23,28 +29,10 @@ function EditExchangeRatePage({ params }) {
23
29
  const [exchangeRate, setExchangeRate] = React.useState(null);
24
30
  const [loading, setLoading] = React.useState(true);
25
31
  const [error, setError] = React.useState(null);
26
- const loadCurrencyOptions = React.useCallback(async (query) => {
27
- try {
28
- const params2 = new URLSearchParams();
29
- if (query) {
30
- params2.set("search", query);
31
- }
32
- params2.set("isActive", "true");
33
- params2.set("pageSize", "100");
34
- const call = await apiCall(
35
- `/api/currencies/currencies?${params2.toString()}`
36
- );
37
- if (call.ok && call.result?.items) {
38
- return call.result.items.map((c) => ({
39
- value: c.code,
40
- label: c.code
41
- }));
42
- }
43
- } catch (error2) {
44
- console.error("Failed to load currencies:", error2);
45
- }
46
- return [];
47
- }, []);
32
+ const loadOptions = React.useCallback(
33
+ (query) => loadCurrencyOptions(apiCall, query),
34
+ []
35
+ );
48
36
  React.useEffect(() => {
49
37
  async function loadExchangeRate() {
50
38
  try {
@@ -63,89 +51,14 @@ function EditExchangeRatePage({ params }) {
63
51
  loadExchangeRate();
64
52
  }, [params, t]);
65
53
  const groups = React.useMemo(
66
- () => [
67
- {
68
- id: "rate-details",
69
- column: 1,
70
- fields: [
71
- {
72
- id: "fromCurrencyCode",
73
- type: "combobox",
74
- label: t("exchangeRates.form.field.fromCurrency"),
75
- placeholder: t("exchangeRates.form.field.fromCurrencyPlaceholder"),
76
- required: true,
77
- loadOptions: loadCurrencyOptions,
78
- allowCustomValues: false,
79
- description: t("exchangeRates.form.field.fromCurrencyHelp")
80
- },
81
- {
82
- id: "toCurrencyCode",
83
- type: "combobox",
84
- label: t("exchangeRates.form.field.toCurrency"),
85
- placeholder: t("exchangeRates.form.field.toCurrencyPlaceholder"),
86
- required: true,
87
- loadOptions: loadCurrencyOptions,
88
- allowCustomValues: false,
89
- description: t("exchangeRates.form.field.toCurrencyHelp")
90
- },
91
- {
92
- id: "rate",
93
- type: "number",
94
- label: t("exchangeRates.form.field.rate"),
95
- placeholder: "1.00000000",
96
- required: true,
97
- description: t("exchangeRates.form.field.rateHelp")
98
- },
99
- {
100
- id: "date",
101
- type: "datetime-local",
102
- label: t("exchangeRates.form.field.date"),
103
- required: true,
104
- description: t("exchangeRates.form.field.dateHelp")
105
- }
106
- ]
107
- },
108
- {
109
- id: "metadata",
110
- column: 2,
111
- title: t("exchangeRates.form.group.metadata"),
112
- fields: [
113
- {
114
- id: "source",
115
- type: "text",
116
- label: t("exchangeRates.form.field.source"),
117
- placeholder: t("exchangeRates.form.field.sourcePlaceholder"),
118
- required: true,
119
- description: t("exchangeRates.form.field.sourceHelp")
120
- },
121
- {
122
- id: "type",
123
- type: "select",
124
- label: t("exchangeRates.form.field.type"),
125
- placeholder: t("exchangeRates.form.field.typePlaceholder"),
126
- required: false,
127
- description: t("exchangeRates.form.field.typeHelp"),
128
- options: [
129
- { value: "", label: t("exchangeRates.form.field.typeNone") },
130
- { value: "buy", label: t("exchangeRates.form.field.typeBuy") },
131
- { value: "sell", label: t("exchangeRates.form.field.typeSell") }
132
- ]
133
- },
134
- {
135
- id: "isActive",
136
- type: "checkbox",
137
- label: t("exchangeRates.form.field.isActive")
138
- }
139
- ]
140
- }
141
- ],
142
- [t, loadCurrencyOptions]
54
+ () => exchangeRateGroups(t, loadOptions),
55
+ [t, loadOptions]
143
56
  );
144
57
  if (loading) {
145
- return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center p-8", children: /* @__PURE__ */ jsx("div", { className: "text-muted-foreground", children: t("exchangeRates.form.loading") }) }) }) });
58
+ return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(LoadingMessage, { label: t("exchangeRates.form.loading") }) }) });
146
59
  }
147
60
  if (error || !exchangeRate) {
148
- return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx("div", { className: "text-destructive", children: error || t("exchangeRates.form.errors.notFound") }) }) });
61
+ return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(ErrorMessage, { label: error || t("exchangeRates.form.errors.notFound") }) }) });
149
62
  }
150
63
  return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
151
64
  CrudForm,
@@ -167,60 +80,10 @@ function EditExchangeRatePage({ params }) {
167
80
  submitLabel: t("exchangeRates.form.action.save"),
168
81
  cancelHref: "/backend/exchange-rates",
169
82
  onSubmit: async (values) => {
170
- const fromCode = String(values.fromCurrencyCode || "").trim().toUpperCase();
171
- const toCode = String(values.toCurrencyCode || "").trim().toUpperCase();
172
- if (!/^[A-Z]{3}$/.test(fromCode)) {
173
- throw createCrudFormError(t("exchangeRates.form.errors.fromCurrencyFormat"), {
174
- fromCurrencyCode: t("exchangeRates.form.errors.currencyCodeFormat")
175
- });
176
- }
177
- if (!/^[A-Z]{3}$/.test(toCode)) {
178
- throw createCrudFormError(t("exchangeRates.form.errors.toCurrencyFormat"), {
179
- toCurrencyCode: t("exchangeRates.form.errors.currencyCodeFormat")
180
- });
181
- }
182
- if (fromCode === toCode) {
183
- throw createCrudFormError(t("exchangeRates.form.errors.sameCurrency"), {
184
- toCurrencyCode: t("exchangeRates.form.errors.sameCurrency")
185
- });
186
- }
187
- const rate = parseFloat(String(values.rate || "0"));
188
- if (isNaN(rate) || rate <= 0) {
189
- throw createCrudFormError(t("exchangeRates.form.errors.invalidRate"), {
190
- rate: t("exchangeRates.form.errors.invalidRate")
191
- });
192
- }
193
- const date = values.date ? new Date(String(values.date)) : null;
194
- if (!date || isNaN(date.getTime())) {
195
- throw createCrudFormError(t("exchangeRates.form.errors.invalidDate"), {
196
- date: t("exchangeRates.form.errors.invalidDate")
197
- });
198
- }
199
- const source = String(values.source || "").trim();
200
- if (!source || source.length < 2) {
201
- throw createCrudFormError(t("exchangeRates.form.errors.sourceTooShort"), {
202
- source: t("exchangeRates.form.errors.sourceTooShort")
203
- });
204
- }
205
- if (source.length > 50) {
206
- throw createCrudFormError(t("exchangeRates.form.errors.sourceTooLong"), {
207
- source: t("exchangeRates.form.errors.sourceTooLong")
208
- });
209
- }
210
- if (!/^[a-zA-Z0-9\s\-_]+$/.test(source)) {
211
- throw createCrudFormError(t("exchangeRates.form.errors.sourceInvalidFormat"), {
212
- source: t("exchangeRates.form.errors.sourceInvalidFormat")
213
- });
214
- }
83
+ const validated = validateExchangeRateForm(values, t);
215
84
  const payload = {
216
85
  id: exchangeRate.id,
217
- fromCurrencyCode: fromCode,
218
- toCurrencyCode: toCode,
219
- rate: rate.toFixed(8),
220
- date: date.toISOString(),
221
- source,
222
- type: values.type && values.type !== "" ? values.type : null,
223
- isActive: values.isActive !== false
86
+ ...buildExchangeRatePayload(values, validated)
224
87
  };
225
88
  await updateCrud("currencies/exchange-rates", payload);
226
89
  flash(t("exchangeRates.flash.updated"), "success");
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/currencies/backend/exchange-rates/%5Bid%5D/page.tsx"],
4
- "sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { useRouter, useParams } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm, type CrudFormGroup, type CrudFieldOption } from '@open-mercato/ui/backend/CrudForm'\nimport { updateCrud } 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 } from '@open-mercato/ui/backend/utils/apiCall'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\n\n/**\n * Formats a Date object to YYYY-MM-DDTHH:MM format in local timezone\n * for use with datetime-local input\n */\nfunction formatDateTimeLocal(date: Date): string {\n const year = date.getFullYear()\n const month = String(date.getMonth() + 1).padStart(2, '0')\n const day = String(date.getDate()).padStart(2, '0')\n const hours = String(date.getHours()).padStart(2, '0')\n const minutes = String(date.getMinutes()).padStart(2, '0')\n return `${year}-${month}-${day}T${hours}:${minutes}`\n}\n\ntype ExchangeRateData = {\n id: string\n fromCurrencyCode: string\n toCurrencyCode: string\n rate: string\n date: string\n source: string | null\n type: string | null\n isActive: boolean\n organizationId: string\n tenantId: string\n}\n\ntype CurrencyOption = {\n id: string\n code: string\n name: string\n isActive: boolean\n}\n\nexport default function EditExchangeRatePage({ params }: { params?: { id?: string } }) {\n const t = useT()\n const router = useRouter()\n\n const [exchangeRate, setExchangeRate] = React.useState<ExchangeRateData | null>(null)\n const [loading, setLoading] = React.useState(true)\n const [error, setError] = React.useState<string | null>(null)\n\n const loadCurrencyOptions = React.useCallback(async (query?: string): Promise<CrudFieldOption[]> => {\n try {\n const params = new URLSearchParams()\n if (query) {\n params.set('search', query)\n }\n params.set('isActive', 'true')\n params.set('pageSize', '100')\n\n const call = await apiCall<{ items: CurrencyOption[] }>(\n `/api/currencies/currencies?${params.toString()}`\n )\n\n if (call.ok && call.result?.items) {\n return call.result.items.map((c) => ({\n value: c.code,\n label: c.code,\n }))\n }\n } catch (error) {\n console.error('Failed to load currencies:', error)\n }\n return []\n }, [])\n\n // Load exchange rate data\n React.useEffect(() => {\n async function loadExchangeRate() {\n try {\n const response = await apiCall<{ items: ExchangeRateData[] }>(`/api/currencies/exchange-rates?id=${params?.id}`)\n if (response.ok && response.result && response.result.items.length > 0) {\n setExchangeRate(response.result.items[0])\n } else {\n setError(t('exchangeRates.form.errors.notFound'))\n }\n } catch (err) {\n setError(t('exchangeRates.form.errors.load'))\n } finally {\n setLoading(false)\n }\n }\n loadExchangeRate()\n }, [params, t])\n\n const groups = React.useMemo<CrudFormGroup[]>(\n () => [\n {\n id: 'rate-details',\n column: 1,\n fields: [\n {\n id: 'fromCurrencyCode',\n type: 'combobox',\n label: t('exchangeRates.form.field.fromCurrency'),\n placeholder: t('exchangeRates.form.field.fromCurrencyPlaceholder'),\n required: true,\n loadOptions: loadCurrencyOptions,\n allowCustomValues: false,\n description: t('exchangeRates.form.field.fromCurrencyHelp'),\n },\n {\n id: 'toCurrencyCode',\n type: 'combobox',\n label: t('exchangeRates.form.field.toCurrency'),\n placeholder: t('exchangeRates.form.field.toCurrencyPlaceholder'),\n required: true,\n loadOptions: loadCurrencyOptions,\n allowCustomValues: false,\n description: t('exchangeRates.form.field.toCurrencyHelp'),\n },\n {\n id: 'rate',\n type: 'number',\n label: t('exchangeRates.form.field.rate'),\n placeholder: '1.00000000',\n required: true,\n description: t('exchangeRates.form.field.rateHelp'),\n },\n {\n id: 'date',\n type: 'datetime-local',\n label: t('exchangeRates.form.field.date'),\n required: true,\n description: t('exchangeRates.form.field.dateHelp'),\n },\n ],\n },\n {\n id: 'metadata',\n column: 2,\n title: t('exchangeRates.form.group.metadata'),\n fields: [\n {\n id: 'source',\n type: 'text',\n label: t('exchangeRates.form.field.source'),\n placeholder: t('exchangeRates.form.field.sourcePlaceholder'),\n required: true,\n description: t('exchangeRates.form.field.sourceHelp'),\n },\n {\n id: 'type',\n type: 'select',\n label: t('exchangeRates.form.field.type'),\n placeholder: t('exchangeRates.form.field.typePlaceholder'),\n required: false,\n description: t('exchangeRates.form.field.typeHelp'),\n options: [\n { value: '', label: t('exchangeRates.form.field.typeNone') },\n { value: 'buy', label: t('exchangeRates.form.field.typeBuy') },\n { value: 'sell', label: t('exchangeRates.form.field.typeSell') },\n ],\n },\n {\n id: 'isActive',\n type: 'checkbox',\n label: t('exchangeRates.form.field.isActive'),\n },\n ],\n },\n ],\n [t, loadCurrencyOptions]\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('exchangeRates.form.loading')}</div>\n </div>\n </PageBody>\n </Page>\n )\n }\n\n if (error || !exchangeRate) {\n return (\n <Page>\n <PageBody>\n <div className=\"text-destructive\">{error || t('exchangeRates.form.errors.notFound')}</div>\n </PageBody>\n </Page>\n )\n }\n\n return (\n <Page>\n <PageBody>\n <CrudForm\n title={t('exchangeRates.edit.title')}\n backHref=\"/backend/exchange-rates\"\n versionHistory={{ resourceKind: 'currencies.exchange_rate', resourceId: exchangeRate.id }}\n fields={[]}\n groups={groups}\n initialValues={{\n fromCurrencyCode: exchangeRate.fromCurrencyCode,\n toCurrencyCode: exchangeRate.toCurrencyCode,\n rate: parseFloat(exchangeRate.rate),\n date: formatDateTimeLocal(new Date(exchangeRate.date)),\n source: exchangeRate.source || '',\n type: exchangeRate.type || '',\n isActive: exchangeRate.isActive,\n }}\n submitLabel={t('exchangeRates.form.action.save')}\n cancelHref=\"/backend/exchange-rates\"\n onSubmit={async (values) => {\n // Validate currency codes\n const fromCode = String(values.fromCurrencyCode || '').trim().toUpperCase()\n const toCode = String(values.toCurrencyCode || '').trim().toUpperCase()\n\n if (!/^[A-Z]{3}$/.test(fromCode)) {\n throw createCrudFormError(t('exchangeRates.form.errors.fromCurrencyFormat'), {\n fromCurrencyCode: t('exchangeRates.form.errors.currencyCodeFormat'),\n })\n }\n\n if (!/^[A-Z]{3}$/.test(toCode)) {\n throw createCrudFormError(t('exchangeRates.form.errors.toCurrencyFormat'), {\n toCurrencyCode: t('exchangeRates.form.errors.currencyCodeFormat'),\n })\n }\n\n if (fromCode === toCode) {\n throw createCrudFormError(t('exchangeRates.form.errors.sameCurrency'), {\n toCurrencyCode: t('exchangeRates.form.errors.sameCurrency'),\n })\n }\n\n // Validate rate\n const rate = parseFloat(String(values.rate || '0'))\n if (isNaN(rate) || rate <= 0) {\n throw createCrudFormError(t('exchangeRates.form.errors.invalidRate'), {\n rate: t('exchangeRates.form.errors.invalidRate'),\n })\n }\n\n // Validate date\n const date = values.date ? new Date(String(values.date)) : null\n\n if (!date || isNaN(date.getTime())) {\n throw createCrudFormError(t('exchangeRates.form.errors.invalidDate'), {\n date: t('exchangeRates.form.errors.invalidDate'),\n })\n }\n\n // Validate source\n const source = String(values.source || '').trim()\n if (!source || source.length < 2) {\n throw createCrudFormError(t('exchangeRates.form.errors.sourceTooShort'), {\n source: t('exchangeRates.form.errors.sourceTooShort'),\n })\n }\n if (source.length > 50) {\n throw createCrudFormError(t('exchangeRates.form.errors.sourceTooLong'), {\n source: t('exchangeRates.form.errors.sourceTooLong'),\n })\n }\n if (!/^[a-zA-Z0-9\\s\\-_]+$/.test(source)) {\n throw createCrudFormError(t('exchangeRates.form.errors.sourceInvalidFormat'), {\n source: t('exchangeRates.form.errors.sourceInvalidFormat'),\n })\n }\n\n const payload = {\n id: exchangeRate.id,\n fromCurrencyCode: fromCode,\n toCurrencyCode: toCode,\n rate: rate.toFixed(8),\n date: date.toISOString(),\n source,\n type: values.type && values.type !== '' ? values.type : null,\n isActive: values.isActive !== false,\n }\n\n await updateCrud('currencies/exchange-rates', payload)\n\n flash(t('exchangeRates.flash.updated'), 'success')\n router.push('/backend/exchange-rates')\n }}\n />\n </PageBody>\n </Page>\n )\n}\n"],
5
- "mappings": ";AAsLY;AApLZ,YAAY,WAAW;AACvB,SAAS,iBAA4B;AACrC,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAA0D;AACnE,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,YAAY;AAMrB,SAAS,oBAAoB,MAAoB;AAC/C,QAAM,OAAO,KAAK,YAAY;AAC9B,QAAM,QAAQ,OAAO,KAAK,SAAS,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG;AACzD,QAAM,MAAM,OAAO,KAAK,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG;AAClD,QAAM,QAAQ,OAAO,KAAK,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,GAAG;AAAA,YACpE,MAAM,EAAE,uCAAuC;AAAA,UACjD,CAAC;AAAA,QACH;AAGA,cAAM,SAAS,OAAO,OAAO,UAAU,EAAE,EAAE,KAAK;AAChD,YAAI,CAAC,UAAU,OAAO,SAAS,GAAG;AAChC,gBAAM,oBAAoB,EAAE,0CAA0C,GAAG;AAAA,YACvE,QAAQ,EAAE,0CAA0C;AAAA,UACtD,CAAC;AAAA,QACH;AACA,YAAI,OAAO,SAAS,IAAI;AACtB,gBAAM,oBAAoB,EAAE,yCAAyC,GAAG;AAAA,YACtE,QAAQ,EAAE,yCAAyC;AAAA,UACrD,CAAC;AAAA,QACH;AACA,YAAI,CAAC,sBAAsB,KAAK,MAAM,GAAG;AACvC,gBAAM,oBAAoB,EAAE,+CAA+C,GAAG;AAAA,YAC5E,QAAQ,EAAE,+CAA+C;AAAA,UAC3D,CAAC;AAAA,QACH;AAEA,cAAM,UAAU;AAAA,UACd,IAAI,aAAa;AAAA,UACjB,kBAAkB;AAAA,UAClB,gBAAgB;AAAA,UAChB,MAAM,KAAK,QAAQ,CAAC;AAAA,UACpB,MAAM,KAAK,YAAY;AAAA,UACvB;AAAA,UACA,MAAM,OAAO,QAAQ,OAAO,SAAS,KAAK,OAAO,OAAO;AAAA,UACxD,UAAU,OAAO,aAAa;AAAA,QAChC;AAEA,cAAM,WAAW,6BAA6B,OAAO;AAErD,cAAM,EAAE,6BAA6B,GAAG,SAAS;AACjD,eAAO,KAAK,yBAAyB;AAAA,MACvC;AAAA;AAAA,EACF,GACF,GACF;AAEJ;",
6
- "names": ["params", "error"]
4
+ "sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { useRouter } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'\nimport { CrudForm } from '@open-mercato/ui/backend/CrudForm'\nimport { updateCrud } from '@open-mercato/ui/backend/utils/crud'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport {\n loadCurrencyOptions,\n exchangeRateGroups,\n validateExchangeRateForm,\n buildExchangeRatePayload,\n} from '../../../lib/exchangeRateFormConfig'\n\n/**\n * Formats a Date object to YYYY-MM-DDTHH:MM format in local timezone\n * for use with datetime-local input\n */\nfunction formatDateTimeLocal(date: Date): string {\n const year = date.getFullYear()\n const month = String(date.getMonth() + 1).padStart(2, '0')\n const day = String(date.getDate()).padStart(2, '0')\n const hours = String(date.getHours()).padStart(2, '0')\n const minutes = String(date.getMinutes()).padStart(2, '0')\n return `${year}-${month}-${day}T${hours}:${minutes}`\n}\n\ntype ExchangeRateData = {\n id: string\n fromCurrencyCode: string\n toCurrencyCode: string\n rate: string\n date: string\n source: string | null\n type: string | null\n isActive: boolean\n organizationId: string\n tenantId: string\n}\n\nexport default function EditExchangeRatePage({ params }: { params?: { id?: string } }) {\n const t = useT()\n const router = useRouter()\n\n const [exchangeRate, setExchangeRate] = React.useState<ExchangeRateData | null>(null)\n const [loading, setLoading] = React.useState(true)\n const [error, setError] = React.useState<string | null>(null)\n\n const loadOptions = React.useCallback(\n (query?: string) => loadCurrencyOptions(apiCall, query),\n []\n )\n\n // Load exchange rate data\n React.useEffect(() => {\n async function loadExchangeRate() {\n try {\n const response = await apiCall<{ items: ExchangeRateData[] }>(`/api/currencies/exchange-rates?id=${params?.id}`)\n if (response.ok && response.result && response.result.items.length > 0) {\n setExchangeRate(response.result.items[0])\n } else {\n setError(t('exchangeRates.form.errors.notFound'))\n }\n } catch (err) {\n setError(t('exchangeRates.form.errors.load'))\n } finally {\n setLoading(false)\n }\n }\n loadExchangeRate()\n }, [params, t])\n\n const groups = React.useMemo(\n () => exchangeRateGroups(t, loadOptions),\n [t, loadOptions]\n )\n\n if (loading) {\n return (\n <Page>\n <PageBody>\n <LoadingMessage label={t('exchangeRates.form.loading')} />\n </PageBody>\n </Page>\n )\n }\n\n if (error || !exchangeRate) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage label={error || t('exchangeRates.form.errors.notFound')} />\n </PageBody>\n </Page>\n )\n }\n\n return (\n <Page>\n <PageBody>\n <CrudForm\n title={t('exchangeRates.edit.title')}\n backHref=\"/backend/exchange-rates\"\n versionHistory={{ resourceKind: 'currencies.exchange_rate', resourceId: exchangeRate.id }}\n fields={[]}\n groups={groups}\n initialValues={{\n fromCurrencyCode: exchangeRate.fromCurrencyCode,\n toCurrencyCode: exchangeRate.toCurrencyCode,\n rate: parseFloat(exchangeRate.rate),\n date: formatDateTimeLocal(new Date(exchangeRate.date)),\n source: exchangeRate.source || '',\n type: exchangeRate.type || '',\n isActive: exchangeRate.isActive,\n }}\n submitLabel={t('exchangeRates.form.action.save')}\n cancelHref=\"/backend/exchange-rates\"\n onSubmit={async (values) => {\n const validated = validateExchangeRateForm(values, t)\n const payload = {\n id: exchangeRate.id,\n ...buildExchangeRatePayload(values, validated),\n }\n\n await updateCrud('currencies/exchange-rates', payload)\n\n flash(t('exchangeRates.flash.updated'), 'success')\n router.push('/backend/exchange-rates')\n }}\n />\n </PageBody>\n </Page>\n )\n}\n"],
5
+ "mappings": ";AAqFU;AAnFV,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAC1B,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP,SAAS,oBAAoB,MAAoB;AAC/C,QAAM,OAAO,KAAK,YAAY;AAC9B,QAAM,QAAQ,OAAO,KAAK,SAAS,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG;AACzD,QAAM,MAAM,OAAO,KAAK,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG;AAClD,QAAM,QAAQ,OAA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A,MAAI,SAAS,CAAC,cAAc;AAC1B,WACE,oBAAC,QACC,8BAAC,YACC,8BAAC,gBAAa,OAAO,SAAS,EAAE,oCAAoC,GAAG,GACzE,GACF;AAAA,EAEJ;AAEA,SACE,oBAAC,QACC,8BAAC,YACC;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,EAAE,0BAA0B;AAAA,MACnC,UAAS;AAAA,MACT,gBAAgB,EAAE,cAAc,4BAA4B,YAAY,aAAa,GAAG;AAAA,MACxF,QAAQ,CAAC;AAAA,MACT;AAAA,MACA,eAAe;AAAA,QACb,kBAAkB,aAAa;AAAA,QAC/B,gBAAgB,aAAa;AAAA,QAC7B,MAAM,WAAW,aAAa,IAAI;AAAA,QAClC,MAAM,oBAAoB,IAAI,KAAK,aAAa,IAAI,CAAC;AAAA,QACrD,QAAQ,aAAa,UAAU;AAAA,QAC/B,MAAM,aAAa,QAAQ;AAAA,QAC3B,UAAU,aAAa;AAAA,MACzB;AAAA,MACA,aAAa,EAAE,gCAAgC;AAAA,MAC/C,YAAW;AAAA,MACX,UAAU,OAAO,WAAW;AAC1B,cAAM,YAAY,yBAAyB,QAAQ,CAAC;AACpD,cAAM,UAAU;AAAA,UACd,IAAI,aAAa;AAAA,UACjB,GAAG,yBAAyB,QAAQ,SAAS;AAAA,QAC/C;AAEA,cAAM,WAAW,6BAA6B,OAAO;AAErD,cAAM,EAAE,6BAA6B,GAAG,SAAS;AACjD,eAAO,KAAK,yBAAyB;AAAA,MACvC;AAAA;AAAA,EACF,GACF,GACF;AAEJ;",
6
+ "names": []
7
7
  }
@@ -5,115 +5,27 @@ import { useRouter } from "next/navigation";
5
5
  import { Page, PageBody } from "@open-mercato/ui/backend/Page";
6
6
  import { CrudForm } from "@open-mercato/ui/backend/CrudForm";
7
7
  import { createCrud } from "@open-mercato/ui/backend/utils/crud";
8
- import { createCrudFormError } from "@open-mercato/ui/backend/utils/serverErrors";
9
8
  import { flash } from "@open-mercato/ui/backend/FlashMessages";
10
9
  import { useT } from "@open-mercato/shared/lib/i18n/context";
11
10
  import { useOrganizationScopeDetail } from "@open-mercato/shared/lib/frontend/useOrganizationScope";
12
11
  import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
12
+ import {
13
+ loadCurrencyOptions,
14
+ exchangeRateGroups,
15
+ validateExchangeRateForm,
16
+ buildExchangeRatePayload
17
+ } from "../../../lib/exchangeRateFormConfig.js";
13
18
  function CreateExchangeRatePage() {
14
19
  const t = useT();
15
20
  const router = useRouter();
16
21
  const { organizationId, tenantId } = useOrganizationScopeDetail();
17
- const loadCurrencyOptions = React.useCallback(async (query) => {
18
- try {
19
- const params = new URLSearchParams();
20
- if (query) {
21
- params.set("search", query);
22
- }
23
- params.set("isActive", "true");
24
- params.set("pageSize", "100");
25
- const call = await apiCall(
26
- `/api/currencies/currencies?${params.toString()}`
27
- );
28
- if (call.ok && call.result?.items) {
29
- return call.result.items.map((c) => ({
30
- value: c.code,
31
- label: c.code
32
- }));
33
- }
34
- } catch (error) {
35
- console.error("Failed to load currencies:", error);
36
- }
37
- return [];
38
- }, []);
22
+ const loadOptions = React.useCallback(
23
+ (query) => loadCurrencyOptions(apiCall, query),
24
+ []
25
+ );
39
26
  const groups = React.useMemo(
40
- () => [
41
- {
42
- id: "rate-details",
43
- column: 1,
44
- fields: [
45
- {
46
- id: "fromCurrencyCode",
47
- type: "combobox",
48
- label: t("exchangeRates.form.field.fromCurrency"),
49
- placeholder: t("exchangeRates.form.field.fromCurrencyPlaceholder"),
50
- required: true,
51
- loadOptions: loadCurrencyOptions,
52
- allowCustomValues: false,
53
- description: t("exchangeRates.form.field.fromCurrencyHelp")
54
- },
55
- {
56
- id: "toCurrencyCode",
57
- type: "combobox",
58
- label: t("exchangeRates.form.field.toCurrency"),
59
- placeholder: t("exchangeRates.form.field.toCurrencyPlaceholder"),
60
- required: true,
61
- loadOptions: loadCurrencyOptions,
62
- allowCustomValues: false,
63
- description: t("exchangeRates.form.field.toCurrencyHelp")
64
- },
65
- {
66
- id: "rate",
67
- type: "number",
68
- label: t("exchangeRates.form.field.rate"),
69
- placeholder: "1.00000000",
70
- required: true,
71
- description: t("exchangeRates.form.field.rateHelp")
72
- },
73
- {
74
- id: "date",
75
- type: "datetime-local",
76
- label: t("exchangeRates.form.field.date"),
77
- required: true,
78
- description: t("exchangeRates.form.field.dateHelp")
79
- }
80
- ]
81
- },
82
- {
83
- id: "metadata",
84
- column: 2,
85
- title: t("exchangeRates.form.group.metadata"),
86
- fields: [
87
- {
88
- id: "source",
89
- type: "text",
90
- label: t("exchangeRates.form.field.source"),
91
- placeholder: t("exchangeRates.form.field.sourcePlaceholder"),
92
- required: true,
93
- description: t("exchangeRates.form.field.sourceHelp")
94
- },
95
- {
96
- id: "type",
97
- type: "select",
98
- label: t("exchangeRates.form.field.type"),
99
- placeholder: t("exchangeRates.form.field.typePlaceholder"),
100
- required: false,
101
- description: t("exchangeRates.form.field.typeHelp"),
102
- options: [
103
- { value: "", label: t("exchangeRates.form.field.typeNone") },
104
- { value: "buy", label: t("exchangeRates.form.field.typeBuy") },
105
- { value: "sell", label: t("exchangeRates.form.field.typeSell") }
106
- ]
107
- },
108
- {
109
- id: "isActive",
110
- type: "checkbox",
111
- label: t("exchangeRates.form.field.isActive")
112
- }
113
- ]
114
- }
115
- ],
116
- [t, loadCurrencyOptions]
27
+ () => exchangeRateGroups(t, loadOptions),
28
+ [t, loadOptions]
117
29
  );
118
30
  return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
119
31
  CrudForm,
@@ -125,61 +37,11 @@ function CreateExchangeRatePage() {
125
37
  submitLabel: t("exchangeRates.form.action.create"),
126
38
  cancelHref: "/backend/exchange-rates",
127
39
  onSubmit: async (values) => {
128
- const fromCode = String(values.fromCurrencyCode || "").trim().toUpperCase();
129
- const toCode = String(values.toCurrencyCode || "").trim().toUpperCase();
130
- if (!/^[A-Z]{3}$/.test(fromCode)) {
131
- throw createCrudFormError(t("exchangeRates.form.errors.fromCurrencyFormat"), {
132
- fromCurrencyCode: t("exchangeRates.form.errors.currencyCodeFormat")
133
- });
134
- }
135
- if (!/^[A-Z]{3}$/.test(toCode)) {
136
- throw createCrudFormError(t("exchangeRates.form.errors.toCurrencyFormat"), {
137
- toCurrencyCode: t("exchangeRates.form.errors.currencyCodeFormat")
138
- });
139
- }
140
- if (fromCode === toCode) {
141
- throw createCrudFormError(t("exchangeRates.form.errors.sameCurrency"), {
142
- toCurrencyCode: t("exchangeRates.form.errors.sameCurrency")
143
- });
144
- }
145
- const rate = parseFloat(String(values.rate || "0"));
146
- if (isNaN(rate) || rate <= 0) {
147
- throw createCrudFormError(t("exchangeRates.form.errors.invalidRate"), {
148
- rate: t("exchangeRates.form.errors.invalidRate")
149
- });
150
- }
151
- const date = values.date ? new Date(String(values.date)) : null;
152
- if (!date || isNaN(date.getTime())) {
153
- throw createCrudFormError(t("exchangeRates.form.errors.invalidDate"), {
154
- date: t("exchangeRates.form.errors.invalidDate")
155
- });
156
- }
157
- const source = String(values.source || "").trim();
158
- if (!source || source.length < 2) {
159
- throw createCrudFormError(t("exchangeRates.form.errors.sourceTooShort"), {
160
- source: t("exchangeRates.form.errors.sourceTooShort")
161
- });
162
- }
163
- if (source.length > 50) {
164
- throw createCrudFormError(t("exchangeRates.form.errors.sourceTooLong"), {
165
- source: t("exchangeRates.form.errors.sourceTooLong")
166
- });
167
- }
168
- if (!/^[a-zA-Z0-9\s\-_]+$/.test(source)) {
169
- throw createCrudFormError(t("exchangeRates.form.errors.sourceInvalidFormat"), {
170
- source: t("exchangeRates.form.errors.sourceInvalidFormat")
171
- });
172
- }
40
+ const validated = validateExchangeRateForm(values, t);
173
41
  const payload = {
174
42
  organizationId,
175
43
  tenantId,
176
- fromCurrencyCode: fromCode,
177
- toCurrencyCode: toCode,
178
- rate: rate.toFixed(8),
179
- date: date.toISOString(),
180
- source,
181
- type: values.type && values.type !== "" ? values.type : null,
182
- isActive: values.isActive !== false
44
+ ...buildExchangeRatePayload(values, validated)
183
45
  };
184
46
  await createCrud("currencies/exchange-rates", payload);
185
47
  flash(t("exchangeRates.flash.created"), "success");
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/currencies/backend/exchange-rates/create/page.tsx"],
4
- "sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { useRouter } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm, type CrudFormGroup, type CrudFieldOption } 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 { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\n\ntype CurrencyOption = {\n id: string\n code: string\n name: string\n isActive: boolean\n}\n\nexport default function CreateExchangeRatePage() {\n const t = useT()\n const router = useRouter()\n const { organizationId, tenantId } = useOrganizationScopeDetail()\n\n const loadCurrencyOptions = React.useCallback(async (query?: string): Promise<CrudFieldOption[]> => {\n try {\n const params = new URLSearchParams()\n if (query) {\n params.set('search', query)\n }\n params.set('isActive', 'true')\n params.set('pageSize', '100')\n\n const call = await apiCall<{ items: CurrencyOption[] }>(\n `/api/currencies/currencies?${params.toString()}`\n )\n\n if (call.ok && call.result?.items) {\n return call.result.items.map((c) => ({\n value: c.code,\n label: c.code,\n }))\n }\n } catch (error) {\n console.error('Failed to load currencies:', error)\n }\n return []\n }, [])\n\n const groups = React.useMemo<CrudFormGroup[]>(\n () => [\n {\n id: 'rate-details',\n column: 1,\n fields: [\n {\n id: 'fromCurrencyCode',\n type: 'combobox',\n label: t('exchangeRates.form.field.fromCurrency'),\n placeholder: t('exchangeRates.form.field.fromCurrencyPlaceholder'),\n required: true,\n loadOptions: loadCurrencyOptions,\n allowCustomValues: false,\n description: t('exchangeRates.form.field.fromCurrencyHelp'),\n },\n {\n id: 'toCurrencyCode',\n type: 'combobox',\n label: t('exchangeRates.form.field.toCurrency'),\n placeholder: t('exchangeRates.form.field.toCurrencyPlaceholder'),\n required: true,\n loadOptions: loadCurrencyOptions,\n allowCustomValues: false,\n description: t('exchangeRates.form.field.toCurrencyHelp'),\n },\n {\n id: 'rate',\n type: 'number',\n label: t('exchangeRates.form.field.rate'),\n placeholder: '1.00000000',\n required: true,\n description: t('exchangeRates.form.field.rateHelp'),\n },\n {\n id: 'date',\n type: 'datetime-local',\n label: t('exchangeRates.form.field.date'),\n required: true,\n description: t('exchangeRates.form.field.dateHelp'),\n },\n ],\n },\n {\n id: 'metadata',\n column: 2,\n title: t('exchangeRates.form.group.metadata'),\n fields: [\n {\n id: 'source',\n type: 'text',\n label: t('exchangeRates.form.field.source'),\n placeholder: t('exchangeRates.form.field.sourcePlaceholder'),\n required: true,\n description: t('exchangeRates.form.field.sourceHelp'),\n },\n {\n id: 'type',\n type: 'select',\n label: t('exchangeRates.form.field.type'),\n placeholder: t('exchangeRates.form.field.typePlaceholder'),\n required: false,\n description: t('exchangeRates.form.field.typeHelp'),\n options: [\n { value: '', label: t('exchangeRates.form.field.typeNone') },\n { value: 'buy', label: t('exchangeRates.form.field.typeBuy') },\n { value: 'sell', label: t('exchangeRates.form.field.typeSell') },\n ],\n },\n {\n id: 'isActive',\n type: 'checkbox',\n label: t('exchangeRates.form.field.isActive'),\n },\n ],\n },\n ],\n [t, loadCurrencyOptions]\n )\n\n return (\n <Page>\n <PageBody>\n <CrudForm\n title={t('exchangeRates.create.title')}\n backHref=\"/backend/exchange-rates\"\n fields={[]}\n groups={groups}\n submitLabel={t('exchangeRates.form.action.create')}\n cancelHref=\"/backend/exchange-rates\"\n onSubmit={async (values) => {\n // Validate currency codes\n const fromCode = String(values.fromCurrencyCode || '').trim().toUpperCase()\n const toCode = String(values.toCurrencyCode || '').trim().toUpperCase()\n\n if (!/^[A-Z]{3}$/.test(fromCode)) {\n throw createCrudFormError(t('exchangeRates.form.errors.fromCurrencyFormat'), {\n fromCurrencyCode: t('exchangeRates.form.errors.currencyCodeFormat'),\n })\n }\n\n if (!/^[A-Z]{3}$/.test(toCode)) {\n throw createCrudFormError(t('exchangeRates.form.errors.toCurrencyFormat'), {\n toCurrencyCode: t('exchangeRates.form.errors.currencyCodeFormat'),\n })\n }\n\n if (fromCode === toCode) {\n throw createCrudFormError(t('exchangeRates.form.errors.sameCurrency'), {\n toCurrencyCode: t('exchangeRates.form.errors.sameCurrency'),\n })\n }\n\n // Validate rate\n const rate = parseFloat(String(values.rate || '0'))\n if (isNaN(rate) || rate <= 0) {\n throw createCrudFormError(t('exchangeRates.form.errors.invalidRate'), {\n rate: t('exchangeRates.form.errors.invalidRate'),\n })\n }\n\n // Validate date\n const date = values.date ? new Date(String(values.date)) : null\n\n if (!date || isNaN(date.getTime())) {\n throw createCrudFormError(t('exchangeRates.form.errors.invalidDate'), {\n date: t('exchangeRates.form.errors.invalidDate'),\n })\n }\n\n // Validate source\n const source = String(values.source || '').trim()\n if (!source || source.length < 2) {\n throw createCrudFormError(t('exchangeRates.form.errors.sourceTooShort'), {\n source: t('exchangeRates.form.errors.sourceTooShort'),\n })\n }\n if (source.length > 50) {\n throw createCrudFormError(t('exchangeRates.form.errors.sourceTooLong'), {\n source: t('exchangeRates.form.errors.sourceTooLong'),\n })\n }\n if (!/^[a-zA-Z0-9\\s\\-_]+$/.test(source)) {\n throw createCrudFormError(t('exchangeRates.form.errors.sourceInvalidFormat'), {\n source: t('exchangeRates.form.errors.sourceInvalidFormat'),\n })\n }\n\n const payload = {\n organizationId,\n tenantId,\n fromCurrencyCode: fromCode,\n toCurrencyCode: toCode,\n rate: rate.toFixed(8),\n date: date.toISOString(),\n source,\n type: values.type && values.type !== '' ? values.type : null,\n isActive: values.isActive !== false,\n }\n\n await createCrud('currencies/exchange-rates', payload)\n\n flash(t('exchange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AAI;AAE3D,YAAI,CAAC,QAAQ,MAAM,KAAK,QAAQ,CAAC,GAAG;AAClC,gBAAM,oBAAoB,EAAE,uCAAuC,GAAG;AAAA,YACpE,MAAM,EAAE,uCAAuC;AAAA,UACjD,CAAC;AAAA,QACH;AAGA,cAAM,SAAS,OAAO,OAAO,UAAU,EAAE,EAAE,KAAK;AAChD,YAAI,CAAC,UAAU,OAAO,SAAS,GAAG;AAChC,gBAAM,oBAAoB,EAAE,0CAA0C,GAAG;AAAA,YACvE,QAAQ,EAAE,0CAA0C;AAAA,UACtD,CAAC;AAAA,QACH;AACA,YAAI,OAAO,SAAS,IAAI;AACtB,gBAAM,oBAAoB,EAAE,yCAAyC,GAAG;AAAA,YACtE,QAAQ,EAAE,yCAAyC;AAAA,UACrD,CAAC;AAAA,QACH;AACA,YAAI,CAAC,sBAAsB,KAAK,MAAM,GAAG;AACvC,gBAAM,oBAAoB,EAAE,+CAA+C,GAAG;AAAA,YAC5E,QAAQ,EAAE,+CAA+C;AAAA,UAC3D,CAAC;AAAA,QACH;AAEA,cAAM,UAAU;AAAA,UACd;AAAA,UACA;AAAA,UACA,kBAAkB;AAAA,UAClB,gBAAgB;AAAA,UAChB,MAAM,KAAK,QAAQ,CAAC;AAAA,UACpB,MAAM,KAAK,YAAY;AAAA,UACvB;AAAA,UACA,MAAM,OAAO,QAAQ,OAAO,SAAS,KAAK,OAAO,OAAO;AAAA,UACxD,UAAU,OAAO,aAAa;AAAA,QAChC;AAEA,cAAM,WAAW,6BAA6B,OAAO;AAErD,cAAM,EAAE,6BAA6B,GAAG,SAAS;AACjD,eAAO,KAAK,yBAAyB;AAAA,MACvC;AAAA;AAAA,EACF,GACF,GACF;AAEJ;",
4
+ "sourcesContent": ["'use client'\n\nimport * as React from 'react'\nimport { useRouter } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm } from '@open-mercato/ui/backend/CrudForm'\nimport { createCrud } from '@open-mercato/ui/backend/utils/crud'\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 { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport {\n loadCurrencyOptions,\n exchangeRateGroups,\n validateExchangeRateForm,\n buildExchangeRatePayload,\n} from '../../../lib/exchangeRateFormConfig'\n\nexport default function CreateExchangeRatePage() {\n const t = useT()\n const router = useRouter()\n const { organizationId, tenantId } = useOrganizationScopeDetail()\n\n const loadOptions = React.useCallback(\n (query?: string) => loadCurrencyOptions(apiCall, query),\n []\n )\n\n const groups = React.useMemo(\n () => exchangeRateGroups(t, loadOptions),\n [t, loadOptions]\n )\n\n return (\n <Page>\n <PageBody>\n <CrudForm\n title={t('exchangeRates.create.title')}\n backHref=\"/backend/exchange-rates\"\n fields={[]}\n groups={groups}\n submitLabel={t('exchangeRates.form.action.create')}\n cancelHref=\"/backend/exchange-rates\"\n onSubmit={async (values) => {\n const validated = validateExchangeRateForm(values, t)\n const payload = {\n organizationId,\n tenantId,\n ...buildExchangeRatePayload(values, validated),\n }\n\n await createCrud('currencies/exchange-rates', payload)\n\n flash(t('exchangeRates.flash.created'), 'success')\n router.push('/backend/exchange-rates')\n }}\n />\n </PageBody>\n </Page>\n )\n}\n"],
5
+ "mappings": ";AAoCQ;AAlCR,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAC1B,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,YAAY;AACrB,SAAS,kCAAkC;AAC3C,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEQ,SAAR,yBAA0C;AAC/C,QAAM,IAAI,KAAK;AACf,QAAM,SAAS,UAAU;AACzB,QAAM,EAAE,gBAAgB,SAAS,IAAI,2BAA2B;AAEhE,QAAM,cAAc,MAAM;AAAA,IACxB,CAAC,UAAmB,oBAAoB,SAAS,KAAK;AAAA,IACtD,CAAC;AAAA,EACH;AAEA,QAAM,SAAS,MAAM;AAAA,IACnB,MAAM,mBAAmB,GAAG,WAAW;AAAA,IACvC,CAAC,GAAG,WAAW;AAAA,EACjB;AAEA,SACE,oBAAC,QACC,8BAAC,YACC;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,EAAE,4BAA4B;AAAA,MACrC,UAAS;AAAA,MACT,QAAQ,CAAC;AAAA,MACT;AAAA,MACA,aAAa,EAAE,kCAAkC;AAAA,MACjD,YAAW;AAAA,MACX,UAAU,OAAO,WAAW;AAC1B,cAAM,YAAY,yBAAyB,QAAQ,CAAC;AACpD,cAAM,UAAU;AAAA,UACd;AAAA,UACA;AAAA,UACA,GAAG,yBAAyB,QAAQ,SAAS;AAAA,QAC/C;AAEA,cAAM,WAAW,6BAA6B,OAAO;AAErD,cAAM,EAAE,6BAA6B,GAAG,SAAS;AACjD,eAAO,KAAK,yBAAyB;AAAA,MACvC;AAAA;AAAA,EACF,GACF,GACF;AAEJ;",
6
6
  "names": []
7
7
  }