-
Notifications
You must be signed in to change notification settings - Fork 0
/
Orderform.jsx
188 lines (152 loc) · 6.71 KB
/
Orderform.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import React,{ useState } from 'react'
import { toast, ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import axios from 'axios';
const OrderForm = () => {
const [order, setOrder] = useState({
UserName:"",
phoneNumber:"",
email:"",
address:"",
LandMark:"",
PinCode:"",
});
const {UserName,phoneNumber,email,address,LandMark,PinCode} = order;
const onChange = (e) => {
setOrder({ ...order, [e.target.name]: e.target.value });
};
const onSubmit = async(e) => {
e.preventDefault();
if (!order.UserName || !validatePhoneNumber(order.phoneNumber) || !validateEmail(order.email) || !order.address || !order.LandMark || !order.PinCode) {
toast.error("Please provide a valid email or Ph number ") ||
toast.error("pleas enter 10 digits")
} else {
toast.success("order placed successfully")
}
axios.post("http://localhost:8001/Orders",{UserName,phoneNumber,email,address,LandMark,PinCode})
.then((res)=> console.log(res))
.catch(err => console.log(err))
return;
};
const validateEmail = (email) => {
const re = /\S+@\S+\.\S+/;
return re.test(email);
};
const validatePhoneNumber = (phoneNumber) => {
const ph = /^\d{10}$/;
return ph.test(phoneNumber);
};
return (
<div className=" max-w-full px-2 w-2/6 mx-auto mt-24 backdrop-blur-2xl rounded-3xl">
<form onSubmit={onSubmit} className=' w-full grid grid-cols-2 gap-6'>
<div className="form-group">
<label id="UserName" className="text-lg mt-6 ml-4 font-semibold text-white ">Name:</label>
<br></br>
<input
type="text"
id="UserName"
name="UserName"
placeholder='Name...'
value={order.UserName}
onChange={onChange}
required
className=" w-4/5 mt-3 ml-4 px-4 py-1.5 text-md text-gray-700 border-white rounded transition duration-100 ease-in
focus:text-gray-700 mb-6 hover:shadow-2xl "
/>
</div>
<div className="form-group">
<label id="phoneNumber" className="text-lg font-semibold text-white ">Phone Number:</label>
<br></br>
<input
type="number"
id="phoneNumber"
name="phoneNumber"
placeholder='phone no...'
value={order.phoneNumber}
onChange={onChange}
pattern='/^\d{10}$/'
required
className="w-4/5 mt-3 mb-6 px-4 py-1.5 text-md text-gray-700 bg-white border-grey-300 rounded transition duration-100 ease-in-out
focus:text-gray-700 focus:bg-white focus:border-slate-600 hover:shadow-2xl "
/>
</div>
<div className="form-group">
<label id="email" className="text-lg mt-6 ml-4 font-semibold text-white ">Email:</label>
<br></br>
<input
type="email"
id="email"
name="email"
placeholder='[email protected]'
value={order.email}
onChange={onChange}
required
className="w-4/5 mt-3 ml-4 px-4 py-1.5 text-md text-gray-700 bg-white border-gray-300 rounded transition duration-100 ease-in-out
focus:text-gray-700 focus:bg-white focus:border-slate-600 mb-6 hover:shadow-2xl"
/>
</div>
<div className="form-group">
<label id="address" className="text-lg mt-6 font-semibold text-white">Address:</label>
<br></br>
<input
type="text"
id="address"
name="address"
placeholder='Address...'
value={order.address}
onChange={onChange}
required
className="w-4/5 mt-3 px-4 py-1.5 text-md text-gray-700 bg-white border-gray-300 rounded transition duration-100 ease-in-out
focus:text-gray-700 focus:bg-white focus:border-slate-600 mb-6 hover:shadow-2xl"
/>
</div>
<div className="form-group">
<label id="LandMark" className="text-lg mt-6 ml-4 font-semibold text-white">LandMark:</label>
<br></br>
<input
type="text"
id="LandMark"
name="LandMark"
placeholder='LandMark...'
value={order.LandMark}
onChange={onChange}
required
className="w-4/5 mt-3 ml-4 px-4 py-1.5 text-md text-gray-700 bg-white border-gray-300 rounded transition duration-100 ease-in-out
focus:text-gray-700 focus:bg-white focus:border-slate-600 mb-6 hover:shadow-2xl"
/>
</div>
<div className="form-group">
<label id="PinCode" className="text-lg mt-6 font-semibold text-white">PinCode:</label>
<br></br>
<input
type="text"
id="PinCode"
name="PinCode"
placeholder='PinCode...'
value={order.pinCode}
onChange={onChange}
required
className="w-4/5 mt-3 px-4 py-1.5 text-md text-gray-700 bg-white border-gray-300 rounded transition duration-100 ease-in-out
focus:text-gray-700 focus:bg-white focus:border-slate-600 mb-6 hover:shadow-2xl"
/>
</div>
<button type="submit" className='mb-6 ml-2 mt-4 w-full px-4 py-3 bg-blue-600 text-white font-medium text-sm uppercase
rounded-2xl shadow-md hover:bg-blue-700 hover:shadow-lg focus:bg-blue-700 focus:shadow-lg active:bg-blue-800 active:shadow-lg transition duration-150
ease-in-out'>Place Order</button>
</form>
<ToastContainer
position="top-center"
autoClose={5000}
hideProgressBar={false}
newestOnTop={false}
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover
theme="dark"
/>
</div>
)
}
export default OrderForm