"""Customer Portal - Track orders and receive updates."""
import streamlit as st
from datetime import datetime, timedelta
import time
# Page configuration
st.set_page_config(
page_title="LogiFlow - Track Your Order",
page_icon="π¦",
layout="centered"
)
# Custom CSS
st.markdown("""
""", unsafe_allow_html=True)
def render_tracking_header():
"""Render the tracking page header."""
st.markdown("""
""", unsafe_allow_html=True)
def render_order_search():
"""Render order search form."""
st.markdown("### π Track Your Order")
col1, col2 = st.columns([3, 1])
with col1:
order_id = st.text_input(
"Enter Order ID",
placeholder="ORD-20240605-ABC12345",
label_visibility="collapsed"
)
with col2:
search_btn = st.button("π Track", use_container_width=True)
return order_id, search_btn
def render_tracking_timeline():
"""Render tracking timeline."""
st.markdown("### π Delivery Progress")
# Sample tracking data
events = [
{"time": "2 hours ago", "status": "Out for Delivery", "location": "Andheri West, Mumbai", "desc": "Your package is out for delivery"},
{"time": "5 hours ago", "status": "Arrived at Hub", "location": "Mumbai West Hub", "desc": "Package arrived at sorting facility"},
{"time": "8 hours ago", "status": "In Transit", "location": "Delhi Sorting Center", "desc": "Package on the way to Mumbai"},
{"time": "12 hours ago", "status": "Picked Up", "location": "Connaught Place, Delhi", "desc": "Package picked up by driver"},
{"time": "1 day ago", "status": "Order Confirmed", "location": "System", "desc": "Order placed and confirmed"},
]
for i, event in enumerate(events):
is_completed = i == 0 # Latest is highlighted
st.markdown(f"""
{event['time']}
{event['status']}
π {event['location']}
{event['desc']}
""", unsafe_allow_html=True)
def render_order_details():
"""Render order details."""
st.markdown("### π Order Details")
col1, col2 = st.columns(2)
with col1:
st.markdown("""
π Delivery Address
Rajesh Kumar
402, Sunshine Apartments
Andheri West, Mumbai - 400053
π +919876543210
""", unsafe_allow_html=True)
with col2:
st.markdown("""
π¦ Package Details
3 items
β’ Wireless Headphones
β’ Phone Case
β’ Screen Protector
Total Weight: 0.8 kg
""", unsafe_allow_html=True)
st.markdown("""
β±οΈ Estimated Delivery
Today, 4:00 PM - 6:00 PM
On schedule - No delays expected
""", unsafe_allow_html=True)
def render_delivery_partner():
"""Render delivery partner info."""
st.markdown("### π΄ Delivery Partner")
col1, col2, col3 = st.columns([1, 2, 1])
with col1:
st.markdown("""
π€
""", unsafe_allow_html=True)
with col2:
st.markdown("""
Arun Sharma
Delivery Executive
π΅ Two-wheeler | MH 14 AB 1234
β 4.8 rating (1,234 deliveries)
""", unsafe_allow_html=True)
with col3:
st.write("")
st.write("")
if st.button("π Call", use_container_width=True):
st.info("Calling Arun Sharma...")
if st.button("π¬ Chat", use_container_width=True):
st.info("Opening chat...")
def render_ai_assistant():
"""Render AI assistant chat."""
st.markdown("### π€ AI Assistant")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = [
{"role": "assistant", "content": "Hi! I'm your LogiFlow AI assistant. How can I help you today?"}
]
# Display chat history
for msg in st.session_state.messages:
if msg["role"] == "user":
st.markdown(f"""
{msg['content']}
""", unsafe_allow_html=True)
else:
st.markdown(f"""
π€ {msg['content']}
""", unsafe_allow_html=True)
# Chat input
if prompt := st.chat_input("Ask me anything about your order..."):
st.session_state.messages.append({"role": "user", "content": prompt})
# AI response
if "where" in prompt.lower() or "track" in prompt.lower():
response = "Your order is currently out for delivery and should arrive by 4:00 PM today. You can see the live location on the map above!"
elif "delay" in prompt.lower() or "late" in prompt.lower():
response = "Good news! Your order is on schedule with no delays. The estimated delivery time remains 4:00 PM - 6:00 PM today."
elif "cancel" in prompt.lower():
response = "I understand you want to cancel. Unfortunately, your order is already out for delivery, so cancellation is no longer possible. Would you like me to reschedule the delivery instead?"
elif "hello" in prompt.lower() or "hi" in prompt.lower():
response = "Hello! I'm here to help you track your order and answer any questions. Your package is doing great and should arrive soon! π¦"
else:
response = "I'm here to help! You can ask me about:\n- π Current location of your order\n- β±οΈ Estimated delivery time\n- π Order details\n- π Delivery partner info\n- β Any other questions!"
st.session_state.messages.append({"role": "assistant", "content": response})
st.rerun()
def render_map_placeholder():
"""Render map placeholder."""
st.markdown("### πΊοΈ Live Tracking Map")
st.markdown("""
πΊοΈ
Live tracking map
Your delivery partner is currently at:
π Andheri Metro Station, 2.3 km away
""", unsafe_allow_html=True)
def render_quick_actions():
"""Render quick action buttons."""
st.markdown("### β‘ Quick Actions")
col1, col2, col3, col4 = st.columns(4)
with col1:
if st.button("π Track Order", use_container_width=True):
st.info("Opening tracking view...")
with col2:
if st.button("π Call Support", use_container_width=True):
st.info("Connecting to support...")
with col3:
if st.button("π Reschedule", use_container_width=True):
st.warning("This will open the reschedule form")
with col4:
if st.button("β Help", use_container_width=True):
st.info("Opening help center...")
def render_delivery_schedule():
"""Render delivery schedule."""
st.markdown("### π
Reschedule Delivery")
with st.expander("Change Delivery Time"):
st.write("**Select a new delivery slot:**")
col1, col2, col3 = st.columns(3)
with col1:
st.write("**Today**")
if st.button("2:00 PM - 4:00 PM", use_container_width=True):
st.success("Delivery rescheduled to 2:00 PM - 4:00 PM today")
if st.button("6:00 PM - 8:00 PM", use_container_width=True):
st.success("Delivery rescheduled to 6:00 PM - 8:00 PM today")
with col2:
st.write("**Tomorrow**")
if st.button("9:00 AM - 12:00 PM", use_container_width=True):
st.success("Delivery rescheduled to tomorrow 9:00 AM - 12:00 PM")
if st.button("2:00 PM - 6:00 PM", use_container_width=True):
st.success("Delivery rescheduled to tomorrow 2:00 PM - 6:00 PM")
with col3:
st.write("**Custom**")
custom_date = st.date_input("Select Date", datetime.now() + timedelta(days=1))
custom_time = st.time_input("Select Time", datetime.now().time())
if st.button("Apply Custom Schedule", use_container_width=True):
st.success(f"Delivery rescheduled to {custom_date} at {custom_time}")
def render_feedback():
"""Render feedback section."""
st.markdown("### β Rate Your Experience")
col1, col2, col3, col4, col5 = st.columns(5)
ratings = ["π", "π", "π", "π", "π€©"]
selected = st.feedback(options="faces")
if selected is not None:
st.success(f"Thank you for your {ratings[selected]} feedback!")
def render_notifications():
"""Render notification preferences."""
st.markdown("### π Notification Preferences")
col1, col2 = st.columns(2)
with col1:
st.checkbox("π± SMS Notifications", value=True)
st.checkbox("π§ Email Updates", value=True)
with col2:
st.checkbox("π¬ WhatsApp Updates", value=True)
st.checkbox("π Push Notifications", value=True)
def main():
"""Main customer portal function."""
# Tabs
tab1, tab2, tab3, tab4 = st.tabs(["π Track", "π Details", "π¬ Help", "βοΈ Settings"])
with tab1:
render_tracking_header()
order_id, search = render_order_search()
if order_id or search:
render_map_placeholder()
render_tracking_timeline()
render_quick_actions()
render_delivery_schedule()
render_ai_assistant()
with tab2:
st.header("π Order Details")
render_order_details()
render_delivery_partner()
with tab3:
st.header("π¬ Help & Support")
st.markdown("### Frequently Asked Questions")
with st.expander("π¦ Where is my order?"):
st.write("Your order is currently out for delivery. Use the tracking tab above to see real-time location updates.")
with st.expander("β±οΈ When will my order arrive?"):
st.write("Expected delivery is today between 4:00 PM - 6:00 PM. You can track the exact location in real-time.")
with st.expander("π Can I reschedule delivery?"):
st.write("Yes! You can reschedule your delivery to any available time slot. Go to the Track tab and use the reschedule option.")
with st.expander("β Can I cancel my order?"):
st.write("Cancellation is possible only before the order is dispatched. Once out for delivery, you can reschedule instead.")
with st.expander("π How do I contact support?"):
st.write("You can call our 24/7 support at 1800-123-4567 or use the in-app chat for instant assistance.")
st.markdown("### Contact Us")
st.write("π 1800-123-4567 (Toll Free)")
st.write("π§ support@logiflow.ai")
st.write("π¬ Chat with us (Available 24/7)")
with tab4:
st.header("βοΈ Settings")
st.markdown("### π± Communication Preferences")
render_notifications()
st.markdown("### π Account")
st.write("**Email:** rajesh@example.com")
st.write("**Phone:** +919876543210")
st.write("**Member since:** January 2024")
if st.button("βοΈ Edit Profile"):
st.info("Profile editing coming soon!")
if st.button("πͺ Sign Out"):
st.warning("Sign out functionality coming soon!")
if __name__ == "__main__":
main()