@using Indotalent.ConfigBackEnd.Extensions @using Indotalent.Features.Pipeline.SalesRepresentative @using Indotalent.Features.Pipeline.SalesRepresentative.Cqrs @using Indotalent.Shared.Utils @using MudBlazor @inject SalesRepresentativeService SalesRepresentativeService @inject ISnackbar Snackbar
@(ReadOnly ? "Representative Profile" : "Edit Representative") @(ReadOnly ? "Viewing personal profile and team assignment." : "Modify representative details.")
@if (_isDataLoading) {
} else { Basic Information Representative Name Sales Team @foreach (var item in _lookupData.SalesTeams) { @item.Name } Job Title Employee Number Contact Details Phone Number Email Address Description / Notes Audit History Created At @DateTimeExtensions.ToString(_model.CreatedAt) Created By @(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System") Last Updated At @DateTimeExtensions.ToString(_model.UpdatedAt) Last Updated By @(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")
@(ReadOnly ? "Back to List" : "Cancel") @if (!ReadOnly) { @if (_processing) { Updating... } else { Save Changes } }
}
@code { [Parameter] public UpdateSalesRepresentativeRequest Data { get; set; } = new(); [Parameter] public bool ReadOnly { get; set; } = false; [Parameter] public EventCallback OnCancel { get; set; } [Parameter] public EventCallback OnSuccess { get; set; } private MudForm _form = default!; private UpdateSalesRepresentativeValidator _validator = new(); private UpdateSalesRepresentativeRequest _model = new(); private LookupSalesRepresentativeResponse _lookupData = new(); private bool _processing = false; private bool _isDataLoading = true; protected override async Task OnInitializedAsync() { _isDataLoading = true; try { var response = await SalesRepresentativeService.GetSalesRepresentativeLookupAsync(); if (response != null && response.IsSuccess) { _lookupData = response.Value!; } _model = Data; } finally { _isDataLoading = false; } } private async Task Submit() { if (ReadOnly) return; await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var response = await SalesRepresentativeService.UpdateSalesRepresentativeAsync(_model); await Task.Delay(500); if (response != null && response.IsSuccess) { Snackbar.Add("Representative updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } finally { _processing = false; } } }