Skip to content

Commit

Permalink
fix: apikey brevo newsletter (janhq#2430)
Browse files Browse the repository at this point in the history
* fix: temprary-newsletter

* fix apikey brevo
  • Loading branch information
urmauur authored Mar 19, 2024
1 parent d33caba commit 16bd263
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
3 changes: 1 addition & 2 deletions docs/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ UMAMI_PROJECT_API_KEY=xxxx
UMAMI_APP_URL=xxxx
ALGOLIA_API_KEY=xxxx
ALGOLIA_APP_ID=xxxx
GITHUB_ACCESS_TOKEN=xxxx
API_KEY_BREVO=xxxx
GITHUB_ACCESS_TOKEN=xxxx
7 changes: 1 addition & 6 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const config = {
},
{
from: '/integrations/tensorrt',
to: '/guides/providers/tensorrt-llm'
to: '/guides/providers/tensorrt-llm',
},
],
},
Expand Down Expand Up @@ -408,11 +408,6 @@ const config = {
},
},

// Put your custom environment here
customFields: {
apiKeyBrevo: process.env.API_KEY_BREVO,
},

themes: ['@docusaurus/theme-live-codeblock', '@docusaurus/theme-mermaid'],
}

Expand Down
21 changes: 13 additions & 8 deletions docs/src/containers/Footer/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState } from 'react'

import useDocusaurusContext from '@docusaurus/useDocusaurusContext'
import { AiOutlineGithub, AiOutlineTwitter } from 'react-icons/ai'
Expand Down Expand Up @@ -130,15 +130,13 @@ export default function Footer() {
siteConfig: { customFields },
} = useDocusaurusContext()

const [formMessage, setFormMessage] = useState('')

const onSubmit = (data) => {
const { email } = data
const options = {
method: 'POST',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'api-key': customFields.apiKeyBrevo,
},

body: JSON.stringify({
updateEnabled: false,
email,
Expand All @@ -147,12 +145,18 @@ export default function Footer() {
}

if (email) {
fetch('https://api.brevo.com/v3/contacts', options)
fetch('https://brevo.jan.ai/', options)
.then((response) => response.json())
.then((response) => {
if (response.id) {
reset()
setFormMessage('You have successfully joined our newsletter')
} else {
setFormMessage(response.message)
}
reset()
setTimeout(() => {
setFormMessage('')
}, 5000)
})
.catch((err) => console.error(err))
}
Expand Down Expand Up @@ -203,6 +207,7 @@ export default function Footer() {
</svg>
</button>
</form>
{formMessage && <p className="text-left mt-4">{formMessage}</p>}
</div>
</div>
</div>
Expand Down
23 changes: 14 additions & 9 deletions docs/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'
import DownloadApp from '@site/src/containers/DownloadApp'
import React, { useState } from 'react'

import { useForm } from 'react-hook-form'

import useBaseUrl from '@docusaurus/useBaseUrl'
Expand Down Expand Up @@ -86,6 +86,7 @@ export default function Home() {
const isBrowser = useIsBrowser()
const { stargazers } = useAppStars()
const { data } = useDiscordWidget()
const [formMessage, setFormMessage] = useState('')

const userAgent = isBrowser && navigator.userAgent
const isBrowserChrome = isBrowser && userAgent.includes('Chrome')
Expand All @@ -104,11 +105,6 @@ export default function Home() {
const { email } = data
const options = {
method: 'POST',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'api-key': customFields.apiKeyBrevo,
},
body: JSON.stringify({
updateEnabled: false,
email,
Expand All @@ -117,12 +113,18 @@ export default function Home() {
}

if (email) {
fetch('https://api.brevo.com/v3/contacts', options)
fetch('https://brevo.jan.ai/', options)
.then((response) => response.json())
.then((response) => {
if (response.id) {
reset()
setFormMessage('You have successfully joined our newsletter')
} else {
setFormMessage(response.message)
}
reset()
setTimeout(() => {
setFormMessage('')
}, 5000)
})
.catch((err) => console.error(err))
}
Expand Down Expand Up @@ -748,6 +750,9 @@ export default function Home() {
Subscribe
</button>
</form>
{formMessage && (
<p className="text-left mt-4">{formMessage}</p>
)}
</div>
</div>
</div>
Expand Down

0 comments on commit 16bd263

Please sign in to comment.