diff --git a/apps/web/composables/useNewsletterConfirmation/index.ts b/apps/web/composables/useNewsletterConfirmation/index.ts new file mode 100644 index 000000000..85027663f --- /dev/null +++ b/apps/web/composables/useNewsletterConfirmation/index.ts @@ -0,0 +1,2 @@ +export * from './useNewsletterConfirmation'; +export * from './types'; diff --git a/apps/web/composables/useNewsletterConfirmation/types.ts b/apps/web/composables/useNewsletterConfirmation/types.ts new file mode 100644 index 000000000..eb4b23202 --- /dev/null +++ b/apps/web/composables/useNewsletterConfirmation/types.ts @@ -0,0 +1,9 @@ +import { Data } from '@plentymarkets/shop-api'; + +export type EmailConfirmationOptin = (newsletterEmailId: string, authString: string) => Promise>; + +export interface UseNewsletterConfirmation { + confirmEmail: EmailConfirmationOptin; +} + +export type UseNewsletterConfirmationReturn = () => UseNewsletterConfirmation; diff --git a/apps/web/composables/useNewsletterConfirmation/useNewsletterConfirmation.ts b/apps/web/composables/useNewsletterConfirmation/useNewsletterConfirmation.ts new file mode 100644 index 000000000..06a4e863a --- /dev/null +++ b/apps/web/composables/useNewsletterConfirmation/useNewsletterConfirmation.ts @@ -0,0 +1,14 @@ +import { EmailConfirmationOptin, UseNewsletterConfirmationReturn } from '~/composables/useNewsletterConfirmation/types'; + +const confirmEmail: EmailConfirmationOptin = async (newsletterEmailId, authString) => { + return await useSdk().plentysystems.doEmailConfirmation({ + newsletterEmailId, + authString, + }); +}; + +export const useNewsletterConfirmation: UseNewsletterConfirmationReturn = () => { + return { + confirmEmail, + }; +}; diff --git a/apps/web/lang/de.json b/apps/web/lang/de.json index 8cc3977a8..2add13dcd 100644 --- a/apps/web/lang/de.json +++ b/apps/web/lang/de.json @@ -427,6 +427,10 @@ "stopEdit": "Abbrechen" }, "email": "E-Mail", + "emailConfirmation": { + "newsletterOptInMessage": "Ihre E-Mail-Adresse wurde bestätigt.", + "newsletterOptInMessageError": "Beim Bestätigen Ihrer E-Mail ist ein Fehler aufgetreten." + }, "emptyCart": "Ihr Warenkorb ist leer", "emptyCartImgAlt": "Bild eines leeren Warenkorbs", "emptyCartNotification": "Sie haben keine Artikel in Ihrem Warenkorb", @@ -687,7 +691,7 @@ "lastName": "Nachname", "policy": "Ich bestätige hiermit, dass ich die {privacyPolicy} gelesen habe. Ich kann meine Einwilligung jederzeit widerrufen.", "subscribe": "Newsletter abonnieren", - "success": "Newsletter erfolgreich abonniert" + "success": "Vielen Dank für Ihre Anmeldung! Bitte prüfen Sie Ihr E-Mail-Postfach und klicken Sie auf den Bestätigungslink in unserer Nachricht, um den Newsletter zu abonnieren." }, "next": "Nächste", "nextAriaLabel": "Zur nächsten Seite navigieren", diff --git a/apps/web/lang/en.json b/apps/web/lang/en.json index f8742bb91..5c9a68336 100644 --- a/apps/web/lang/en.json +++ b/apps/web/lang/en.json @@ -427,6 +427,10 @@ "stopEdit": "Cancel" }, "email": "Email", + "emailConfirmation": { + "newsletterOptInMessage": "Your email address has been confirmed.", + "newsletterOptInMessageError": "An error occurred while confirming your email." + }, "emptyCart": "Your cart is empty", "emptyCartImgAlt": "Image of an empty cart", "emptyCartNotification": "You don't have any items in your cart", @@ -687,7 +691,7 @@ "lastName": "Last Name", "policy": "I hereby confirm that I have read the {privacyPolicy}. I can revoke my consent at any time.", "subscribe": "Subscribe To Newsletter", - "success": "Newsletter successfully subscribed" + "success": "Thank you for signing up! Please check your email inbox and click on the confirmation link in our message to complete your newsletter subscription." }, "next": "Next", "nextAriaLabel": "Navigate to next page", diff --git a/apps/web/middleware/newsletter-confirmation.ts b/apps/web/middleware/newsletter-confirmation.ts new file mode 100644 index 000000000..34b104fbd --- /dev/null +++ b/apps/web/middleware/newsletter-confirmation.ts @@ -0,0 +1,23 @@ +export default defineNuxtRouteMiddleware(async ({ query }) => { + if (query.ActionCall === 'WebActionConfirmNewsletter' && import.meta.client) { + const { confirmEmail } = useNewsletterConfirmation(); + const { send } = useNotification(); + const { $i18n } = useNuxtApp(); + + if (query.newsletterEmailId && query.authString) { + const response = await confirmEmail(query.newsletterEmailId.toString(), query.authString.toString()); + if (response && response.data) { + send({ + message: $i18n.t('emailConfirmation.newsletterOptInMessage'), + type: 'positive', + persist: true, + }); + } else { + send({ + message: $i18n.t('emailConfirmation.newsletterOptInMessageError'), + type: 'negative', + }); + } + } + } +}); diff --git a/apps/web/pages/index.vue b/apps/web/pages/index.vue index d1c9a7d6a..924487b23 100644 --- a/apps/web/pages/index.vue +++ b/apps/web/pages/index.vue @@ -35,7 +35,8 @@ diff --git a/docs/changelog/changelog_en.md b/docs/changelog/changelog_en.md index 91b512463..14465f16c 100644 --- a/docs/changelog/changelog_en.md +++ b/docs/changelog/changelog_en.md @@ -1,5 +1,11 @@ # Changelog plentyshopPWA +## v1.x.x (yyyy-mm-dd) + +### 👷 Changed + +- Newsletter email confirmation + ## v1.7.0 (2024-11-06) Overview of all changes ### New diff --git a/package.json b/package.json index fb44c7e61..1a6e5af19 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lhci:mobile": "lhci autorun" }, "dependencies": { - "@plentymarkets/shop-api": "^0.72.2", + "@plentymarkets/shop-api": "^0.72.3", "@types/applepayjs": "^14.0.8", "@types/googlepay": "^0.7.6", "@vee-validate/nuxt": "^4.13.2", diff --git a/yarn.lock b/yarn.lock index b492b1c0b..afdca44ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4237,7 +4237,7 @@ __metadata: "@nuxt/test-utils": ^3.13.1 "@nuxtjs/turnstile": ^0.8.0 "@paypal/paypal-js": 8.1.0 - "@plentymarkets/shop-api": ^0.72.2 + "@plentymarkets/shop-api": ^0.72.3 "@types/applepayjs": ^14.0.8 "@types/googlepay": ^0.7.6 "@types/uuid": ^9.0.8 @@ -4271,14 +4271,14 @@ __metadata: languageName: unknown linkType: soft -"@plentymarkets/shop-api@npm:^0.72.2": - version: 0.72.2 - resolution: "@plentymarkets/shop-api@npm:0.72.2::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40plentymarkets%2Fshop-api%2F0.72.2%2F7371967a71ce02df820ea101fb9d994088eda326" +"@plentymarkets/shop-api@npm:^0.72.3": + version: 0.72.3 + resolution: "@plentymarkets/shop-api@npm:0.72.3::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40plentymarkets%2Fshop-api%2F0.72.3%2F4ad974b92d73b1f72631858bfb033a8903024002" dependencies: "@vue-storefront/middleware": ^3.10.0 axios: ^1.7.7 consola: ^3.2.3 - checksum: 8fe6d4bf487d9a6f2b8714a75d876c77fdd2009a1b4139cd436ea90f5233dca710ae019ffd31fd91ebc66239f0334dc062d7d3e1c7486c7959762b463a049c27 + checksum: cde1b652b795987c68e938f301d80de123e1418ef7ef61522887e155e6ae48f6d496aae7d7733f4b6548486e53e102861066df7d252b5dd13929d772424041af languageName: node linkType: hard