@revenexx/cover 0.2.6 → 0.2.8
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/api/account.ts +4 -0
- package/app/app.config.ts +2 -0
- package/app/components/account/orders/AccountOrderDetail.vue +198 -2
- package/app/components/account/organization/AccountOrganization.vue +159 -0
- package/app/components/account/team/AccountTeam.vue +346 -0
- package/app/composables/useAccountOrganization.ts +25 -0
- package/app/composables/useAccountTeam.ts +34 -0
- package/app/config/navigation.ts +2 -1
- package/app/interfaces/account/order-list.ts +13 -0
- package/app/interfaces/account/organization.ts +19 -0
- package/app/interfaces/account/team.ts +25 -0
- package/i18n/locales/de/account.json +86 -0
- package/i18n/locales/en/account.json +86 -0
- package/package.json +2 -2
- package/server/api/account/orders/[id]/return.post.ts +69 -0
- package/server/api/account/orders/[id].get.ts +27 -2
- package/server/api/account/organization.get.ts +5 -0
- package/server/api/account/organization.put.ts +9 -0
- package/server/api/account/team/[id].put.ts +21 -0
- package/server/api/account/team.get.ts +5 -0
- package/server/api/account/team.post.ts +21 -0
- package/server/interfaces/organization.ts +16 -0
- package/server/interfaces/team.ts +17 -0
- package/server/services/ApiOrganizationService.ts +68 -0
- package/server/services/ApiTeamService.ts +109 -0
- package/server/services/MockOrganizationService.ts +29 -0
- package/server/services/MockTeamService.ts +48 -0
- package/server/utils/liveOrders.ts +68 -3
- package/server/utils/organizationService.ts +25 -0
- package/server/utils/teamService.ts +25 -0
package/app/api/account.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export const accountApi = {
|
|
2
2
|
profile: () => "/api/account/profile",
|
|
3
3
|
orders: () => "/api/account/orders",
|
|
4
|
+
orderReturn: (id: string) => `/api/account/orders/${id}/return`,
|
|
4
5
|
addresses: () => "/api/account/addresses",
|
|
5
6
|
addressUpdate: (id: string) => `/api/account/address/${id}`,
|
|
6
7
|
addressCreate: () => "/api/account/address",
|
|
7
8
|
addressDelete: (id: string) => `/api/account/address/${id}`,
|
|
9
|
+
organization: () => "/api/account/organization",
|
|
10
|
+
team: () => "/api/account/team",
|
|
11
|
+
teamMemberUpdate: (id: string) => `/api/account/team/${id}`,
|
|
8
12
|
};
|
package/app/app.config.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { accountApi } from "../../../api/account";
|
|
2
3
|
import type { AccountOrder, AccountOrderStatus, AccountOrderPaymentStatus } from "../../../interfaces/account/order-list";
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -19,7 +20,7 @@ const cart = useCartStore();
|
|
|
19
20
|
const { getImage } = useProductImage();
|
|
20
21
|
const { formatCurrency } = useCartSummaryFormatting();
|
|
21
22
|
|
|
22
|
-
const { data: order, status, error } = useFetch<AccountOrder>(
|
|
23
|
+
const { data: order, status, error, refresh } = useFetch<AccountOrder>(
|
|
23
24
|
`/api/account/orders/${props.orderId}`,
|
|
24
25
|
{ key: `account-order:${props.orderId}` },
|
|
25
26
|
);
|
|
@@ -119,6 +120,82 @@ async function orderAgain(): Promise<void> {
|
|
|
119
120
|
});
|
|
120
121
|
await navigateTo(to("/cart"));
|
|
121
122
|
}
|
|
123
|
+
|
|
124
|
+
/* ---- self-service returns -------------------------------------------- */
|
|
125
|
+
/** Positions that still have units available to return. */
|
|
126
|
+
const returnablePositions = computed(() =>
|
|
127
|
+
(order.value?.positions ?? []).filter(p => (p.returnableQuantity ?? 0) > 0 && p.orderItemId));
|
|
128
|
+
|
|
129
|
+
const canRequestReturn = computed(() =>
|
|
130
|
+
(order.value?.status === "shipped" || order.value?.status === "delivered")
|
|
131
|
+
&& returnablePositions.value.length > 0);
|
|
132
|
+
|
|
133
|
+
const returnStatusColors: Record<string, "info" | "warning" | "success" | "neutral"> = {
|
|
134
|
+
requested: "warning",
|
|
135
|
+
approved: "info",
|
|
136
|
+
received: "info",
|
|
137
|
+
completed: "success",
|
|
138
|
+
rejected: "neutral",
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const returnOpen = ref(false);
|
|
142
|
+
const submittingReturn = ref(false);
|
|
143
|
+
const returnReason = ref("");
|
|
144
|
+
/** order_item id → quantity to return. */
|
|
145
|
+
const returnQuantities = reactive<Record<string, number>>({});
|
|
146
|
+
|
|
147
|
+
function openReturn(): void {
|
|
148
|
+
returnReason.value = "";
|
|
149
|
+
for (const key of Object.keys(returnQuantities)) {
|
|
150
|
+
delete returnQuantities[key];
|
|
151
|
+
}
|
|
152
|
+
for (const position of returnablePositions.value) {
|
|
153
|
+
if (position.orderItemId) {
|
|
154
|
+
returnQuantities[position.orderItemId] = 0;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
returnOpen.value = true;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const selectedReturnPositions = computed(() =>
|
|
161
|
+
returnablePositions.value
|
|
162
|
+
.filter(p => p.orderItemId && (returnQuantities[p.orderItemId] ?? 0) > 0)
|
|
163
|
+
.map(p => ({ orderItemId: p.orderItemId as string, quantity: returnQuantities[p.orderItemId as string]! })));
|
|
164
|
+
|
|
165
|
+
async function submitReturn(): Promise<void> {
|
|
166
|
+
if (!order.value || selectedReturnPositions.value.length === 0) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
submittingReturn.value = true;
|
|
170
|
+
try {
|
|
171
|
+
await $fetch(accountApi.orderReturn(order.value.id), {
|
|
172
|
+
method: "POST",
|
|
173
|
+
body: {
|
|
174
|
+
positions: selectedReturnPositions.value,
|
|
175
|
+
...(returnReason.value.trim() ? { reason: returnReason.value.trim() } : {}),
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
returnOpen.value = false;
|
|
179
|
+
toast.add({
|
|
180
|
+
title: t("orders.returns.success"),
|
|
181
|
+
color: "success",
|
|
182
|
+
icon: icon("success"),
|
|
183
|
+
duration: 2500,
|
|
184
|
+
});
|
|
185
|
+
await refresh();
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
toast.add({
|
|
189
|
+
title: t("orders.returns.error"),
|
|
190
|
+
color: "error",
|
|
191
|
+
icon: icon("error"),
|
|
192
|
+
duration: 3000,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
submittingReturn.value = false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
122
199
|
</script>
|
|
123
200
|
|
|
124
201
|
<template>
|
|
@@ -382,8 +459,62 @@ async function orderAgain(): Promise<void> {
|
|
|
382
459
|
</dl>
|
|
383
460
|
</section>
|
|
384
461
|
|
|
462
|
+
<!-- Existing returns -->
|
|
463
|
+
<section
|
|
464
|
+
v-if="order.returns?.length"
|
|
465
|
+
class="border border-(--ui-border) rounded-xl overflow-hidden"
|
|
466
|
+
>
|
|
467
|
+
<h2 class="px-4 sm:px-5 py-3 text-sm font-semibold text-highlighted bg-elevated/60 border-b border-(--ui-border)">
|
|
468
|
+
{{ t('orders.returns.existingTitle') }}
|
|
469
|
+
</h2>
|
|
470
|
+
<ul class="divide-y divide-(--ui-border) px-4 sm:px-5">
|
|
471
|
+
<li
|
|
472
|
+
v-for="ret in order.returns"
|
|
473
|
+
:key="ret.id"
|
|
474
|
+
class="py-3"
|
|
475
|
+
>
|
|
476
|
+
<div class="flex items-center gap-3">
|
|
477
|
+
<UIcon
|
|
478
|
+
:name="icon('package')"
|
|
479
|
+
class="size-5 text-primary shrink-0"
|
|
480
|
+
/>
|
|
481
|
+
<span class="text-sm font-medium text-highlighted">
|
|
482
|
+
{{ ret.number }}
|
|
483
|
+
</span>
|
|
484
|
+
<UBadge
|
|
485
|
+
class="ms-auto"
|
|
486
|
+
:color="returnStatusColors[ret.status] ?? 'neutral'"
|
|
487
|
+
variant="subtle"
|
|
488
|
+
size="sm"
|
|
489
|
+
:label="t(`orders.returns.status.${ret.status}`, ret.status)"
|
|
490
|
+
/>
|
|
491
|
+
</div>
|
|
492
|
+
<ul
|
|
493
|
+
v-if="ret.positions.length"
|
|
494
|
+
class="mt-1.5 ps-8 text-xs text-muted"
|
|
495
|
+
>
|
|
496
|
+
<li
|
|
497
|
+
v-for="(pos, posIndex) in ret.positions"
|
|
498
|
+
:key="posIndex"
|
|
499
|
+
>
|
|
500
|
+
{{ pos.quantity }}× {{ pos.name }}
|
|
501
|
+
</li>
|
|
502
|
+
</ul>
|
|
503
|
+
</li>
|
|
504
|
+
</ul>
|
|
505
|
+
</section>
|
|
506
|
+
|
|
385
507
|
<!-- Actions -->
|
|
386
|
-
<div class="flex justify-end">
|
|
508
|
+
<div class="flex flex-wrap justify-end gap-2">
|
|
509
|
+
<UButton
|
|
510
|
+
v-if="canRequestReturn"
|
|
511
|
+
color="neutral"
|
|
512
|
+
variant="outline"
|
|
513
|
+
tabindex="0"
|
|
514
|
+
:icon="icon('package')"
|
|
515
|
+
:label="t('orders.returns.requestReturn')"
|
|
516
|
+
@click="openReturn"
|
|
517
|
+
/>
|
|
387
518
|
<UButton
|
|
388
519
|
v-if="order.status !== 'cancelled'"
|
|
389
520
|
color="primary"
|
|
@@ -394,6 +525,71 @@ async function orderAgain(): Promise<void> {
|
|
|
394
525
|
@click="orderAgain"
|
|
395
526
|
/>
|
|
396
527
|
</div>
|
|
528
|
+
|
|
529
|
+
<!-- Request return modal -->
|
|
530
|
+
<UModal
|
|
531
|
+
v-model:open="returnOpen"
|
|
532
|
+
:title="t('orders.returns.modalTitle')"
|
|
533
|
+
>
|
|
534
|
+
<template #body>
|
|
535
|
+
<div class="space-y-4">
|
|
536
|
+
<p
|
|
537
|
+
v-if="returnablePositions.length === 0"
|
|
538
|
+
class="text-sm text-muted"
|
|
539
|
+
>
|
|
540
|
+
{{ t('orders.returns.emptyReturnable') }}
|
|
541
|
+
</p>
|
|
542
|
+
<template v-else>
|
|
543
|
+
<div
|
|
544
|
+
v-for="position in returnablePositions"
|
|
545
|
+
:key="position.orderItemId"
|
|
546
|
+
class="flex items-center gap-3"
|
|
547
|
+
>
|
|
548
|
+
<div class="min-w-0 flex-1">
|
|
549
|
+
<p class="text-sm font-medium text-highlighted truncate">
|
|
550
|
+
{{ position.name }}
|
|
551
|
+
</p>
|
|
552
|
+
<p class="text-xs text-muted">
|
|
553
|
+
{{ t('orders.returns.maxReturnable', { count: position.returnableQuantity ?? 0 }) }}
|
|
554
|
+
</p>
|
|
555
|
+
</div>
|
|
556
|
+
<UInputNumber
|
|
557
|
+
v-model="returnQuantities[position.orderItemId as string]"
|
|
558
|
+
:min="0"
|
|
559
|
+
:max="position.returnableQuantity ?? 0"
|
|
560
|
+
class="w-28 shrink-0"
|
|
561
|
+
:aria-label="t('orders.returns.quantity')"
|
|
562
|
+
/>
|
|
563
|
+
</div>
|
|
564
|
+
<UFormField :label="t('orders.returns.reason')">
|
|
565
|
+
<UTextarea
|
|
566
|
+
v-model="returnReason"
|
|
567
|
+
class="w-full"
|
|
568
|
+
:rows="3"
|
|
569
|
+
:placeholder="t('orders.returns.reasonPlaceholder')"
|
|
570
|
+
/>
|
|
571
|
+
</UFormField>
|
|
572
|
+
</template>
|
|
573
|
+
</div>
|
|
574
|
+
</template>
|
|
575
|
+
<template #footer>
|
|
576
|
+
<div class="flex items-center justify-end gap-2 w-full">
|
|
577
|
+
<UButton
|
|
578
|
+
color="neutral"
|
|
579
|
+
variant="ghost"
|
|
580
|
+
:label="t('orders.returns.cancel')"
|
|
581
|
+
@click="returnOpen = false"
|
|
582
|
+
/>
|
|
583
|
+
<UButton
|
|
584
|
+
color="primary"
|
|
585
|
+
:loading="submittingReturn"
|
|
586
|
+
:disabled="selectedReturnPositions.length === 0"
|
|
587
|
+
:label="t('orders.returns.submit')"
|
|
588
|
+
@click="submitReturn"
|
|
589
|
+
/>
|
|
590
|
+
</div>
|
|
591
|
+
</template>
|
|
592
|
+
</UModal>
|
|
397
593
|
</div>
|
|
398
594
|
</div>
|
|
399
595
|
</template>
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The buyer's own company (organization) — read view of the company identity
|
|
4
|
+
* (name, VAT id, status) with an edit modal for the touchable fields. Backed
|
|
5
|
+
* by the organization service (customers.organizations on the live API).
|
|
6
|
+
* Private buyers (no organization in the session) get an empty state.
|
|
7
|
+
*/
|
|
8
|
+
import type { AccountOrganizationFormState } from "../../../interfaces/account/organization";
|
|
9
|
+
|
|
10
|
+
const { icon } = useIcons();
|
|
11
|
+
const { t } = useI18n();
|
|
12
|
+
const toast = useToast();
|
|
13
|
+
const { organization, status, error, updateOrganization } = useAccountOrganization();
|
|
14
|
+
|
|
15
|
+
const editing = ref(false);
|
|
16
|
+
const saving = ref(false);
|
|
17
|
+
const form = reactive<AccountOrganizationFormState>({ name: "", vatId: "" });
|
|
18
|
+
|
|
19
|
+
function openEdit(): void {
|
|
20
|
+
form.name = organization.value?.name ?? "";
|
|
21
|
+
form.vatId = organization.value?.vatId ?? "";
|
|
22
|
+
editing.value = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function save(): Promise<void> {
|
|
26
|
+
if (!form.name.trim()) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
saving.value = true;
|
|
30
|
+
try {
|
|
31
|
+
await updateOrganization({ name: form.name.trim(), vatId: form.vatId.trim() });
|
|
32
|
+
editing.value = false;
|
|
33
|
+
toast.add({ title: t("organization.saved"), color: "success", icon: icon("success"), duration: 2000 });
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
toast.add({ title: t("organization.saveError"), color: "error", icon: icon("error"), duration: 3000 });
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
saving.value = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<div>
|
|
46
|
+
<UiFeedbackErrorBoundary
|
|
47
|
+
v-if="error"
|
|
48
|
+
:title="t('organization.errorTitle')"
|
|
49
|
+
:description="t('organization.errorDescription')"
|
|
50
|
+
:show-retry="false"
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<div
|
|
54
|
+
v-else-if="status === 'pending'"
|
|
55
|
+
class="space-y-3"
|
|
56
|
+
>
|
|
57
|
+
<USkeleton class="h-9 w-full" />
|
|
58
|
+
<USkeleton class="h-9 w-2/3" />
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<UiFeedbackEmptyState
|
|
62
|
+
v-else-if="!organization"
|
|
63
|
+
:icon="icon('user')"
|
|
64
|
+
:title="t('organization.empty.title')"
|
|
65
|
+
:description="t('organization.empty.description')"
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
<section
|
|
69
|
+
v-else
|
|
70
|
+
class="border border-(--ui-border) rounded-xl overflow-hidden"
|
|
71
|
+
>
|
|
72
|
+
<div class="flex items-center justify-between gap-3 px-4 sm:px-5 py-3 bg-elevated/60 border-b border-(--ui-border)">
|
|
73
|
+
<h2 class="text-sm font-semibold text-highlighted">
|
|
74
|
+
{{ t('organization.companySection') }}
|
|
75
|
+
</h2>
|
|
76
|
+
<UButton
|
|
77
|
+
color="neutral"
|
|
78
|
+
variant="outline"
|
|
79
|
+
size="sm"
|
|
80
|
+
:icon="icon('edit')"
|
|
81
|
+
:label="t('organization.edit')"
|
|
82
|
+
@click="openEdit"
|
|
83
|
+
/>
|
|
84
|
+
</div>
|
|
85
|
+
<dl class="p-4 sm:p-5 grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-4">
|
|
86
|
+
<div>
|
|
87
|
+
<dt class="text-xs text-muted">
|
|
88
|
+
{{ t('organization.fields.name') }}
|
|
89
|
+
</dt>
|
|
90
|
+
<dd class="text-highlighted font-medium">
|
|
91
|
+
{{ organization.name || '—' }}
|
|
92
|
+
</dd>
|
|
93
|
+
</div>
|
|
94
|
+
<div>
|
|
95
|
+
<dt class="text-xs text-muted">
|
|
96
|
+
{{ t('organization.fields.vatId') }}
|
|
97
|
+
</dt>
|
|
98
|
+
<dd class="text-highlighted tabular-nums">
|
|
99
|
+
{{ organization.vatId || '—' }}
|
|
100
|
+
</dd>
|
|
101
|
+
</div>
|
|
102
|
+
<div>
|
|
103
|
+
<dt class="text-xs text-muted">
|
|
104
|
+
{{ t('organization.fields.status') }}
|
|
105
|
+
</dt>
|
|
106
|
+
<dd>
|
|
107
|
+
<UBadge
|
|
108
|
+
:color="organization.status === 'active' ? 'success' : 'error'"
|
|
109
|
+
variant="subtle"
|
|
110
|
+
size="sm"
|
|
111
|
+
:label="t(`organization.status.${organization.status}`)"
|
|
112
|
+
/>
|
|
113
|
+
</dd>
|
|
114
|
+
</div>
|
|
115
|
+
</dl>
|
|
116
|
+
</section>
|
|
117
|
+
|
|
118
|
+
<UModal
|
|
119
|
+
v-model:open="editing"
|
|
120
|
+
:title="t('organization.editTitle')"
|
|
121
|
+
>
|
|
122
|
+
<template #body>
|
|
123
|
+
<div class="space-y-4">
|
|
124
|
+
<UFormField :label="t('organization.fields.name')" required>
|
|
125
|
+
<UInput
|
|
126
|
+
v-model="form.name"
|
|
127
|
+
class="w-full"
|
|
128
|
+
:placeholder="t('organization.fields.name')"
|
|
129
|
+
/>
|
|
130
|
+
</UFormField>
|
|
131
|
+
<UFormField :label="t('organization.fields.vatId')">
|
|
132
|
+
<UInput
|
|
133
|
+
v-model="form.vatId"
|
|
134
|
+
class="w-full"
|
|
135
|
+
placeholder="DE123456789"
|
|
136
|
+
/>
|
|
137
|
+
</UFormField>
|
|
138
|
+
</div>
|
|
139
|
+
</template>
|
|
140
|
+
<template #footer>
|
|
141
|
+
<div class="flex items-center justify-end gap-2 w-full">
|
|
142
|
+
<UButton
|
|
143
|
+
color="neutral"
|
|
144
|
+
variant="ghost"
|
|
145
|
+
:label="t('organization.cancel')"
|
|
146
|
+
@click="editing = false"
|
|
147
|
+
/>
|
|
148
|
+
<UButton
|
|
149
|
+
color="primary"
|
|
150
|
+
:loading="saving"
|
|
151
|
+
:disabled="!form.name.trim()"
|
|
152
|
+
:label="t('organization.save')"
|
|
153
|
+
@click="save"
|
|
154
|
+
/>
|
|
155
|
+
</div>
|
|
156
|
+
</template>
|
|
157
|
+
</UModal>
|
|
158
|
+
</div>
|
|
159
|
+
</template>
|