-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for GetResponse api
- Loading branch information
Mateusz Cholcha
committed
Oct 22, 2024
1 parent
44129b3
commit bf723dd
Showing
5 changed files
with
55 additions
and
13 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
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,27 @@ | ||
export const useGetResponse = () => { | ||
const config = usePublicRuntimeConfig() | ||
|
||
const enabled = computed(() => config.getresponseApiEnabled) | ||
const webConnectEnabled = computed(() => !!config.getresponseWebConnect) | ||
|
||
const subscribe = async (data: { email: string }) => { | ||
if (!config.getresponseApiEnabled) { | ||
// eslint-disable-next-line no-console | ||
console.error('[useGetResponse] GetResponse key not set in environment variables') | ||
return Promise.resolve({ success: false }) | ||
} | ||
|
||
// sending a request to the server (nuxt) | ||
return await fetch('/api/newsletter', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ email: data.email }), | ||
}) | ||
.then(() => ({ success: true })) | ||
.catch(() => ({ success: false })) | ||
} | ||
|
||
return { subscribe, enabled, webConnectEnabled } | ||
} |
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