OrderSummary.jsx 2.33 KB
import React from 'react'
import { formatDate, formatPrice } from '../../utils/formatters'

const OrderSummary = ({ order }) => {
  const getStatusColor = (status) => {
    const statusColors = {
      pending: '#ffc107',
      confirmed: '#17a2b8',
      shipped: '#007bff',
      delivered: '#28a745',
      cancelled: '#dc3545'
    }
    return statusColors[status] || '#6c757d'
  }

  return (
    <div className="order-summary">
      <div className="order-header">
        <div className="order-info">
          <h3>Order #{order.orderNumber}</h3>
          <p>Placed on {formatDate(order.createdAt)}</p>
        </div>
        <div className="order-status">
          <span 
            className="status-badge"
            style={{ backgroundColor: getStatusColor(order.status) }}
          >
            {order.status.charAt(0).toUpperCase() + order.status.slice(1)}
          </span>
        </div>
      </div>

      <div className="order-items">
        <h4>Items ({order.items.length})</h4>
        {order.items.map(item => (
          <div key={item._id} className="order-item">
            <div className="item-image">
              <img 
                src={item.product.image} 
                alt={item.product.name}
                onError={(e) => {
                  e.target.src = '/placeholder-image.jpg'
                }}
              />
            </div>
            <div className="item-details">
              <h5>{item.product.name}</h5>
              <p>Quantity: {item.quantity}</p>
              <p>Price: {formatPrice(item.price)}</p>
            </div>
            <div className="item-total">
              {formatPrice(item.price * item.quantity)}
            </div>
          </div>
        ))}
      </div>

      <div className="order-totals">
        <div className="total-row">
          <span>Subtotal:</span>
          <span>{formatPrice(order.subtotal)}</span>
        </div>
        <div className="total-row">
          <span>Shipping:</span>
          <span>{formatPrice(order.shipping)}</span>
        </div>
        <div className="total-row">
          <span>Tax:</span>
          <span>{formatPrice(order.tax)}</span>
        </div>
        <div className="total-row grand-total">
          <span>Total:</span>
          <span>{formatPrice(order.total)}</span>
        </div>
      </div>
    </div>
  )
}

export default OrderSummary