-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: newsletter confirmation (GH-65) * feat: newsletter confirmation (GH-65) * feat: newsletter confirmation (GH-65) --------- Co-authored-by: Maciej Daniłowicz <[email protected]>
- Loading branch information
1 parent
cbe16cc
commit e13d3d9
Showing
10 changed files
with
171 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"vue-demo-store": minor | ||
--- | ||
|
||
Add a confirmation instruction box to the newsletter subscription panel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@shopware-pwa/api-client": minor | ||
--- | ||
|
||
Add newsletter confirmation endpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/api-client/src/services/NewsletterServiceTests/newsletterConfirmation.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { newsletterConfirmation } from "../newsletterService"; | ||
import { defaultInstance } from "../../apiService"; | ||
import { describe, expect, it, beforeEach, vi } from "vitest"; | ||
|
||
vi.mock("../../../src/apiService"); | ||
const mockedApiInstance = defaultInstance; | ||
|
||
describe("NewsletterService - newsletterConfirmation", () => { | ||
const mockedPost = vi.fn(); | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
mockedApiInstance.invoke = { | ||
post: mockedPost, | ||
} as any; | ||
}); | ||
|
||
it("should confirm newsletter", async () => { | ||
mockedPost.mockResolvedValueOnce({ data: { data: {} } }); | ||
const result = await newsletterConfirmation({ | ||
hash: "232323", | ||
em: "44242456", | ||
}); | ||
expect(mockedPost).toBeCalledTimes(1); | ||
expect(mockedPost).toBeCalledWith(`/store-api/newsletter/confirm`, { | ||
hash: "232323", | ||
em: "44242456", | ||
}); | ||
expect(result).toMatchObject({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { getStoreNewsletterConfirmEndpoint } from "../endpoints"; | ||
import { defaultInstance, ShopwareApiInstance } from "../apiService"; | ||
|
||
type NewsletterConfirmationParams = { | ||
em: string; | ||
hash: string; | ||
}; | ||
|
||
/** | ||
* Confirmation from newsletter | ||
* | ||
* @param {NewsletterConfirmationParams} params | ||
* @param {ShopwareApiInstance} contextInstance | ||
* @returns | ||
*/ | ||
export async function newsletterConfirmation( | ||
params: NewsletterConfirmationParams, | ||
contextInstance: ShopwareApiInstance = defaultInstance | ||
): Promise<void> { | ||
const response = await contextInstance.invoke.post( | ||
getStoreNewsletterConfirmEndpoint(), | ||
params | ||
); | ||
return response.data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script setup lang="ts"> | ||
import { newsletterConfirmation } from "@shopware-pwa/api-client"; | ||
const route = useRoute(); | ||
const { apiInstance } = useShopwareContext(); | ||
const error = ref(false); | ||
try { | ||
await newsletterConfirmation( | ||
{ | ||
em: route.query.em as string, | ||
hash: route.query.hash as string, | ||
}, | ||
apiInstance | ||
); | ||
} catch (e) { | ||
error.value = true; | ||
} | ||
</script> | ||
<template> | ||
<div class="max-w-screen-xl mx-auto px-6 sm:px-4"> | ||
<h1 class="text-3xl mb-3">Newsletter subscription</h1> | ||
<div class="text-xl" :class="{ 'text-red': error, 'text-green': !error }"> | ||
{{ | ||
error | ||
? "Something goes wrong please try again later" | ||
: "Thank you! We have signed up your address." | ||
}} | ||
</div> | ||
</div> | ||
</template> |
e13d3d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
frontends-demo – ./templates/vue-demo-store
frontends-demo-git-main-shopware-frontends.vercel.app
frontends-demo-shopware-frontends.vercel.app
frontends-demo.vercel.app
e13d3d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shopware-frontends-docs – ./
shopware-frontends-docs-shopware-frontends.vercel.app
shopware-frontends-docs-git-main-shopware-frontends.vercel.app
shopware-frontends-docs.vercel.app