@revenexx/cover 0.18.0 → 0.20.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/loyalty/AccountLoyalty.vue +205 -0
- package/app/components/cart/view/CartSummaryPanel.vue +4 -0
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +4 -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/product/detail/ProductDetailImageGallery.vue +39 -13
- package/app/components/product/detail/ProductDetailView.vue +3 -1
- package/app/components/review/form/ReviewForm.vue +211 -0
- package/app/composables/useCampaignAttribution.ts +120 -0
- package/app/composables/useCheckoutOnePage.ts +9 -0
- package/app/composables/useLoyaltyAccount.ts +79 -0
- package/app/composables/useMarketingConsent.ts +49 -0
- package/app/composables/useProduct.ts +6 -1
- package/app/config/navigation.ts +1 -1
- package/app/config/quickActions.ts +1 -0
- package/app/interfaces/product-detail.ts +11 -0
- package/app/pages/account/points.vue +26 -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/plugins/campaign-attribution.client.ts +47 -0
- package/app/shared/campaignAttribution.ts +281 -0
- package/app/shared/personalisation.ts +107 -0
- package/i18n/locales/de/account.json +3 -2
- package/i18n/locales/de/marketing.json +71 -0
- package/i18n/locales/en/account.json +3 -2
- package/i18n/locales/en/marketing.json +71 -0
- package/package.json +1 -1
- package/server/api/campaigns/touches.post.ts +42 -0
- package/server/api/cart/attribution.put.ts +31 -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 +10 -1
- 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 +16 -0
- package/server/services/ApiMarketingService.ts +292 -0
- package/server/services/ApiProductService.ts +20 -1
- package/server/services/LocalFileProductService.ts +9 -1
- package/server/services/MockMarketingService.ts +178 -0
- package/server/utils/liveCatalog.ts +178 -2
- package/server/utils/marketingService.ts +63 -0
- package/server/utils/orderAttribution.ts +65 -0
- package/server/utils/personalisationViewer.ts +28 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** BFF paths of the marketing pages (RAD-293). Tokens are encoded here, once. */
|
|
2
|
+
export const marketingApi = {
|
|
3
|
+
confirm: (token: string) => `/api/newsletter/confirm/${encodeURIComponent(token)}`,
|
|
4
|
+
preferences: (token: string) => `/api/newsletter/preferences/${encodeURIComponent(token)}`,
|
|
5
|
+
reviewRequest: (token: string) => `/api/reviews/requests/${encodeURIComponent(token)}`,
|
|
6
|
+
reviewSubmit: (token: string) => `/api/reviews/submit/${encodeURIComponent(token)}`,
|
|
7
|
+
loyaltyAccount: () => "/api/loyalty/account",
|
|
8
|
+
touches: () => "/api/campaigns/touches",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** Why a token page refused: the link is unknown, expired, or the shop failed. */
|
|
12
|
+
export type LinkRefusal = "unknown" | "expired" | "error";
|
|
13
|
+
|
|
14
|
+
export function linkRefusalOf(err: unknown): LinkRefusal {
|
|
15
|
+
const status = (err as { statusCode?: number; status?: number } | null)?.statusCode
|
|
16
|
+
?? (err as { status?: number } | null)?.status;
|
|
17
|
+
if (status === 410) {
|
|
18
|
+
return "expired";
|
|
19
|
+
}
|
|
20
|
+
if (status === 404) {
|
|
21
|
+
return "unknown";
|
|
22
|
+
}
|
|
23
|
+
return "error";
|
|
24
|
+
}
|
package/app/app.config.ts
CHANGED
|
@@ -50,6 +50,28 @@ export default defineAppConfig({
|
|
|
50
50
|
// through transpose and merged over the theme's locale files. Mock reads
|
|
51
51
|
// nothing, so the demo shows the theme's texts; a theme switches it to "api".
|
|
52
52
|
translationsService: "mock",
|
|
53
|
+
// The marketing apps (RAD-293): the newsletter confirmation and preference
|
|
54
|
+
// centre (marketing-consents), the review form (reviews), the loyalty page
|
|
55
|
+
// and perk hint (loyalty), audiences for personalised content and campaign
|
|
56
|
+
// touches. `mock` serves demo answers for every one of those pages.
|
|
57
|
+
marketingService: "mock",
|
|
58
|
+
// Which purposes of the merchant's cookie choice each marketing function
|
|
59
|
+
// rests on — codes of the Consent Manager's policy (its defaults are
|
|
60
|
+
// `statistics` and `marketing`). A function whose purpose was not allowed
|
|
61
|
+
// does nothing: no attribution is kept, no pop-up is counted, no audience
|
|
62
|
+
// is asked for.
|
|
63
|
+
marketing: {
|
|
64
|
+
purposes: {
|
|
65
|
+
// Where a visit came from (UTM parameters, first/last touch).
|
|
66
|
+
analytics: "statistics",
|
|
67
|
+
// The ad click id, and telling ad platforms about a conversion.
|
|
68
|
+
ads: "marketing",
|
|
69
|
+
// Showing a signed-in buyer content meant for their audiences.
|
|
70
|
+
personalisation: "marketing",
|
|
71
|
+
// Counting a campaign's pop-up impressions and clicks.
|
|
72
|
+
touches: "statistics",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
53
75
|
// How an ordered quote is paid. A quote is a negotiated B2B price, so the
|
|
54
76
|
// order it becomes goes on account; a storefront that takes quotes on
|
|
55
77
|
// another method names its code here.
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The buyer's loyalty programme in the account (RAD-293): their tier and its
|
|
4
|
+
* perks, a points balance where the programme counts points, and — for a
|
|
5
|
+
* yearly turnover bonus like eltric "Premium" — the stages, the turnover so
|
|
6
|
+
* far, the projection to year end and what is left to the next stage.
|
|
7
|
+
*
|
|
8
|
+
* The figures are the loyalty app's; this page computes nothing, so what the
|
|
9
|
+
* buyer reads is what the merchant settles.
|
|
10
|
+
*/
|
|
11
|
+
const { t, locale } = useI18n();
|
|
12
|
+
const { data, status, error, label } = useLoyaltyAccount();
|
|
13
|
+
|
|
14
|
+
const memberships = computed(() => data.value?.memberships ?? []);
|
|
15
|
+
const progress = computed(() => data.value?.progress ?? null);
|
|
16
|
+
|
|
17
|
+
function money(value: number | null | undefined): string {
|
|
18
|
+
if (value === null || value === undefined) {
|
|
19
|
+
return "–";
|
|
20
|
+
}
|
|
21
|
+
return new Intl.NumberFormat(locale.value, {
|
|
22
|
+
style: "currency",
|
|
23
|
+
currency: progress.value?.currency ?? "EUR",
|
|
24
|
+
maximumFractionDigits: 0,
|
|
25
|
+
}).format(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const share = computed(() => {
|
|
29
|
+
const tiers = progress.value?.tiers ?? [];
|
|
30
|
+
const top = tiers.reduce((max, tier) => Math.max(max, tier.threshold ?? 0), 0);
|
|
31
|
+
return top > 0 ? Math.min(100, Math.round(((progress.value?.turnoverYtd ?? 0) / top) * 100)) : 0;
|
|
32
|
+
});
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<template>
|
|
36
|
+
<div
|
|
37
|
+
class="space-y-6"
|
|
38
|
+
data-account-loyalty
|
|
39
|
+
>
|
|
40
|
+
<USkeleton
|
|
41
|
+
v-if="status === 'pending' && !data"
|
|
42
|
+
class="h-40 w-full"
|
|
43
|
+
/>
|
|
44
|
+
<UAlert
|
|
45
|
+
v-else-if="error"
|
|
46
|
+
color="error"
|
|
47
|
+
variant="soft"
|
|
48
|
+
:description="t('marketing.loyalty.error')"
|
|
49
|
+
/>
|
|
50
|
+
<UiFeedbackEmptyState
|
|
51
|
+
v-else-if="!memberships.length"
|
|
52
|
+
icon="star"
|
|
53
|
+
:title="t('marketing.loyalty.none')"
|
|
54
|
+
/>
|
|
55
|
+
<template v-else>
|
|
56
|
+
<section
|
|
57
|
+
v-for="membership in memberships"
|
|
58
|
+
:key="membership.program.code"
|
|
59
|
+
class="border border-(--ui-border) rounded-xl p-5 space-y-3"
|
|
60
|
+
>
|
|
61
|
+
<h2 class="text-lg font-semibold text-highlighted">
|
|
62
|
+
{{ label(membership.program.labels, membership.program.code) }}
|
|
63
|
+
</h2>
|
|
64
|
+
<dl class="grid gap-3 sm:grid-cols-2 text-sm">
|
|
65
|
+
<div v-if="membership.tier">
|
|
66
|
+
<dt class="text-muted">
|
|
67
|
+
{{ t('marketing.loyalty.tier') }}
|
|
68
|
+
</dt>
|
|
69
|
+
<dd
|
|
70
|
+
class="font-medium text-highlighted"
|
|
71
|
+
data-loyalty-tier
|
|
72
|
+
>
|
|
73
|
+
{{ label(membership.tier.labels, membership.tier.code) }}
|
|
74
|
+
</dd>
|
|
75
|
+
</div>
|
|
76
|
+
<div v-if="membership.pointsBalance !== null">
|
|
77
|
+
<dt class="text-muted">
|
|
78
|
+
{{ t('marketing.loyalty.points') }}
|
|
79
|
+
</dt>
|
|
80
|
+
<dd class="font-medium text-highlighted">
|
|
81
|
+
{{ t('marketing.loyalty.pointsValue', { points: membership.pointsBalance }) }}
|
|
82
|
+
</dd>
|
|
83
|
+
</div>
|
|
84
|
+
</dl>
|
|
85
|
+
<div v-if="membership.tier?.perks.length">
|
|
86
|
+
<p class="text-sm text-muted mb-1">
|
|
87
|
+
{{ t('marketing.loyalty.perks') }}
|
|
88
|
+
</p>
|
|
89
|
+
<ul class="list-disc ps-5 text-sm space-y-0.5">
|
|
90
|
+
<li
|
|
91
|
+
v-for="(perk, index) in membership.tier.perks"
|
|
92
|
+
:key="index"
|
|
93
|
+
>
|
|
94
|
+
{{ label(perk) }}
|
|
95
|
+
</li>
|
|
96
|
+
</ul>
|
|
97
|
+
</div>
|
|
98
|
+
</section>
|
|
99
|
+
|
|
100
|
+
<section
|
|
101
|
+
v-if="progress"
|
|
102
|
+
class="border border-(--ui-border) rounded-xl p-5 space-y-4"
|
|
103
|
+
data-loyalty-progress
|
|
104
|
+
>
|
|
105
|
+
<h2 class="text-lg font-semibold text-highlighted">
|
|
106
|
+
{{ t('marketing.loyalty.progressTitle', { period: progress.period ?? '' }) }}
|
|
107
|
+
</h2>
|
|
108
|
+
<dl class="grid gap-3 sm:grid-cols-2 lg:grid-cols-4 text-sm">
|
|
109
|
+
<div>
|
|
110
|
+
<dt class="text-muted">
|
|
111
|
+
{{ t('marketing.loyalty.turnoverYtd') }}
|
|
112
|
+
</dt>
|
|
113
|
+
<dd class="font-semibold text-highlighted">
|
|
114
|
+
{{ money(progress.turnoverYtd) }}
|
|
115
|
+
</dd>
|
|
116
|
+
</div>
|
|
117
|
+
<div>
|
|
118
|
+
<dt class="text-muted">
|
|
119
|
+
{{ t('marketing.loyalty.projected') }}
|
|
120
|
+
</dt>
|
|
121
|
+
<dd class="font-semibold text-highlighted">
|
|
122
|
+
{{ money(progress.projectedTurnover) }}
|
|
123
|
+
</dd>
|
|
124
|
+
</div>
|
|
125
|
+
<div>
|
|
126
|
+
<dt class="text-muted">
|
|
127
|
+
{{ t('marketing.loyalty.bonusNow') }}
|
|
128
|
+
</dt>
|
|
129
|
+
<dd class="font-semibold text-highlighted">
|
|
130
|
+
{{ money(progress.bonusNow) }}
|
|
131
|
+
</dd>
|
|
132
|
+
</div>
|
|
133
|
+
<div>
|
|
134
|
+
<dt class="text-muted">
|
|
135
|
+
{{ t('marketing.loyalty.expectedBonus') }}
|
|
136
|
+
</dt>
|
|
137
|
+
<dd class="font-semibold text-highlighted">
|
|
138
|
+
{{ money(progress.expectedBonus) }}
|
|
139
|
+
</dd>
|
|
140
|
+
</div>
|
|
141
|
+
</dl>
|
|
142
|
+
|
|
143
|
+
<div
|
|
144
|
+
class="h-2 rounded-full bg-elevated overflow-hidden"
|
|
145
|
+
role="presentation"
|
|
146
|
+
>
|
|
147
|
+
<div
|
|
148
|
+
class="h-full rounded-full bg-primary w-(--loyalty-progress)"
|
|
149
|
+
:style="{ '--loyalty-progress': `${share}%` }"
|
|
150
|
+
/>
|
|
151
|
+
</div>
|
|
152
|
+
|
|
153
|
+
<p
|
|
154
|
+
class="text-sm font-medium text-highlighted"
|
|
155
|
+
data-loyalty-next
|
|
156
|
+
>
|
|
157
|
+
{{ progress.nextTier
|
|
158
|
+
? t('marketing.loyalty.nextTier', {
|
|
159
|
+
gap: money(progress.nextTier.gap),
|
|
160
|
+
tier: label(progress.nextTier.labels, progress.nextTier.code),
|
|
161
|
+
percent: progress.nextTier.bonusPercent,
|
|
162
|
+
})
|
|
163
|
+
: t('marketing.loyalty.topTier') }}
|
|
164
|
+
</p>
|
|
165
|
+
|
|
166
|
+
<ul class="space-y-1 text-sm">
|
|
167
|
+
<li
|
|
168
|
+
v-for="tier in progress.tiers"
|
|
169
|
+
:key="tier.code"
|
|
170
|
+
class="flex items-center gap-2"
|
|
171
|
+
:class="tier.reached ? 'text-highlighted' : 'text-muted'"
|
|
172
|
+
>
|
|
173
|
+
<span>{{ t('marketing.loyalty.stage', {
|
|
174
|
+
tier: label(tier.labels, tier.code),
|
|
175
|
+
threshold: money(tier.threshold),
|
|
176
|
+
percent: tier.bonusPercent,
|
|
177
|
+
}) }}</span>
|
|
178
|
+
<UBadge
|
|
179
|
+
v-if="tier.current"
|
|
180
|
+
size="sm"
|
|
181
|
+
variant="soft"
|
|
182
|
+
>
|
|
183
|
+
{{ t('marketing.loyalty.current') }}
|
|
184
|
+
</UBadge>
|
|
185
|
+
<UBadge
|
|
186
|
+
v-else-if="tier.reached"
|
|
187
|
+
size="sm"
|
|
188
|
+
variant="soft"
|
|
189
|
+
color="neutral"
|
|
190
|
+
>
|
|
191
|
+
{{ t('marketing.loyalty.reached') }}
|
|
192
|
+
</UBadge>
|
|
193
|
+
</li>
|
|
194
|
+
</ul>
|
|
195
|
+
|
|
196
|
+
<p class="text-xs text-muted">
|
|
197
|
+
{{ t('marketing.loyalty.rules') }}
|
|
198
|
+
<template v-if="progress.requiresNoOverdue">
|
|
199
|
+
{{ t('marketing.loyalty.rulesOverdue') }}
|
|
200
|
+
</template>
|
|
201
|
+
</p>
|
|
202
|
+
</section>
|
|
203
|
+
</template>
|
|
204
|
+
</div>
|
|
205
|
+
</template>
|
|
@@ -3,6 +3,7 @@ import CartApprovalsPanel from "./CartApprovalsPanel.vue";
|
|
|
3
3
|
import CartWorkflowPickerModal from "../actions/CartWorkflowPickerModal.vue";
|
|
4
4
|
import PunchoutTransferAction from "../../punchout/action/PunchoutTransferAction.vue";
|
|
5
5
|
import CartQuoteRequestModal from "../quote/CartQuoteRequestModal.vue";
|
|
6
|
+
import LoyaltyPerkHint from "../../loyalty/hint/LoyaltyPerkHint.vue";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Cart summary 2.0: the calculated totals block in document order, the
|
|
@@ -206,6 +207,9 @@ const trustItems = computed(() => {
|
|
|
206
207
|
</template>
|
|
207
208
|
</div>
|
|
208
209
|
|
|
210
|
+
<!-- The perks of the buyer's loyalty tier (RAD-293) -->
|
|
211
|
+
<LoyaltyPerkHint class="print:hidden" />
|
|
212
|
+
|
|
209
213
|
<!-- What this cart has not earned yet. Nearest first, because the top of
|
|
210
214
|
a list is what a buyer acts on. -->
|
|
211
215
|
<div
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import CartApprovalsPanel from "../../cart/view/CartApprovalsPanel.vue";
|
|
3
|
+
import LoyaltyPerkHint from "../../loyalty/hint/LoyaltyPerkHint.vue";
|
|
3
4
|
|
|
4
5
|
const { icon } = useIcons();
|
|
5
6
|
const { getImage } = useProductImage();
|
|
@@ -66,6 +67,9 @@ async function handlePlaceOrder() {
|
|
|
66
67
|
</h2>
|
|
67
68
|
<USeparator />
|
|
68
69
|
|
|
70
|
+
<!-- The perks of the buyer's loyalty tier (RAD-293) -->
|
|
71
|
+
<LoyaltyPerkHint />
|
|
72
|
+
|
|
69
73
|
<!-- Submit error -->
|
|
70
74
|
<UAlert
|
|
71
75
|
v-if="submitError"
|
|
@@ -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>
|
|
@@ -13,7 +13,9 @@ const props = defineProps<{
|
|
|
13
13
|
const has3d = computed(() => !!props.modelUrl);
|
|
14
14
|
|
|
15
15
|
// 'image' shows the selected still; 'model' shows the interactive 3D viewer.
|
|
16
|
-
|
|
16
|
+
// A product with a model but no picture opens in 3D rather than on an empty stage.
|
|
17
|
+
const initialMode = (): "image" | "model" => (props.images.length || !props.modelUrl ? "image" : "model");
|
|
18
|
+
const mode = ref<"image" | "model">(initialMode());
|
|
17
19
|
const selectedIndex = ref(0);
|
|
18
20
|
const selectedImage = computed(() => props.images[selectedIndex.value]);
|
|
19
21
|
|
|
@@ -22,9 +24,9 @@ function showImage(index: number): void {
|
|
|
22
24
|
mode.value = "image";
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
watch(() => props.images, () => {
|
|
27
|
+
watch([() => props.images, () => props.modelUrl], () => {
|
|
26
28
|
selectedIndex.value = 0;
|
|
27
|
-
mode.value =
|
|
29
|
+
mode.value = initialMode();
|
|
28
30
|
});
|
|
29
31
|
</script>
|
|
30
32
|
|
|
@@ -77,26 +79,50 @@ watch(() => props.images, () => {
|
|
|
77
79
|
>
|
|
78
80
|
</button>
|
|
79
81
|
|
|
80
|
-
<!-- 3D entry
|
|
82
|
+
<!-- 3D entry: the model's preview still with a 3D badge in the corner,
|
|
83
|
+
so it reads as "this picture turns"; the bare icon when there is no still. -->
|
|
81
84
|
<button
|
|
82
85
|
v-if="has3d"
|
|
83
86
|
type="button"
|
|
84
87
|
tabindex="0"
|
|
85
|
-
class="aspect-square rounded-lg overflow-hidden bg-elevated/60
|
|
88
|
+
class="relative aspect-square rounded-lg overflow-hidden bg-elevated/60
|
|
86
89
|
ring-1 transition-all cursor-pointer flex flex-col items-center justify-center gap-0.5
|
|
87
90
|
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--ui-primary)"
|
|
88
|
-
:class="
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
:class="[
|
|
92
|
+
mode === 'model'
|
|
93
|
+
? 'ring-2 ring-(--ui-primary)'
|
|
94
|
+
: 'ring-(--ui-border) hover:ring-(--ui-primary)/50',
|
|
95
|
+
modelPoster ? 'p-1.5' : '',
|
|
96
|
+
]"
|
|
91
97
|
aria-label="3D view"
|
|
92
98
|
:aria-pressed="mode === 'model'"
|
|
93
99
|
@click="mode = 'model'"
|
|
94
100
|
>
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
<template v-if="modelPoster">
|
|
102
|
+
<img
|
|
103
|
+
:src="modelPoster"
|
|
104
|
+
alt=""
|
|
105
|
+
class="w-full h-full object-contain"
|
|
106
|
+
data-testid="gallery-3d-poster"
|
|
107
|
+
>
|
|
108
|
+
<span
|
|
109
|
+
class="absolute top-1 right-1 flex items-center gap-0.5 rounded-md
|
|
110
|
+
bg-inverted px-1 py-0.5 text-[9px] font-bold leading-none tracking-wide text-inverted"
|
|
111
|
+
>
|
|
112
|
+
<UIcon
|
|
113
|
+
name="i-lucide-rotate-3d"
|
|
114
|
+
class="size-2.5"
|
|
115
|
+
/>
|
|
116
|
+
3D
|
|
117
|
+
</span>
|
|
118
|
+
</template>
|
|
119
|
+
<template v-else>
|
|
120
|
+
<UIcon
|
|
121
|
+
name="i-lucide-rotate-3d"
|
|
122
|
+
class="size-5 text-muted"
|
|
123
|
+
/>
|
|
124
|
+
<span class="text-[10px] font-semibold uppercase tracking-wide text-muted">3D</span>
|
|
125
|
+
</template>
|
|
100
126
|
</button>
|
|
101
127
|
</div>
|
|
102
128
|
</div>
|