Skip to content

Commit a1ae0ab

Browse files
committed
.
1 parent 654f398 commit a1ae0ab

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

app/(default)/(home)/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ import {
2222
} from "@/components/ui/drawer"
2323

2424

25+
2526
import { Landing } from "./landing"
2627
import { Embodied, E2EAD } from "@/components/app-drawer"
28+
29+
30+
2731
import { publications } from "@/data/publications"
2832
import { events } from "@/data/events"
2933

34+
35+
3036
export default function Home() {
3137

3238
return (

app/(default)/layout.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222

2323

2424
import { WeChat, WeChatGroup } from "@/components/app-drawer"
25+
import { EmailSubscribe } from "@/components/mailing"
2526

2627

2728

@@ -137,6 +138,10 @@ export default function RootLayout({
137138

138139
</div>
139140

141+
<div className="w-full max-w-7xl text-xs">
142+
<EmailSubscribe />
143+
</div>
144+
140145
<div className="w-full max-w-7xl text-xs">
141146
OpenDriveLab © 2021 - 2025
142147
</div>

components/mailing.tsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'use client'
2+
import { useState, useEffect } from 'react'
3+
import { Input } from '@/components/ui/input'
4+
import { Button } from '@/components/ui/button'
5+
const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
6+
export function EmailSubscribe() {
7+
const [email, setEmail] = useState('')
8+
const [valid, setValid] = useState(false)
9+
const [loading, setLoading] = useState(false)
10+
const [placeholder, setPlaceholder] = useState('enter your email');
11+
useEffect(() => {
12+
const isValid = emailRegex.test(email.trim())
13+
setValid(isValid && email.trim() !== '')
14+
}, [email])
15+
16+
const handleSubmit = async () => {
17+
if (!valid) return
18+
setLoading(true)
19+
20+
const payload = {
21+
email,
22+
message: '',
23+
organization: '',
24+
first_name: '',
25+
last_name: '',
26+
}
27+
28+
try {
29+
const res = await fetch('https://drivelab.openxlab.org.cn/gw/drivelab-register-api-service/signup/', {
30+
method: 'POST',
31+
headers: { 'Content-Type': 'application/json' },
32+
body: JSON.stringify(payload),
33+
})
34+
35+
if (res.ok) {
36+
setEmail('')
37+
setPlaceholder('subscribed!');
38+
} else {
39+
}
40+
} catch (err) {
41+
} finally {
42+
setLoading(false)
43+
}
44+
}
45+
46+
return (
47+
<div className="w-full flex flex-col md:flex-row gap-3 md:items-center">
48+
<span>
49+
Subscribe & stay tuned!
50+
</span>
51+
<div className="flex gap-3 items-center">
52+
<Input
53+
type="email"
54+
placeholder={placeholder}
55+
value={email}
56+
onChange={(e) => setEmail(e.target.value)}
57+
className='rounded-sm text-xs md:text-xs h-5 max-w-xs'
58+
/>
59+
<Button onClick={handleSubmit} disabled={!valid || loading} className='text-xs h-5 p-2 hover:cursor-pointer font-normal rounded-sm'>
60+
{loading ? '...' : 'subscribe'}
61+
</Button>
62+
</div>
63+
</div>
64+
)
65+
}

package-lock.json

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@next/third-parties": "^15.3.2",
13+
"@radix-ui/react-alert-dialog": "^1.1.14",
1314
"@radix-ui/react-aspect-ratio": "^1.1.2",
1415
"@radix-ui/react-collapsible": "^1.1.11",
1516
"@radix-ui/react-dialog": "^1.1.14",

0 commit comments

Comments
 (0)