@revenexx/cover 0.2.4 → 0.2.5
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/app/components/account/orders/AccountOrdersTable.vue +37 -1
- package/app/composables/useAccountOrders.ts +16 -4
- package/app/interfaces/account/order-list.ts +4 -0
- package/i18n/locales/de/account.json +1 -0
- package/i18n/locales/en/account.json +1 -0
- package/package.json +2 -2
- package/server/api/account/orders.get.ts +20 -8
- package/server/utils/liveOrderLists.ts +6 -7
- package/server/utils/liveOrders.ts +4 -3
|
@@ -14,8 +14,16 @@ const localePath = useLocalePath();
|
|
|
14
14
|
const { to } = useAppUrl();
|
|
15
15
|
const toast = useToast();
|
|
16
16
|
const cart = useCartStore();
|
|
17
|
-
const { orders, status, error } = useAccountOrders();
|
|
17
|
+
const { orders, total, page, pageSize, status, error } = useAccountOrders();
|
|
18
18
|
const { formatCurrency } = useCartSummaryFormatting();
|
|
19
|
+
|
|
20
|
+
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / pageSize)));
|
|
21
|
+
function prevPage(): void {
|
|
22
|
+
if (page.value > 1) page.value -= 1;
|
|
23
|
+
}
|
|
24
|
+
function nextPage(): void {
|
|
25
|
+
if (page.value < pageCount.value) page.value += 1;
|
|
26
|
+
}
|
|
19
27
|
const { tableUi } = useDataTable();
|
|
20
28
|
|
|
21
29
|
const statusColors: Record<AccountOrderStatus, "info" | "warning" | "primary" | "success" | "error"> = {
|
|
@@ -276,6 +284,34 @@ async function orderAgain(order: AccountOrder): Promise<void> {
|
|
|
276
284
|
/>
|
|
277
285
|
</template>
|
|
278
286
|
</UTable>
|
|
287
|
+
|
|
288
|
+
<div
|
|
289
|
+
v-if="total > pageSize"
|
|
290
|
+
class="flex items-center justify-between gap-4 pt-4 border-t border-(--ui-border)"
|
|
291
|
+
>
|
|
292
|
+
<span class="text-sm text-muted">
|
|
293
|
+
{{ t('orders.pagination.summary', { from: (page - 1) * pageSize + 1, to: Math.min(page * pageSize, total), total }) }}
|
|
294
|
+
</span>
|
|
295
|
+
<div class="flex items-center gap-2">
|
|
296
|
+
<UButton
|
|
297
|
+
:icon="icon('chevron-left')"
|
|
298
|
+
color="neutral"
|
|
299
|
+
variant="outline"
|
|
300
|
+
:disabled="page <= 1"
|
|
301
|
+
:label="t('orders.pagination.prev')"
|
|
302
|
+
@click="prevPage"
|
|
303
|
+
/>
|
|
304
|
+
<UButton
|
|
305
|
+
:icon="icon('chevron-right')"
|
|
306
|
+
color="neutral"
|
|
307
|
+
variant="outline"
|
|
308
|
+
trailing
|
|
309
|
+
:disabled="page >= pageCount"
|
|
310
|
+
:label="t('orders.pagination.next')"
|
|
311
|
+
@click="nextPage"
|
|
312
|
+
/>
|
|
313
|
+
</div>
|
|
314
|
+
</div>
|
|
279
315
|
</template>
|
|
280
316
|
</div>
|
|
281
317
|
</template>
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { accountApi } from "../api/account";
|
|
2
2
|
import type { AccountOrder, AccountOrderListResponse } from "../interfaces/account/order-list";
|
|
3
3
|
|
|
4
|
+
const PAGE_SIZE = 20;
|
|
5
|
+
|
|
4
6
|
export const useAccountOrders = () => {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const page = ref(1);
|
|
8
|
+
|
|
9
|
+
const { data, status, error, refresh } = useFetch<AccountOrderListResponse>(
|
|
10
|
+
() => `${accountApi.orders()}?offset=${(page.value - 1) * PAGE_SIZE}&limit=${PAGE_SIZE}`,
|
|
11
|
+
{
|
|
12
|
+
key: "account-orders",
|
|
13
|
+
default: () => ({ orders: [] as AccountOrder[] }),
|
|
14
|
+
watch: [page],
|
|
15
|
+
},
|
|
16
|
+
);
|
|
9
17
|
|
|
10
18
|
const orders = computed(() => data.value.orders);
|
|
19
|
+
const total = computed(() => data.value.total ?? orders.value.length);
|
|
11
20
|
|
|
12
21
|
return {
|
|
13
22
|
orders,
|
|
23
|
+
total,
|
|
24
|
+
page,
|
|
25
|
+
pageSize: PAGE_SIZE,
|
|
14
26
|
status,
|
|
15
27
|
error,
|
|
16
28
|
refresh,
|
|
@@ -50,4 +50,8 @@ export interface AccountOrder {
|
|
|
50
50
|
|
|
51
51
|
export interface AccountOrderListResponse {
|
|
52
52
|
readonly orders: AccountOrder[];
|
|
53
|
+
/** Total orders for the contact (server-paginated history). */
|
|
54
|
+
readonly total?: number;
|
|
55
|
+
/** More pages beyond this window. */
|
|
56
|
+
readonly hasMore?: boolean;
|
|
53
57
|
}
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"orders": {
|
|
57
57
|
"title": "Ihre Bestellungen",
|
|
58
58
|
"description": "Alle Ihre bisherigen Bestellungen im Überblick.",
|
|
59
|
+
"pagination": { "summary": "{from}–{to} von {total} Bestellungen", "prev": "Zurück", "next": "Weiter" },
|
|
59
60
|
"errorTitle": "Bestellungen konnten nicht geladen werden",
|
|
60
61
|
"errorDescription": "Bitte versuchen Sie es später erneut.",
|
|
61
62
|
"empty": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"orders": {
|
|
57
57
|
"title": "Your orders",
|
|
58
58
|
"description": "View and track all your past orders.",
|
|
59
|
+
"pagination": { "summary": "{from}–{to} of {total} orders", "prev": "Back", "next": "Next" },
|
|
59
60
|
"errorTitle": "Orders could not be loaded",
|
|
60
61
|
"errorDescription": "Please try again later.",
|
|
61
62
|
"empty": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Cover — revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@formkit/vue": "^1.6.0",
|
|
39
39
|
"@iconify-json/lucide": "^1.2.111",
|
|
40
40
|
"@internationalized/date": "^3.12.0",
|
|
41
|
-
"@revenexx/sdk": "^0.0.
|
|
41
|
+
"@revenexx/sdk": "^0.0.10",
|
|
42
42
|
"@revenexx/storage-model-viewer": "^0.3.0",
|
|
43
43
|
"@vueuse/core": "^14.3.0",
|
|
44
44
|
"typesense": "^3.0.5"
|
|
@@ -19,20 +19,32 @@ export default defineEventHandler(async (event): Promise<AccountOrderListRespons
|
|
|
19
19
|
}
|
|
20
20
|
try {
|
|
21
21
|
const sdk = useRevenexxSdk();
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
//
|
|
22
|
+
// Server-paginated: page through the contact's full history.
|
|
23
|
+
const q = getQuery(event);
|
|
24
|
+
const limit = Math.min(Math.max(Number(q.limit) || LIVE_HISTORY_LIMIT, 1), 100);
|
|
25
|
+
const offset = Math.max(Number(q.offset) || 0, 0);
|
|
26
|
+
// Typed list call (orders.list now declares its query parameters —
|
|
27
|
+
// @revenexx/sdk >= 0.0.9). order=created_at.desc is REQUIRED: without
|
|
28
|
+
// it mountCrud returns the oldest rows first, so with a limit the
|
|
29
|
+
// NEWEST orders fall outside the window and never show. created_at is
|
|
30
|
+
// not-null (placed_at can be null), so it sorts deterministically.
|
|
31
|
+
// The list response stays untyped (the page schema is unnamed), so
|
|
32
|
+
// cast to the known list shape.
|
|
33
|
+
const { items, page } = await sdk.orders.ordersList({
|
|
34
|
+
contactId, limit, offset, order: "created_at.desc",
|
|
35
|
+
}) as unknown as {
|
|
36
|
+
items: LiveOrder[];
|
|
37
|
+
page?: { total?: number; hasMore?: boolean };
|
|
38
|
+
};
|
|
39
|
+
// The list rows carry no positions — load the aggregates (one page
|
|
40
|
+
// at a time, so this stays a bounded fan-out).
|
|
29
41
|
const aggregates = await Promise.all(
|
|
30
42
|
items.map(async row => await sdk.orders.ordersGet({ id: row.id }) as unknown as LiveOrder),
|
|
31
43
|
);
|
|
32
44
|
const orders = aggregates
|
|
33
45
|
.sort((a, b) => (b.placed_at ?? b.created_at).localeCompare(a.placed_at ?? a.created_at))
|
|
34
46
|
.map(mapLiveOrderToAccount);
|
|
35
|
-
return { orders };
|
|
47
|
+
return { orders, total: page?.total ?? offset + orders.length, hasMore: page?.hasMore ?? false };
|
|
36
48
|
}
|
|
37
49
|
catch (err) {
|
|
38
50
|
getLogService().error("Live order history failed", apiErrorContext(err));
|
|
@@ -76,13 +76,12 @@ function toCoverPosition(item: AppItem): OrderListPosition {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* cover position → the gateway's item payload.
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* TODO(sdk-generator): deep-convert nested object params so this cast can go.
|
|
79
|
+
* cover position → the gateway's item payload. `Models.OrderListItemInput`
|
|
80
|
+
* is snake_case (tax_rate, cost_center_id, …), so we build snake_case keys
|
|
81
|
+
* that match the typed shape directly. (The SDK also deep-converts nested
|
|
82
|
+
* camelCase keys since @revenexx/sdk >= 0.0.10 / DX-55, but building the
|
|
83
|
+
* wire keys here keeps this type-aligned with the model.) The conditional
|
|
84
|
+
* spreads still need a cast for exactness.
|
|
86
85
|
*/
|
|
87
86
|
function toItemInput(position: OrderListPosition): Models.OrderListItemInput {
|
|
88
87
|
const item: Record<string, unknown> = {
|
|
@@ -136,9 +136,10 @@ export function mapLiveOrderToAccount(order: LiveOrder): AccountOrder {
|
|
|
136
136
|
/** Fetch one live order by its display number (the account history id). */
|
|
137
137
|
export async function getLiveOrderByNumber(number: string): Promise<LiveOrder | null> {
|
|
138
138
|
const sdk = useRevenexxSdk();
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
139
|
+
// Typed list filter — orders.list now declares its query parameters
|
|
140
|
+
// (@revenexx/sdk >= 0.0.10). The list response stays untyped (unnamed page
|
|
141
|
+
// schema), so cast to the known shape.
|
|
142
|
+
const { items } = await sdk.orders.ordersList({ number, limit: 1 }) as unknown as { items: LiveOrder[] };
|
|
142
143
|
const row = items[0];
|
|
143
144
|
if (!row) {
|
|
144
145
|
return null;
|