219 lines
11 KiB
Plaintext
219 lines
11 KiB
Plaintext
@using Indotalent.ConfigBackEnd.Extensions
|
|
@using Indotalent.Features.Multitenant.Tenant.Cqrs
|
|
@using Indotalent.Features.Multitenant.Tenant.Components
|
|
@using Indotalent.Shared.Utils
|
|
@using MudBlazor
|
|
@inject TenantService TenantService
|
|
@inject ISnackbar Snackbar
|
|
|
|
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #DCEBFA;">
|
|
<div class="d-flex align-center gap-4">
|
|
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
|
<div>
|
|
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Tenant Details" : "Edit Tenant")</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing tenant information." : "Modify tenant details and manage users.")</MudText>
|
|
</div>
|
|
</div>
|
|
</MudPaper>
|
|
|
|
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
|
@if (_isDataLoading)
|
|
{
|
|
<div class="d-flex justify-center pa-10"><MudProgressCircular Color="Color.Primary" Indeterminate="true" /></div>
|
|
}
|
|
else
|
|
{
|
|
<MudForm @ref="_form" Model="_model">
|
|
<MudGrid Spacing="3">
|
|
<MudItem xs="12">
|
|
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">General Information</MudText>
|
|
<MudDivider Class="mt-2 mb-4" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="12">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Tenant Name</MudText>
|
|
<MudTextField @bind-Value="_model.Name" For="@(() => _model.Name)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Phone Number</MudText>
|
|
<MudTextField @bind-Value="_model.PhoneNumber" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Fax Number</MudText>
|
|
<MudTextField @bind-Value="_model.FaxNumber" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Email Address</MudText>
|
|
<MudTextField @bind-Value="_model.EmailAddress" For="@(() => _model.EmailAddress)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Website</MudText>
|
|
<MudTextField @bind-Value="_model.Website" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" Class="mt-4">
|
|
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Address Information</MudText>
|
|
<MudDivider Class="mt-2 mb-4" />
|
|
</MudItem>
|
|
<MudItem xs="12">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Street</MudText>
|
|
<MudTextField @bind-Value="_model.Street" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">City</MudText>
|
|
<MudTextField @bind-Value="_model.City" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">State</MudText>
|
|
<MudTextField @bind-Value="_model.State" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Zip Code</MudText>
|
|
<MudTextField @bind-Value="_model.ZipCode" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Country</MudText>
|
|
<MudTextField @bind-Value="_model.Country" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" Class="mt-4">
|
|
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Status</MudText>
|
|
<MudDivider Class="mt-2 mb-4" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Is Active</MudText>
|
|
<MudSwitch @bind-Value="_model.IsActive" ReadOnly="ReadOnly" Color="Color.Success" Disabled="ReadOnly" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" Class="mt-4">
|
|
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
|
<MudTextField @bind-Value="_model.Description" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" Class="mt-6">
|
|
<_TenantUserDataTable Users="_model.Users" TenantId="@(_model.Id ?? string.Empty)" ReadOnly="ReadOnly" OnChanged="RefreshData" />
|
|
</MudItem>
|
|
|
|
<MudItem xs="12" Class="mt-4">
|
|
<MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Audit History</MudText>
|
|
<MudDivider Class="mt-2 mb-4" />
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2">Created At</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.CreatedAt)</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2">Created By</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System")</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2">Last Updated At</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@DateTimeExtensions.ToString(_model.UpdatedAt)</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.subtitle2">Last Updated By</MudText>
|
|
<MudText Typo="Typo.body2" Style="color: #1a1a1a; font-weight: 600;">@(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")</MudText>
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
<div class="d-flex justify-end gap-2 mt-10">
|
|
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border-radius: 4px; border: 1px solid #e0e0e0; text-transform: none; font-weight: 700;">@(ReadOnly ? "Back to List" : "Cancel")</MudButton>
|
|
@if (!ReadOnly)
|
|
{
|
|
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
|
|
@if (_processing)
|
|
{
|
|
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
|
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Updating...</MudText>
|
|
}
|
|
else
|
|
{
|
|
<MudText>Save Changes</MudText>
|
|
}
|
|
</MudButton>
|
|
}
|
|
</div>
|
|
</MudForm>
|
|
}
|
|
</MudPaper>
|
|
|
|
@code {
|
|
[Parameter] public UpdateTenantRequest 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 UpdateTenantValidator _validator = new();
|
|
private GetTenantByIdResponse _model = new();
|
|
private bool _processing = false;
|
|
private bool _isDataLoading = true;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await RefreshData();
|
|
}
|
|
|
|
private async Task RefreshData()
|
|
{
|
|
_isDataLoading = true;
|
|
try
|
|
{
|
|
var tenant = await TenantService.GetTenantByIdAsync(Data.Id!);
|
|
if (tenant != null && tenant.IsSuccess) { _model = tenant.Value!; }
|
|
}
|
|
finally { _isDataLoading = false; }
|
|
}
|
|
|
|
private async Task Submit()
|
|
{
|
|
if (ReadOnly) return;
|
|
|
|
await _form.Validate();
|
|
if (!_form.IsValid) return;
|
|
|
|
_processing = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
var updateRequest = new UpdateTenantRequest
|
|
{
|
|
Id = _model.Id,
|
|
Name = _model.Name,
|
|
Description = _model.Description,
|
|
Street = _model.Street,
|
|
City = _model.City,
|
|
State = _model.State,
|
|
ZipCode = _model.ZipCode,
|
|
Country = _model.Country,
|
|
PhoneNumber = _model.PhoneNumber,
|
|
FaxNumber = _model.FaxNumber,
|
|
EmailAddress = _model.EmailAddress,
|
|
Website = _model.Website,
|
|
IsActive = _model.IsActive,
|
|
CreatedAt = _model.CreatedAt,
|
|
CreatedBy = _model.CreatedBy,
|
|
UpdatedAt = _model.UpdatedAt,
|
|
UpdatedBy = _model.UpdatedBy
|
|
};
|
|
|
|
var response = await TenantService.UpdateTenantAsync(updateRequest);
|
|
await Task.Delay(500);
|
|
|
|
if (response != null && response.IsSuccess)
|
|
{
|
|
Snackbar.Add("Updated successfully", Severity.Success);
|
|
await OnSuccess.InvokeAsync();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
|
}
|
|
finally
|
|
{
|
|
_processing = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
} |