-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tiago Barbosa <tbarbos@hotmail.com>
- Loading branch information
Showing
2 changed files
with
57 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,73 @@ | ||
import { Button } from '@headlessui/react' | ||
import { Button } from "@headlessui/react"; | ||
import { useState } from "react"; | ||
|
||
type Props = { | ||
food: string; | ||
drink: string; | ||
email: string; | ||
}; | ||
|
||
type SubmitOrderResponse = { | ||
id: string; | ||
}; | ||
|
||
export async function fetchSettings() { | ||
function OrderCommand({ food, drink }: Props) { | ||
console.log("API URL: " + process.env.API_URL); | ||
|
||
const response = await fetch('/api/settings'); | ||
return await response.json(); | ||
} | ||
const [orderId, setOrderId] = useState(""); | ||
|
||
async function submitOrder() { | ||
const response = await fetch( | ||
`https://cors-anywhere.herokuapp.com/http://51.8.246.178/order`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
origin: "daprcafe", | ||
"X-Requested-With": "XMLHttpRequest", | ||
}, | ||
body: JSON.stringify({ | ||
customer_email: "john.doe@email.com", | ||
items: [food, drink], | ||
}), | ||
} | ||
); | ||
|
||
function OrderCommand({food, drink}: Props) { | ||
console.log("API URL: " + process.env.API_URL); | ||
const order: SubmitOrderResponse = await response.json(); | ||
|
||
const apiUrl = process.env.API_URL; | ||
function submitOrder() { | ||
fetch(`${apiUrl}/order`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
origin: "daprcafe", | ||
"X-Requested-With": "XMLHttpRequest", | ||
}, | ||
body: JSON.stringify({ | ||
customer_email: "john.doe@email.com", | ||
items: [food, drink], | ||
}), | ||
}) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
console.log(data); | ||
}); | ||
} | ||
setOrderId(order.id); | ||
} | ||
|
||
return ( | ||
<div className="bg-red-500 opacity-90 h-14 sticky top-0 bottom-0 flex flex-col items-center"> | ||
<Button | ||
onClick={submitOrder} | ||
disabled={food === "" || drink === ""} | ||
className="bg-red-100 font-semibold mt-3 text-red-900 rounded-md text-2xl w-80 disabled:opacity-60" | ||
> | ||
Order | ||
</Button> | ||
</div> | ||
<> | ||
{(food !== "" && drink !== "") ? ( | ||
<div className="bg-red-500 opacity-90 h-14 sticky top-0 bottom-0 flex flex-col items-center"> | ||
{orderId !== "" ? ( | ||
<> | ||
<p className="text-white font-semibold text-2xl mt-1"> | ||
Order submitted. We will get back to you shortly. Thank you! | ||
</p> | ||
<p className="text-white font-semibold text-xs"> | ||
Order ID: {orderId} | ||
</p> | ||
</> | ||
) : ( | ||
<Button | ||
onClick={submitOrder} | ||
className="bg-red-100 font-semibold mt-3 text-red-900 rounded-md text-2xl w-80" | ||
> | ||
Order | ||
</Button> | ||
)} | ||
</div> | ||
): | ||
( | ||
<> | ||
</> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default OrderCommand | ||
export default OrderCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters