Skip to content

Commit

Permalink
test on table index
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Barbosa <tbarbos@hotmail.com>
  • Loading branch information
t1agob committed May 15, 2024
1 parent b2db10c commit eba13ce
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 38 deletions.
93 changes: 56 additions & 37 deletions frontend/src/components/OrderCommand.tsx
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;
2 changes: 1 addition & 1 deletion order-processor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func newOrderEventHandler(ctx context.Context, e *common.TopicEvent) (retry bool
}

fmt.Println("Saving order state: ", orderData.Id)
err = client.SaveState(ctx, stateStoreName, orderData.Id, data, nil)
err = client.SaveState(ctx, stateStoreName, "orderprocessor", data, nil)
if err != nil {
log.Printf("error saving order state: %v", err)
}
Expand Down

0 comments on commit eba13ce

Please sign in to comment.