@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.
Files changed (30) hide show
  1. package/app/api/account.ts +4 -0
  2. package/app/app.config.ts +2 -0
  3. package/app/components/account/orders/AccountOrderDetail.vue +198 -2
  4. package/app/components/account/organization/AccountOrganization.vue +159 -0
  5. package/app/components/account/team/AccountTeam.vue +346 -0
  6. package/app/composables/useAccountOrganization.ts +25 -0
  7. package/app/composables/useAccountTeam.ts +34 -0
  8. package/app/config/navigation.ts +2 -1
  9. package/app/interfaces/account/order-list.ts +13 -0
  10. package/app/interfaces/account/organization.ts +19 -0
  11. package/app/interfaces/account/team.ts +25 -0
  12. package/i18n/locales/de/account.json +86 -0
  13. package/i18n/locales/en/account.json +86 -0
  14. package/package.json +2 -2
  15. package/server/api/account/orders/[id]/return.post.ts +69 -0
  16. package/server/api/account/orders/[id].get.ts +27 -2
  17. package/server/api/account/organization.get.ts +5 -0
  18. package/server/api/account/organization.put.ts +9 -0
  19. package/server/api/account/team/[id].put.ts +21 -0
  20. package/server/api/account/team.get.ts +5 -0
  21. package/server/api/account/team.post.ts +21 -0
  22. package/server/interfaces/organization.ts +16 -0
  23. package/server/interfaces/team.ts +17 -0
  24. package/server/services/ApiOrganizationService.ts +68 -0
  25. package/server/services/ApiTeamService.ts +109 -0
  26. package/server/services/MockOrganizationService.ts +29 -0
  27. package/server/services/MockTeamService.ts +48 -0
  28. package/server/utils/liveOrders.ts +68 -3
  29. package/server/utils/organizationService.ts +25 -0
  30. package/server/utils/teamService.ts +25 -0
