@mohasinac/appkit 4.14.0 → 4.16.0
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/_internal/server/features/auctions/actions.js +2 -2
- package/dist/_internal/server/features/cart/service.d.ts +3 -3
- package/dist/_internal/server/features/checkout/actions.js +19 -0
- package/dist/_internal/server/features/checkout/source-context.d.ts +5 -0
- package/dist/_internal/server/features/checkout/source-context.js +157 -0
- package/dist/_internal/server/features/offers/adapters.d.ts +103 -0
- package/dist/_internal/server/features/offers/adapters.js +88 -0
- package/dist/_internal/server/features/offers/index.d.ts +2 -0
- package/dist/_internal/server/features/offers/index.js +1 -0
- package/dist/_internal/server/features/orders/adapters.js +24 -0
- package/dist/_internal/server/jobs/core/offerExpiry.js +10 -10
- package/dist/_internal/shared/actions/action-registry.d.ts +9 -2
- package/dist/_internal/shared/actions/action-registry.js +458 -7
- package/dist/_internal/shared/features/auctions/schema.d.ts +14 -2
- package/dist/_internal/shared/features/auctions/schema.js +13 -1
- package/dist/_internal/shared/features/blog/schema.d.ts +4 -4
- package/dist/_internal/shared/features/cart/schema.d.ts +25 -20
- package/dist/_internal/shared/features/cart/schema.js +15 -0
- package/dist/_internal/shared/features/categories/bundle-schemas.d.ts +22 -22
- package/dist/_internal/shared/features/orders/schema.d.ts +4 -4
- package/dist/_internal/shared/features/products/schema.d.ts +27 -27
- package/dist/_internal/shared/features/promotions/schema.d.ts +4 -4
- package/dist/_internal/shared/features/reviews/schema.d.ts +2 -2
- package/dist/_internal/shared/history/history.d.ts +22 -0
- package/dist/_internal/shared/history/history.js +41 -1
- package/dist/client.d.ts +13 -2
- package/dist/client.js +20 -2
- package/dist/constants/field-names.d.ts +8 -6
- package/dist/constants/field-names.js +48 -6
- package/dist/contracts/extend.d.ts +29 -0
- package/dist/contracts/extend.js +20 -0
- package/dist/contracts/index.d.ts +2 -1
- package/dist/contracts/index.js +2 -0
- package/dist/features/account/components/UserBidsView.js +12 -4
- package/dist/features/account/components/UserReturnsView.d.ts +3 -0
- package/dist/features/account/components/UserReturnsView.js +17 -1
- package/dist/features/admin/components/AdminAuditLogView.js +1 -0
- package/dist/features/admin/components/AdminBidsView.js +15 -2
- package/dist/features/admin/components/AdminBlogEditorView.js +65 -33
- package/dist/features/admin/components/AdminFeatureEditorView.js +35 -6
- package/dist/features/admin/components/AdminNavEditorView.js +15 -5
- package/dist/features/admin/components/AdminNewsletterView.js +18 -2
- package/dist/features/admin/components/AdminOffersView.js +62 -18
- package/dist/features/admin/components/AdminPaymentMethodsView.js +24 -4
- package/dist/features/admin/components/AdminScammerEditorView.d.ts +2 -1
- package/dist/features/admin/components/AdminScammerEditorView.js +3 -13
- package/dist/features/admin/components/AdminScammersView.js +3 -8
- package/dist/features/admin/components/AdminSectionsView.js +32 -23
- package/dist/features/admin/components/AdminSessionsView.js +17 -2
- package/dist/features/admin/components/AdminViewCards.js +24 -17
- package/dist/features/admin/components/DataListingView.js +15 -1
- package/dist/features/admin/components/DataTable.js +7 -17
- package/dist/features/admin/components/ViewAuditLogEntryModal.js +1 -0
- package/dist/features/admin/components/sections/adminSectionsTypes.d.ts +4 -2
- package/dist/features/admin/components/sections/adminSectionsTypes.js +45 -27
- package/dist/features/admin/constants/filter-tabs.d.ts +3 -0
- package/dist/features/admin/constants/filter-tabs.js +1 -0
- package/dist/features/admin/schemas/homepage-section-form.d.ts +22 -0
- package/dist/features/admin/schemas/homepage-section-form.js +68 -0
- package/dist/features/admin/schemas/nav-item-form.d.ts +74 -0
- package/dist/features/admin/schemas/nav-item-form.js +72 -0
- package/dist/features/auctions/components/AuctionBidsTable.d.ts +10 -1
- package/dist/features/auctions/components/AuctionBidsTable.js +22 -4
- package/dist/features/auctions/components/bid-detail-fields.d.ts +29 -0
- package/dist/features/auctions/components/bid-detail-fields.js +103 -0
- package/dist/features/auctions/schemas/index.d.ts +14 -14
- package/dist/features/audit-log/schemas/firestore.d.ts +14 -0
- package/dist/features/audit-log/schemas/firestore.js +7 -0
- package/dist/features/auth/schemas/index.d.ts +2 -2
- package/dist/features/blog/actions/blog-actions.d.ts +7 -7
- package/dist/features/blog/schemas/blog-form.d.ts +80 -0
- package/dist/features/blog/schemas/blog-form.js +100 -0
- package/dist/features/blog/schemas/index.d.ts +10 -10
- package/dist/features/cart/schemas/index.d.ts +3 -3
- package/dist/features/catalogue/schemas/validation.d.ts +12 -12
- package/dist/features/categories/schemas/index.d.ts +16 -16
- package/dist/features/collections/schemas/index.d.ts +8 -8
- package/dist/features/events/components/AdminEventEditorView.js +32 -54
- package/dist/features/events/components/AdminEventEntriesView.js +22 -3
- package/dist/features/events/schemas/event-form.d.ts +113 -0
- package/dist/features/events/schemas/event-form.js +82 -0
- package/dist/features/events/schemas/index.d.ts +2 -2
- package/dist/features/faq/actions/faq-actions.d.ts +6 -6
- package/dist/features/faq/schemas/index.d.ts +6 -6
- package/dist/features/grouped/schemas/grouped-listing-form.d.ts +101 -0
- package/dist/features/grouped/schemas/grouped-listing-form.js +89 -0
- package/dist/features/grouped/schemas/index.d.ts +4 -4
- package/dist/features/homepage/actions/homepage-section-actions.d.ts +11 -3
- package/dist/features/homepage/actions/homepage-section-actions.js +33 -1
- package/dist/features/homepage/schemas/index.d.ts +71 -40
- package/dist/features/homepage/schemas/index.js +24 -0
- package/dist/features/messages/schemas/index.d.ts +2 -2
- package/dist/features/orders/components/OrderStatusTimeline.d.ts +5 -1
- package/dist/features/orders/components/OrderStatusTimeline.js +39 -20
- package/dist/features/orders/repository/orders.repository.js +5 -0
- package/dist/features/orders/schemas/firestore.d.ts +36 -1
- package/dist/features/orders/schemas/index.d.ts +24 -24
- package/dist/features/orders/types/index.d.ts +35 -7
- package/dist/features/pre-orders/schemas/index.d.ts +4 -4
- package/dist/features/products/components/GroupSettingsPanel.js +5 -1
- package/dist/features/products/schemas/index.d.ts +38 -38
- package/dist/features/products/schemas/product-features.validators.d.ts +75 -2
- package/dist/features/products/schemas/product-features.validators.js +63 -0
- package/dist/features/promotions/schemas/index.d.ts +14 -14
- package/dist/features/reviews/schemas/index.d.ts +14 -14
- package/dist/features/scams/constants/scammer-status-display.d.ts +28 -0
- package/dist/features/scams/constants/scammer-status-display.js +79 -0
- package/dist/features/scams/schemas/index.d.ts +2 -2
- package/dist/features/search/schemas/index.d.ts +2 -2
- package/dist/features/seller/actions/offer-actions.js +32 -2
- package/dist/features/seller/components/OfferPhaseTimeline.d.ts +59 -0
- package/dist/features/seller/components/OfferPhaseTimeline.js +107 -0
- package/dist/features/seller/components/SellerBidsView.js +11 -4
- package/dist/features/seller/components/SellerCouponEditorView.js +17 -17
- package/dist/features/seller/components/SellerOffersView.js +2 -1
- package/dist/features/seller/components/SellerPayoutSettingsView.js +38 -14
- package/dist/features/seller/repository/offer.repository.d.ts +69 -8
- package/dist/features/seller/repository/offer.repository.js +127 -23
- package/dist/features/seller/schemas/coupon-form.d.ts +72 -0
- package/dist/features/seller/schemas/coupon-form.js +116 -0
- package/dist/features/seller/schemas/firestore.d.ts +56 -2
- package/dist/features/seller/schemas/firestore.js +27 -0
- package/dist/features/seller/schemas/index.d.ts +2 -2
- package/dist/features/seller/schemas/offer-forms.d.ts +21 -0
- package/dist/features/seller/schemas/offer-forms.js +21 -0
- package/dist/features/shell/build-sections.d.ts +63 -0
- package/dist/features/shell/build-sections.js +207 -0
- package/dist/features/shell/field-ui-meta.d.ts +115 -0
- package/dist/features/shell/field-ui-meta.js +324 -0
- package/dist/features/shell/index.d.ts +4 -0
- package/dist/features/shell/index.js +2 -0
- package/dist/features/shipments/schemas/validation.d.ts +22 -22
- package/dist/features/status-history/components/StatusTimeline.d.ts +74 -0
- package/dist/features/status-history/components/StatusTimeline.js +46 -0
- package/dist/features/status-history/index.d.ts +11 -0
- package/dist/features/status-history/index.js +10 -0
- package/dist/features/store-extensions/components/ReviewDecisionModal.d.ts +27 -0
- package/dist/features/store-extensions/components/ReviewDecisionModal.js +82 -0
- package/dist/features/store-extensions/index.d.ts +12 -0
- package/dist/features/store-extensions/index.js +12 -0
- package/dist/features/store-extensions/schemas/admin-notification-form.d.ts +36 -0
- package/dist/features/store-extensions/schemas/admin-notification-form.js +114 -0
- package/dist/features/store-extensions/schemas/analytics-forms.d.ts +57 -0
- package/dist/features/store-extensions/schemas/analytics-forms.js +158 -0
- package/dist/features/store-extensions/schemas/custom-role-form.d.ts +85 -0
- package/dist/features/store-extensions/schemas/custom-role-form.js +118 -0
- package/dist/features/store-extensions/schemas/firestore.d.ts +21 -1
- package/dist/features/store-extensions/schemas/firestore.js +60 -0
- package/dist/features/store-extensions/schemas/google-config-form.d.ts +53 -0
- package/dist/features/store-extensions/schemas/google-config-form.js +105 -0
- package/dist/features/store-extensions/schemas/item-request-create-form.d.ts +28 -0
- package/dist/features/store-extensions/schemas/item-request-create-form.js +80 -0
- package/dist/features/store-extensions/schemas/listing-template-form.d.ts +78 -0
- package/dist/features/store-extensions/schemas/listing-template-form.js +87 -0
- package/dist/features/store-extensions/schemas/moderation-review-form.d.ts +49 -0
- package/dist/features/store-extensions/schemas/moderation-review-form.js +101 -0
- package/dist/features/store-extensions/schemas/payout-method-form.d.ts +153 -0
- package/dist/features/store-extensions/schemas/payout-method-form.js +155 -0
- package/dist/features/store-extensions/schemas/report-create-form.d.ts +25 -0
- package/dist/features/store-extensions/schemas/report-create-form.js +79 -0
- package/dist/features/store-extensions/schemas/report-review-form.d.ts +47 -0
- package/dist/features/store-extensions/schemas/report-review-form.js +111 -0
- package/dist/features/store-extensions/schemas/shipping-config-form.d.ts +148 -0
- package/dist/features/store-extensions/schemas/shipping-config-form.js +104 -0
- package/dist/features/store-extensions/schemas/store-category-form.d.ts +54 -0
- package/dist/features/store-extensions/schemas/store-category-form.js +73 -0
- package/dist/features/stores/schemas/index.d.ts +4 -4
- package/dist/features/support/schemas/index.d.ts +4 -4
- package/dist/features/tester/seed-data/tester-checklist-seed-data.js +350 -0
- package/dist/features/wishlist/hooks/useWishlistWithGuest.d.ts +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.js +12 -2
- package/dist/next/routing/route-map.d.ts +16 -2
- package/dist/next/routing/route-map.js +9 -2
- package/dist/schemas/firestore-value.d.ts +8 -0
- package/dist/schemas/firestore-value.js +44 -0
- package/dist/schemas/index.d.ts +1 -1
- package/dist/schemas/index.js +1 -1
- package/dist/schemas/registry.d.ts +734 -101
- package/dist/schemas/registry.js +64 -1
- package/dist/seed/bids-seed-data.js +30 -0
- package/dist/seed/offers-seed-data.js +212 -7
- package/dist/seed/orders-seed-data.js +336 -1
- package/dist/seed/products-auctions-seed-data.js +41 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +5 -0
- package/dist/styles.css +1 -1
- package/dist/tailwind-utilities.css +1 -1
- package/dist/ui/DataTable.js +4 -2
- package/dist/ui/columns/build-columns.d.ts +6 -1
- package/dist/ui/columns/build-columns.js +53 -0
- package/dist/ui/columns/cell-renderers.d.ts +68 -0
- package/dist/ui/columns/cell-renderers.js +111 -0
- package/dist/ui/columns/column-renderers.d.ts +6 -1
- package/dist/ui/columns/column-renderers.js +6 -1
- package/dist/ui/columns/index.d.ts +2 -1
- package/dist/ui/columns/index.js +5 -1
- package/dist/ui/components/Button.js +27 -2
- package/dist/ui/components/RecordDetailModal.d.ts +10 -1
- package/dist/ui/components/RecordDetailModal.js +2 -2
- package/dist/ui/icons/icon-registry.d.ts +65 -0
- package/dist/ui/icons/icon-registry.js +115 -0
- package/package.json +2 -1
- package/scripts/node-esm-loader.mjs +65 -0
- package/scripts/seed-cli-loader.mjs +6 -49
- package/scripts/seed-cli.mjs +1 -1
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* WHY: Which section a field belongs to, and whether it shares a row with its
|
|
3
|
+
* neighbour, were conventions written in a table in a plan document. A
|
|
4
|
+
* convention drifts; 70 bare `grid-cols-2` in the tree — each one two
|
|
5
|
+
* columns wide at 320px — are what that drift looks like. Zod 4 lets the
|
|
6
|
+
* rule live on the field it describes, so the schema becomes the single
|
|
7
|
+
* source of validation, section membership AND layout.
|
|
8
|
+
* WHAT: `FieldUiMeta`, the typed `ui` registry, and `inferFieldUiMeta` — the
|
|
9
|
+
* heuristic that means only `section` has to be stated per field.
|
|
10
|
+
*
|
|
11
|
+
* ## 🛑 There are TWO zods in this repo, and that decided the design
|
|
12
|
+
*
|
|
13
|
+
* Measured 2026-08-24: the app depends on **zod 4.4.3**, but `appkit`'s own
|
|
14
|
+
* `package.json` declares `zod: ^3.24.0` and a v3 copy is nested at
|
|
15
|
+
* `node_modules/@mohasinac/appkit/node_modules/zod` (3.25.76). Verified with
|
|
16
|
+
* `createRequire`: appkit's shipped `dist` resolves `"zod"` to that nested v3,
|
|
17
|
+
* while consumer code resolves to root v4. Two instances, one bundle — the
|
|
18
|
+
* Root Cause #19 shape, on a package the dedupe script does not cover.
|
|
19
|
+
*
|
|
20
|
+
* So `z.registry<FieldUiMeta>()` is **not usable here**: it is a zod-4 API and
|
|
21
|
+
* appkit compiles against v3. Aligning the two is a dependency major across
|
|
22
|
+
* the 76 appkit files that import zod — its own wave, not a drive-by inside a
|
|
23
|
+
* spine wave.
|
|
24
|
+
*
|
|
25
|
+
* This registry is therefore a plain `WeakMap` keyed by schema instance, which
|
|
26
|
+
* is what `z.registry()` is internally. It behaves identically, works on both
|
|
27
|
+
* majors, and is strictly MORE robust to the split: object identity does not
|
|
28
|
+
* care which zod class produced the object. `annotate()` is typed, so a typo
|
|
29
|
+
* (`rows:` for `row:`) is a compile error — the property `.meta()` never had.
|
|
30
|
+
*
|
|
31
|
+
* Everything that introspects a schema below reads BOTH shapes for the same
|
|
32
|
+
* reason: zod 3 says `_def.typeName === "ZodOptional"`, zod 4 says
|
|
33
|
+
* `_def.type === "optional"`, and this file sees both at runtime.
|
|
34
|
+
*
|
|
35
|
+
* ## 🛑 The ordering trap — metadata MUST be the last call in the chain
|
|
36
|
+
*
|
|
37
|
+
* Verified at runtime:
|
|
38
|
+
*
|
|
39
|
+
* annotate(z.string(), {...}).optional() // ✗ meta LOST → lookup undefined
|
|
40
|
+
* annotate(z.string().optional(), {...}) // ✓ survives
|
|
41
|
+
*
|
|
42
|
+
* Every wrapper (`.optional()`, `.nullable()`, `.default()`, `.catch()`)
|
|
43
|
+
* returns a NEW schema instance, and the registry is keyed by instance. Most
|
|
44
|
+
* fields are optional, so getting this backwards silently drops layout for the
|
|
45
|
+
* majority of them. `audit-field-ui-meta` enforces the ordering.
|
|
46
|
+
*
|
|
47
|
+
* EXPORTS:
|
|
48
|
+
* FieldUiMeta, FieldRow, FieldKind, CalculatedTier, ui, annotate,
|
|
49
|
+
* inferFieldUiMeta, resolveFieldUiMeta, unwrapSchema, ROW_COLUMNS
|
|
50
|
+
*
|
|
51
|
+
* @tag domain:forms
|
|
52
|
+
* @tag layer:shared
|
|
53
|
+
* @tag pattern:registry
|
|
54
|
+
* @tag access:isomorphic
|
|
55
|
+
* @tag consumers:buildSectionsFromSchema,audit-field-ui-meta
|
|
56
|
+
* @tag sideEffects:none
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* The registry. A module-level singleton, because the whole point is that
|
|
60
|
+
* every form schema in the app annotates into the same place and can be
|
|
61
|
+
* queried as one ("every media field", "every quick field", "every field with
|
|
62
|
+
* no section").
|
|
63
|
+
*
|
|
64
|
+
* `WeakMap` so annotating a schema never keeps it alive.
|
|
65
|
+
*/
|
|
66
|
+
const REGISTRY = new WeakMap();
|
|
67
|
+
export const ui = {
|
|
68
|
+
/** Attach metadata to a schema instance. Returns the SAME instance. */
|
|
69
|
+
add(schema, meta) {
|
|
70
|
+
REGISTRY.set(schema, meta);
|
|
71
|
+
return schema;
|
|
72
|
+
},
|
|
73
|
+
get(schema) {
|
|
74
|
+
return REGISTRY.get(schema);
|
|
75
|
+
},
|
|
76
|
+
has(schema) {
|
|
77
|
+
return REGISTRY.has(schema);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Annotate a field. **Must be the outermost call in the chain** — see the
|
|
82
|
+
* ordering trap in the header.
|
|
83
|
+
*
|
|
84
|
+
* name: annotate(z.string().min(1), { section: "basics", quick: true }),
|
|
85
|
+
* photo: annotate(z.string().optional(), { section: "media" }),
|
|
86
|
+
*
|
|
87
|
+
* Wrapping the call rather than chaining off it (`.register()`-style) is
|
|
88
|
+
* deliberate: it puts the schema visually INSIDE the annotation, so appending
|
|
89
|
+
* `.optional()` afterwards looks as wrong as it is.
|
|
90
|
+
*/
|
|
91
|
+
export function annotate(schema, meta) {
|
|
92
|
+
return ui.add(schema, meta);
|
|
93
|
+
}
|
|
94
|
+
/** `row` → the `<FormGroup columns>` value it packs into. */
|
|
95
|
+
export const ROW_COLUMNS = {
|
|
96
|
+
full: 1,
|
|
97
|
+
pair: 2,
|
|
98
|
+
third: 3,
|
|
99
|
+
quarter: 4,
|
|
100
|
+
};
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// Inference
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
/**
|
|
105
|
+
* Normalise a zod type discriminator across majors.
|
|
106
|
+
* zod 3: `_def.typeName === "ZodOptional"` · zod 4: `_def.type === "optional"`.
|
|
107
|
+
*/
|
|
108
|
+
function typeOf(schema) {
|
|
109
|
+
const def = schema._def;
|
|
110
|
+
if (def?.type)
|
|
111
|
+
return def.type; // v4, already lowercase
|
|
112
|
+
const name = def?.typeName; // v3, "ZodOptional"
|
|
113
|
+
return name ? name.replace(/^Zod/, "").toLowerCase() : "";
|
|
114
|
+
}
|
|
115
|
+
/** Wrappers that produce a new instance around an inner type. */
|
|
116
|
+
const WRAPPERS = new Set(["optional", "nullable", "default", "catch", "readonly", "nonoptional"]);
|
|
117
|
+
/**
|
|
118
|
+
* Strip `.optional()` / `.nullable()` / `.default()` / `.catch()` to reach the
|
|
119
|
+
* type that actually decides the control. Returns the innermost schema and its
|
|
120
|
+
* normalised type discriminator.
|
|
121
|
+
*
|
|
122
|
+
* Reads `_def` because zod exposes no public accessor for this, on either
|
|
123
|
+
* major. Depth-bounded rather than trusting the shape: `_def` is internal, and
|
|
124
|
+
* this must degrade to "text" rather than loop if a future zod reshapes it.
|
|
125
|
+
*/
|
|
126
|
+
export function unwrapSchema(schema) {
|
|
127
|
+
let current = schema;
|
|
128
|
+
for (let depth = 0; depth < 10; depth++) {
|
|
129
|
+
const def = current._def;
|
|
130
|
+
const type = typeOf(current);
|
|
131
|
+
if (!WRAPPERS.has(type) || !def?.innerType)
|
|
132
|
+
return { schema: current, type };
|
|
133
|
+
current = def.innerType;
|
|
134
|
+
}
|
|
135
|
+
return { schema: current, type: "" };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The `max()` bound on a string schema, when it declares one — the signal that
|
|
139
|
+
* separates a text input from a textarea.
|
|
140
|
+
*
|
|
141
|
+
* The two majors store checks completely differently:
|
|
142
|
+
* v3: `_def.checks = [{ kind: "max", value: 300 }]`
|
|
143
|
+
* v4: `_def.checks = [{ _zod: { def: { check: "max_length", maximum: 300 } } }]`
|
|
144
|
+
*/
|
|
145
|
+
function stringMaxLength(schema) {
|
|
146
|
+
const checks = schema._def?.checks;
|
|
147
|
+
if (!Array.isArray(checks))
|
|
148
|
+
return undefined;
|
|
149
|
+
for (const check of checks) {
|
|
150
|
+
const v4 = check?._zod?.def;
|
|
151
|
+
if (v4?.check === "max_length" && typeof v4.maximum === "number")
|
|
152
|
+
return v4.maximum;
|
|
153
|
+
const v3 = check;
|
|
154
|
+
if (v3?.kind === "max" && typeof v3.value === "number")
|
|
155
|
+
return v3.value;
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Enum members. v4 exposes `.options`; v3 keeps them on `_def.values`, and for
|
|
161
|
+
* a native enum on `_def.values` as an object.
|
|
162
|
+
*/
|
|
163
|
+
function enumOptions(schema) {
|
|
164
|
+
const direct = schema.options;
|
|
165
|
+
if (Array.isArray(direct))
|
|
166
|
+
return direct.filter((o) => typeof o === "string");
|
|
167
|
+
const values = schema._def?.values;
|
|
168
|
+
if (Array.isArray(values))
|
|
169
|
+
return values.filter((o) => typeof o === "string");
|
|
170
|
+
if (values && typeof values === "object") {
|
|
171
|
+
return Object.values(values).filter((o) => typeof o === "string");
|
|
172
|
+
}
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
/** Public: the option list for a select-shaped field, or null. */
|
|
176
|
+
export function schemaEnumOptions(schema) {
|
|
177
|
+
const { schema: inner } = unwrapSchema(schema);
|
|
178
|
+
return enumOptions(inner) ?? null;
|
|
179
|
+
}
|
|
180
|
+
/** Public: whether a field's type is optional-wrapped (i.e. not required). */
|
|
181
|
+
export function schemaIsOptional(schema) {
|
|
182
|
+
const type = typeOf(schema);
|
|
183
|
+
return type === "optional" || type === "default" || type === "nullish";
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The `.shape` of an object schema, seeing through effects wrappers.
|
|
187
|
+
*
|
|
188
|
+
* `.superRefine()` / `.refine()` / `.transform()` return a wrapper that does
|
|
189
|
+
* NOT expose `.shape` — verified: `z.object({...}).superRefine(fn)` has
|
|
190
|
+
* `_def.typeName === "ZodEffects"`, `.shape === undefined`, and the real object
|
|
191
|
+
* on `_def.schema`. Reading `.shape` directly therefore returns nothing for any
|
|
192
|
+
* schema with a cross-field rule, which is most of the interesting ones (the
|
|
193
|
+
* payout form's UPI-vs-bank branch is exactly this shape).
|
|
194
|
+
*
|
|
195
|
+
* Failing to unwrap would not error — it would silently derive a form with
|
|
196
|
+
* ZERO sections, which is the quiet-wrong-answer failure mode this whole wave
|
|
197
|
+
* exists to eliminate.
|
|
198
|
+
*/
|
|
199
|
+
export function objectShape(schema) {
|
|
200
|
+
let current = schema;
|
|
201
|
+
for (let depth = 0; depth < 10; depth++) {
|
|
202
|
+
const direct = current.shape;
|
|
203
|
+
if (direct)
|
|
204
|
+
return direct;
|
|
205
|
+
const def = current._def;
|
|
206
|
+
const next = def?.schema ?? def?.innerType ?? def?.in;
|
|
207
|
+
if (!next)
|
|
208
|
+
return null;
|
|
209
|
+
current = next;
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Name patterns override the Zod type, because a name carries intent a type
|
|
215
|
+
* cannot. `images` is `ZodArray` but it is a media field, not a list editor;
|
|
216
|
+
* `description` is `ZodString` but it is a textarea.
|
|
217
|
+
*
|
|
218
|
+
* Ordered — the first match wins, so the media test runs before the long-text
|
|
219
|
+
* one (`coverImage` must not become a textarea).
|
|
220
|
+
*/
|
|
221
|
+
const NAME_RULES = [
|
|
222
|
+
{
|
|
223
|
+
// Media claims a full row ALWAYS, and forces its section to keepMounted:
|
|
224
|
+
// a MediaUploadField stacks a source-tab strip, a drop target, a progress
|
|
225
|
+
// bar and a preview, and collapsing it mid-upload discards the transfer.
|
|
226
|
+
test: /(^|[a-z])(image|images|photo|video|media|avatar|banner|logo|cover|thumbnail)([A-Z]|s?$)/i,
|
|
227
|
+
meta: { kind: "media", row: "full", sectionKeepMounted: true },
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
test: /^(description|body|content|notes?|bio|message|excerpt|answer|returnPolicy)$/i,
|
|
231
|
+
meta: { kind: "textarea", row: "full" },
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
// Long single inputs: truncating a URL or an address into half a row makes
|
|
235
|
+
// it unreadable, so they take the whole row even though they are short types.
|
|
236
|
+
test: /^(url|slug|email|title|name|displayName|headline|address|addressLine1|addressLine2|line1|line2)$/i,
|
|
237
|
+
meta: { row: "full" },
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
test: /^(firstName|lastName|city|state|postcode|pincode|postalCode|ifsc|gstin|pan|hsn|price|rate|percent|quantity|phone)$/i,
|
|
241
|
+
meta: { row: "pair" },
|
|
242
|
+
},
|
|
243
|
+
];
|
|
244
|
+
/**
|
|
245
|
+
* Fields nothing should ever render as an input — ids, audit stamps and
|
|
246
|
+
* counters. Marked `derived` so `audit-form-field-roundtrip` reads them as
|
|
247
|
+
* server-owned rather than as unreachable schema fields.
|
|
248
|
+
*/
|
|
249
|
+
const SERVER_OWNED = /^(id|createdAt|updatedAt|createdBy|updatedBy|ownerId|authorId|userId|views|viewCount|productCount|usageCount|helpfulCount|replyCount|reportCount)$/;
|
|
250
|
+
/** Zod type → its default control and row span. */
|
|
251
|
+
function fromZodType(type, inner) {
|
|
252
|
+
switch (type) {
|
|
253
|
+
case "boolean":
|
|
254
|
+
// Several per wrapping row — a switch plus label is short, and stacking
|
|
255
|
+
// them one-per-row makes a settings section endless.
|
|
256
|
+
return { kind: "toggle", row: "quarter" };
|
|
257
|
+
case "enum":
|
|
258
|
+
case "nativeEnum":
|
|
259
|
+
case "literal":
|
|
260
|
+
case "union":
|
|
261
|
+
return { kind: "select", row: "pair" };
|
|
262
|
+
case "date":
|
|
263
|
+
return { kind: "date", row: "pair" };
|
|
264
|
+
case "number":
|
|
265
|
+
case "bigint":
|
|
266
|
+
return { kind: "number", row: "pair" };
|
|
267
|
+
case "array":
|
|
268
|
+
return { kind: "list", row: "full" };
|
|
269
|
+
case "object":
|
|
270
|
+
case "record":
|
|
271
|
+
return { kind: "list", row: "full" };
|
|
272
|
+
case "string": {
|
|
273
|
+
const max = stringMaxLength(inner);
|
|
274
|
+
return max != null && max > 200
|
|
275
|
+
? { kind: "textarea", row: "full" }
|
|
276
|
+
: { kind: "text", row: "pair" };
|
|
277
|
+
}
|
|
278
|
+
default:
|
|
279
|
+
return { kind: "text", row: "pair" };
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Everything about a field's layout that can be derived from its name and its
|
|
284
|
+
* Zod type. `section` is never inferred, so the return type is a Partial —
|
|
285
|
+
* `resolveFieldUiMeta` is what merges it with the explicit registration.
|
|
286
|
+
*
|
|
287
|
+
* This is what makes annotation cheap: a 13-field form is 13 short
|
|
288
|
+
* `.register(ui, { section: "…" })` calls, not 13 full metadata objects.
|
|
289
|
+
*/
|
|
290
|
+
export function inferFieldUiMeta(name, schema) {
|
|
291
|
+
const { schema: inner, type } = unwrapSchema(schema);
|
|
292
|
+
const meta = { ...fromZodType(type, inner) };
|
|
293
|
+
for (const rule of NAME_RULES) {
|
|
294
|
+
if (rule.test.test(name)) {
|
|
295
|
+
Object.assign(meta, rule.meta);
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (SERVER_OWNED.test(name)) {
|
|
300
|
+
meta.derived = true;
|
|
301
|
+
meta.tier = meta.tier ?? "t2-server";
|
|
302
|
+
}
|
|
303
|
+
// >5 options is the standing PaginatedSelect threshold. Recorded as `help`
|
|
304
|
+
// rather than a separate flag so the renderer can decide without a second
|
|
305
|
+
// source of truth about what "many options" means.
|
|
306
|
+
const options = enumOptions(inner);
|
|
307
|
+
if (meta.kind === "select" && options != null && options.length > 5) {
|
|
308
|
+
meta.help = meta.help ?? "paginated";
|
|
309
|
+
}
|
|
310
|
+
return meta;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* The field's final metadata: inference first, explicit registration on top.
|
|
314
|
+
*
|
|
315
|
+
* Returns `null` when the field has no registration at all — the caller
|
|
316
|
+
* decides whether that is a hard error (a registered form schema, where
|
|
317
|
+
* `section` is mandatory) or a fallback (an ad-hoc schema being previewed).
|
|
318
|
+
*/
|
|
319
|
+
export function resolveFieldUiMeta(name, schema) {
|
|
320
|
+
const explicit = ui.get(schema);
|
|
321
|
+
if (!explicit)
|
|
322
|
+
return null;
|
|
323
|
+
return { ...inferFieldUiMeta(name, schema), ...explicit };
|
|
324
|
+
}
|
|
@@ -10,5 +10,9 @@ export type { SectionDef, SectionFormProps, UseSectionFormNavResult, } from "./S
|
|
|
10
10
|
export { SectionForm, useSectionFormNav, orderSections, buildFieldToSectionIndex, sectionAnchorId, } from "./SectionForm";
|
|
11
11
|
export type { EntityFormDefinition } from "./entity-form";
|
|
12
12
|
export { deriveQuickFields, deriveQuickFieldNames, allDefinitionFields, applyDerive, assertNoDeriveCollision, humaniseFieldName, } from "./entity-form";
|
|
13
|
+
export type { FieldUiMeta, FieldRow, FieldKind, CalculatedTier, } from "./field-ui-meta";
|
|
14
|
+
export { ui, annotate, ROW_COLUMNS, inferFieldUiMeta, resolveFieldUiMeta, unwrapSchema, schemaEnumOptions, schemaIsOptional, objectShape, } from "./field-ui-meta";
|
|
15
|
+
export type { ResolvedField, FieldRenderer, BuildSectionsOptions, } from "./build-sections";
|
|
16
|
+
export { buildSectionsFromSchema, resolveFields, groupFieldsBySection, packRows, } from "./build-sections";
|
|
13
17
|
export type { TitleDescriptionGroupProps, ImageFieldGroupProps, SeoFieldGroupProps, StatusFieldGroupProps, StatusFieldGroupOption, } from "./field-groups";
|
|
14
18
|
export { TitleDescriptionGroup, ImageFieldGroup, SeoFieldGroup, StatusFieldGroup, } from "./field-groups";
|
|
@@ -4,4 +4,6 @@ export { QuickFormDrawer } from "./QuickFormDrawer";
|
|
|
4
4
|
export { StepForm, StepFormActions, StepIndicator } from "./StepForm";
|
|
5
5
|
export { SectionForm, useSectionFormNav, orderSections, buildFieldToSectionIndex, sectionAnchorId, } from "./SectionForm";
|
|
6
6
|
export { deriveQuickFields, deriveQuickFieldNames, allDefinitionFields, applyDerive, assertNoDeriveCollision, humaniseFieldName, } from "./entity-form";
|
|
7
|
+
export { ui, annotate, ROW_COLUMNS, inferFieldUiMeta, resolveFieldUiMeta, unwrapSchema, schemaEnumOptions, schemaIsOptional, objectShape, } from "./field-ui-meta";
|
|
8
|
+
export { buildSectionsFromSchema, resolveFields, groupFieldsBySection, packRows, } from "./build-sections";
|
|
7
9
|
export { TitleDescriptionGroup, ImageFieldGroup, SeoFieldGroup, StatusFieldGroup, } from "./field-groups";
|
|
@@ -230,36 +230,36 @@ export declare const createShipmentItemSchema: z.ZodEffects<z.ZodObject<{
|
|
|
230
230
|
quantity: number;
|
|
231
231
|
isForSelfUse: boolean;
|
|
232
232
|
notes?: string | undefined;
|
|
233
|
-
categorySlugs?: string[] | undefined;
|
|
234
|
-
brandSlug?: string | undefined;
|
|
235
233
|
price?: number | undefined;
|
|
234
|
+
brandSlug?: string | undefined;
|
|
235
|
+
categorySlugs?: string[] | undefined;
|
|
236
236
|
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
237
237
|
}, {
|
|
238
238
|
title: string;
|
|
239
239
|
quantity: number;
|
|
240
240
|
isForSelfUse: boolean;
|
|
241
241
|
notes?: string | undefined;
|
|
242
|
-
categorySlugs?: string[] | undefined;
|
|
243
|
-
brandSlug?: string | undefined;
|
|
244
242
|
price?: number | undefined;
|
|
243
|
+
brandSlug?: string | undefined;
|
|
244
|
+
categorySlugs?: string[] | undefined;
|
|
245
245
|
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
246
246
|
}>, {
|
|
247
247
|
title: string;
|
|
248
248
|
quantity: number;
|
|
249
249
|
isForSelfUse: boolean;
|
|
250
250
|
notes?: string | undefined;
|
|
251
|
-
categorySlugs?: string[] | undefined;
|
|
252
|
-
brandSlug?: string | undefined;
|
|
253
251
|
price?: number | undefined;
|
|
252
|
+
brandSlug?: string | undefined;
|
|
253
|
+
categorySlugs?: string[] | undefined;
|
|
254
254
|
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
255
255
|
}, {
|
|
256
256
|
title: string;
|
|
257
257
|
quantity: number;
|
|
258
258
|
isForSelfUse: boolean;
|
|
259
259
|
notes?: string | undefined;
|
|
260
|
-
categorySlugs?: string[] | undefined;
|
|
261
|
-
brandSlug?: string | undefined;
|
|
262
260
|
price?: number | undefined;
|
|
261
|
+
brandSlug?: string | undefined;
|
|
262
|
+
categorySlugs?: string[] | undefined;
|
|
263
263
|
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
264
264
|
}>;
|
|
265
265
|
export declare const updateShipmentItemSchema: z.ZodObject<{
|
|
@@ -278,11 +278,11 @@ export declare const updateShipmentItemSchema: z.ZodObject<{
|
|
|
278
278
|
}, "strip", z.ZodTypeAny, {
|
|
279
279
|
title?: string | undefined;
|
|
280
280
|
notes?: string | undefined;
|
|
281
|
-
categorySlugs?: string[] | undefined;
|
|
282
|
-
brandSlug?: string | undefined;
|
|
283
281
|
price?: number | undefined;
|
|
284
|
-
|
|
282
|
+
brandSlug?: string | undefined;
|
|
285
283
|
quantity?: number | undefined;
|
|
284
|
+
categorySlugs?: string[] | undefined;
|
|
285
|
+
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
286
286
|
isForSelfUse?: boolean | undefined;
|
|
287
287
|
linkedProductId?: string | null | undefined;
|
|
288
288
|
linkedProductSlug?: string | null | undefined;
|
|
@@ -290,11 +290,11 @@ export declare const updateShipmentItemSchema: z.ZodObject<{
|
|
|
290
290
|
}, {
|
|
291
291
|
title?: string | undefined;
|
|
292
292
|
notes?: string | undefined;
|
|
293
|
-
categorySlugs?: string[] | undefined;
|
|
294
|
-
brandSlug?: string | undefined;
|
|
295
293
|
price?: number | undefined;
|
|
296
|
-
|
|
294
|
+
brandSlug?: string | undefined;
|
|
297
295
|
quantity?: number | undefined;
|
|
296
|
+
categorySlugs?: string[] | undefined;
|
|
297
|
+
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
298
298
|
isForSelfUse?: boolean | undefined;
|
|
299
299
|
linkedProductId?: string | null | undefined;
|
|
300
300
|
linkedProductSlug?: string | null | undefined;
|
|
@@ -319,36 +319,36 @@ export declare const bulkShipmentItemsSchema: z.ZodEffects<z.ZodArray<z.ZodObjec
|
|
|
319
319
|
quantity: number;
|
|
320
320
|
isForSelfUse: boolean;
|
|
321
321
|
notes?: string | undefined;
|
|
322
|
-
categorySlugs?: string[] | undefined;
|
|
323
|
-
brandSlug?: string | undefined;
|
|
324
322
|
price?: number | undefined;
|
|
323
|
+
brandSlug?: string | undefined;
|
|
324
|
+
categorySlugs?: string[] | undefined;
|
|
325
325
|
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
326
326
|
}, {
|
|
327
327
|
title: string;
|
|
328
328
|
quantity: number;
|
|
329
329
|
isForSelfUse: boolean;
|
|
330
330
|
notes?: string | undefined;
|
|
331
|
-
categorySlugs?: string[] | undefined;
|
|
332
|
-
brandSlug?: string | undefined;
|
|
333
331
|
price?: number | undefined;
|
|
332
|
+
brandSlug?: string | undefined;
|
|
333
|
+
categorySlugs?: string[] | undefined;
|
|
334
334
|
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
335
335
|
}>, "many">, {
|
|
336
336
|
title: string;
|
|
337
337
|
quantity: number;
|
|
338
338
|
isForSelfUse: boolean;
|
|
339
339
|
notes?: string | undefined;
|
|
340
|
-
categorySlugs?: string[] | undefined;
|
|
341
|
-
brandSlug?: string | undefined;
|
|
342
340
|
price?: number | undefined;
|
|
341
|
+
brandSlug?: string | undefined;
|
|
342
|
+
categorySlugs?: string[] | undefined;
|
|
343
343
|
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
344
344
|
}[], {
|
|
345
345
|
title: string;
|
|
346
346
|
quantity: number;
|
|
347
347
|
isForSelfUse: boolean;
|
|
348
348
|
notes?: string | undefined;
|
|
349
|
-
categorySlugs?: string[] | undefined;
|
|
350
|
-
brandSlug?: string | undefined;
|
|
351
349
|
price?: number | undefined;
|
|
350
|
+
brandSlug?: string | undefined;
|
|
351
|
+
categorySlugs?: string[] | undefined;
|
|
352
352
|
condition?: "new" | "used" | "refurbished" | "like_new" | "good" | "fair" | "poor" | "broken" | "graded" | undefined;
|
|
353
353
|
}[]>;
|
|
354
354
|
export type CreateShipmentInput = z.infer<typeof createShipmentSchema>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StatusTimeline — the one rail that renders any entity's status history.
|
|
3
|
+
*
|
|
4
|
+
* Both the order timeline and the offer timeline were about to be written
|
|
5
|
+
* separately, against the same `StatusChangeEntry[]` shape, with the same
|
|
6
|
+
* dot-and-connector rail and the same two load-bearing rules. That is the
|
|
7
|
+
* duplication the Rule of Three exists to prevent, so this is the single
|
|
8
|
+
* implementation and each feature supplies only its own phase vocabulary.
|
|
9
|
+
*
|
|
10
|
+
* ## Two rules this component must never break
|
|
11
|
+
*
|
|
12
|
+
* **1. Never fabricate a timestamp.** A step with no recorded date renders an
|
|
13
|
+
* em-dash. Not `new Date()`, and not a proxy field: `updatedAt` means "last
|
|
14
|
+
* write of any kind" and `expiresAt` is a deadline, not an event. An offer
|
|
15
|
+
* that expired has no timestamp at all because `expireMany` never wrote one
|
|
16
|
+
* before this wave, and inventing one would make the record lie.
|
|
17
|
+
*
|
|
18
|
+
* **2. It never fetches.** A client component that loaded its own chain would
|
|
19
|
+
* fire one request per opened modal per portal. The API returns the chain;
|
|
20
|
+
* this renders it.
|
|
21
|
+
*/
|
|
22
|
+
import type { ReactNode } from "react";
|
|
23
|
+
import type { FieldChange } from "../../../_internal/shared/history/index";
|
|
24
|
+
/** The client-facing entry shape — dates already serialised to ISO. */
|
|
25
|
+
export interface TimelineEntry {
|
|
26
|
+
at: string;
|
|
27
|
+
actorUid?: string;
|
|
28
|
+
actorRole: "buyer" | "seller" | "admin" | "system";
|
|
29
|
+
changes: Record<string, FieldChange>;
|
|
30
|
+
reason?: string;
|
|
31
|
+
note?: string;
|
|
32
|
+
trigger: string;
|
|
33
|
+
}
|
|
34
|
+
export interface TimelineStep {
|
|
35
|
+
key: string;
|
|
36
|
+
label: string;
|
|
37
|
+
/** ISO string, or absent — absent renders an em-dash, never a guess. */
|
|
38
|
+
date?: string;
|
|
39
|
+
/** Terminal-negative: cancelled, declined, rejected. Renders in error tone. */
|
|
40
|
+
negative?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Neutral-but-ended, e.g. a superseded offer round. Deliberately distinct
|
|
43
|
+
* from `negative`: the buyer did not walk away, they countered, and the
|
|
44
|
+
* negotiation continued.
|
|
45
|
+
*/
|
|
46
|
+
muted?: boolean;
|
|
47
|
+
actorRole?: TimelineEntry["actorRole"];
|
|
48
|
+
reason?: string;
|
|
49
|
+
note?: string;
|
|
50
|
+
/** Round divider text for multi-round chains ("Round 2"). */
|
|
51
|
+
roundLabel?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface StatusTimelineProps {
|
|
54
|
+
title?: string;
|
|
55
|
+
steps: TimelineStep[];
|
|
56
|
+
/** Entries trimmed off the front of the capped history, if any. */
|
|
57
|
+
truncatedCount?: number;
|
|
58
|
+
/** Rendered below the rail — tracking details, chain summary, etc. */
|
|
59
|
+
footer?: ReactNode;
|
|
60
|
+
/** Suppress `footer` when the last step is terminal-negative. */
|
|
61
|
+
hideFooterWhenNegative?: boolean;
|
|
62
|
+
emptyLabel?: string;
|
|
63
|
+
className?: string;
|
|
64
|
+
}
|
|
65
|
+
export declare function StatusTimeline({ title, steps, truncatedCount, footer, hideFooterWhenNegative, emptyLabel, className, }: StatusTimelineProps): import("react").JSX.Element;
|
|
66
|
+
/**
|
|
67
|
+
* Turn recorded history entries into steps.
|
|
68
|
+
*
|
|
69
|
+
* Only entries that actually changed `status` become steps — an entry
|
|
70
|
+
* recording a tracking number or a payment-review outcome is real history but
|
|
71
|
+
* is not a phase, and putting every entry on the rail would bury the five
|
|
72
|
+
* transitions anyone reads.
|
|
73
|
+
*/
|
|
74
|
+
export declare function stepsFromEntries(entries: TimelineEntry[] | undefined, labelFor: (status: string) => string, isNegative: (status: string) => boolean): TimelineStep[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Badge, Div, Heading, Row, Stack, Text } from "../../../ui";
|
|
4
|
+
const ACTOR_LABEL = {
|
|
5
|
+
buyer: "Buyer",
|
|
6
|
+
seller: "Store",
|
|
7
|
+
admin: "Admin",
|
|
8
|
+
system: "System",
|
|
9
|
+
};
|
|
10
|
+
export function StatusTimeline({ title = "Timeline", steps, truncatedCount, footer, hideFooterWhenNegative = true, emptyLabel = "No history yet", className = "", }) {
|
|
11
|
+
const isTerminalNegative = steps[steps.length - 1]?.negative === true;
|
|
12
|
+
const showFooter = footer && !(hideFooterWhenNegative && isTerminalNegative);
|
|
13
|
+
return (_jsxs(Div, { className: className, rounded: "xl", padding: "md", surface: "muted", border: "default", children: [_jsx(Heading, { level: 3, size: "sm", weight: "semibold", color: "muted", className: "mb-3", children: title }), truncatedCount && truncatedCount > 0 ? (
|
|
14
|
+
// Say what is not being shown. Silent truncation reads as "this is all
|
|
15
|
+
// of it", which is the same lie as a silently dropped field.
|
|
16
|
+
_jsxs(Text, { size: "xs", color: "muted", className: "mb-2", children: [truncatedCount, " earlier ", truncatedCount === 1 ? "entry" : "entries", " trimmed"] })) : null, steps.length === 0 ? (_jsx(Badge, { variant: "default", children: emptyLabel })) : (_jsx(Stack, { gap: "none", children: steps.map((step, i) => {
|
|
17
|
+
const isLast = i === steps.length - 1;
|
|
18
|
+
return (_jsxs(Stack, { gap: "none", children: [step.roundLabel && (_jsx(Text, { size: "xs", weight: "semibold", color: "muted", className: "mb-1 mt-2", children: step.roundLabel })), _jsxs(Row, { gap: "sm", padding: isLast ? "none" : "b-md", children: [_jsxs(Stack, { gap: "none", align: "center", className: "shrink-0", children: [_jsx(Div, { className: `h-2.5 w-2.5 ${step.negative || step.muted ? "" : "bg-[var(--appkit-color-primary)]"}`, rounded: "full", surface: step.negative ? "danger-surface" : step.muted ? "subtle" : "none" }), !isLast && _jsx(Div, { className: "w-px flex-1 min-h-[24px]", surface: "subtle" })] }), _jsxs(Stack, { gap: "none", className: "min-w-0 flex-1", children: [_jsxs(Row, { gap: "xs", align: "center", wrap: true, children: [_jsx(Text, { size: "sm", weight: "medium", className: step.negative ? "text-error" : undefined, color: step.muted ? "muted" : undefined, children: step.label }), step.actorRole && step.actorRole !== "system" && (_jsx(Badge, { variant: "default", size: "xs", children: ACTOR_LABEL[step.actorRole] }))] }), _jsx(Text, { size: "xs", color: "muted", children: step.date ? new Date(step.date).toLocaleString() : "—" }), step.reason && (_jsx(Text, { size: "xs", color: "muted", className: "mt-0.5", children: step.reason })), step.note && (_jsxs(Text, { size: "xs", color: "muted", italic: true, className: "mt-0.5", children: ["\u201C", step.note, "\u201D"] }))] })] })] }, `${step.key}-${i}`));
|
|
19
|
+
}) })), showFooter ? (_jsx(Div, { className: "mt-3 border-t border-[var(--appkit-color-border)]", padding: "t-sm", children: footer })) : null] }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Turn recorded history entries into steps.
|
|
23
|
+
*
|
|
24
|
+
* Only entries that actually changed `status` become steps — an entry
|
|
25
|
+
* recording a tracking number or a payment-review outcome is real history but
|
|
26
|
+
* is not a phase, and putting every entry on the rail would bury the five
|
|
27
|
+
* transitions anyone reads.
|
|
28
|
+
*/
|
|
29
|
+
export function stepsFromEntries(entries, labelFor, isNegative) {
|
|
30
|
+
if (!entries?.length)
|
|
31
|
+
return [];
|
|
32
|
+
return entries
|
|
33
|
+
.filter((e) => "status" in e.changes)
|
|
34
|
+
.map((e) => {
|
|
35
|
+
const to = String(e.changes.status?.to ?? "");
|
|
36
|
+
return {
|
|
37
|
+
key: to,
|
|
38
|
+
label: labelFor(to),
|
|
39
|
+
date: e.at,
|
|
40
|
+
negative: isNegative(to),
|
|
41
|
+
actorRole: e.actorRole,
|
|
42
|
+
reason: e.reason,
|
|
43
|
+
note: e.note,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status history — the shared timeline rail for any entity that records how
|
|
3
|
+
* it reached its current state (orders, offers, and the 8 more adopting the
|
|
4
|
+
* primitive in W15).
|
|
5
|
+
*
|
|
6
|
+
* Deliberately NOT `features/history/` — that name was already taken by the
|
|
7
|
+
* buyer's browsing-history feature (`useHistory`, guest-history utils), which
|
|
8
|
+
* is an entirely unrelated concept.
|
|
9
|
+
*/
|
|
10
|
+
export { StatusTimeline, stepsFromEntries } from "./components/StatusTimeline";
|
|
11
|
+
export type { StatusTimelineProps, TimelineEntry, TimelineStep } from "./components/StatusTimeline";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status history — the shared timeline rail for any entity that records how
|
|
3
|
+
* it reached its current state (orders, offers, and the 8 more adopting the
|
|
4
|
+
* primitive in W15).
|
|
5
|
+
*
|
|
6
|
+
* Deliberately NOT `features/history/` — that name was already taken by the
|
|
7
|
+
* buyer's browsing-history feature (`useHistory`, guest-history utils), which
|
|
8
|
+
* is an entirely unrelated concept.
|
|
9
|
+
*/
|
|
10
|
+
export { StatusTimeline, stepsFromEntries } from "./components/StatusTimeline";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Generic over the schema's OUTPUT type, so a caller's `onConfirm` receives
|
|
4
|
+
* `ModerationReviewFormValues` / `ReportReviewFormValues` rather than an
|
|
5
|
+
* untyped bag. A `Record<string, unknown>` here would put the very seam this
|
|
6
|
+
* component exists to close straight back into the callback signature.
|
|
7
|
+
*/
|
|
8
|
+
export interface ReviewDecisionModalProps<TValues> {
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
/** Modal heading, e.g. "Reject media". */
|
|
12
|
+
title: string;
|
|
13
|
+
/** The schema BOTH this modal and its route validate against. */
|
|
14
|
+
schema: ZodType<TValues>;
|
|
15
|
+
/** The status this decision sets — parsed as part of the payload. */
|
|
16
|
+
status: string;
|
|
17
|
+
/** Which key carries the note: `reason` for moderation, `resolution` for reports. */
|
|
18
|
+
noteField: string;
|
|
19
|
+
noteLabel: string;
|
|
20
|
+
noteHelp?: string;
|
|
21
|
+
notePlaceholder?: string;
|
|
22
|
+
confirmLabel: string;
|
|
23
|
+
confirmVariant?: "primary" | "danger";
|
|
24
|
+
/** Called only once the payload has parsed cleanly, with the PARSED value. */
|
|
25
|
+
onConfirm: (values: TValues) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare function ReviewDecisionModal<TValues>({ isOpen, onClose, title, schema, status, noteField, noteLabel, noteHelp, notePlaceholder, confirmLabel, confirmVariant, onConfirm, }: ReviewDecisionModalProps<TValues>): import("react").JSX.Element;
|