11<script setup lang="ts">
2- import { ref , onMounted } from ' vue'
2+ import { ref , onMounted , onUnmounted } from ' vue'
33import { Vue3Marquee } from ' vue3-marquee'
4- import axios from ' axios'
5- import VueTurnstile from ' vue-turnstile'
64import Accordion from ' ./Accordion.vue'
75
8- const error = ref (' ' )
9- const email = ref (' ' )
10- const token = ref (' ' )
11- const favoriteDevOpsTool = ref (' ' )
12- const isBusy = ref (false )
136const isSubscribed = ref (false )
14- const isSuccess = ref (false )
15- const isProd = import .meta .env .PROD
16-
17- const subscribeToNewsletter = async () => {
18- isBusy .value = true
19-
20- // Validate the captcha token with the server
21- try {
22- await axios .post (' https://newsprxy.gorkem.workers.dev/' , {
23- email: email .value ,
24- userGroup: ' KitOps' ,
25- formName: ' KitOps-Community' ,
26- favoriteDevOpsTool: favoriteDevOpsTool .value
27- }, {
28- headers: {
29- ' cf-turnstile-response' : token .value ,
30- ' Content-Type' : ' application/x-www-form-urlencoded' ,
31- ' Expect' : ' ' ,
32- }
33- })
347
35- isSuccess .value = true
36- localStorage .setItem (' subscribed' , ' true' )
37- }
38- catch (err : any ) {
39- error .value = err .response ?.data ?.errors ?.flatMap ((e : Error ) => e .message )[0 ] || ' An unknown error occurred'
40- }
41- finally {
42- isBusy .value = false
43- }
44- }
8+ let hubspotScript: HTMLScriptElement | null = null ;
459
4610onMounted (() => {
4711 isSubscribed .value = localStorage .getItem (' subscribed' ) === ' true'
@@ -58,6 +22,34 @@ onMounted(() => {
5822 }
5923 }
6024 }, 100 )
25+
26+ // Render the HubSpot form
27+ const script = document .createElement (" script" );
28+ script .src = " https://js.hsforms.net/forms/v2.js" ;
29+ document .body .appendChild (script );
30+
31+ script .addEventListener (" load" , onHubSpotLoad );
32+ hubspotScript = script ;
33+ })
34+
35+ const onHubSpotLoad = () => {
36+ if (window .hbspt ) {
37+ window .hbspt .forms .create ({
38+ portalId: " 244807631" ,
39+ formId: " db1e95f1-fcaa-41e5-b9f6-2cead07c3806" ,
40+ region: " na2" ,
41+ target: " #hubspotForm"
42+ });
43+ }
44+ };
45+
46+ onUnmounted (() => {
47+ if (hubspotScript ) {
48+ console .log (' removing hubspot script' );
49+ hubspotScript .removeEventListener (" load" , onHubSpotLoad );
50+ hubspotScript .remove ();
51+ hubspotScript = null ;
52+ }
6153})
6254 </script >
6355
@@ -168,42 +160,7 @@ onMounted(() => {
168160 <h2 class =" text-center" >stay informed About Kitops</h2 >
169161
170162 <div class =" text-center max-w-[600px] mx-auto mt-12" >
171- <template v-if =" ! isSuccess " >
172- <form @submit.prevent =" subscribeToNewsletter" class =" flex flex-col md:flex-row gap-10 lg:gap-4" >
173- <input required
174- :disabled =" isBusy"
175- id =" email"
176- type =" email"
177- pattern =" ^[a-zA-Z0-9]+([._+\-][a-zA-Z0-9]+)*@[a-zA-Z0-9\-]+\.[a-zA-Z]{2,}$"
178- name =" email"
179- placeholder =" you@example.com"
180- class =" input"
181- v-model =" email"
182- style =" border : 1px solid var (--color-off-white )" />
183-
184- <input
185- type =" text"
186- id =" favoriteDevOpsTool"
187- placeholder =" What's your favorite devops tool?"
188- name =" favoriteDevOpsTool"
189- v-model =" favoriteDevOpsTool"
190- class =" hidden" />
191-
192- <button type =" submit" :disabled =" isBusy" class =" kit-button kit-button-gold text-center mx-auto" >
193- JOIN THE LIST
194- </button >
195- </form >
196-
197- <div v-if =" isProd" class =" mt-10" >
198- <vue-turnstile site-key =" 0x4AAAAAAA1WT4LYaVrBtAD7" v-model =" token" />
199- </div >
200-
201- <p v-if =" error" class =" text-red-500 mt-6" >{{ error }}</p >
202- </template >
203-
204- <template v-else >
205- <p class =" mt-12" >You are now subscribed to the newsletter.</p >
206- </template >
163+ <div id =" hubspotForm" class =" space-y-5" ></div >
207164 </div >
208165</div >
209166
@@ -629,8 +586,25 @@ onMounted(() => {
629586<!-- Our custom home styles -->
630587<style scoped src="@theme /assets/css/home.css "></style >
631588
632- <style scoped>
633- .input {
589+ <style >
590+ .grecaptcha-badge {
591+ margin-inline : auto ;
592+ }
593+ .hs-form > * {
594+ margin-top : 12px ;
595+ }
596+
597+ .hs-form-field {
598+ text-align : left ;
599+ }
600+
601+ .hs-error-msg {
602+ color : var (--color-red-500 );
603+ margin-top : 4px ;
604+ font-size : 0.875rem ;
605+ }
606+
607+ .hs-input {
634608 display : block ;
635609 border : 1px solid var (--color-off-white );
636610 color : var (--color-off-white );
0 commit comments