Spaces:
Sleeping
Sleeping
File size: 1,270 Bytes
bace2df |
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 |
import gradio as gr
from utils.excel_operations import read_excel, write_excel
from utils.state_management import state
def order_history_page():
def fetch_order_history(email):
orders = read_excel('data/orders.xlsx')
user_orders = [order for order in orders if order["Customer Email"] == email]
return user_orders
def reorder(order_id):
orders = read_excel('data/orders.xlsx')
order = next((o for o in orders if o["Order ID"] == order_id), None)
if order:
state["cart"] = order["Items"]
return "Reordered items added to cart!"
return "Order not found!"
with gr.Group():
gr.Markdown("### Order History")
if state.get("user"):
email = state["user"]["Email"]
order_history = fetch_order_history(email)
for order in order_history:
gr.Text(f"Order ID: {order['Order ID']}")
gr.Text(f"Items: {', '.join([item['Item'] for item in order['Items']])}")
gr.Text(f"Total Cost: {order['Total Cost']} ₹")
gr.Button("Reorder").click(reorder, inputs=[order["Order ID"]], outputs="Status")
else:
gr.Markdown("Please log in to view your order history.")
|