forked from codex-iter/website-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubscribe.jsx
128 lines (121 loc) · 4.44 KB
/
Subscribe.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import React, { useState } from 'react'
import Toastify from "toastify-js";
import "toastify-js/src/toastify.css";
import { RxCross2 } from "react-icons/rx";
import {motion} from "framer-motion";
import { API_URL } from '../lib/constants';
const Subscribe = (props) => {
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [reg, setReg] = useState("");
const handleSend = async () => {
if (name === "" || email === "" || reg === "") {
Toastify({
text: "Form can't be empty!",
duration: 3000,
backgroundColor: "#56ccf2",
stopOnFocus: true,
position: "right",
}).showToast();
return;
}
try {
const response = await fetch(`${API_URL}/subscribe/subscribe`, {
method: "POST",
body: JSON.stringify({
name: name,
email: email,
reg: reg,
}),
headers: {
"Content-type": "application/json; charset=UTF-8",
},
});
if (response.status === 200) {
const result = await response.json(); // Assuming the response is in JSON format
Toastify({
text: result.message || "Subscription successful!", // Adjust according to your API response
duration: 3000,
backgroundColor: "#56ccf2",
stopOnFocus: true,
position: "right",
}).showToast();
setName("");
setEmail("");
setReg("");
props.handle(false);
} else {
Toastify({
text: "Something went wrong!",
duration: 3000,
backgroundColor: "#ff0000",
stopOnFocus: true,
position: "right",
}).showToast();
}
} catch (err) {
console.error(err);
Toastify({
text: "An error occurred!",
duration: 3000,
backgroundColor: "#ff0000",
stopOnFocus: true,
position: "right",
}).showToast();
}
};
return (
<div
className='bg-black/10 backdrop-blur-xl flex justify-center align-middle text-white fixed h-screen w-screen z-50'>
<motion.div
initial={{opacity: 0, scale: 0.8}}
animate={{opacity: 1, scale: 1}}
transition={{duration: 0.2}}
className='m-auto w-5/6 md:w-full'>
<div className='flex justify-end md:w-1/2 mx-auto'>
<RxCross2 onClick={()=> props.handle(false)} size={32} className="cursor-pointer hover:scale-[1.2] a" />
</div>
<h1 className='text-4xl text-center my-4'>Subscribe to Our Newsletter</h1>
<div className="grid grid-cols-1 gap-6 lg:w-1/2 mx-auto">
<label className="block">
<span className="text-slate-400">Full name</span>
<input
type="text"
className="mt-1 block w-full rounded-md border-secondary text-pastel shadow-sm focus:border-secondary focus:ring focus:ring-secondary focus:ring-opacity-50 bg-primary"
placeholder="John Doe"
value={name}
onChange={(e) => setName(e.target.value)}
/>
</label>
<label className="block">
<span className="text-slate-400">Email address</span>
<input
type="email"
className="mt-1 block w-full rounded-md border-secondary shadow-sm text-pastel focus:border-secondary focus:ring focus:ring-secondary focus:ring-opacity-50 bg-primary"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
</label>
<label className="block">
<span className="text-slate-400">Registration Number</span>
<input
type="text"
className="mt-1 block w-full rounded-md border-secondary shadow-sm text-pastel focus:border-secondary focus:ring focus:ring-secondary focus:ring-opacity-50 bg-primary"
placeholder="214100****"
value={reg}
onChange={(e) => setReg(e.target.value)}
/>
</label>
<button
onClick={handleSend}
className="w-full mx-auto flex items-center justify-center px-8 py-2 border border-transparent text-lg font-semibold rounded-lg text-slate-800 bg-secondary hover:scale-105 will-change-transform transition-transform md:py-3 md:text-lg md:px-10"
>
Subscribe
</button>
</div>
</motion.div>
</div>
)
}
export default Subscribe