Skip to content

Commit 0ca3e40

Browse files
authored
Merge pull request #47 from jinyang1994/main
feat: add newsletter component
2 parents d417bd1 + a8d6c8a commit 0ca3e40

File tree

6 files changed

+207
-5
lines changed

6 files changed

+207
-5
lines changed

docusaurus.config.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,28 @@ const config: Config = {
3838
defaultLocale: 'en',
3939
locales: ['en']
4040
},
41-
41+
plugins: [
42+
function () {
43+
return {
44+
name: 'proxy-webpack-plugin',
45+
configureWebpack() {
46+
return {
47+
mergeStrategy: { 'devServer.proxy': 'replace' },
48+
devServer: {
49+
proxy: {
50+
'/api': {
51+
target: 'http://localhost:3001/',
52+
secure: false,
53+
changeOrigin: true,
54+
logLevel: 'debug'
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
],
4263
presets: [
4364
[
4465
'classic',

src/components/Button/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ interface LinkButtonProps {
1212
| 'pink'
1313
| 'light-purple'
1414
| 'yellow'
15+
buttonType?: 'button' | 'submit' | 'reset'
16+
disabled?: boolean
1517
className?: string
18+
arrow?: boolean
1619
}
1720

1821
const colors: { [key in LinkButtonProps['type']]: string } = {
@@ -28,16 +31,20 @@ const colors: { [key in LinkButtonProps['type']]: string } = {
2831
function Button({
2932
children,
3033
type,
31-
className
34+
buttonType = 'button',
35+
className,
36+
arrow = true,
37+
disabled
3238
}: PropsWithChildren<LinkButtonProps>) {
3339
return (
3440
<button
35-
type="button"
41+
type={buttonType}
3642
className={clsx(styles.button, colors[type], className)}
43+
disabled={disabled}
3744
>
3845
<span className={styles.buttonInner}>
3946
{children}
40-
<ArrowSquare className={styles.buttonIcon} />
47+
{arrow && <ArrowSquare className={styles.buttonIcon} />}
4148
</span>
4249
</button>
4350
)

src/components/Button/styles.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.button {
2-
display: block;
2+
display: inline-block;
33
border: none;
44
background: none;
55
cursor: pointer;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { useState, useCallback, FormEvent } from 'react'
2+
import Button from '@site/src/components/Button'
3+
import styles from './styles.module.css'
4+
5+
enum Text {
6+
Subscribe = 'Subscribe',
7+
Subscribing = 'Subscribing...',
8+
Subscribed = 'Subscribed'
9+
}
10+
11+
function LinkList() {
12+
const [text, setText] = useState<Text>(Text.Subscribe)
13+
const submit = useCallback(async (e: FormEvent<HTMLFormElement>) => {
14+
try {
15+
const email = e.target.email.value
16+
const form = new FormData()
17+
18+
e.preventDefault()
19+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
20+
return
21+
}
22+
form.append(
23+
'data',
24+
JSON.stringify({ email, table: 'handbook-newsletter' })
25+
)
26+
setText(Text.Subscribing)
27+
await fetch('/api/newsletter', {
28+
method: 'POST',
29+
body: form
30+
})
31+
setText(Text.Subscribed)
32+
} catch (error) {
33+
console.error(error)
34+
setText(Text.Subscribe)
35+
}
36+
}, [])
37+
38+
return (
39+
<div className={styles.root}>
40+
<i className={styles.emailIcon} />
41+
<h3>Stay updated with the handbook</h3>
42+
<p>
43+
Get the latest insights and updates on LLM inference and optimization
44+
techniques.
45+
</p>
46+
<form onSubmit={submit}>
47+
<input
48+
type="email"
49+
placeholder="Enter your email address"
50+
name="email"
51+
/>
52+
<Button
53+
arrow={false}
54+
disabled={text === Text.Subscribing}
55+
type="green"
56+
buttonType="submit"
57+
>
58+
{text}
59+
</Button>
60+
</form>
61+
<p className={styles.note}>
62+
No spam, unsubscribe at any time. We respect your privacy.
63+
</p>
64+
<ul>
65+
<li>Monthly insights</li>
66+
<li>Latest techniques</li>
67+
<li>Handbook updates</li>
68+
</ul>
69+
</div>
70+
)
71+
}
72+
73+
export default LinkList
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
.emailIcon {
2+
display: block;
3+
width: 1.5rem;
4+
height: 1.5rem;
5+
background-image: url('/img/email.svg');
6+
background-size: contain;
7+
background-repeat: no-repeat;
8+
background-position: center;
9+
}
10+
11+
.root {
12+
border: 1px solid #dcfce7;
13+
border-radius: 0.5rem;
14+
display: flex;
15+
flex-direction: column;
16+
align-items: center;
17+
margin: 1.5rem 0;
18+
padding: 2rem 1rem;
19+
background-image: linear-gradient(to right, #f8fafc, #f0fdf4);
20+
text-align: center;
21+
}
22+
23+
.root h3 {
24+
font-size: 1.5rem;
25+
line-height: 1.5;
26+
font-weight: 700;
27+
color: #111827;
28+
margin: 0.5rem 0;
29+
}
30+
31+
.root p {
32+
color: #4b5563;
33+
margin-bottom: 1rem;
34+
line-height: 1.4;
35+
}
36+
37+
.root ul {
38+
display: flex;
39+
flex-wrap: wrap;
40+
justify-content: center;
41+
gap: 1rem;
42+
row-gap: 0.1rem;
43+
list-style: none;
44+
margin: 0;
45+
padding: 0;
46+
}
47+
48+
.root form {
49+
display: flex;
50+
align-items: center;
51+
justify-content: center;
52+
margin-bottom: 0.75rem;
53+
gap: 0.75rem;
54+
width: 100%;
55+
}
56+
57+
.root form input {
58+
height: 32px;
59+
font-family: inherit;
60+
flex: 1;
61+
display: block;
62+
border: 1px solid #d1d5db;
63+
border-radius: 0.625rem;
64+
padding: 0 0.75rem;
65+
font-size: 0.875rem;
66+
max-width: 300px;
67+
transition: all 0.3s ease-in-out;
68+
}
69+
70+
.root form input:focus {
71+
outline: none;
72+
border: 1px solid #4ade80;
73+
box-shadow: 0 0 0 2px #bbf7d0;
74+
}
75+
76+
.root .note {
77+
font-size: 0.875rem;
78+
}
79+
80+
.root ul li {
81+
margin: 0;
82+
display: flex;
83+
align-items: center;
84+
gap: 0.5rem;
85+
font-size: 0.875rem;
86+
line-height: 1rem;
87+
color: #4b5563;
88+
font-weight: 500;
89+
}
90+
91+
.root ul li::before {
92+
content: '';
93+
display: block;
94+
width: 1rem;
95+
height: 1rem;
96+
background-image: url('/img/check.svg');
97+
background-size: contain;
98+
background-repeat: no-repeat;
99+
background-position: center;
100+
}

static/img/email.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)