From c7e6d01c11b86d742ead5b0d0f3bae8d0b0c2cbc Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Fri, 7 Aug 2026 18:28:38 +0330 Subject: [PATCH] feat(orders): enhance order display and interaction for improved user experience - Refactored the Orders page to improve the layout and presentation of order information, including a new responsive design for mobile and desktop views. - Added a button to navigate to the store when no orders are present, enhancing user engagement. - Updated the order details display to include payment and delivery status with color-coded chips for better visual feedback. - Introduced helper methods for formatting prices and dates, improving code readability and maintainability. These changes significantly enhance the usability and clarity of the order management interface, providing users with a more intuitive experience. --- src/FrontOffice.Main/Pages/Store/Orders.razor | 166 ++++++++++-------- .../Pages/Store/Orders.razor.cs | 94 +++++++--- 2 files changed, 167 insertions(+), 93 deletions(-) diff --git a/src/FrontOffice.Main/Pages/Store/Orders.razor b/src/FrontOffice.Main/Pages/Store/Orders.razor index 811451b..0aa3ab3 100644 --- a/src/FrontOffice.Main/Pages/Store/Orders.razor +++ b/src/FrontOffice.Main/Pages/Store/Orders.razor @@ -1,80 +1,102 @@ @attribute [Route(RouteConstants.Store.Orders)] -@* Injection is handled in code-behind *@ سفارشات من - - @if (_loading) - { - - } - else if (_orders.Count == 0) - { - هنوز سفارشی ثبت نکرده‌اید. - } - else - { - - - - شناسه - تاریخ - وضعیت - مبلغ - - - - @context.Id - - @if (context.PaymentDate != null) - { - @context.PaymentDate.ToDateTime().MiladiToJalaliWithTime() - } - else - { - در انتظار پرداخت - } - - @GetStatusText(context.PaymentStatus) - @FormatPrice(context.FactorDetails.Sum(s=>(s.UnitPrice ?? 0) * (s.Count ?? 0))) - - جزئیات - - - - + + - - - @foreach (var o in _orders) - { - - - - سفارش #@o.Id - - @if (o.PaymentDate != null) - { - @o.PaymentDate.ToDateTime().MiladiToJalaliWithTime() - } - else - { - در انتظار پرداخت - } - + @if (_loading) + { + + } + else if (_orders.Count == 0) + { + هنوز سفارشی ثبت نشده است. + + مشاهده فروشگاه + + } + else + { + + + + + + شماره سفارش + تعداد اقلام + مبلغ کل + وضعیت پرداخت + وضعیت ارسال + تاریخ + + + + @context.Id + @GetItemsCount(context) + @FormatPrice(GetTotalAmount(context)) + + + @GetPaymentStatusText(context.PaymentStatus) + + + + + @GetDeliveryStatusText((int)context.DeliveryStatus) + + + @FormatDate(context) + + + جزئیات + + + + + + + + + + + @foreach (var order in _orders) + { + + + + سفارش #@order.Id + + @GetPaymentStatusText(order.PaymentStatus) + + + + @FormatDate(order) + + @GetDeliveryStatusText((int)order.DeliveryStatus) + + + + + @GetItemsCount(order) قلم + @FormatPrice(GetTotalAmount(order)) تومان + - - وضعیت: @GetStatusText(o.PaymentStatus) - @FormatPrice(o.FactorDetails.Sum(s=>(s.UnitPrice ?? 0) * (s.Count ?? 0))) - - - جزئیات - - - - } - - - } + + } + + + } + diff --git a/src/FrontOffice.Main/Pages/Store/Orders.razor.cs b/src/FrontOffice.Main/Pages/Store/Orders.razor.cs index 0ce3138..da4304d 100644 --- a/src/FrontOffice.Main/Pages/Store/Orders.razor.cs +++ b/src/FrontOffice.Main/Pages/Store/Orders.razor.cs @@ -1,5 +1,5 @@ -using System; using CMSMicroservice.Protobuf.Protos.UserOrder; +using DateTimeConverterCL; using FrontOffice.Main.Utilities; using Microsoft.AspNetCore.Components; using Messages = CMSMicroservice.Protobuf.Protos; @@ -10,7 +10,6 @@ namespace FrontOffice.Main.Pages.Store; public partial class Orders : ComponentBase { [Inject] private OrderService OrderService { get; set; } = default!; - [Inject] private VATService VAT { get; set; } = default!; private List _orders = new(); private bool _loading; @@ -33,28 +32,81 @@ public partial class Orders : ComponentBase } } - protected override async Task OnAfterRenderAsync(bool firstRender) + private void ViewOrder(long orderId) { - if (firstRender) + Navigation.NavigateTo($"{RouteConstants.Store.OrderDetail}{orderId}"); + } + + private static string FormatPrice(long price) => $"{price:N0}"; + + private static string FormatDate(GetUserOrderResponse order) + { + try { - // بارگذاری نرخ VAT - await VAT.LoadAsync(); + var timestamp = order.PaymentDate; + if (timestamp is null) + return "در انتظار پرداخت"; + + return timestamp.ToDateTime().ToLocalTime().MiladiToJalaliWithTime(); } - await base.OnAfterRenderAsync(firstRender); - } - - private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price); - - - private string GetStatusText(Messages.PaymentStatus contextPaymentStatus) - { - return contextPaymentStatus switch + catch { - Messages.PaymentStatus.Pending => "در انتظار پرداخت", - Messages.PaymentStatus.Success => "پرداخت شده", - Messages.PaymentStatus.Reject => "پرداخت ناموفق", - _ => "نامشخص", - }; + return "—"; + } } -} + private static int GetItemsCount(GetUserOrderResponse order) => + order.FactorDetails.Sum(f => f.Count ?? 0); + + private static long GetTotalAmount(GetUserOrderResponse order) + { + if (order.VatInfo is not null && order.VatInfo.TotalAmount > 0) + return order.VatInfo.TotalAmount; + + if (order.Amount > 0) + return order.Amount; + + return order.FactorDetails.Sum(f => (f.UnitPrice ?? 0) * (f.Count ?? 0)); + } + + private static string GetPaymentStatusText(Messages.PaymentStatus status) => status switch + { + Messages.PaymentStatus.Pending => "در انتظار پرداخت", + Messages.PaymentStatus.Success => "پرداخت شده", + Messages.PaymentStatus.Reject => "پرداخت ناموفق", + _ => "نامشخص" + }; + + private static Color GetPaymentStatusColor(Messages.PaymentStatus status) => status switch + { + Messages.PaymentStatus.Pending => Color.Warning, + Messages.PaymentStatus.Success => Color.Success, + Messages.PaymentStatus.Reject => Color.Error, + _ => Color.Default + }; + + // Domain/public_messages: None=0, Pending=1, InTransit=2, Delivered=3, Returned=4, Cancelled=5, ReadyForOfficePickup=6 + private static string GetDeliveryStatusText(int status) => status switch + { + 0 => "بدون ارسال", + 1 => "در انتظار ارسال", + 2 => "ارسال شده", + 3 => "تحویل داده شده", + 4 => "مرجوع شده", + 5 => "لغو شده", + 6 => "آماده تحویل در دفتر", + _ => "نامشخص" + }; + + private static Color GetDeliveryStatusColor(int status) => status switch + { + 0 => Color.Default, + 1 => Color.Warning, + 2 => Color.Primary, + 3 => Color.Success, + 4 => Color.Error, + 5 => Color.Dark, + 6 => Color.Primary, + _ => Color.Default + }; +}