@micromerce/formbuilder-react 1.0.1015 → 1.0.1016

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/dist/index.d.ts CHANGED
@@ -18,11 +18,13 @@ import { queryControl } from "./components/QueryControl/data/defaultControls";
18
18
  import { FormBuilderConfig } from "./types";
19
19
  import { compactVatId, vatIdProblem } from "./components/controls/SubtypeInput/vatId";
20
20
  import type { VatIdProblem } from "./components/controls/SubtypeInput/vatId";
21
+ import { DUE_SOON_DAYS, PAYMENT_PILLS, PAYMENT_TONES, formatAmount, formatPaymentDate, parseAmount, paymentFieldsOf, paymentLines, paymentState, paymentTotal, transactionRefsOf } from "./utils/payment";
22
+ import type { IPaymentValues, PaymentRole, PaymentState, PaymentTone } from "./utils/payment";
21
23
  import { getCountries, parsePhoneNumber } from "react-phone-number-input/max";
22
24
  import PHONE_FLAGS from "react-phone-number-input/flags";
23
25
  import { SOCIAL_NETWORKS, handleOf, isValidSocialLink, networkOf } from "./utils/subtypes/socialNetworks";
24
26
  import { FormBuilderThemeProvider, FORM_BUILDER_TOKENS, LEGACY_CSS_VARS, toCssVars } from "./theme";
25
27
  import type { FormBuilderTheme, FormBuilderThemeKey, FormBuilderThemePreset } from "./theme";
26
- export type { FormBuilderTheme, FormBuilderThemeKey, FormBuilderThemePreset, VatIdProblem };
27
- export { FormBuilderThemeProvider, FORM_BUILDER_TOKENS, LEGACY_CSS_VARS, toCssVars, FormBuilder, FormBuilderConfig, queryControl, Select, MultiSelect, Checkbox, ControlWrapper, FormFooter, Input, InputFreeSolo, FormList, FormGroup, MrnInput, PasswordInput, Textarea, TrafficLightCardSelect, useValueGenerator, compactVatId, vatIdProblem, SOCIAL_NETWORKS, isValidSocialLink, networkOf, handleOf, parsePhoneNumber, getCountries, PHONE_FLAGS, };
28
+ export type { FormBuilderTheme, FormBuilderThemeKey, FormBuilderThemePreset, VatIdProblem, IPaymentValues, PaymentRole, PaymentState, PaymentTone, };
29
+ export { FormBuilderThemeProvider, FORM_BUILDER_TOKENS, LEGACY_CSS_VARS, toCssVars, FormBuilder, FormBuilderConfig, queryControl, Select, MultiSelect, Checkbox, ControlWrapper, FormFooter, Input, InputFreeSolo, FormList, FormGroup, MrnInput, PasswordInput, Textarea, TrafficLightCardSelect, useValueGenerator, compactVatId, vatIdProblem, SOCIAL_NETWORKS, isValidSocialLink, networkOf, handleOf, parsePhoneNumber, getCountries, PHONE_FLAGS, DUE_SOON_DAYS, PAYMENT_PILLS, PAYMENT_TONES, formatAmount, formatPaymentDate, parseAmount, paymentFieldsOf, paymentLines, paymentState, paymentTotal, transactionRefsOf, };
28
30
  export default FormBuilder;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The payment type (COP-4613): the rules of an invoice's payment state, shared by the form (PaymentGroup's
