File tree Expand file tree Collapse file tree 5 files changed +84
-21
lines changed Expand file tree Collapse file tree 5 files changed +84
-21
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import { defineConfig } from 'astro/config';
2
2
import tailwind from '@astrojs/tailwind' ;
3
3
import image from '@astrojs/image' ;
4
4
import react from '@astrojs/react' ;
5
-
6
5
import prefetch from '@astrojs/prefetch' ;
7
6
8
7
// https://astro.build/config
Original file line number Diff line number Diff line change 16
16
"@astrojs/tailwind" : " ^3.1.2" ,
17
17
"@types/react" : " ^18.0.21" ,
18
18
"@types/react-dom" : " ^18.0.6" ,
19
- "astro" : " ^2.4.5 " ,
19
+ "astro" : " ^2.5.1 " ,
20
20
"prettier" : " ^2.8.8" ,
21
21
"prettier-plugin-tailwindcss" : " ^0.3.0" ,
22
22
"react" : " ^18.0.0" ,
23
23
"react-dom" : " ^18.0.0" ,
24
24
"sharp" : " ^0.32.1" ,
25
- "tailwindcss" : " ^3.0.24"
25
+ "tailwindcss" : " ^3.0.24" ,
26
+ "zod" : " ^3.21.4"
26
27
}
27
28
}
Original file line number Diff line number Diff line change
1
+ ---
2
+ ---
3
+
4
+ <div class =" mx-auto w-96 py-4" >
5
+ <label class =" mb-2 block text-lg font-bold text-white" for =" email"
6
+ >Subscribe to our newsletter</label
7
+ >
8
+ <form data-email-subscription class =" flex place-content-between" >
9
+ <input
10
+ class =" w-full rounded-lg bg-slate-900 p-2 text-white"
11
+ type =" email"
12
+ name =" email"
13
+ id =" email"
14
+ placeholder =" Enter your email"
15
+ required
16
+ />
17
+ <button class =" ml-2 rounded-lg bg-slate-900 p-2 text-white" type =" submit"
18
+ >Subscribe</button
19
+ >
20
+ </form >
21
+ </div >
22
+
23
+ <script >
24
+ import { z } from 'zod';
25
+
26
+ const forms = document.querySelectorAll('[data-email-subscription]');
27
+ forms.forEach((form) => {
28
+ form.addEventListener('submit', (e) => {
29
+ e.preventDefault();
30
+ // TODO: Send email to some service
31
+ const email = z
32
+ .string()
33
+ .email()
34
+ .safeParse((e.target as any)?.email?.value);
35
+
36
+ if (!email.success) {
37
+ alert('Please enter a valid email address');
38
+ return;
39
+ }
40
+
41
+ console.log(email.data);
42
+ form.innerHTML = 'Thank you for subscribing!';
43
+ });
44
+ });
45
+ </script >
Original file line number Diff line number Diff line change 1
1
---
2
2
import { Image } from ' @astrojs/image/components' ;
3
+ import EmailSub from ' ../components/EmailSub.astro' ;
3
4
4
5
interface Props {
5
6
title: string ;
@@ -35,5 +36,6 @@ const { title } = Astro.props;
35
36
>
36
37
</header >
37
38
<slot />
39
+ <EmailSub />
38
40
</body >
39
41
</html >
You can’t perform that action at this time.
0 commit comments