MCPcopy Create free account
hub / github.com/GreatStackDev/gocart / AddressModal

Function AddressModal

components/AddressModal.jsx:6–53  ·  view source on GitHub ↗
({ setShowAddressModal })

Source from the content-addressed store, hash-verified

4import { toast } from "react-hot-toast"
5
6const AddressModal = ({ setShowAddressModal }) => {
7
8 const [address, setAddress] = useState({
9 name: '',
10 email: '',
11 street: '',
12 city: '',
13 state: '',
14 zip: '',
15 country: '',
16 phone: ''
17 })
18
19 const handleAddressChange = (e) => {
20 setAddress({
21 ...address,
22 [e.target.name]: e.target.value
23 })
24 }
25
26 const handleSubmit = async (e) => {
27 e.preventDefault()
28
29 setShowAddressModal(false)
30 }
31
32 return (
33 <form onSubmit={e => toast.promise(handleSubmit(e), { loading: 'Adding Address...' })} className="fixed inset-0 z-50 bg-white/60 backdrop-blur h-screen flex items-center justify-center">
34 <div className="flex flex-col gap-5 text-slate-700 w-full max-w-sm mx-6">
35 <h2 className="text-3xl ">Add New <span className="font-semibold">Address</span></h2>
36 <input name="name" onChange={handleAddressChange} value={address.name} className="p-2 px-4 outline-none border border-slate-200 rounded w-full" type="text" placeholder="Enter your name" required />
37 <input name="email" onChange={handleAddressChange} value={address.email} className="p-2 px-4 outline-none border border-slate-200 rounded w-full" type="email" placeholder="Email address" required />
38 <input name="street" onChange={handleAddressChange} value={address.street} className="p-2 px-4 outline-none border border-slate-200 rounded w-full" type="text" placeholder="Street" required />
39 <div className="flex gap-4">
40 <input name="city" onChange={handleAddressChange} value={address.city} className="p-2 px-4 outline-none border border-slate-200 rounded w-full" type="text" placeholder="City" required />
41 <input name="state" onChange={handleAddressChange} value={address.state} className="p-2 px-4 outline-none border border-slate-200 rounded w-full" type="text" placeholder="State" required />
42 </div>
43 <div className="flex gap-4">
44 <input name="zip" onChange={handleAddressChange} value={address.zip} className="p-2 px-4 outline-none border border-slate-200 rounded w-full" type="number" placeholder="Zip code" required />
45 <input name="country" onChange={handleAddressChange} value={address.country} className="p-2 px-4 outline-none border border-slate-200 rounded w-full" type="text" placeholder="Country" required />
46 </div>
47 <input name="phone" onChange={handleAddressChange} value={address.phone} className="p-2 px-4 outline-none border border-slate-200 rounded w-full" type="text" placeholder="Phone" required />
48 <button className="bg-slate-800 text-white text-sm font-medium py-2.5 rounded-md hover:bg-slate-900 active:scale-95 transition-all">SAVE ADDRESS</button>
49 </div>
50 <XIcon size={30} className="absolute top-5 right-5 text-slate-500 hover:text-slate-700 cursor-pointer" onClick={() => setShowAddressModal(false)} />
51 </form>
52 )
53}
54
55export default AddressModal

Callers

nothing calls this directly

Calls 1

handleSubmitFunction · 0.70

Tested by

no test coverage detected