@@ -0,0 +1,346 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * The buyer's company team (contacts) — a data table of members with an
4
+ * Invite button opening the create modal, and a per-row edit action that
5
+ * changes the member's role. Backed by the team service
6
+ * (customers.contacts on the live API). Private buyers (no organization in
7
+ * the session) get an empty state.
8
+ */
9
+ import type { TableColumn } from "@nuxt/ui";
10
+
11
+ import type { AccountTeamMember, AccountTeamMemberFormState, AccountTeamRole, AccountTeamStatus } from "../../../interfaces/account/team";
12
+
13
+ const { icon } = useIcons();
14
+ const { t } = useI18n();
15
+ const toast = useToast();
16
+ const { members, status, error, inviteMember, updateMemberRole } = useAccountTeam();
17
+ const { tableUi } = useDataTable();
18
+
19
+ const ROLES: AccountTeamRole[] = ["buyer", "approver", "admin", "requester"];
20
+
21
+ const roleColors: Record<AccountTeamRole, "primary" | "info" | "warning" | "neutral"> = {
22
+ admin: "primary",
23
+ approver: "warning",
24
+ buyer: "info",
25
+ requester: "neutral",
26
+ };
27
+
28
+ const statusColors: Record<AccountTeamStatus, "success" | "warning" | "error"> = {
29
+ active: "success",
30
+ invited: "warning",
31
+ blocked: "error",
32
+ };
33
+
34
+ const roleItems = computed(() =>
35
+ ROLES.map(value => ({ value, label: t(`team.roles.${value}`) })),
36
+ );
37
+
38
+ /* ---- search ------------------------------------------------------------ */
39
+ const search = ref("");
40
+
41
+ const filtered = computed(() => {
42
+ const query = search.value.trim().toLowerCase();
43
+ if (!query) {
44
+ return members.value;
45
+ }
46
+ return members.value.filter(member =>
47
+ [`${member.firstName} ${member.lastName}`, member.email, t(`team.roles.${member.role}`)]
48
+ .some(value => value.toLowerCase().includes(query)),
49
+ );
50
+ });
51
+
52
+ /* ---- columns + sorting ------------------------------------------------- */
53
+ const sorting = ref([{ id: "name", desc: false }]);
54
+
55
+ const columns = computed<TableColumn<AccountTeamMember>[]>(() => [
56
+ {
57
+ id: "name",
58
+ accessorFn: row => `${row.firstName} ${row.lastName}`.trim(),
59
+ header: t("team.columns.name"),
60
+ },
61
+ { accessorKey: "email", header: t("team.columns.email") },
62
+ { accessorKey: "role", header: t("team.columns.role"), enableSorting: false },
63
+ { accessorKey: "status", header: t("team.columns.status"), enableSorting: false },
64
+ { id: "actions", header: "", enableSorting: false },
65
+ ]);
66
+
67
+ /* ---- invite modal ------------------------------------------------------ */
68
+ const inviting = ref(false);
69
+ const savingInvite = ref(false);
70
+ const inviteForm = reactive<AccountTeamMemberFormState>({ email: "", firstName: "", lastName: "", role: "buyer" });
71
+
72
+ function openInvite(): void {
73
+ inviteForm.email = "";
74
+ inviteForm.firstName = "";
75
+ inviteForm.lastName = "";
76
+ inviteForm.role = "buyer";
77
+ inviting.value = true;
78
+ }
79
+
80
+ async function saveInvite(): Promise<void> {
81
+ if (!inviteForm.email.trim()) {
82
+ return;
83
+ }
84
+ savingInvite.value = true;
85
+ try {
86
+ await inviteMember({
87
+ email: inviteForm.email.trim(),
88
+ firstName: inviteForm.firstName.trim(),
89
+ lastName: inviteForm.lastName.trim(),
90
+ role: inviteForm.role,
91
+ });
92
+ inviting.value = false;
93
+ toast.add({ title: t("team.saved"), color: "success", icon: icon("success"), duration: 2000 });
94
+ }
95
+ catch {
96
+ toast.add({ title: t("team.saveError"), color: "error", icon: icon("error"), duration: 3000 });
97
+ }
98
+ finally {
99
+ savingInvite.value = false;
100
+ }
101
+ }
102
+
103
+ /* ---- edit-role modal --------------------------------------------------- */
104
+ const editing = ref(false);
105
+ const savingEdit = ref(false);
106
+ const editTarget = ref<AccountTeamMember | null>(null);
107
+ const editRole = ref<AccountTeamRole>("buyer");
108
+
109
+ function openEdit(member: AccountTeamMember): void {
110
+ editTarget.value = member;
111
+ editRole.value = member.role;
112
+ editing.value = true;
113
+ }
114
+
115
+ async function saveEdit(): Promise<void> {
116
+ if (!editTarget.value) {
117
+ return;
118
+ }
119
+ savingEdit.value = true;
120
+ try {
121
+ await updateMemberRole(editTarget.value.id, editRole.value);
122
+ editing.value = false;
123
+ toast.add({ title: t("team.saved"), color: "success", icon: icon("success"), duration: 2000 });
124
+ }
125
+ catch {
126
+ toast.add({ title: t("team.saveError"), color: "error", icon: icon("error"), duration: 3000 });
127
+ }
128
+ finally {
129
+ savingEdit.value = false;
130
+ }
131
+ }
132
+ </script>
133
+
134
+ <template>
135
+ <div>
136
+ <UiFeedbackErrorBoundary
137
+ v-if="error"
138
+ :title="t('team.errorTitle')"
139
+ :description="t('team.errorDescription')"
140
+ :show-retry="false"
141
+ />
142
+
143
+ <template v-else>
144
+ <UiTableToolbar
145
+ v-model:search="search"
146
+ :search-placeholder="t('team.searchPlaceholder')"
147
+ >
148
+ <template #actions>
149
+ <UButton
150
+ color="primary"
151
+ tabindex="0"
152
+ :icon="icon('plus')"
153
+ :label="t('team.invite')"
154
+ @click="openInvite"
155
+ />
156
+ </template>
157
+ </UiTableToolbar>
158
+
159
+ <UTable
160
+ v-model:sorting="sorting"
161
+ :data="filtered"
162
+ :columns="columns"
163
+ :loading="status === 'pending'"
164
+ :ui="tableUi"
165
+ >
166
+ <template #name-header="{ column }">
167
+ <UiTableSortButton
168
+ :column="column"
169
+ :label="t('team.columns.name')"
170
+ />
171
+ </template>
172
+ <template #email-header="{ column }">
173
+ <UiTableSortButton
174
+ :column="column"
175
+ :label="t('team.columns.email')"
176
+ />
177
+ </template>
178
+
179
+ <template #name-cell="{ row }">
180
+ <span class="font-semibold text-highlighted">
181
+ {{ `${row.original.firstName} ${row.original.lastName}`.trim() || '—' }}
182
+ </span>
183
+ <UBadge
184
+ v-if="row.original.isPrimary"
185
+ color="primary"
186
+ variant="subtle"
187
+ size="sm"
188
+ class="ml-1.5"
189
+ :label="t('team.primary')"
190
+ />
191
+ </template>
192
+ <template #role-cell="{ row }">
193
+ <UBadge
194
+ :color="roleColors[row.original.role]"
195
+ variant="subtle"
196
+ size="sm"
197
+ :label="t(`team.roles.${row.original.role}`)"
198
+ />
199
+ </template>
200
+ <template #status-cell="{ row }">
201
+ <UBadge
202
+ :color="statusColors[row.original.status]"
203
+ variant="outline"
204
+ size="sm"
205
+ :label="t(`team.statuses.${row.original.status}`)"
206
+ />
207
+ </template>
208
+ <template #actions-cell="{ row }">
209
+ <div class="flex items-center justify-end gap-1">
210
+ <UTooltip :text="t('team.editTitle')">
211
+ <UButton
212
+ :icon="icon('edit')"
213
+ color="neutral"
214
+ variant="ghost"
215
+ size="sm"
216
+ tabindex="0"
217
+ :aria-label="t('team.editTitle')"
218
+ @click="openEdit(row.original)"
219
+ />
220
+ </UTooltip>
221
+ </div>
222
+ </template>
223
+
224
+ <template #loading>
225
+ <div class="space-y-3 py-2">
226
+ <USkeleton
227
+ v-for="index in 5"
228
+ :key="index"
229
+ class="h-9 w-full"
230
+ />
231
+ </div>
232
+ </template>
233
+ <template #empty>
234
+ <UiFeedbackEmptyState
235
+ v-if="search"
236
+ :icon="icon('no-results')"
237
+ :title="t('table.noResults.title')"
238
+ :description="t('table.noResults.description')"
239
+ />
240
+ <UiFeedbackEmptyState
241
+ v-else
242
+ :icon="icon('users')"
243
+ :title="t('team.empty.title')"
244
+ :description="t('team.empty.description')"
245
+ />
246
+ </template>
247
+ </UTable>
248
+ </template>
249
+
250
+ <UModal
251
+ v-model:open="inviting"
252
+ :title="t('team.inviteTitle')"
253
+ >
254
+ <template #body>
255
+ <div class="space-y-4">
256
+ <UFormField
257
+ :label="t('team.columns.email')"
258
+ required
259
+ >
260
+ <UInput
261
+ v-model="inviteForm.email"
262
+ type="email"
263
+ class="w-full"
264
+ placeholder="name@firma.de"
265
+ />
266
+ </UFormField>
267
+ <div class="grid grid-cols-2 gap-4">
268
+ <UFormField :label="t('team.firstName')">
269
+ <UInput
270
+ v-model="inviteForm.firstName"
271
+ class="w-full"
272
+ />
273
+ </UFormField>
274
+ <UFormField :label="t('team.lastName')">
275
+ <UInput
276
+ v-model="inviteForm.lastName"
277
+ class="w-full"
278
+ />
279
+ </UFormField>
280
+ </div>
281
+ <UFormField :label="t('team.columns.role')">
282
+ <USelect
283
+ v-model="inviteForm.role"
284
+ :items="roleItems"
285
+ class="w-full"
286
+ />
287
+ </UFormField>
288
+ </div>
289
+ </template>
290
+ <template #footer>
291
+ <div class="flex items-center justify-end gap-2 w-full">
292
+ <UButton
293
+ color="neutral"
294
+ variant="ghost"
295
+ tabindex="0"
296
+ :label="t('team.cancel')"
297
+ @click="inviting = false"
298
+ />
299
+ <UButton
300
+ color="primary"
301
+ tabindex="0"
302
+ :loading="savingInvite"
303
+ :disabled="!inviteForm.email.trim()"
304
+ :label="t('team.invite')"
305
+ @click="saveInvite"
306
+ />
307
+ </div>
308
+ </template>
309
+ </UModal>
310
+
311
+ <UModal
312
+ v-model:open="editing"
313
+ :title="t('team.editTitle')"
314
+ >
315
+ <template #body>
316
+ <div class="space-y-4">
317
+ <UFormField :label="t('team.columns.role')">
318
+ <USelect
319
+ v-model="editRole"
320
+ :items="roleItems"
321
+ class="w-full"
322
+ />
323
+ </UFormField>
324
+ </div>
325
+ </template>
326
+ <template #footer>
327
+ <div class="flex items-center justify-end gap-2 w-full">
328
+ <UButton
329
+ color="neutral"
330
+ variant="ghost"
331
+ tabindex="0"
332
+ :label="t('team.cancel')"
333
+ @click="editing = false"
334
+ />
335
+ <UButton
336
+ color="primary"
337
+ tabindex="0"
338
+ :loading="savingEdit"
339
+ :label="t('team.save')"
340
+ @click="saveEdit"
341
+ />
342
+ </div>
343
+ </template>
344
+ </UModal>
345
+ </div>
346
+ </template>
@@ -0,0 +1,25 @@
1
+ import { accountApi } from "../api/account";
2
+ import type { AccountOrganization, AccountOrganizationFormState, AccountOrganizationResponse } from "../interfaces/account/organization";
3
+
4
+ export const useAccountOrganization = () => {
5
+ const { data, status, error, refresh } = useFetch<AccountOrganizationResponse>(
6
+ accountApi.organization(),
7
+ {
8
+ key: "account-organization",
9
+ default: () => ({ organization: null }),
10
+ },
11
+ );
12
+
13
+ const organization = computed(() => data.value.organization);
14
+
15
+ async function updateOrganization(formState: AccountOrganizationFormState): Promise<AccountOrganization> {
16
+ const updated = await $fetch<AccountOrganization>(accountApi.organization(), {
17
+ method: "PUT",
18
+ body: formState,
19
+ });
20
+ data.value = { organization: updated };
21
+ return updated;
22
+ }
23
+
24
+ return { organization, status, error, refresh, updateOrganization };
25
+ };
@@ -0,0 +1,34 @@
1
+ import { accountApi } from "../api/account";
2
+ import type { AccountTeamMember, AccountTeamMemberFormState, AccountTeamResponse, AccountTeamRole } from "../interfaces/account/team";
3
+
4
+ export const useAccountTeam = () => {
5
+ const { data, status, error, refresh } = useFetch<AccountTeamResponse>(
6
+ accountApi.team(),
7
+ {
8
+ key: "account-team",
9
+ default: () => ({ members: [] }),
10
+ },
11
+ );
12
+
13
+ const members = computed(() => data.value.members);
14
+
15
+ async function inviteMember(formState: AccountTeamMemberFormState): Promise<AccountTeamMember> {
16
+ const created = await $fetch<AccountTeamMember>(accountApi.team(), {
17
+ method: "POST",
18
+ body: formState,
19
+ });
20
+ data.value = { members: [...data.value.members, created] };
21
+ return created;
22
+ }
23
+
24
+ async function updateMemberRole(id: string, role: AccountTeamRole): Promise<AccountTeamMember> {
25
+ const updated = await $fetch<AccountTeamMember>(accountApi.teamMemberUpdate(id), {
26
+ method: "PUT",
27
+ body: { role },
28
+ });
29
+ data.value = { members: data.value.members.map(m => (m.id === id ? updated : m)) };
30
+ return updated;
31
+ }
32
+
33
+ return { members, status, error, refresh, inviteMember, updateMemberRole };
34
+ };
@@ -170,9 +170,10 @@ export const accountNavigation: AccountNavGroup[] = [
170
170
  links: [
171
171
  { labelKey: "account.nav.catalogs", icon: "book-2", to: "/account/catalogs" },
172
172
  { labelKey: "account.nav.accountSettings", icon: "user", to: "/account/profile", implemented: true },
173
+ { labelKey: "account.nav.organization", icon: "users", to: "/account/organization", implemented: true },
173
174
  { labelKey: "account.nav.orderSettings", icon: "settings", to: "/account/preferences", implemented: true },
174
175
  { labelKey: "account.nav.addresses", icon: "location", to: "/account/addresses", implemented: true },
175
- { labelKey: "account.nav.users", icon: "users", to: "/account/users" },
176
+ { labelKey: "account.nav.users", icon: "users", to: "/account/team", implemented: true },
176
177
  { labelKey: "account.nav.roles", icon: "key", to: "/account/roles" },
177
178
  { labelKey: "account.nav.customArticleNumbers", icon: "hash", to: "/account/custom-article-numbers" },
178
179
  ],
@@ -17,6 +17,17 @@ export interface AccountOrderPosition {
17
17
  readonly lineTotal: number;
18
18
  readonly categorySlug?: string;
19
19
  readonly subcategorySlug?: string;
20
+ /** The order_item id — needed to request a return for this position. */
21
+ readonly orderItemId?: string;
22
+ /** How many units of this position can still be returned (shipped − already returned). */
23
+ readonly returnableQuantity?: number;
24
+ }
25
+
26
+ export interface AccountOrderReturn {
27
+ readonly id: string;
28
+ readonly number: string;
29
+ readonly status: string;
30
+ readonly positions: { readonly name: string; readonly quantity: number }[];
20
31
  }
21
32
 
22
33
  export interface AccountOrder {
@@ -46,6 +57,8 @@ export interface AccountOrder {
46
57
  readonly progress?: { step: "ordered" | "processing" | "shipped" | "delivered"; date?: string }[];
47
58
  /** Approvers when the order awaits approval. */
48
59
  readonly approvers?: string[];
60
+ /** Returns already requested against this order. */
61
+ readonly returns?: AccountOrderReturn[];
49
62
  }
50
63
 
51
64
  export interface AccountOrderListResponse {
@@ -0,0 +1,19 @@
1
+ export type AccountOrganizationStatus = "active" | "blocked";
2
+
3
+ /** The buyer's own company, as shown on the account organization page. */
4
+ export interface AccountOrganization {
5
+ readonly id: string;
6
+ readonly name: string;
7
+ readonly vatId: string;
8
+ readonly status: AccountOrganizationStatus;
9
+ }
10
+
11
+ /** Editable company fields (the customers app's defined columns). */
12
+ export interface AccountOrganizationFormState {
13
+ name: string;
14
+ vatId: string;
15
+ }
16
+
17
+ export interface AccountOrganizationResponse {
18
+ readonly organization: AccountOrganization | null;
19
+ }
@@ -0,0 +1,25 @@
1
+ export type AccountTeamRole = "buyer" | "approver" | "admin" | "requester";
2
+ export type AccountTeamStatus = "invited" | "active" | "blocked";
3
+
4
+ /** A member (contact) of the buyer's company, as shown on the team page. */
5
+ export interface AccountTeamMember {
6
+ readonly id: string;
7
+ readonly firstName: string;
8
+ readonly lastName: string;
9
+ readonly email: string;
10
+ readonly role: AccountTeamRole;
11
+ readonly status: AccountTeamStatus;
12
+ readonly isPrimary: boolean;
13
+ }
14
+
15
+ /** Editable member fields (the invite form). */
16
+ export interface AccountTeamMemberFormState {
17
+ email: string;
18
+ firstName: string;
19
+ lastName: string;
20
+ role: AccountTeamRole;
21
+ }
22
+
23
+ export interface AccountTeamResponse {
24
+ readonly members: AccountTeamMember[];
25
+ }
@@ -96,6 +96,27 @@
96
96
  "refresh": "Aktualisieren",
97
97
  "notFound": "Bestellung nicht gefunden",
98
98
  "searchPlaceholder": "Nach Bestellnummer oder Artikel suchen …",
99
+ "returns": {
100
+ "requestReturn": "Rücksendung anfragen",
101
+ "modalTitle": "Rücksendung anfragen",
102
+ "reason": "Grund (optional)",
103
+ "reasonPlaceholder": "Warum möchten Sie diese Artikel zurücksenden?",
104
+ "quantity": "Menge",
105
+ "maxReturnable": "Bis zu {count} rücksendbar",
106
+ "submit": "Rücksendung absenden",
107
+ "cancel": "Abbrechen",
108
+ "success": "Rücksendung angefragt",
109
+ "error": "Rücksendung konnte nicht angefragt werden",
110
+ "existingTitle": "Rücksendungen",
111
+ "emptyReturnable": "Keine dieser Positionen kann zurückgesendet werden.",
112
+ "status": {
113
+ "requested": "Angefragt",
114
+ "approved": "Genehmigt",
115
+ "received": "Eingegangen",
116
+ "completed": "Abgeschlossen",
117
+ "rejected": "Abgelehnt"
118
+ }
119
+ },
99
120
  "detail": {
100
121
  "progressTitle": "Bestellstatus",
101
122
  "steps": {
@@ -186,6 +207,7 @@
186
207
  "iotDevices": "IoT-Geräte",
187
208
  "catalogs": "Kataloge",
188
209
  "accountSettings": "Stammdaten",
210
+ "organization": "Firmendaten",
189
211
  "addresses": "Adressen",
190
212
  "users": "Benutzer",
191
213
  "roles": "Rollen",
@@ -458,5 +480,69 @@
458
480
  "alwaysActive": "Immer in den aktiven Warenkorb legen",
459
481
  "alwaysActiveHint": "Beim Hinzufügen von Artikeln wird nicht mehr gefragt, in welchen Warenkorb die Position gelegt werden soll.",
460
482
  "saved": "Einstellung gespeichert"
483
+ },
484
+ "organization": {
485
+ "title": "Firmendaten",
486
+ "description": "Daten Ihres Unternehmens ansehen und bearbeiten.",
487
+ "companySection": "Unternehmen",
488
+ "edit": "Bearbeiten",
489
+ "editTitle": "Firmendaten bearbeiten",
490
+ "save": "Speichern",
491
+ "cancel": "Abbrechen",
492
+ "saved": "Firmendaten gespeichert",
493
+ "saveError": "Speichern fehlgeschlagen",
494
+ "errorTitle": "Firmendaten nicht verfügbar",
495
+ "errorDescription": "Die Firmendaten konnten nicht geladen werden.",
496
+ "fields": {
497
+ "name": "Firmenname",
498
+ "vatId": "USt-IdNr.",
499
+ "status": "Status"
500
+ },
501
+ "status": {
502
+ "active": "Aktiv",
503
+ "blocked": "Gesperrt"
504
+ },
505
+ "empty": {
506
+ "title": "Kein Unternehmen",
507
+ "description": "Ihr Konto ist keinem Unternehmen zugeordnet."
508
+ }
509
+ },
510
+ "team": {
511
+ "title": "Benutzer",
512
+ "description": "Verwalten Sie die Benutzer Ihres Unternehmens und deren Rollen.",
513
+ "searchPlaceholder": "Nach Name, E-Mail oder Rolle suchen …",
514
+ "invite": "Benutzer einladen",
515
+ "inviteTitle": "Benutzer einladen",
516
+ "editTitle": "Rolle ändern",
517
+ "primary": "Hauptkontakt",
518
+ "firstName": "Vorname",
519
+ "lastName": "Nachname",
520
+ "save": "Speichern",
521
+ "cancel": "Abbrechen",
522
+ "saved": "Gespeichert",
523
+ "saveError": "Speichern fehlgeschlagen",
524
+ "errorTitle": "Benutzer nicht verfügbar",
525
+ "errorDescription": "Die Benutzer konnten nicht geladen werden.",
526
+ "columns": {
527
+ "name": "Name",
528
+ "email": "E-Mail",
529
+ "role": "Rolle",
530
+ "status": "Status"
531
+ },
532
+ "roles": {
533
+ "buyer": "Einkäufer",
534
+ "approver": "Genehmiger",
535
+ "admin": "Administrator",
536
+ "requester": "Anforderer"
537
+ },
538
+ "statuses": {
539
+ "invited": "Eingeladen",
540
+ "active": "Aktiv",
541
+ "blocked": "Gesperrt"
542
+ },
543
+ "empty": {
544
+ "title": "Keine Benutzer",
545
+ "description": "Laden Sie über „Benutzer einladen“ den ersten Benutzer ein."
546
+ }
461
547
  }
462
548
  }