Redesigned account, checkout Added stock management design elements
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
namespace MidrandBookshop.Components.Pages;
|
||||
|
||||
public partial class Account
|
||||
public partial class Account : ComponentBase
|
||||
{
|
||||
[Inject] private AuthenticationStateProvider AuthStateProvider { get; set; } = default!;
|
||||
|
||||
private ClaimsPrincipal? User { get; set; }
|
||||
private bool showAddForm = false;
|
||||
private AddressItem? editingAddress = null;
|
||||
private string newAddressName = "";
|
||||
@@ -12,27 +15,84 @@ public partial class Account
|
||||
|
||||
private List<OrderItem> orderHistory = new()
|
||||
{
|
||||
new OrderItem { OrderId = "#MB-2026-9481", ProductId = "introduction-to-blazor", ProductTitle = "Introduction to Blazor WebAssembly Framework Development", OrderDate = new DateTime(2026, 5, 20), ShippingAddressName = "Home Address", Status = "Shipped", Total = 720.00 },
|
||||
new OrderItem { OrderId = "#MB-2026-8712", ProductId = "mastering-css-isolation", ProductTitle = "Mastering CSS Isolation in Modern .NET Web Applications Architecture", OrderDate = new DateTime(2026, 4, 14), ShippingAddressName = "Midrand Books Warehouse", Status = "Delivered", Total = 890.00 }
|
||||
// 1. Delivered + Paid (Green Mapping Rules)
|
||||
new OrderItem { OrderId = "#MB-2026-8712", ProductId = "mastering-css-isolation", ProductTitle = "Mastering CSS Isolation in Modern .NET Web Applications Architecture", OrderDate = new DateTime(2026, 4, 14), ShippingAddressName = "Midrand Warehouse", Status = "Delivered", PaymentStatus = "Paid", Total = 890.00 },
|
||||
|
||||
// 2. Shipped + Paid (Amber Logistics + Green Payment Rules)
|
||||
new OrderItem { OrderId = "#MB-2026-9481", ProductId = "introduction-to-blazor", ProductTitle = "Introduction to Blazor WebAssembly Framework Development", OrderDate = new DateTime(2026, 5, 20), ShippingAddressName = "Home Address", Status = "Shipped", PaymentStatus = "Paid", Total = 720.00 },
|
||||
|
||||
// 3. Unshipped + Abandoned/Unpaid (Muted Grey / Soft Red Rules — Hides Invoice Button)
|
||||
new OrderItem { OrderId = "#MB-2026-1034", ProductId = "csharp-functional-paradigms", ProductTitle = "Advanced Functional Architecture & Monadic Paradigms in Modern C#", OrderDate = new DateTime(2026, 6, 11), ShippingAddressName = "Home Address", Status = "Unshipped", PaymentStatus = "Unpaid", Total = 650.00 }
|
||||
};
|
||||
|
||||
private List<AddressItem> savedAddresses = new()
|
||||
{
|
||||
new AddressItem { Id = 1, Name = "Home Address", Street = "12 Main Road", City = "Midrand", PostalCode = "1685", IsBilling = true, IsShipping = true, IsPrimary = true },
|
||||
new AddressItem { Id = 2, Name = "Corporate Office", Street = "45 Challink Street", City = "Halfway House", PostalCode = "1682", IsBilling = true, IsShipping = false, IsPrimary = false },
|
||||
new AddressItem { Id = 3, Name = "Midrand Books Warehouse", Street = "Unit 8, Corporate Park North", City = "Randjespark", PostalCode = "1683", IsBilling = false, IsShipping = true, IsPrimary = false }
|
||||
new AddressItem { Id = 2, Name = "Midrand Warehouse", Street = "Corner of Church & Third Roads", City = "Midrand", PostalCode = "1685", IsBilling = false, IsShipping = false, IsPrimary = false }
|
||||
};
|
||||
|
||||
private void TriggerLogout() => Navigation.NavigateTo("/logout", forceLoad: true);
|
||||
private void DownloadInvoice(string orderId) { /* Handle download sequence here */ }
|
||||
private void OpenAddForm() { editingAddress = null; showAddForm = true; }
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
||||
User = authState?.User;
|
||||
}
|
||||
|
||||
private void DownloadInvoice(string orderId)
|
||||
{
|
||||
Navigation.NavigateTo($"/api/invoices/download/{orderId.Replace("#", "")}", forceLoad: true);
|
||||
}
|
||||
|
||||
private string GetStatusClass(string status) => status?.ToLower() switch
|
||||
{
|
||||
"delivered" => "status-delivered", // Green
|
||||
"shipped" => "status-shipped", // Amber
|
||||
_ => "status-processing" // Muted Architectural Dark Grey
|
||||
};
|
||||
|
||||
private string GetPaymentStatusClass(string paymentStatus) => paymentStatus?.ToLower() switch
|
||||
{
|
||||
"paid" => "pay-paid", // Green
|
||||
"refunded" => "pay-refunded", // Grey
|
||||
_ => "pay-pending" // Red Alert Tone
|
||||
};
|
||||
|
||||
private void EditAddress(AddressItem addr)
|
||||
{
|
||||
editingAddress = addr;
|
||||
showAddForm = false;
|
||||
newAddressName = addr.Name;
|
||||
newStreetAddress = addr.Street;
|
||||
newCity = addr.City;
|
||||
newPostalCode = addr.PostalCode;
|
||||
isBilling = addr.IsBilling;
|
||||
isShipping = addr.IsShipping;
|
||||
}
|
||||
|
||||
private void CancelAddressActions()
|
||||
{
|
||||
showAddForm = false;
|
||||
editingAddress = null;
|
||||
ClearFormFields();
|
||||
}
|
||||
|
||||
private void ClearFormFields()
|
||||
{
|
||||
newAddressName = "";
|
||||
newStreetAddress = "";
|
||||
newCity = "";
|
||||
newPostalCode = "";
|
||||
isBilling = false;
|
||||
isShipping = false;
|
||||
}
|
||||
|
||||
private void SaveAddress()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(newAddressName) && !string.IsNullOrWhiteSpace(newStreetAddress))
|
||||
if (string.IsNullOrWhiteSpace(newAddressName) || string.IsNullOrWhiteSpace(newStreetAddress)) return;
|
||||
|
||||
if (editingAddress == null)
|
||||
{
|
||||
var nextId = savedAddresses.Any() ? savedAddresses.Max(a => a.Id) + 1 : 1;
|
||||
savedAddresses.Add(new AddressItem
|
||||
var newAddr = new AddressItem
|
||||
{
|
||||
Id = nextId,
|
||||
Name = newAddressName,
|
||||
@@ -42,34 +102,71 @@ public partial class Account
|
||||
IsBilling = isBilling,
|
||||
IsShipping = isShipping,
|
||||
IsPrimary = !savedAddresses.Any()
|
||||
});
|
||||
ResetAddForm();
|
||||
};
|
||||
savedAddresses.Add(newAddr);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetAddForm() { newAddressName = ""; newStreetAddress = ""; newCity = ""; newPostalCode = ""; isBilling = isShipping = showAddForm = false; }
|
||||
private void StartEditing(AddressItem addr) { showAddForm = false; editingAddress = new AddressItem { Id = addr.Id, Name = addr.Name, Street = addr.Street, City = addr.City, PostalCode = addr.PostalCode, IsBilling = addr.IsBilling, IsShipping = addr.IsShipping, IsPrimary = addr.IsPrimary }; }
|
||||
private void CancelEditing() => editingAddress = null;
|
||||
|
||||
private void UpdateAddress()
|
||||
{
|
||||
if (editingAddress != null)
|
||||
else
|
||||
{
|
||||
var target = savedAddresses.FirstOrDefault(a => a.Id == editingAddress.Id);
|
||||
if (target != null) { target.Name = editingAddress.Name; target.Street = editingAddress.Street; target.City = editingAddress.City; target.PostalCode = editingAddress.PostalCode; target.IsBilling = editingAddress.IsBilling; target.IsShipping = editingAddress.IsShipping; }
|
||||
if (target != null)
|
||||
{
|
||||
target.Name = newAddressName;
|
||||
target.Street = newStreetAddress;
|
||||
target.City = newCity;
|
||||
target.PostalCode = newPostalCode;
|
||||
target.IsBilling = isBilling;
|
||||
target.IsShipping = isShipping;
|
||||
}
|
||||
editingAddress = null;
|
||||
}
|
||||
|
||||
showAddForm = false;
|
||||
ClearFormFields();
|
||||
}
|
||||
|
||||
private void DeleteAddress(AddressItem addr) { if (editingAddress?.Id == addr.Id) editingAddress = null; savedAddresses.Remove(addr); if (addr.IsPrimary && savedAddresses.Any()) savedAddresses.First().IsPrimary = true; }
|
||||
private void DeleteAddress(AddressItem addr)
|
||||
{
|
||||
if (editingAddress?.Id == addr.Id) editingAddress = null;
|
||||
savedAddresses.Remove(addr);
|
||||
if (addr.IsPrimary && savedAddresses.Any()) savedAddresses.First().IsPrimary = true;
|
||||
}
|
||||
|
||||
private void SetPrimary(AddressItem target, ChangeEventArgs e)
|
||||
{
|
||||
var isChecked = (bool)(e.Value ?? false);
|
||||
if (isChecked) { foreach (var addr in savedAddresses) addr.IsPrimary = (addr.Id == target.Id); }
|
||||
if (isChecked)
|
||||
{
|
||||
foreach (var addr in savedAddresses) addr.IsPrimary = (addr.Id == target.Id);
|
||||
}
|
||||
else target.IsPrimary = false;
|
||||
}
|
||||
|
||||
public class AddressItem { public int Id { get; set; } public string Name { get; set; } = ""; public string Street { get; set; } = ""; public string City { get; set; } = ""; public string PostalCode { get; set; } = ""; public bool IsBilling { get; set; } public bool IsShipping { get; set; } public bool IsPrimary { get; set; } }
|
||||
public class OrderItem { public string OrderId { get; set; } = ""; public string ProductId { get; set; } = ""; public string ProductTitle { get; set; } = ""; public DateTime OrderDate { get; set; } public string ShippingAddressName { get; set; } = ""; public string Status { get; set; } = ""; public double Total { get; set; } }
|
||||
}
|
||||
private void TriggerLogout()
|
||||
{
|
||||
Navigation.NavigateTo("/logout", forceLoad: true);
|
||||
}
|
||||
|
||||
public class AddressItem
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public string Street { get; set; } = "";
|
||||
public string City { get; set; } = "";
|
||||
public string PostalCode { get; set; } = "";
|
||||
public bool IsBilling { get; set; }
|
||||
public bool IsShipping { get; set; }
|
||||
public bool IsPrimary { get; set; }
|
||||
}
|
||||
|
||||
public class OrderItem
|
||||
{
|
||||
public string OrderId { get; set; } = "";
|
||||
public string ProductId { get; set; } = "";
|
||||
public string ProductTitle { get; set; } = "";
|
||||
public DateTime OrderDate { get; set; }
|
||||
public string ShippingAddressName { get; set; } = "";
|
||||
public string Status { get; set; } = "";
|
||||
public string PaymentStatus { get; set; } = "Pending";
|
||||
public double Total { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user