3
+ * live pill and hint) and service-entity's detail view (exported from the package), so the two never
4
+ * judge a payment differently. Nothing here writes a value; it only reads what the invoice holds.
5
+ */
6
+ export declare const PAYMENT_ROLES: readonly ["due", "paidOn", "method", "transactions", "amount"];
7
+ export type PaymentRole = (typeof PAYMENT_ROLES)[number];
8
+ /** The field of each role: `custom-attributes.fields`, else the defaults of the form (anchor or group). */
9
+ export declare const paymentFieldsOf: (customAttributes: unknown, isGroup?: boolean) => Partial<Record<PaymentRole, string>>;
10
+ export interface IPaymentValues {
11
+ due?: string;
12
+ paidOn?: string;
13
+ /** The stored value of the payment method. */
14
+ method?: string;
15
+ /** Its option text, for the lines. */
16
+ methodText?: string;
17
+ transactions: string[];
18
+ /**
19
+ * Whether a payment is expected to be linked to a transaction: false when the form has no field for the
20
+ * transactions, or `custom-attributes.unlinkedPayment` is "ignore". Then a payment date alone means paid.
21
+ */
22
+ linksTransactions?: boolean;
23
+ }
24
+ export type PaymentState = {
25
+ kind: "paid";
26
+ } | {
27
+ kind: "paidUnlinked";
28
+ } | {
29
+ kind: "expected";
30
+ } | {
31
+ kind: "overdue";
32
+ days: number;
33
+ } | {
34
+ kind: "dueSoon";
35
+ days: number;
36
+ } | {
37
+ kind: "open";
38
+ };
39
+ export declare const isPaymentDate: (value?: string) => boolean;
40
+ /** "27.11.2026"; empty for no date. */
41
+ export declare const formatPaymentDate: (value?: string) => string;
42
+ /** Days until the date (negative: past); undefined for no date. */
43
+ export declare const daysUntil: (value: string | undefined, today?: Date) => number | undefined;
44
+ /** An open invoice due within this many days (inclusive) is due soon. */
45
+ export declare const DUE_SOON_DAYS = 7;
46
+ /**
47
+ * The state of a payment. Paid wins (a payment date is set): linked to a transaction or not — the unlinked
48
+ * case is the one that made invoices look paid while the bank showed an unexplained payment. Without a
49
+ * payment date a method listed in `paidAutomatically` (card, direct debit) is expected to pay itself;
50
+ * otherwise the due date decides: overdue after it, due soon within `dueSoonDays`, else open.
51
+ */
52
+ export declare const paymentState: (values: IPaymentValues, paidAutomatically: string[], today?: Date, dueSoonDays?: number) => PaymentState;
53
+ export type PaymentTone = "green" | "amber" | "blue" | "red" | "grey";
54
+ /** The pill of a state: its text and its tone. */
55
+ export declare const PAYMENT_PILLS: Record<PaymentState["kind"], {
56
+ text: string;
57
+ tone: PaymentTone;
58
+ }>;
59
+ /** The colours of a tone: background, text, dot. */
60
+ export declare const PAYMENT_TONES: Record<PaymentTone, {
61
+ background: string;
62
+ color: string;
63
+ dot: string;
64
+ }>;
65
+ export interface IPaymentLines {
66
+ /** What the state is about, beside the pill: "Paid on 02.11.2026", "Due 27.11.2026", "Overdue by 12 days". */
67
+ primary: string;
68
+ /** The details below it, muted. */
69
+ secondary: string[];
70
+ /** Paid without a linked transaction: the warning below it. */
71
+ warning?: string;
72
+ }
73
+ /** The lines of a state (English, as the detail view); the pill says the state, the lines the facts. */
74
+ export declare const paymentLines: (state: PaymentState, values: IPaymentValues, today?: Date) => IPaymentLines;
75
+ /** The MRNs of the linked transactions: a list of {transactionRef} (or of plain MRN strings), or one MRN. */
76
+ export declare const transactionRefsOf: (value: unknown, refField?: string) => string[];
77
+ /** An amount as stored ("1380.50", "1.380,50", 1380.5); undefined for anything else. */
78
+ export declare const parseAmount: (value: unknown) => number | undefined;
79
+ /** "1.380,50" — two decimals, German grouping, no currency (the invoice's currency is not known here). */
80
+ export declare const formatAmount: (value: number) => string;
81
+ /**
82
+ * The linked transactions against the invoice: their total (by magnitude — an outgoing payment is negative
83
+ * on the bank side) and whether it matches the invoice amount to the cent. `matches` is undefined without
84
+ * an invoice amount.
85
+ */
86
+ export declare const paymentTotal: (transactionAmounts: number[], invoiceAmount?: number) => {
87
+ total: number;
88
+ matches?: boolean;
89
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromerce/formbuilder-react",
3
- "version": "1.0.1015",
3
+ "version": "1.0.1016",
4
4
  "description": "creates a form based on configuration",
5
5
  "main": "dist/formbuilder.js",
6
6
  "types": "dist/index.d.ts",