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.")