fixed order form not resetting
This commit is contained in:
parent
ae824b4def
commit
e5ed0ef29d
Binary file not shown.
Binary file not shown.
@ -18,23 +18,27 @@ const Popp = Poppins({ weight: "400", subsets: ["latin"] });
|
|||||||
export default function Home() {
|
export default function Home() {
|
||||||
const [email, setEmail] = React.useState<string>("");
|
const [email, setEmail] = React.useState<string>("");
|
||||||
const [order, setOrder] = React.useState<string>("");
|
const [order, setOrder] = React.useState<string>("");
|
||||||
|
const [records, setRecords] = React.useState<any>([]);
|
||||||
|
const [formValues, setFormValues] = React.useState({
|
||||||
const [isOpen, setIsOpen] = React.useState(false);
|
emails: "",
|
||||||
const [showPortal, setShowPortal] = React.useState(false);
|
orders: "",
|
||||||
const handleModal = () => {
|
});
|
||||||
setShowPortal(!showPortal);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
async function newOrder(event: React.FormEvent<HTMLFormElement>) {
|
async function newOrder(event: React.FormEvent<HTMLFormElement>) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const response = await fetch("http://192.168.50.107:5580/new-order", {
|
const formData = new FormData(event.currentTarget);
|
||||||
|
const payload = Object.fromEntries(formData);
|
||||||
|
// console.log(payload)
|
||||||
|
// console.log(JSON.stringify(payload))
|
||||||
|
// console.log({email:formData.get("email"), order:formData.get("order")})
|
||||||
|
|
||||||
|
// const response = await fetch("http://192.168.50.107:5580/new-order", {
|
||||||
|
const response = await fetch("http://localhost:5080/new-order", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-type': 'application/json',
|
"Content-type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({email:email, order:order }),
|
body: JSON.stringify(payload),
|
||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
@ -43,6 +47,12 @@ export default function Home() {
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setRecords([...records, formValues]);
|
||||||
|
setFormValues({
|
||||||
|
emails: "",
|
||||||
|
orders: "",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -60,13 +70,6 @@ export default function Home() {
|
|||||||
<MenuCard Menu={Product} />
|
<MenuCard Menu={Product} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* <div>
|
|
||||||
<Button onClick={() => setIsOpen(true)}>Open Modal</Button>
|
|
||||||
<Modal open={isOpen} onClose={() => setIsOpen(false)}>
|
|
||||||
Fancy Modal
|
|
||||||
</Modal>
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
<form
|
<form
|
||||||
className="mt-10 flex flex-col w-full items-center gap-4"
|
className="mt-10 flex flex-col w-full items-center gap-4"
|
||||||
// action={async (formData) => {
|
// action={async (formData) => {
|
||||||
@ -78,17 +81,26 @@ export default function Home() {
|
|||||||
<input
|
<input
|
||||||
className="h-14 px-4 rounded-lg border-black bg-slate-600 lg:w-1/3 md:w-1/2 text-[#EEEEEE]"
|
className="h-14 px-4 rounded-lg border-black bg-slate-600 lg:w-1/3 md:w-1/2 text-[#EEEEEE]"
|
||||||
type="email"
|
type="email"
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
// onChange={(e) => setEmail(e.target.value)}
|
||||||
|
value={formValues.emails}
|
||||||
|
onChange={(e) =>
|
||||||
|
setFormValues({ ...formValues, emails: e.target.value })
|
||||||
|
}
|
||||||
required
|
required
|
||||||
maxLength={500}
|
maxLength={500}
|
||||||
placeholder="Your email"
|
placeholder="Your email"
|
||||||
name="senderEmail"
|
// name="senderEmail"
|
||||||
|
name="email"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<textarea
|
<textarea
|
||||||
className="h-52 my-3 rounded-lg lg:w-1/3 md:w-1/2 bg-slate-600 p-4 text-[#EEEEEE]"
|
className="h-52 my-3 rounded-lg lg:w-1/3 md:w-1/2 bg-slate-600 p-4 text-[#EEEEEE]"
|
||||||
name="order"
|
name="order"
|
||||||
onChange={(e) => setOrder(e.target.value)}
|
// onChange={(e) => setOrder(e.target.value)}
|
||||||
|
value={formValues.orders}
|
||||||
|
onChange={(e) =>
|
||||||
|
setFormValues({ ...formValues, orders: e.target.value })
|
||||||
|
}
|
||||||
placeholder="Your order"
|
placeholder="Your order"
|
||||||
required
|
required
|
||||||
maxLength={500}
|
maxLength={500}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user