@revenexx/cover 0.19.0 → 0.21.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/app/api/marketing.ts +24 -0
- package/app/app.config.ts +22 -0
- package/app/components/account/approvals/AccountPendingApprovals.vue +54 -13
- package/app/components/account/approvals/AccountPendingOrderDetail.vue +156 -0
- package/app/components/account/loyalty/AccountLoyalty.vue +205 -0
- package/app/components/account/orders/AccountOrderContents.vue +142 -0
- package/app/components/account/orders/AccountOrderDetail.vue +16 -178
- package/app/components/account/orders/AccountOrderHead.vue +79 -0
- package/app/components/account/orders/AccountOrderPay.vue +13 -3
- package/app/components/account/orders/AccountOrdersTable.vue +2 -0
- package/app/components/cart/position/CartPosition.vue +6 -6
- package/app/components/cart/view/CartSummaryPanel.vue +4 -0
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +20 -8
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +4 -0
- package/app/components/checkout/return/CheckoutPaymentReturn.vue +209 -0
- package/app/components/loyalty/hint/LoyaltyPerkHint.vue +28 -0
- package/app/components/newsletter/confirm/NewsletterConfirmation.vue +54 -0
- package/app/components/newsletter/preferences/NewsletterPreferenceCentre.vue +183 -0
- package/app/components/newsletter/state/NewsletterLinkRefusal.vue +45 -0
- package/app/components/review/form/ReviewForm.vue +211 -0
- package/app/composables/useAccountDashboard.ts +1 -0
- package/app/composables/useCampaignAttribution.ts +120 -0
- package/app/composables/useCheckoutOnePage.ts +80 -7
- package/app/composables/useLoyaltyAccount.ts +79 -0
- package/app/composables/useMarketingConsent.ts +49 -0
- package/app/composables/usePendingApprovals.ts +11 -3
- package/app/composables/usePspCheckout.ts +130 -29
- package/app/config/colorRamp.ts +55 -0
- package/app/config/navigation.ts +1 -1
- package/app/config/quickActions.ts +1 -0
- package/app/interfaces/account/approvals.ts +34 -1
- package/app/interfaces/account/order-list.ts +8 -1
- package/app/interfaces/cart-calculation.ts +7 -1
- package/app/interfaces/cart-item.ts +12 -0
- package/app/interfaces/payment.ts +22 -0
- package/app/pages/account/points.vue +26 -0
- package/app/pages/checkout/payment-return.vue +17 -0
- package/app/pages/newsletter/confirm/[token].vue +23 -0
- package/app/pages/newsletter/preferences/[token].vue +24 -0
- package/app/pages/review/[token].vue +23 -0
- package/app/payments/psp/novalnet.ts +255 -0
- package/app/payments/psp/registry.ts +7 -3
- package/app/payments/psp/rules.ts +99 -0
- package/app/payments/psp/stripe.ts +6 -2
- package/app/payments/psp/types.ts +72 -6
- package/app/plugins/campaign-attribution.client.ts +47 -0
- package/app/shared/campaignAttribution.ts +281 -0
- package/app/shared/personalisation.ts +107 -0
- package/app/shared/pspReturn.ts +62 -0
- package/i18n/locales/de/account.json +20 -5
- package/i18n/locales/de/cart.json +4 -2
- package/i18n/locales/de/checkout.json +32 -0
- package/i18n/locales/de/editor.json +10 -0
- package/i18n/locales/de/marketing.json +71 -0
- package/i18n/locales/en/account.json +20 -5
- package/i18n/locales/en/cart.json +4 -2
- package/i18n/locales/en/checkout.json +32 -0
- package/i18n/locales/en/editor.json +10 -0
- package/i18n/locales/en/marketing.json +71 -0
- package/package.json +3 -2
- package/server/api/account/orders/[id]/pay.post.ts +47 -7
- package/server/api/account/pending-approvals/index.get.ts +16 -12
- package/server/api/account/pending-approvals/orders/[number]/approve.post.ts +6 -0
- package/server/api/account/pending-approvals/orders/[number]/reject.post.ts +6 -0
- package/server/api/account/pending-approvals/orders/[number].get.ts +15 -0
- package/server/api/campaigns/touches.post.ts +42 -0
- package/server/api/cart/attribution.put.ts +31 -0
- package/server/api/checkout/payment-return.post.ts +30 -0
- package/server/api/loyalty/account.get.ts +27 -0
- package/server/api/newsletter/confirm/[token].post.ts +21 -0
- package/server/api/newsletter/preferences/[token].get.ts +14 -0
- package/server/api/newsletter/preferences/[token].post.ts +36 -0
- package/server/api/orders/index.post.ts +47 -12
- package/server/api/payment/methods.post.ts +19 -9
- package/server/api/payment/psp-config.get.ts +5 -4
- package/server/api/reviews/requests/[token].get.ts +14 -0
- package/server/api/reviews/submit/[token].post.ts +31 -0
- package/server/interfaces/cart.ts +6 -0
- package/server/interfaces/marketing.ts +150 -0
- package/server/services/ApiCartService.ts +22 -0
- package/server/services/ApiMarketingService.ts +292 -0
- package/server/services/ApiProductService.ts +6 -2
- package/server/services/MockCartCalculationService.ts +29 -0
- package/server/services/MockMarketingService.ts +178 -0
- package/server/utils/cartItemHints.ts +29 -0
- package/server/utils/checkoutSession.ts +16 -0
- package/server/utils/liveCatalog.ts +244 -31
- package/server/utils/liveOrders.ts +33 -0
- package/server/utils/marketingService.ts +63 -0
- package/server/utils/orderAttribution.ts +65 -0
- package/server/utils/orderPayment.ts +79 -0
- package/server/utils/pendingApprovals.ts +157 -2
- package/server/utils/personalisationViewer.ts +28 -0
- package/server/utils/pspConfig.ts +125 -13
- package/server/utils/pspReturn.ts +267 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { PSP_RETURN_ORDER_PARAM, type PspReturnOutcome } from "../../../shared/pspReturn";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where a payment provider returns the buyer (FE-5), whichever provider it
|
|
6
|
+
* was. The page hands what it was given to the BFF, which confirms the payment
|
|
7
|
+
* with the payments app, and then:
|
|
8
|
+
*
|
|
9
|
+
* - paid → the order confirmation the checkout shows after any order;
|
|
10
|
+
* - failed → says the payment did not go through, and offers to pay again;
|
|
11
|
+
* - retry → the buyer left the provider's page without paying; the same
|
|
12
|
+
* payment's page is offered again (guests too — the checkout's claim covers it);
|
|
13
|
+
* - pending → says the payment is being processed, with a way to look again;
|
|
14
|
+
* - unverified → says the payment could not be verified (the payments app
|
|
15
|
+
* refused the return): not paid, not failed — a case for the merchant.
|
|
16
|
+
*
|
|
17
|
+
* The confirm runs in the browser, once, after hydration: a server render and
|
|
18
|
+
* a hydration would otherwise ask the provider twice.
|
|
19
|
+
*/
|
|
20
|
+
const { t } = useI18n();
|
|
21
|
+
const { icon } = useIcons();
|
|
22
|
+
const { to } = useAppUrl();
|
|
23
|
+
const localePath = useLocalePath();
|
|
24
|
+
const route = useRoute();
|
|
25
|
+
|
|
26
|
+
const orderId = computed(() => {
|
|
27
|
+
const raw = route.query[PSP_RETURN_ORDER_PARAM];
|
|
28
|
+
return typeof raw === "string" ? raw : "";
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
type State = "checking" | Exclude<PspReturnOutcome, "paid"> | "error";
|
|
32
|
+
const state = ref<State>("checking");
|
|
33
|
+
const canRetryFromAccount = ref(false);
|
|
34
|
+
const retryUrl = ref<string | null>(null);
|
|
35
|
+
const checking = ref(false);
|
|
36
|
+
|
|
37
|
+
const orderLink = computed(() => (orderId.value ? localePath(`/account/orders/${orderId.value}`) : localePath("/")));
|
|
38
|
+
|
|
39
|
+
async function confirm(): Promise<void> {
|
|
40
|
+
if (checking.value) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!orderId.value) {
|
|
44
|
+
state.value = "error";
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
checking.value = true;
|
|
48
|
+
try {
|
|
49
|
+
const answer = await $fetch<{ outcome: PspReturnOutcome; orderId: string; canRetryFromAccount: boolean; retryUrl?: string }>(
|
|
50
|
+
"/api/checkout/payment-return",
|
|
51
|
+
{ method: "POST", body: { order: orderId.value, params: route.query } },
|
|
52
|
+
);
|
|
53
|
+
canRetryFromAccount.value = answer.canRetryFromAccount;
|
|
54
|
+
retryUrl.value = answer.retryUrl ?? null;
|
|
55
|
+
if (answer.outcome === "paid") {
|
|
56
|
+
await navigateTo(to("/checkout/confirmation", { id: answer.orderId }), { replace: true });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
state.value = answer.outcome;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
state.value = "error";
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
checking.value = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onMounted(() => void confirm());
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<template>
|
|
73
|
+
<div class="max-w-xl mx-auto py-16 px-4 space-y-6">
|
|
74
|
+
<div
|
|
75
|
+
v-if="state === 'checking'"
|
|
76
|
+
class="flex flex-col items-center gap-4 text-center"
|
|
77
|
+
role="status"
|
|
78
|
+
>
|
|
79
|
+
<UIcon
|
|
80
|
+
:name="icon('loading')"
|
|
81
|
+
class="w-8 h-8 animate-spin text-muted"
|
|
82
|
+
/>
|
|
83
|
+
<p class="text-default">
|
|
84
|
+
{{ t('paymentReturn.checking') }}
|
|
85
|
+
</p>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
<template v-else-if="state === 'failed'">
|
|
89
|
+
<UAlert
|
|
90
|
+
color="error"
|
|
91
|
+
variant="soft"
|
|
92
|
+
:icon="icon('error')"
|
|
93
|
+
:title="t('paymentReturn.failed.title')"
|
|
94
|
+
:description="t('paymentReturn.failed.text', { id: orderId })"
|
|
95
|
+
/>
|
|
96
|
+
<div class="flex flex-wrap gap-3">
|
|
97
|
+
<UButton
|
|
98
|
+
v-if="canRetryFromAccount"
|
|
99
|
+
color="primary"
|
|
100
|
+
:to="orderLink"
|
|
101
|
+
:label="t('paymentReturn.failed.payAgain')"
|
|
102
|
+
/>
|
|
103
|
+
<p
|
|
104
|
+
v-else
|
|
105
|
+
class="text-sm text-muted"
|
|
106
|
+
>
|
|
107
|
+
{{ t('paymentReturn.failed.guestHint') }}
|
|
108
|
+
</p>
|
|
109
|
+
<UButton
|
|
110
|
+
color="neutral"
|
|
111
|
+
variant="outline"
|
|
112
|
+
:to="localePath('/')"
|
|
113
|
+
:label="t('paymentReturn.toShop')"
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
</template>
|
|
117
|
+
|
|
118
|
+
<template v-else-if="state === 'retry'">
|
|
119
|
+
<UAlert
|
|
120
|
+
color="warning"
|
|
121
|
+
variant="soft"
|
|
122
|
+
:icon="icon('info')"
|
|
123
|
+
:title="t('paymentReturn.retry.title')"
|
|
124
|
+
:description="t('paymentReturn.retry.text', { id: orderId })"
|
|
125
|
+
/>
|
|
126
|
+
<div class="flex flex-wrap gap-3">
|
|
127
|
+
<UButton
|
|
128
|
+
v-if="retryUrl"
|
|
129
|
+
color="primary"
|
|
130
|
+
:to="retryUrl"
|
|
131
|
+
external
|
|
132
|
+
:label="t('paymentReturn.retry.again')"
|
|
133
|
+
/>
|
|
134
|
+
<UButton
|
|
135
|
+
color="neutral"
|
|
136
|
+
variant="outline"
|
|
137
|
+
:to="localePath('/')"
|
|
138
|
+
:label="t('paymentReturn.toShop')"
|
|
139
|
+
/>
|
|
140
|
+
</div>
|
|
141
|
+
</template>
|
|
142
|
+
|
|
143
|
+
<template v-else-if="state === 'pending'">
|
|
144
|
+
<UAlert
|
|
145
|
+
color="info"
|
|
146
|
+
variant="soft"
|
|
147
|
+
:icon="icon('info')"
|
|
148
|
+
:title="t('paymentReturn.pending.title')"
|
|
149
|
+
:description="t('paymentReturn.pending.text', { id: orderId })"
|
|
150
|
+
/>
|
|
151
|
+
<div class="flex flex-wrap gap-3">
|
|
152
|
+
<UButton
|
|
153
|
+
color="primary"
|
|
154
|
+
:loading="checking"
|
|
155
|
+
:label="t('paymentReturn.pending.checkAgain')"
|
|
156
|
+
@click="confirm"
|
|
157
|
+
/>
|
|
158
|
+
<UButton
|
|
159
|
+
v-if="canRetryFromAccount"
|
|
160
|
+
color="neutral"
|
|
161
|
+
variant="outline"
|
|
162
|
+
:to="orderLink"
|
|
163
|
+
:label="t('paymentReturn.toOrder')"
|
|
164
|
+
/>
|
|
165
|
+
</div>
|
|
166
|
+
</template>
|
|
167
|
+
|
|
168
|
+
<template v-else-if="state === 'unverified'">
|
|
169
|
+
<UAlert
|
|
170
|
+
color="warning"
|
|
171
|
+
variant="soft"
|
|
172
|
+
:icon="icon('alert')"
|
|
173
|
+
:title="t('paymentReturn.unverified.title')"
|
|
174
|
+
:description="t('paymentReturn.unverified.text', { id: orderId })"
|
|
175
|
+
/>
|
|
176
|
+
<div class="flex flex-wrap gap-3">
|
|
177
|
+
<UButton
|
|
178
|
+
v-if="canRetryFromAccount"
|
|
179
|
+
color="neutral"
|
|
180
|
+
variant="outline"
|
|
181
|
+
:to="orderLink"
|
|
182
|
+
:label="t('paymentReturn.toOrder')"
|
|
183
|
+
/>
|
|
184
|
+
<UButton
|
|
185
|
+
color="neutral"
|
|
186
|
+
variant="outline"
|
|
187
|
+
:to="localePath('/')"
|
|
188
|
+
:label="t('paymentReturn.toShop')"
|
|
189
|
+
/>
|
|
190
|
+
</div>
|
|
191
|
+
</template>
|
|
192
|
+
|
|
193
|
+
<template v-else>
|
|
194
|
+
<UAlert
|
|
195
|
+
color="warning"
|
|
196
|
+
variant="soft"
|
|
197
|
+
:icon="icon('alert')"
|
|
198
|
+
:title="t('paymentReturn.error.title')"
|
|
199
|
+
:description="t('paymentReturn.error.text')"
|
|
200
|
+
/>
|
|
201
|
+
<UButton
|
|
202
|
+
color="neutral"
|
|
203
|
+
variant="outline"
|
|
204
|
+
:to="localePath('/')"
|
|
205
|
+
:label="t('paymentReturn.toShop')"
|
|
206
|
+
/>
|
|
207
|
+
</template>
|
|
208
|
+
</div>
|
|
209
|
+
</template>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The perks of the buyer's loyalty tier where they matter — in the cart and
|
|
4
|
+
* the checkout (RAD-293, eltric "Premium": "frachtfrei ab 75 € statt 145 €").
|
|
5
|
+
* Only the words: the discount itself is a promotion with a tier condition
|
|
6
|
+
* and arrives through the cart calculation like every other one.
|
|
7
|
+
*/
|
|
8
|
+
const { t } = useI18n();
|
|
9
|
+
const { icon } = useIcons();
|
|
10
|
+
const { perks } = useLoyaltyAccount();
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<div
|
|
15
|
+
v-if="perks && perks.items.length"
|
|
16
|
+
class="flex items-start gap-1.5 text-xs text-highlighted"
|
|
17
|
+
data-loyalty-perk-hint
|
|
18
|
+
>
|
|
19
|
+
<UIcon
|
|
20
|
+
:name="icon('star')"
|
|
21
|
+
class="size-4 shrink-0 mt-px text-primary"
|
|
22
|
+
/>
|
|
23
|
+
<p>
|
|
24
|
+
<span class="font-semibold">{{ t('marketing.loyalty.perkHint', { tier: perks.tier }) }}</span>
|
|
25
|
+
{{ perks.items.join(' · ') }}
|
|
26
|
+
</p>
|
|
27
|
+
</div>
|
|
28
|
+
</template>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { linkRefusalOf, marketingApi, type LinkRefusal } from "../../../api/marketing";
|
|
3
|
+
import NewsletterLinkRefusal from "../state/NewsletterLinkRefusal.vue";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The double opt-in confirmation (RAD-293). The link in the confirmation
|
|
7
|
+
* mail lands here; the page confirms in the browser, after it is shown —
|
|
8
|
+
* never while the server renders it — so a mail scanner that fetches the link
|
|
9
|
+
* without running it confirms nobody.
|
|
10
|
+
*/
|
|
11
|
+
const props = defineProps<{ token: string }>();
|
|
12
|
+
|
|
13
|
+
const { t } = useI18n();
|
|
14
|
+
|
|
15
|
+
type State = "working" | "done" | "already" | LinkRefusal;
|
|
16
|
+
const state = ref<State>("working");
|
|
17
|
+
|
|
18
|
+
onMounted(async () => {
|
|
19
|
+
try {
|
|
20
|
+
const answer = await $fetch<{ alreadyConfirmed?: boolean }>(marketingApi.confirm(props.token), {
|
|
21
|
+
method: "POST",
|
|
22
|
+
body: { page_url: window.location.origin + window.location.pathname },
|
|
23
|
+
});
|
|
24
|
+
state.value = answer?.alreadyConfirmed ? "already" : "done";
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
state.value = linkRefusalOf(err);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<template>
|
|
33
|
+
<div data-newsletter-confirmation>
|
|
34
|
+
<p
|
|
35
|
+
v-if="state === 'working'"
|
|
36
|
+
class="text-muted"
|
|
37
|
+
role="status"
|
|
38
|
+
>
|
|
39
|
+
{{ t('marketing.confirm.working') }}
|
|
40
|
+
</p>
|
|
41
|
+
<UiFeedbackEmptyState
|
|
42
|
+
v-else-if="state === 'done' || state === 'already'"
|
|
43
|
+
icon="success"
|
|
44
|
+
:title="t('marketing.confirm.doneTitle')"
|
|
45
|
+
:description="state === 'already' ? t('marketing.confirm.alreadyText') : t('marketing.confirm.doneText')"
|
|
46
|
+
role="status"
|
|
47
|
+
/>
|
|
48
|
+
<NewsletterLinkRefusal
|
|
49
|
+
v-else
|
|
50
|
+
:refusal="state"
|
|
51
|
+
:expired-text="t('marketing.confirm.expiredText')"
|
|
52
|
+
/>
|
|
53
|
+
</div>
|
|
54
|
+
</template>
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { linkRefusalOf, marketingApi } from "../../../api/marketing";
|
|
3
|
+
import NewsletterLinkRefusal from "../state/NewsletterLinkRefusal.vue";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The preference centre (RAD-293), behind the personal link in every mail's
|
|
7
|
+
* footer: which of the shop's mails go to this address, with the wording each
|
|
8
|
+
* one was agreed under, and leaving all of them at once.
|
|
9
|
+
*
|
|
10
|
+
* Choosing a type that needs a double opt-in does not subscribe it: the
|
|
11
|
+
* recipient gets a confirmation mail and is told so, because a box that
|
|
12
|
+
* looks ticked but sends nothing is worse than an honest "check your inbox".
|
|
13
|
+
*/
|
|
14
|
+
const props = defineProps<{ token: string }>();
|
|
15
|
+
|
|
16
|
+
interface PreferenceType {
|
|
17
|
+
code: string;
|
|
18
|
+
label: string;
|
|
19
|
+
description: string | null;
|
|
20
|
+
subscribed: boolean;
|
|
21
|
+
consentTextId: string | null;
|
|
22
|
+
consentText: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface PreferenceView {
|
|
26
|
+
addressHint: string;
|
|
27
|
+
types: PreferenceType[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface SaveAnswer {
|
|
31
|
+
view: PreferenceView;
|
|
32
|
+
changes: { subscription_type: string | null; action: string }[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const { t } = useI18n();
|
|
36
|
+
|
|
37
|
+
const { data, error, status } = await useFetch<PreferenceView>(() => marketingApi.preferences(props.token), {
|
|
38
|
+
key: `newsletter-preferences:${props.token}`,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const choices = reactive<Record<string, boolean>>({});
|
|
42
|
+
watch(data, (view) => {
|
|
43
|
+
for (const type of view?.types ?? []) {
|
|
44
|
+
choices[type.code] = type.subscribed;
|
|
45
|
+
}
|
|
46
|
+
}, { immediate: true });
|
|
47
|
+
|
|
48
|
+
const saving = ref(false);
|
|
49
|
+
const saveError = ref(false);
|
|
50
|
+
const outcome = ref<null | { kind: "saved"; requested: string[] } | { kind: "unsubscribed" }>(null);
|
|
51
|
+
|
|
52
|
+
const refusal = computed(() => (error.value ? linkRefusalOf(error.value) : null));
|
|
53
|
+
|
|
54
|
+
async function send(body: Record<string, unknown>): Promise<SaveAnswer | null> {
|
|
55
|
+
saving.value = true;
|
|
56
|
+
saveError.value = false;
|
|
57
|
+
try {
|
|
58
|
+
const answer = await $fetch<SaveAnswer>(marketingApi.preferences(props.token), { method: "POST", body });
|
|
59
|
+
data.value = answer.view;
|
|
60
|
+
return answer;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
saveError.value = true;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
saving.value = false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function save(): Promise<void> {
|
|
72
|
+
const types = data.value?.types ?? [];
|
|
73
|
+
const answer = await send({
|
|
74
|
+
choices: types.map(type => ({
|
|
75
|
+
subscription_type: type.code,
|
|
76
|
+
subscribed: choices[type.code] === true,
|
|
77
|
+
...(type.consentTextId ? { consent_text_id: type.consentTextId } : {}),
|
|
78
|
+
})),
|
|
79
|
+
});
|
|
80
|
+
if (answer) {
|
|
81
|
+
const labelOf = (code: string | null) => types.find(type => type.code === code)?.label ?? code ?? "";
|
|
82
|
+
outcome.value = {
|
|
83
|
+
kind: "saved",
|
|
84
|
+
requested: answer.changes.filter(change => change.action === "requested").map(change => labelOf(change.subscription_type)),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function unsubscribeAll(): Promise<void> {
|
|
90
|
+
if (await send({ unsubscribe_all: true })) {
|
|
91
|
+
outcome.value = { kind: "unsubscribed" };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<template>
|
|
97
|
+
<div data-newsletter-preferences>
|
|
98
|
+
<NewsletterLinkRefusal
|
|
99
|
+
v-if="refusal"
|
|
100
|
+
:refusal="refusal"
|
|
101
|
+
:expired-text="t('marketing.preferences.expiredText')"
|
|
102
|
+
/>
|
|
103
|
+
<USkeleton
|
|
104
|
+
v-else-if="status === 'pending' && !data"
|
|
105
|
+
class="h-40 w-full"
|
|
106
|
+
/>
|
|
107
|
+
<template v-else-if="data">
|
|
108
|
+
<p class="text-muted mb-6">
|
|
109
|
+
{{ t('marketing.preferences.intro', { address: data.addressHint }) }}
|
|
110
|
+
</p>
|
|
111
|
+
|
|
112
|
+
<UAlert
|
|
113
|
+
v-if="outcome"
|
|
114
|
+
class="mb-6"
|
|
115
|
+
color="success"
|
|
116
|
+
variant="soft"
|
|
117
|
+
role="status"
|
|
118
|
+
:title="outcome.kind === 'unsubscribed' ? t('marketing.preferences.unsubscribedAll') : t('marketing.preferences.saved')"
|
|
119
|
+
:description="outcome.kind === 'saved' && outcome.requested.length
|
|
120
|
+
? t('marketing.preferences.requested', { types: outcome.requested.join(', ') })
|
|
121
|
+
: undefined"
|
|
122
|
+
/>
|
|
123
|
+
<UAlert
|
|
124
|
+
v-if="saveError"
|
|
125
|
+
class="mb-6"
|
|
126
|
+
color="error"
|
|
127
|
+
variant="soft"
|
|
128
|
+
:title="t('marketing.link.errorTitle')"
|
|
129
|
+
:description="t('marketing.link.errorText')"
|
|
130
|
+
/>
|
|
131
|
+
|
|
132
|
+
<p
|
|
133
|
+
v-if="!data.types.length"
|
|
134
|
+
class="text-muted"
|
|
135
|
+
>
|
|
136
|
+
{{ t('marketing.preferences.empty') }}
|
|
137
|
+
</p>
|
|
138
|
+
<form
|
|
139
|
+
v-else
|
|
140
|
+
class="space-y-5"
|
|
141
|
+
@submit.prevent="save"
|
|
142
|
+
>
|
|
143
|
+
<div
|
|
144
|
+
v-for="type in data.types"
|
|
145
|
+
:key="type.code"
|
|
146
|
+
class="border border-(--ui-border) rounded-lg p-4"
|
|
147
|
+
>
|
|
148
|
+
<UCheckbox
|
|
149
|
+
v-model="choices[type.code]"
|
|
150
|
+
:name="type.code"
|
|
151
|
+
:label="type.label"
|
|
152
|
+
:description="type.description ?? undefined"
|
|
153
|
+
/>
|
|
154
|
+
<p
|
|
155
|
+
v-if="type.consentText"
|
|
156
|
+
class="text-xs text-muted mt-2 ms-6"
|
|
157
|
+
>
|
|
158
|
+
{{ type.consentText }}
|
|
159
|
+
</p>
|
|
160
|
+
</div>
|
|
161
|
+
|
|
162
|
+
<div class="flex flex-wrap items-center gap-3 pt-2">
|
|
163
|
+
<UButton
|
|
164
|
+
type="submit"
|
|
165
|
+
:loading="saving"
|
|
166
|
+
>
|
|
167
|
+
{{ t('marketing.preferences.save') }}
|
|
168
|
+
</UButton>
|
|
169
|
+
<UButton
|
|
170
|
+
type="button"
|
|
171
|
+
variant="link"
|
|
172
|
+
color="neutral"
|
|
173
|
+
:disabled="saving"
|
|
174
|
+
data-unsubscribe-all
|
|
175
|
+
@click="unsubscribeAll"
|
|
176
|
+
>
|
|
177
|
+
{{ t('marketing.preferences.unsubscribeAll') }}
|
|
178
|
+
</UButton>
|
|
179
|
+
</div>
|
|
180
|
+
</form>
|
|
181
|
+
</template>
|
|
182
|
+
</div>
|
|
183
|
+
</template>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { LinkRefusal } from "../../../api/marketing";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a personal link from a mail says when it cannot be used: unknown,
|
|
6
|
+
* expired, or the shop failed to ask. Shared by the newsletter and the review
|
|
7
|
+
* pages, which reach the visitor the same way.
|
|
8
|
+
*/
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
refusal: LinkRefusal;
|
|
11
|
+
/** What to do about an expired link differs per page. */
|
|
12
|
+
expiredText: string;
|
|
13
|
+
}>();
|
|
14
|
+
|
|
15
|
+
const { t } = useI18n();
|
|
16
|
+
const { to } = useAppUrl();
|
|
17
|
+
|
|
18
|
+
const title = computed(() => {
|
|
19
|
+
if (props.refusal === "expired") return t("marketing.link.expiredTitle");
|
|
20
|
+
if (props.refusal === "unknown") return t("marketing.link.unknownTitle");
|
|
21
|
+
return t("marketing.link.errorTitle");
|
|
22
|
+
});
|
|
23
|
+
const description = computed(() => {
|
|
24
|
+
if (props.refusal === "expired") return props.expiredText;
|
|
25
|
+
if (props.refusal === "unknown") return t("marketing.link.unknownText");
|
|
26
|
+
return t("marketing.link.errorText");
|
|
27
|
+
});
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<UiFeedbackEmptyState
|
|
32
|
+
:icon="refusal === 'error' ? 'error' : 'warning'"
|
|
33
|
+
:title="title"
|
|
34
|
+
:description="description"
|
|
35
|
+
:data-link-refusal="refusal"
|
|
36
|
+
>
|
|
37
|
+
<UButton
|
|
38
|
+
class="mt-6"
|
|
39
|
+
:to="to('/')"
|
|
40
|
+
variant="outline"
|
|
41
|
+
>
|
|
42
|
+
{{ t('marketing.link.toShop') }}
|
|
43
|
+
</UButton>
|
|
44
|
+
</UiFeedbackEmptyState>
|
|
45
|
+
</template>
|