initial commit
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget;
|
||||
|
||||
public static class BudgetEndpoint
|
||||
{
|
||||
public static void MapBudgetEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/budget").WithTags("Budgets")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBudgetListQuery());
|
||||
return result.ToApiResponse("Budgets retrieved successfully");
|
||||
})
|
||||
.WithName("GetBudgetList");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBudgetByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Budget detail retrieved successfully"
|
||||
: $"Budget with ID {id} not found");
|
||||
})
|
||||
.WithName("GetBudgetById");
|
||||
|
||||
group.MapPost("/", async (CreateBudgetRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateBudgetCommand(request));
|
||||
return result.ToApiResponse("Budget has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateBudget");
|
||||
|
||||
group.MapPost("/update", async (UpdateBudgetRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateBudgetCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The budget data could not be found.");
|
||||
}
|
||||
return result.ToApiResponse("Budget has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateBudget");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteBudgetByIdCommand(new DeleteBudgetByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The budget data could not be found.");
|
||||
}
|
||||
return true.ToApiResponse("Budget has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteBudgetById");
|
||||
|
||||
group.MapGet("/lookup", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetBudgetLookupQuery());
|
||||
return result.ToApiResponse("Budget lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetBudgetLookup");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget;
|
||||
|
||||
public class BudgetService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public BudgetService(
|
||||
IHttpClientFactory clientFactory,
|
||||
NavigationManager nav,
|
||||
ISnackbar snackbar,
|
||||
ICurrentUserService currentUserService,
|
||||
TokenProvider tokenProvider)
|
||||
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
|
||||
{
|
||||
_client = new RestClient(nav.BaseUri);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<List<GetBudgetListResponse>>?> GetBudgetListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/budget", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetBudgetListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetBudgetByIdResponse>?> GetBudgetByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/budget/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetBudgetByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateBudgetResponse>?> CreateBudgetAsync(CreateBudgetRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/budget", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateBudgetResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteBudgetByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/budget/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateBudgetResponse>?> UpdateBudgetAsync(UpdateBudgetRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/budget/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateBudgetResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<BudgetLookupResponse>?> GetBudgetLookupAsync()
|
||||
{
|
||||
var request = new RestRequest("api/budget/lookup", Method.Get);
|
||||
return await ExecuteWithResponseAsync<BudgetLookupResponse>(_client, request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
@page "/pipeline/budget"
|
||||
@using Indotalent.Features.Pipeline.Budget
|
||||
@using Indotalent.Features.Pipeline.Budget.Cqrs
|
||||
@using Indotalent.Features.Pipeline.Budget.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_BudgetCreateForm OnCancel="BackToTable"
|
||||
OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_BudgetUpdateForm Data="_selectedData!"
|
||||
ReadOnly="@(_currentView == ViewMode.View)"
|
||||
OnCancel="BackToTable"
|
||||
OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_BudgetDataTable OnAdd="() => ShowCreate()"
|
||||
OnEdit="(item) => ShowUpdate(item, false)"
|
||||
OnView="(item) => ShowUpdate(item, true)" />
|
||||
}
|
||||
|
||||
@code {
|
||||
private enum ViewMode { Table, Create, Update, View }
|
||||
private ViewMode _currentView = ViewMode.Table;
|
||||
private UpdateBudgetRequest? _selectedData;
|
||||
|
||||
private void ShowCreate()
|
||||
{
|
||||
_currentView = ViewMode.Create;
|
||||
}
|
||||
|
||||
private void ShowUpdate(UpdateBudgetRequest data, bool isReadOnly)
|
||||
{
|
||||
_selectedData = data;
|
||||
_currentView = isReadOnly ? ViewMode.View : ViewMode.Update;
|
||||
}
|
||||
|
||||
private void BackToTable()
|
||||
{
|
||||
_currentView = ViewMode.Table;
|
||||
_selectedData = null;
|
||||
}
|
||||
|
||||
private void HandleSuccess()
|
||||
{
|
||||
_currentView = ViewMode.Table;
|
||||
_selectedData = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
@using Indotalent.Features.Pipeline.Budget
|
||||
@using Indotalent.Features.Pipeline.Budget.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject BudgetService BudgetService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center gap-4" Style="border: 1px solid #DCEBFA;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add New Budget</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Allocate budget resources for your campaign.</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title"
|
||||
For="@(() => _model.Title)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Campaign</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.CampaignId"
|
||||
For="@(() => _model.CampaignId)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
|
||||
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Campaigns)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.BudgetStatus" @bind-Value="_model.Status"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
|
||||
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.BudgetStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Amount</MudText>
|
||||
<MudNumericField @bind-Value="_model.Amount"
|
||||
T="decimal?"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true"
|
||||
HideSpinButtons="false" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Budget Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.BudgetDate"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<div class="d-flex justify-end gap-2 mt-8">
|
||||
<MudButton OnClick="() => OnCancel.InvokeAsync()"
|
||||
Variant="Variant.Outlined"
|
||||
Disabled="_processing"
|
||||
Style="border-radius: 4px; border: 1px solid #e0e0e0; text-transform: none; font-weight: 700;">
|
||||
Cancel
|
||||
</MudButton>
|
||||
<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;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Create Budget</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
|
||||
private MudForm _form = default!;
|
||||
private CreateBudgetValidator _validator = new();
|
||||
private CreateBudgetRequest _model = new();
|
||||
private BudgetLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var response = await BudgetService.GetBudgetLookupAsync();
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_lookup = response.Value ?? new BudgetLookupResponse();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await BudgetService.CreateBudgetAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Budget created successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.Budget
|
||||
@using Indotalent.Features.Pipeline.Budget.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject BudgetService BudgetService
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Budget Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Monitor and control budget allocations for your campaigns.</MudText>
|
||||
</div>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Pipeline</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Budget</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
|
||||
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<MudTextField @bind-Value="_searchString"
|
||||
Placeholder="Search..."
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
IconSize="Size.Small"
|
||||
Class="mt-0"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
Style="background-color: white; width: 280px; border-radius: 8px;"
|
||||
OnKeyDown="@HandleSearchKeyDown" />
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
OnClick="OnSearchClick"
|
||||
Size="Size.Small"
|
||||
Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none;">
|
||||
Search
|
||||
</MudButton>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Success"
|
||||
OnClick="ExportToExcel"
|
||||
Size="Size.Small"
|
||||
Disabled="_isExporting"
|
||||
StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)"
|
||||
Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isExporting)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Primary"
|
||||
OnClick="LoadData"
|
||||
Size="Size.Small"
|
||||
StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)"
|
||||
Disabled="_isRefreshing"
|
||||
Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isRefreshing)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
|
||||
@if (_selectedBudget != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedBudget = null" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">
|
||||
Add New Budget
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Striped="true" Class="mud-table-styled" Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetBudgetListResponse" OnRowClick="@((args) => _selectedBudget = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetBudgetListResponse, object>(x => x.AutoNumber!)">Number</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetBudgetListResponse, object>(x => x.Title!)">Title</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Campaign</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Amount</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Status</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
|
||||
<MudCheckBox T="bool" Value="@(_selectedBudget?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.AutoNumber</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.Title</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.CampaignTitle</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.Amount?.ToString("N0")</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;"><MudChip T="string" Size="Size.Small" Color="Color.Info" Variant="Variant.Text" Style="border-radius:0px; font-weight:700;">@context.Status</MudChip></MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
|
||||
<div style="display: flex; align-items: center; gap: 12px;">
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
|
||||
<MudSelect T="int"
|
||||
Value="@_top"
|
||||
ValueChanged="OnPageSizeChanged"
|
||||
Dense="true"
|
||||
Margin="Margin.Dense"
|
||||
Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;"
|
||||
Variant="Variant.Outlined"
|
||||
Class="mt-0 custom-select-dense"
|
||||
AnchorOrigin="Origin.BottomCenter"
|
||||
TransformOrigin="Origin.TopCenter">
|
||||
<MudSelectItem Value="5" /><MudSelectItem Value="10" /><MudSelectItem Value="50" /><MudSelectItem Value="500" /><MudSelectItem Value="1000" />
|
||||
</MudSelect>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF; font-size: 0.75rem; font-weight: 500; margin-left: 12px;">
|
||||
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
|
||||
</MudText>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" />
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="@(_currentPage == 1 ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #D1D5DB; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">Prev</MudButton>
|
||||
@{
|
||||
var totalPages = _totalPage == 0 ? 1 : _totalPage;
|
||||
var maxVisible = 5;
|
||||
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
|
||||
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
|
||||
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
|
||||
}
|
||||
@for (int i = startPage; i <= endPage; i++)
|
||||
{
|
||||
var pageNum = i;
|
||||
var isActive = pageNum == _currentPage;
|
||||
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
|
||||
Variant="Variant.Text" Size="Size.Small"
|
||||
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
|
||||
}
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #D1D5DB; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">Next</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<style>
|
||||
.mud-input-outlined-border { border-radius: 0px !important; }
|
||||
.custom-select-dense .mud-input-control { margin-top: 0 !important; }
|
||||
.custom-select-dense .mud-input-slot { padding-top: 4px !important; padding-bottom: 4px !important; padding-left: 8px !important; font-size: 12px !important; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateBudgetRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateBudgetRequest> OnView { get; set; }
|
||||
|
||||
private List<GetBudgetListResponse> _budgets = new();
|
||||
private GetBudgetListResponse? _selectedBudget;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
|
||||
private int _skip = 0;
|
||||
private int _top = 5;
|
||||
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
|
||||
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedBudget = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await BudgetService.GetBudgetListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_budgets = response.Value ?? new List<GetBudgetListResponse>();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRefreshing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GetBudgetListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _budgets;
|
||||
return _budgets.Where(x =>
|
||||
(x.Title?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.CampaignTitle?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetBudgetListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private void OnSearchClick()
|
||||
{
|
||||
_skip = 0;
|
||||
_selectedBudget = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Enter") OnSearchClick();
|
||||
}
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("Budgets");
|
||||
var currentRow = 1;
|
||||
worksheet.Cell(currentRow, 1).Value = "Number";
|
||||
worksheet.Cell(currentRow, 2).Value = "Title";
|
||||
worksheet.Cell(currentRow, 3).Value = "Campaign";
|
||||
worksheet.Cell(currentRow, 4).Value = "Amount";
|
||||
worksheet.Cell(currentRow, 5).Value = "Status";
|
||||
|
||||
var headerRange = worksheet.Range(1, 1, 1, 5);
|
||||
headerRange.Style.Font.Bold = true;
|
||||
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#0D47A1");
|
||||
headerRange.Style.Font.FontColor = XLColor.White;
|
||||
|
||||
foreach (var item in GetFilteredData())
|
||||
{
|
||||
currentRow++;
|
||||
worksheet.Cell(currentRow, 1).Value = item.AutoNumber;
|
||||
worksheet.Cell(currentRow, 2).Value = item.Title;
|
||||
worksheet.Cell(currentRow, 3).Value = item.CampaignTitle;
|
||||
worksheet.Cell(currentRow, 4).Value = item.Amount;
|
||||
worksheet.Cell(currentRow, 5).Value = item.Status.ToString();
|
||||
}
|
||||
|
||||
worksheet.Columns().AdjustToContents();
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "Budget_List.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
|
||||
Snackbar.Add("Excel exported successfully", Severity.Success);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Export failed: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isExporting = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page)
|
||||
{
|
||||
if (page >= 1 && page <= _totalPage)
|
||||
{
|
||||
_skip = (page - 1) * _top;
|
||||
_selectedBudget = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageSizeChanged(int size)
|
||||
{
|
||||
_top = size;
|
||||
_skip = 0;
|
||||
_selectedBudget = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task InvokeEdit()
|
||||
{
|
||||
if (_selectedBudget == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedBudget.Id!);
|
||||
if (request != null) await OnEdit.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task InvokeView()
|
||||
{
|
||||
if (_selectedBudget == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedBudget.Id!);
|
||||
if (request != null) await OnView.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task<UpdateBudgetRequest?> MapToUpdateRequest(string id)
|
||||
{
|
||||
var response = await BudgetService.GetBudgetByIdAsync(id);
|
||||
if (response != null && response.IsSuccess && response.Value != null)
|
||||
{
|
||||
var detail = response.Value;
|
||||
return new UpdateBudgetRequest
|
||||
{
|
||||
Id = detail.Id,
|
||||
Title = detail.Title,
|
||||
Description = detail.Description,
|
||||
Amount = detail.Amount,
|
||||
BudgetDate = detail.BudgetDate,
|
||||
Status = detail.Status,
|
||||
CampaignId = detail.CampaignId,
|
||||
CreatedAt = detail.CreatedAt,
|
||||
CreatedBy = detail.CreatedBy,
|
||||
UpdatedAt = detail.UpdatedAt,
|
||||
UpdatedBy = detail.UpdatedBy
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedBudget == null) return;
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedBudget.Title } };
|
||||
var options = new DialogOptions { CloseButton = false, MaxWidth = MaxWidth.ExtraSmall, FullWidth = true };
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, options);
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
var isSuccess = await BudgetService.DeleteBudgetByIdAsync(_selectedBudget.Id!);
|
||||
if (isSuccess)
|
||||
{
|
||||
_selectedBudget = null;
|
||||
await LoadData();
|
||||
Snackbar.Add("Budget deleted successfully", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Delete failed.", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.Budget
|
||||
@using Indotalent.Features.Pipeline.Budget.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject BudgetService BudgetService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center gap-4" Style="border: 1px solid #DCEBFA;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Budget Details" : "Edit Budget")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing allocated resources." : "Modify existing budget allocation.")</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title"
|
||||
For="@(() => _model.Title)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Campaign</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.CampaignId"
|
||||
For="@(() => _model.CampaignId)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
|
||||
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Campaigns)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.BudgetStatus" @bind-Value="_model.Status"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
|
||||
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.BudgetStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Amount</MudText>
|
||||
<MudNumericField @bind-Value="_model.Amount"
|
||||
T="decimal?"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true"
|
||||
HideSpinButtons="false" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Budget Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.BudgetDate"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
|
||||
</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 UpdateBudgetRequest 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 UpdateBudgetValidator _validator = new();
|
||||
private UpdateBudgetRequest _model = new();
|
||||
private BudgetLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var response = await BudgetService.GetBudgetLookupAsync();
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_lookup = response.Value ?? new BudgetLookupResponse();
|
||||
}
|
||||
|
||||
_model = new UpdateBudgetRequest
|
||||
{
|
||||
Id = Data.Id,
|
||||
Title = Data.Title,
|
||||
Description = Data.Description,
|
||||
Amount = Data.Amount,
|
||||
BudgetDate = Data.BudgetDate,
|
||||
Status = Data.Status,
|
||||
CampaignId = Data.CampaignId,
|
||||
CreatedAt = Data.CreatedAt,
|
||||
CreatedBy = Data.CreatedBy,
|
||||
UpdatedAt = Data.UpdatedAt,
|
||||
UpdatedBy = Data.UpdatedBy
|
||||
};
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (ReadOnly) return;
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await BudgetService.UpdateBudgetAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Budget updated successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
|
||||
public class CreateBudgetRequest
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? BudgetDate { get; set; } = DateTime.Today;
|
||||
public BudgetStatus Status { get; set; } = BudgetStatus.Draft;
|
||||
public decimal? Amount { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateBudgetResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
}
|
||||
|
||||
public record CreateBudgetCommand(CreateBudgetRequest Data) : IRequest<CreateBudgetResponse>;
|
||||
|
||||
public class CreateBudgetHandler : IRequestHandler<CreateBudgetCommand, CreateBudgetResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateBudgetHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateBudgetResponse> Handle(CreateBudgetCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.Budget);
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.Budget
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
Title = request.Data.Title,
|
||||
Description = request.Data.Description,
|
||||
BudgetDate = request.Data.BudgetDate,
|
||||
Status = request.Data.Status,
|
||||
Amount = request.Data.Amount,
|
||||
CampaignId = request.Data.CampaignId
|
||||
};
|
||||
|
||||
_context.Budget.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateBudgetResponse { Id = entity.Id, AutoNumber = entity.AutoNumber };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
|
||||
public class CreateBudgetValidator : AbstractValidator<CreateBudgetRequest>
|
||||
{
|
||||
public CreateBudgetValidator()
|
||||
{
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty().WithMessage("Title is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.CampaignId)
|
||||
.NotEmpty().WithMessage("Campaign is required");
|
||||
|
||||
RuleFor(x => x.Amount)
|
||||
.GreaterThanOrEqualTo(0).WithMessage("Amount must be zero or greater");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue() => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CreateBudgetRequest>.CreateWithOptions((CreateBudgetRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid) return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
|
||||
public record DeleteBudgetByIdRequest(string Id);
|
||||
|
||||
public record DeleteBudgetByIdCommand(DeleteBudgetByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteBudgetByIdHandler : IRequestHandler<DeleteBudgetByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteBudgetByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteBudgetByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Budget
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Budget.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
|
||||
public class GetBudgetByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? BudgetDate { get; set; }
|
||||
public BudgetStatus Status { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetBudgetByIdQuery(string Id) : IRequest<GetBudgetByIdResponse?>;
|
||||
|
||||
public class GetBudgetByIdHandler : IRequestHandler<GetBudgetByIdQuery, GetBudgetByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBudgetByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetBudgetByIdResponse?> Handle(GetBudgetByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Budget
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetBudgetByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
Description = x.Description,
|
||||
BudgetDate = x.BudgetDate,
|
||||
Status = x.Status,
|
||||
Amount = x.Amount,
|
||||
CampaignId = x.CampaignId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
|
||||
public class GetBudgetListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? CampaignTitle { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public DateTime? BudgetDate { get; set; }
|
||||
public BudgetStatus Status { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetBudgetListQuery() : IRequest<List<GetBudgetListResponse>>;
|
||||
|
||||
public class GetBudgetListHandler : IRequestHandler<GetBudgetListQuery, List<GetBudgetListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBudgetListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetBudgetListResponse>> Handle(GetBudgetListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Budget
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Campaign)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetBudgetListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
CampaignTitle = x.Campaign != null ? x.Campaign.Title : string.Empty,
|
||||
Amount = x.Amount,
|
||||
BudgetDate = x.BudgetDate,
|
||||
Status = x.Status,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
|
||||
public class BudgetLookupResponse
|
||||
{
|
||||
public List<LookupItem> Campaigns { get; set; } = new();
|
||||
public List<LookupItem> Statuses { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public record GetBudgetLookupQuery() : IRequest<BudgetLookupResponse>;
|
||||
|
||||
public class GetBudgetLookupHandler : IRequestHandler<GetBudgetLookupQuery, BudgetLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetBudgetLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<BudgetLookupResponse> Handle(GetBudgetLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new BudgetLookupResponse();
|
||||
|
||||
response.Campaigns = await _context.Campaign
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Title)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Title })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Statuses = Enum.GetValues(typeof(BudgetStatus))
|
||||
.Cast<BudgetStatus>()
|
||||
.Select(x => new LookupItem
|
||||
{
|
||||
Value = (int)x,
|
||||
Name = x.ToString()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
|
||||
public class UpdateBudgetRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? BudgetDate { get; set; }
|
||||
public BudgetStatus Status { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateBudgetResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateBudgetCommand(UpdateBudgetRequest Data) : IRequest<UpdateBudgetResponse>;
|
||||
|
||||
public class UpdateBudgetHandler : IRequestHandler<UpdateBudgetCommand, UpdateBudgetResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateBudgetHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateBudgetResponse> Handle(UpdateBudgetCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Budget
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return new UpdateBudgetResponse { Success = false };
|
||||
|
||||
entity.Title = request.Data.Title;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.BudgetDate = request.Data.BudgetDate;
|
||||
entity.Status = request.Data.Status;
|
||||
entity.Amount = request.Data.Amount;
|
||||
entity.CampaignId = request.Data.CampaignId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateBudgetResponse { Id = entity.Id, Success = true };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Budget.Cqrs;
|
||||
|
||||
public class UpdateBudgetValidator : AbstractValidator<UpdateBudgetRequest>
|
||||
{
|
||||
public UpdateBudgetValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required for update");
|
||||
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty().WithMessage("Title is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.CampaignId)
|
||||
.NotEmpty().WithMessage("Campaign is required");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue() => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<UpdateBudgetRequest>.CreateWithOptions((UpdateBudgetRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid) return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign;
|
||||
|
||||
public static class CampaignEndpoint
|
||||
{
|
||||
public static void MapCampaignEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/campaign").WithTags("Campaign")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/lookup", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetCampaignLookupQuery());
|
||||
return result.ToApiResponse("Lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetCampaignLookup");
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetCampaignListQuery());
|
||||
return result.ToApiResponse("Campaign list retrieved successfully");
|
||||
})
|
||||
.WithName("GetCampaignList");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetCampaignByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Campaign detail retrieved successfully"
|
||||
: "Campaign not found");
|
||||
})
|
||||
.WithName("GetCampaignById");
|
||||
|
||||
group.MapPost("/", async (CreateCampaignRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateCampaignCommand(request));
|
||||
return result.ToApiResponse("Campaign created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateCampaign");
|
||||
|
||||
group.MapPost("/update", async (UpdateCampaignRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateCampaignCommand(request));
|
||||
return result.ToApiResponse("Campaign updated successfully");
|
||||
})
|
||||
.WithName("UpdateCampaign");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteCampaignByIdCommand(id));
|
||||
return result.ToApiResponse("Campaign deleted successfully");
|
||||
})
|
||||
.WithName("DeleteCampaign");
|
||||
|
||||
group.MapPost("/budget", async (CreateBudgetRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateBudgetCommand(request));
|
||||
return result.ToApiResponse("Budget added successfully");
|
||||
})
|
||||
.WithName("AddCampaignBudget");
|
||||
|
||||
group.MapPost("/budget/update", async (UpdateBudgetRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateBudgetCommand(request));
|
||||
return result.ToApiResponse("Budget updated successfully");
|
||||
})
|
||||
.WithName("UpdateCampaignBudget");
|
||||
|
||||
group.MapPost("/budget/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteBudgetCommand(id));
|
||||
return result.ToApiResponse("Budget deleted successfully");
|
||||
})
|
||||
.WithName("DeleteCampaignBudget");
|
||||
|
||||
group.MapPost("/expense", async (CreateExpenseRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateExpenseCommand(request));
|
||||
return result.ToApiResponse("Expense added successfully");
|
||||
})
|
||||
.WithName("AddCampaignExpense");
|
||||
|
||||
group.MapPost("/expense/update", async (UpdateExpenseRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateExpenseCommand(request));
|
||||
return result.ToApiResponse("Expense updated successfully");
|
||||
})
|
||||
.WithName("UpdateCampaignExpense");
|
||||
|
||||
group.MapPost("/expense/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteExpenseCommand(id));
|
||||
return result.ToApiResponse("Expense deleted successfully");
|
||||
})
|
||||
.WithName("DeleteCampaignExpense");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign;
|
||||
|
||||
public class CampaignService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public CampaignService(
|
||||
IHttpClientFactory clientFactory,
|
||||
NavigationManager nav,
|
||||
ISnackbar snackbar,
|
||||
ICurrentUserService currentUserService,
|
||||
TokenProvider tokenProvider)
|
||||
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
|
||||
{
|
||||
_client = new RestClient(nav.BaseUri);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CampaignLookupResponse>?> GetLookupDataAsync()
|
||||
{
|
||||
var request = new RestRequest("api/campaign/lookup", Method.Get);
|
||||
return await ExecuteWithResponseAsync<CampaignLookupResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<List<GetCampaignListResponse>>?> GetCampaignListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/campaign", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetCampaignListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetCampaignByIdResponse>?> GetCampaignByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/campaign/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetCampaignByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateCampaignResponse>?> CreateCampaignAsync(CreateCampaignRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/campaign", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateCampaignResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateCampaignResponse>?> UpdateCampaignAsync(UpdateCampaignRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/campaign/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateCampaignResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteCampaignAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/campaign/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateBudgetResponse>?> AddBudgetAsync(CreateBudgetRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/campaign/budget", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateBudgetResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateBudgetResponse>?> UpdateBudgetAsync(UpdateBudgetRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/campaign/budget/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateBudgetResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteBudgetAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/campaign/budget/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateExpenseResponse>?> AddExpenseAsync(CreateExpenseRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/campaign/expense", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateExpenseResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateExpenseResponse>?> UpdateExpenseAsync(UpdateExpenseRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/campaign/expense/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateExpenseResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteExpenseAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/campaign/expense/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
@page "/pipeline/campaign"
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using Indotalent.Features.Pipeline.Campaign.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_CampaignCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_CampaignUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_CampaignDataTable OnAdd="() => ShowCreate()" OnEdit="(item) => ShowUpdate(item, false)" OnView="(item) => ShowUpdate(item, true)" />
|
||||
}
|
||||
|
||||
@code {
|
||||
private enum ViewMode { Table, Create, Update, View }
|
||||
private ViewMode _currentView = ViewMode.Table;
|
||||
private UpdateCampaignRequest? _selectedData;
|
||||
|
||||
private void ShowCreate() => _currentView = ViewMode.Create;
|
||||
private void ShowUpdate(UpdateCampaignRequest data, bool isReadOnly) { _selectedData = data; _currentView = isReadOnly ? ViewMode.View : ViewMode.Update; }
|
||||
private void BackToTable() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
private void HandleSuccess() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using MudBlazor
|
||||
@inject CampaignService CampaignService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Budget Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title" Required="true" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Amount</MudText>
|
||||
<MudNumericField @bind-Value="_model.Amount" Variant="Variant.Outlined" Margin="Margin.Dense" T="decimal?" HideSpinButtons="true" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.BudgetDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.BudgetStatus" @bind-Value="_model.Status" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in Lookup.BudgetStatuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.BudgetStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudForm>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel" Variant="Variant.Text" Style="text-transform: none; font-weight: 700;">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit" Variant="Variant.Filled" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Add Budget</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
[Parameter] public string CampaignId { get; set; } = string.Empty;
|
||||
[Parameter] public CampaignLookupResponse Lookup { get; set; } = new();
|
||||
private MudForm _form = default!;
|
||||
private CreateBudgetRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
_model.CampaignId = CampaignId;
|
||||
try
|
||||
{
|
||||
var response = await CampaignService.AddBudgetAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Budget added successfully", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using Indotalent.Features.Root.Shared
|
||||
@using MudBlazor
|
||||
@inject CampaignService CampaignService
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; border: 1px solid #E5E7EB;">
|
||||
<div style="padding: 16px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #F9FAFB;">
|
||||
<MudText Typo="Typo.button" Style="font-weight: 600;">Campaign Budgets</MudText>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="OnAddClick" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px;">Add Budget</MudButton>
|
||||
}
|
||||
</div>
|
||||
<MudTable Striped="true" Class="mud-table-styled" Items="Items" Hover="true" Elevation="0" Dense="true" T="CampaignBudgetResponse" Context="budgetContext">
|
||||
<HeaderContent>
|
||||
<MudTh Style="font-weight: 700; color: #111827;">No</MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827;">Title</MudTh>
|
||||
<MudTh Style="text-align: right; font-weight: 700;">Amount</MudTh>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudTh Style="width: 100px; text-align: right; font-weight: 700;">Actions</MudTh>
|
||||
}
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="No" Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@budgetContext.AutoNumber</MudTd>
|
||||
<MudTd DataLabel="Title" Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@budgetContext.Title</MudTd>
|
||||
<MudTd DataLabel="Amount" Style="text-align: right;">@budgetContext.Amount?.ToString("N0")</MudTd>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudTd Style="text-align: right; padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small" Color="Color.Primary" OnClick="@(() => OnEditClick(budgetContext))" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error" OnClick="@(() => OnDeleteClick(budgetContext))" />
|
||||
</MudTd>
|
||||
}
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public string CampaignId { get; set; } = string.Empty;
|
||||
[Parameter] public List<CampaignBudgetResponse> Items { get; set; } = new();
|
||||
[Parameter] public CampaignLookupResponse Lookup { get; set; } = new();
|
||||
[Parameter] public bool ReadOnly { get; set; } = false;
|
||||
[Parameter] public EventCallback OnChanged { get; set; }
|
||||
|
||||
private async Task OnAddClick()
|
||||
{
|
||||
var p = new DialogParameters { ["CampaignId"] = CampaignId, ["Lookup"] = Lookup };
|
||||
var d = await DialogService.ShowAsync<_BudgetCreateForm>("Add Budget", p, new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true });
|
||||
var result = await d.Result;
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
await OnChanged.InvokeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnEditClick(CampaignBudgetResponse item)
|
||||
{
|
||||
var p = new DialogParameters { ["Data"] = item, ["Lookup"] = Lookup };
|
||||
var d = await DialogService.ShowAsync<_BudgetUpdateForm>("Edit Budget", p, new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true });
|
||||
var result = await d.Result;
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
await OnChanged.InvokeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnDeleteClick(CampaignBudgetResponse item)
|
||||
{
|
||||
var p = new DialogParameters { ["ContentText"] = $"Are you sure you want to delete budget {item.AutoNumber}?" };
|
||||
var d = await DialogService.ShowAsync<_DeleteConfirmation>("Delete Confirmation", p, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true });
|
||||
var result = await d.Result;
|
||||
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
if (await CampaignService.DeleteBudgetAsync(item.Id!))
|
||||
{
|
||||
Snackbar.Add("Budget deleted successfully", Severity.Success);
|
||||
await OnChanged.InvokeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using MudBlazor
|
||||
@inject CampaignService CampaignService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Budget Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title" Required="true" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Amount</MudText>
|
||||
<MudNumericField @bind-Value="_model.Amount" Variant="Variant.Outlined" Margin="Margin.Dense" T="decimal?" HideSpinButtons="true" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.BudgetDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.BudgetStatus" @bind-Value="_model.Status" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in Lookup.BudgetStatuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.BudgetStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudForm>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel" Variant="Variant.Text" Style="text-transform: none; font-weight: 700;">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit" Variant="Variant.Filled" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Save Changes</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
[Parameter] public CampaignBudgetResponse Data { get; set; } = new();
|
||||
[Parameter] public CampaignLookupResponse Lookup { get; set; } = new();
|
||||
private MudForm _form = default!;
|
||||
private UpdateBudgetRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_model.Id = Data.Id;
|
||||
_model.Title = Data.Title;
|
||||
_model.Amount = Data.Amount;
|
||||
_model.BudgetDate = Data.BudgetDate;
|
||||
_model.Status = Data.Status;
|
||||
_model.Description = Data.Description;
|
||||
}
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var res = await CampaignService.UpdateBudgetAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Budget updated successfully", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject CampaignService CampaignService
|
||||
@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;">Add New Campaign</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Initiate a new marketing campaign and track progress.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Campaign Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title"
|
||||
For="@(() => _model.Title)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Sales Team</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.SalesTeamId" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.SalesTeams)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.CampaignStatus" @bind-Value="_model.Status" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.CampaignStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.CampaignDateStart" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Finish Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.CampaignDateFinish" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Target Revenue</MudText>
|
||||
<MudNumericField @bind-Value="_model.TargetRevenueAmount" Variant="Variant.Outlined" Margin="Margin.Dense" T="decimal?" HideSpinButtons="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<div class="d-flex justify-end gap-2 mt-8">
|
||||
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Disabled="_processing" Style="border-radius: 4px; border: 1px solid #e0e0e0; text-transform: none; font-weight: 700;">Cancel</MudButton>
|
||||
<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;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Create Campaign</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
|
||||
private MudForm _form = default!;
|
||||
private CreateCampaignValidator _validator = new();
|
||||
private CreateCampaignRequest _model = new() { Status = Indotalent.Data.Enums.CampaignStatus.Draft };
|
||||
private CampaignLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await CampaignService.GetLookupDataAsync();
|
||||
if (res != null && res.IsSuccess) { _lookup = res.Value!; }
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await CampaignService.CreateCampaignAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Campaign created successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.Campaign
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject CampaignService CampaignService
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Campaign Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Manage marketing campaigns, budgets, and expenses.</MudText>
|
||||
</div>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Campaign" Size="Size.Small" Color="Color.Default" />
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Pipeline</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Campaign</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
|
||||
|
||||
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
|
||||
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<MudTextField @bind-Value="_searchString"
|
||||
Placeholder="Search..."
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
IconSize="Size.Small"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
Style="background-color: white; width: 280px; border-radius: 8px;"
|
||||
OnKeyDown="@HandleSearchKeyDown" />
|
||||
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
OnClick="OnSearchClick"
|
||||
Size="Size.Small"
|
||||
Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none;">
|
||||
Search
|
||||
</MudButton>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Success" OnClick="ExportToExcel" Size="Size.Small" Disabled="_isExporting" StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)" Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isExporting) { <MudProgressCircular Size="Size.Small" Indeterminate="true" /> } else { <MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText> }
|
||||
</MudButton>
|
||||
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" OnClick="LoadData" Size="Size.Small" StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)" Disabled="_isRefreshing" Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isRefreshing) { <MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText> } else { <MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText> }
|
||||
</MudButton>
|
||||
|
||||
@if (_selectedItem != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedItem = null" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">
|
||||
Add New Campaign
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Striped="true" Class="mud-table-styled" Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetCampaignListResponse" OnRowClick="@((args) => _selectedItem = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetCampaignListResponse, object>(x => x.AutoNumber!)">No</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetCampaignListResponse, object>(x => x.Title!)">Title</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetCampaignListResponse, object>(x => x.SalesTeamName!)">Sales Team</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetCampaignListResponse, object>(x => x.TargetRevenueAmount!)">Target Revenue</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetCampaignListResponse, object>(x => x.Status!)">Status</MudTableSortLabel>
|
||||
</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd><MudCheckBox T="bool" Value="@(_selectedItem?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" /></MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.AutoNumber</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;"><MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.Title</MudText></MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.SalesTeamName</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.TargetRevenueAmount?.ToString("N0")</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
|
||||
<MudChip T="string" Color="@GetStatusColor(context.Status)" Size="Size.Small" Variant="Variant.Filled" Style="font-weight: 600; border-radius: 4px;">@context.Status?.ToUpper()</MudChip>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
|
||||
<div style="display: flex; align-items: center; gap: 12px;">
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
|
||||
<MudSelect T="int" Value="@_top" ValueChanged="OnPageSizeChanged" Dense="true" Margin="Margin.Dense" Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;" Variant="Variant.Outlined" Class="mt-0 custom-select-dense" AnchorOrigin="Origin.BottomCenter">
|
||||
<MudSelectItem Value="5" /><MudSelectItem Value="10" /><MudSelectItem Value="50" /><MudSelectItem Value="500" /><MudSelectItem Value="1000" />
|
||||
</MudSelect>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF; font-size: 0.75rem; font-weight: 500; margin-left: 12px;">
|
||||
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
|
||||
</MudText>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" />
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="@(_currentPage == 1 ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #D1D5DB; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">Prev</MudButton>
|
||||
@{
|
||||
var totalPages = _totalPage == 0 ? 1 : _totalPage;
|
||||
var maxVisible = 5;
|
||||
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
|
||||
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
|
||||
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
|
||||
}
|
||||
@for (int i = startPage; i <= endPage; i++)
|
||||
{
|
||||
var pageNum = i;
|
||||
var isActive = pageNum == _currentPage;
|
||||
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
|
||||
Variant="Variant.Text" Size="Size.Small"
|
||||
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
|
||||
}
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #D1D5DB; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">Next</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<style>
|
||||
.mud-input-outlined-border { border-radius: 0px !important; }
|
||||
.custom-select-dense .mud-input-control { margin-top: 0 !important; }
|
||||
.custom-select-dense .mud-input-slot { padding-top: 4px !important; padding-bottom: 4px !important; padding-left: 8px !important; font-size: 12px !important; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateCampaignRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateCampaignRequest> OnView { get; set; }
|
||||
|
||||
private List<GetCampaignListResponse> _items = new();
|
||||
private GetCampaignListResponse? _selectedItem;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
private int _skip = 0;
|
||||
private int _top = 5;
|
||||
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
|
||||
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedItem = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await CampaignService.GetCampaignListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess) { _items = response.Value ?? new(); }
|
||||
}
|
||||
finally { _isRefreshing = false; StateHasChanged(); }
|
||||
}
|
||||
|
||||
private IEnumerable<GetCampaignListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _items;
|
||||
return _items.Where(x =>
|
||||
(x.Title?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.SalesTeamName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetCampaignListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private Color GetStatusColor(string? status) => status switch {
|
||||
"Finished" => Color.Success, "OnProgress" => Color.Info, "Confirmed" => Color.Primary, "Cancelled" => Color.Error, "Draft" => Color.Default, _ => Color.Default
|
||||
};
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("Campaigns");
|
||||
worksheet.Cell(1, 1).Value = "No"; worksheet.Cell(1, 2).Value = "Title";
|
||||
worksheet.Cell(1, 3).Value = "Sales Team"; worksheet.Cell(1, 4).Value = "Target Revenue";
|
||||
worksheet.Cell(1, 5).Value = "Status";
|
||||
var row = 1;
|
||||
foreach (var item in GetFilteredData())
|
||||
{
|
||||
row++;
|
||||
worksheet.Cell(row, 1).Value = item.AutoNumber; worksheet.Cell(row, 2).Value = item.Title;
|
||||
worksheet.Cell(row, 3).Value = item.SalesTeamName; worksheet.Cell(row, 4).Value = item.TargetRevenueAmount;
|
||||
worksheet.Cell(row, 5).Value = item.Status;
|
||||
}
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "Campaign_List.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { _isExporting = false; }
|
||||
}
|
||||
|
||||
private void OnSearchClick() { _skip = 0; _selectedItem = null; StateHasChanged(); }
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") OnSearchClick(); }
|
||||
private void OnPageChanged(int page) { _skip = (page - 1) * _top; _selectedItem = null; }
|
||||
private void OnPageSizeChanged(int size) { _top = size; _skip = 0; }
|
||||
|
||||
private async Task InvokeEdit() { if (_selectedItem == null) return; var request = await MapToUpdateRequest(_selectedItem.Id!); if (request != null) await OnEdit.InvokeAsync(request); }
|
||||
private async Task InvokeView() { if (_selectedItem == null) return; var request = await MapToUpdateRequest(_selectedItem.Id!); if (request != null) await OnView.InvokeAsync(request); }
|
||||
|
||||
private async Task<UpdateCampaignRequest?> MapToUpdateRequest(string id)
|
||||
{
|
||||
var response = await CampaignService.GetCampaignByIdAsync(id);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
var d = response.Value!;
|
||||
return new UpdateCampaignRequest {
|
||||
Id = d.Id, Title = d.Title, Description = d.Description, TargetRevenueAmount = d.TargetRevenueAmount,
|
||||
CampaignDateStart = d.CampaignDateStart, CampaignDateFinish = d.CampaignDateFinish,
|
||||
Status = d.Status, SalesTeamId = d.SalesTeamId,
|
||||
CreatedAt = d.CreatedAt, CreatedBy = d.CreatedBy, UpdatedAt = d.UpdatedAt, UpdatedBy = d.UpdatedBy
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedItem.Title } };
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true });
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled) { if (await CampaignService.DeleteCampaignAsync(_selectedItem.Id!)) { await LoadData(); Snackbar.Add("Deleted successfully", Severity.Success); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using Indotalent.Features.Pipeline.Campaign.Components
|
||||
@using MudBlazor
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@inject CampaignService CampaignService
|
||||
@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 ? "Campaign Details" : "Edit Campaign")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Manage campaign specifications and financial tracking.</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.subtitle2" Class="mb-1">Campaign Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Sales Team</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.SalesTeamId" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter" FullWidth="true">
|
||||
@foreach (var item in _lookup.SalesTeams)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.CampaignStatus" @bind-Value="_model.Status" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter" FullWidth="true">
|
||||
@foreach (var item in _lookup.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.CampaignStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Start Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.CampaignDateStart" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Finish Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.CampaignDateFinish" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Target Revenue</MudText>
|
||||
<MudNumericField @bind-Value="_model.TargetRevenueAmount" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" T="decimal?" HideSpinButtons="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" Class="mt-6">
|
||||
<MudTabs Elevation="0" Outlined="true" Position="Position.Top" Rounded="false" Border="true" ApplyEffectsToContainer="true">
|
||||
<MudTabPanel Text="Budgets">
|
||||
<div class="pa-4">
|
||||
<_BudgetDataTable CampaignId="@_model.Id" Items="_budgets" Lookup="_lookup" ReadOnly="ReadOnly" OnChanged="RefreshDetails" />
|
||||
</div>
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="Expenses">
|
||||
<div class="pa-4">
|
||||
<_ExpenseDataTable CampaignId="@_model.Id" Items="_expenses" Lookup="_lookup" ReadOnly="ReadOnly" OnChanged="RefreshDetails" />
|
||||
</div>
|
||||
</MudTabPanel>
|
||||
</MudTabs>
|
||||
</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" 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 Size="Size.Small" Indeterminate="true" Class="ms-n1" />
|
||||
<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 UpdateCampaignRequest 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 UpdateCampaignRequest _model = new();
|
||||
private CampaignLookupResponse _lookup = new();
|
||||
private List<CampaignBudgetResponse> _budgets = new();
|
||||
private List<CampaignExpenseResponse> _expenses = new();
|
||||
private bool _processing = false;
|
||||
private bool _isDataLoading = true;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_isDataLoading = true;
|
||||
try
|
||||
{
|
||||
var resLookup = await CampaignService.GetLookupDataAsync();
|
||||
if (resLookup != null && resLookup.IsSuccess)
|
||||
{
|
||||
_lookup = resLookup.Value!;
|
||||
}
|
||||
|
||||
var resDetail = await CampaignService.GetCampaignByIdAsync(Data.Id!);
|
||||
if (resDetail != null && resDetail.IsSuccess)
|
||||
{
|
||||
var d = resDetail.Value!;
|
||||
_model = new UpdateCampaignRequest
|
||||
{
|
||||
Id = d.Id,
|
||||
Title = d.Title,
|
||||
Description = d.Description,
|
||||
TargetRevenueAmount = d.TargetRevenueAmount,
|
||||
CampaignDateStart = d.CampaignDateStart,
|
||||
CampaignDateFinish = d.CampaignDateFinish,
|
||||
Status = d.Status,
|
||||
SalesTeamId = d.SalesTeamId,
|
||||
CreatedAt = d.CreatedAt,
|
||||
CreatedBy = d.CreatedBy,
|
||||
UpdatedAt = d.UpdatedAt,
|
||||
UpdatedBy = d.UpdatedBy
|
||||
};
|
||||
|
||||
_budgets = d.Budgets;
|
||||
_expenses = d.Expenses;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isDataLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RefreshDetails()
|
||||
{
|
||||
var res = await CampaignService.GetCampaignByIdAsync(_model.Id!);
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
_budgets = res.Value!.Budgets;
|
||||
_expenses = res.Value!.Expenses;
|
||||
|
||||
_model.CreatedAt = res.Value.CreatedAt;
|
||||
_model.CreatedBy = res.Value.CreatedBy;
|
||||
_model.UpdatedAt = res.Value.UpdatedAt;
|
||||
_model.UpdatedBy = res.Value.UpdatedBy;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var response = await CampaignService.UpdateCampaignAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Campaign updated successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using MudBlazor
|
||||
@inject CampaignService CampaignService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Expense Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title" Required="true" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Amount</MudText>
|
||||
<MudNumericField @bind-Value="_model.Amount" Variant="Variant.Outlined" Margin="Margin.Dense" T="decimal?" HideSpinButtons="true" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.ExpenseDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.ExpenseStatus" @bind-Value="_model.Status" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in Lookup.ExpenseStatuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ExpenseStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudForm>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel" Variant="Variant.Text" Style="text-transform: none; font-weight: 700;">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit" Variant="Variant.Filled" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Add Expense</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
[Parameter] public string CampaignId { get; set; } = string.Empty;
|
||||
[Parameter] public CampaignLookupResponse Lookup { get; set; } = new();
|
||||
private MudForm _form = default!;
|
||||
private CreateExpenseRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
_model.CampaignId = CampaignId;
|
||||
try
|
||||
{
|
||||
var response = await CampaignService.AddExpenseAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Expense added successfully", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using Indotalent.Features.Root.Shared
|
||||
@using MudBlazor
|
||||
@inject CampaignService CampaignService
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; border: 1px solid #E5E7EB;">
|
||||
<div style="padding: 16px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #F9FAFB;">
|
||||
<MudText Typo="Typo.button" Style="font-weight: 600;">Campaign Expenses</MudText>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="OnAddClick" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px;">Add Expense</MudButton>
|
||||
}
|
||||
</div>
|
||||
<MudTable Striped="true" Class="mud-table-styled" Items="Items" Hover="true" Elevation="0" Dense="true" T="CampaignExpenseResponse" Context="expenseContext">
|
||||
<HeaderContent>
|
||||
<MudTh Style="font-weight: 700; color: #111827;">No</MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827;">Title</MudTh>
|
||||
<MudTh Style="text-align: right; font-weight: 700;">Amount</MudTh>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudTh Style="width: 100px; text-align: right; font-weight: 700;">Actions</MudTh>
|
||||
}
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="No" Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@expenseContext.AutoNumber</MudTd>
|
||||
<MudTd DataLabel="Title" Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@expenseContext.Title</MudTd>
|
||||
<MudTd DataLabel="Amount" Style="text-align: right;">@expenseContext.Amount?.ToString("N0")</MudTd>
|
||||
@if (!ReadOnly)
|
||||
{
|
||||
<MudTd Style="text-align: right; padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small" Color="Color.Primary" OnClick="@(() => OnEditClick(expenseContext))" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error" OnClick="@(() => OnDeleteClick(expenseContext))" />
|
||||
</MudTd>
|
||||
}
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public string CampaignId { get; set; } = string.Empty;
|
||||
[Parameter] public List<CampaignExpenseResponse> Items { get; set; } = new();
|
||||
[Parameter] public CampaignLookupResponse Lookup { get; set; } = new();
|
||||
[Parameter] public bool ReadOnly { get; set; } = false;
|
||||
[Parameter] public EventCallback OnChanged { get; set; }
|
||||
|
||||
private async Task OnAddClick()
|
||||
{
|
||||
var p = new DialogParameters { ["CampaignId"] = CampaignId, ["Lookup"] = Lookup };
|
||||
var d = await DialogService.ShowAsync<_ExpenseCreateForm>("Add Expense", p, new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true });
|
||||
var result = await d.Result;
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
await OnChanged.InvokeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnEditClick(CampaignExpenseResponse item)
|
||||
{
|
||||
var p = new DialogParameters { ["Data"] = item, ["Lookup"] = Lookup };
|
||||
var d = await DialogService.ShowAsync<_ExpenseUpdateForm>("Edit Expense", p, new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true });
|
||||
var result = await d.Result;
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
await OnChanged.InvokeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnDeleteClick(CampaignExpenseResponse item)
|
||||
{
|
||||
var p = new DialogParameters { ["ContentText"] = $"Are you sure you want to delete expense {item.AutoNumber}?" };
|
||||
var d = await DialogService.ShowAsync<_DeleteConfirmation>("Delete Confirmation", p, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true });
|
||||
var result = await d.Result;
|
||||
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
if (await CampaignService.DeleteExpenseAsync(item.Id!))
|
||||
{
|
||||
Snackbar.Add("Expense removed successfully", Severity.Success);
|
||||
await OnChanged.InvokeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
@using Indotalent.Features.Pipeline.Campaign.Cqrs
|
||||
@using MudBlazor
|
||||
@inject CampaignService CampaignService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Expense Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title" Required="true" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Amount</MudText>
|
||||
<MudNumericField @bind-Value="_model.Amount" Variant="Variant.Outlined" Margin="Margin.Dense" T="decimal?" HideSpinButtons="true" FullWidth="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.ExpenseDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.ExpenseStatus" @bind-Value="_model.Status" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in Lookup.ExpenseStatuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ExpenseStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudForm>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel" Variant="Variant.Text" Style="text-transform: none; font-weight: 700;">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit" Variant="Variant.Filled" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Save Changes</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
[Parameter] public CampaignExpenseResponse Data { get; set; } = new();
|
||||
[Parameter] public CampaignLookupResponse Lookup { get; set; } = new();
|
||||
private MudForm _form = default!;
|
||||
private UpdateExpenseRequest _model = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_model.Id = Data.Id;
|
||||
_model.Title = Data.Title;
|
||||
_model.Amount = Data.Amount;
|
||||
_model.ExpenseDate = Data.ExpenseDate;
|
||||
_model.Status = Data.Status;
|
||||
_model.Description = Data.Description;
|
||||
}
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var res = await CampaignService.UpdateExpenseAsync(_model);
|
||||
await Task.Delay(500);
|
||||
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Expense updated successfully", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class CreateBudgetRequest
|
||||
{
|
||||
public string? CampaignId { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? BudgetDate { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public BudgetStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public class CreateBudgetResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
|
||||
public record CreateBudgetCommand(CreateBudgetRequest Data) : IRequest<CreateBudgetResponse>;
|
||||
|
||||
public class CreateBudgetHandler : IRequestHandler<CreateBudgetCommand, CreateBudgetResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public CreateBudgetHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateBudgetResponse> Handle(CreateBudgetCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new Data.Entities.Budget
|
||||
{
|
||||
CampaignId = request.Data.CampaignId,
|
||||
Title = request.Data.Title,
|
||||
Description = request.Data.Description,
|
||||
BudgetDate = request.Data.BudgetDate,
|
||||
Amount = request.Data.Amount,
|
||||
Status = request.Data.Status
|
||||
};
|
||||
|
||||
_context.Budget.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateBudgetResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Title = entity.Title
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class CreateCampaignRequest
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public decimal? TargetRevenueAmount { get; set; }
|
||||
public DateTime? CampaignDateStart { get; set; }
|
||||
public DateTime? CampaignDateFinish { get; set; }
|
||||
public CampaignStatus Status { get; set; }
|
||||
public string? SalesTeamId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateCampaignResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
|
||||
public record CreateCampaignCommand(CreateCampaignRequest Data) : IRequest<CreateCampaignResponse>;
|
||||
|
||||
public class CreateCampaignHandler : IRequestHandler<CreateCampaignCommand, CreateCampaignResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public CreateCampaignHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateCampaignResponse> Handle(CreateCampaignCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new Data.Entities.Campaign
|
||||
{
|
||||
Title = request.Data.Title,
|
||||
Description = request.Data.Description,
|
||||
TargetRevenueAmount = request.Data.TargetRevenueAmount,
|
||||
CampaignDateStart = request.Data.CampaignDateStart,
|
||||
CampaignDateFinish = request.Data.CampaignDateFinish,
|
||||
Status = request.Data.Status,
|
||||
SalesTeamId = request.Data.SalesTeamId
|
||||
};
|
||||
|
||||
_context.Campaign.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateCampaignResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Title = entity.Title
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class CreateCampaignValidator : AbstractValidator<CreateCampaignRequest>
|
||||
{
|
||||
public CreateCampaignValidator()
|
||||
{
|
||||
RuleFor(x => x.Title).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
|
||||
RuleFor(x => x.SalesTeamId).NotEmpty().WithMessage("Sales Team is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class CreateExpenseRequest
|
||||
{
|
||||
public string? CampaignId { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? ExpenseDate { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public ExpenseStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public class CreateExpenseResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
|
||||
public record CreateExpenseCommand(CreateExpenseRequest Data) : IRequest<CreateExpenseResponse>;
|
||||
|
||||
public class CreateExpenseHandler : IRequestHandler<CreateExpenseCommand, CreateExpenseResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public CreateExpenseHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateExpenseResponse> Handle(CreateExpenseCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new Data.Entities.Expense
|
||||
{
|
||||
CampaignId = request.Data.CampaignId,
|
||||
Title = request.Data.Title,
|
||||
Description = request.Data.Description,
|
||||
ExpenseDate = request.Data.ExpenseDate,
|
||||
Amount = request.Data.Amount,
|
||||
Status = request.Data.Status
|
||||
};
|
||||
|
||||
_context.Expense.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateExpenseResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Title = entity.Title
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public record DeleteBudgetCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteBudgetHandler : IRequestHandler<DeleteBudgetCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public DeleteBudgetHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteBudgetCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Budget
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Budget.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public record DeleteCampaignByIdCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteCampaignByIdHandler : IRequestHandler<DeleteCampaignByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public DeleteCampaignByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteCampaignByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Campaign
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Campaign.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public record DeleteExpenseCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteExpenseHandler : IRequestHandler<DeleteExpenseCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public DeleteExpenseHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteExpenseCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Expense
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Expense.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class CampaignBudgetResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public DateTime? BudgetDate { get; set; }
|
||||
public BudgetStatus Status { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public class CampaignExpenseResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public DateTime? ExpenseDate { get; set; }
|
||||
public ExpenseStatus Status { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public class GetCampaignByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public decimal? TargetRevenueAmount { get; set; }
|
||||
public DateTime? CampaignDateStart { get; set; }
|
||||
public DateTime? CampaignDateFinish { get; set; }
|
||||
public CampaignStatus Status { get; set; }
|
||||
public string? SalesTeamId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
public List<CampaignBudgetResponse> Budgets { get; set; } = new();
|
||||
public List<CampaignExpenseResponse> Expenses { get; set; } = new();
|
||||
}
|
||||
|
||||
public record GetCampaignByIdQuery(string Id) : IRequest<GetCampaignByIdResponse?>;
|
||||
|
||||
public class GetCampaignByIdHandler : IRequestHandler<GetCampaignByIdQuery, GetCampaignByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetCampaignByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetCampaignByIdResponse?> Handle(GetCampaignByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Campaign
|
||||
.AsNoTracking()
|
||||
.Include(x => x.BudgetList)
|
||||
.Include(x => x.ExpenseList)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetCampaignByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
Description = x.Description,
|
||||
TargetRevenueAmount = x.TargetRevenueAmount,
|
||||
CampaignDateStart = x.CampaignDateStart,
|
||||
CampaignDateFinish = x.CampaignDateFinish,
|
||||
Status = x.Status,
|
||||
SalesTeamId = x.SalesTeamId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy,
|
||||
Budgets = x.BudgetList.Select(b => new CampaignBudgetResponse
|
||||
{
|
||||
Id = b.Id,
|
||||
AutoNumber = b.AutoNumber,
|
||||
Title = b.Title,
|
||||
Amount = b.Amount,
|
||||
BudgetDate = b.BudgetDate,
|
||||
Status = b.Status,
|
||||
Description = b.Description
|
||||
}).ToList(),
|
||||
Expenses = x.ExpenseList.Select(e => new CampaignExpenseResponse
|
||||
{
|
||||
Id = e.Id,
|
||||
AutoNumber = e.AutoNumber,
|
||||
Title = e.Title,
|
||||
Amount = e.Amount,
|
||||
ExpenseDate = e.ExpenseDate,
|
||||
Status = e.Status,
|
||||
Description = e.Description
|
||||
}).ToList()
|
||||
}).FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class GetCampaignListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? SalesTeamName { get; set; }
|
||||
public DateTime? CampaignDateStart { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public decimal? TargetRevenueAmount { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetCampaignListQuery() : IRequest<List<GetCampaignListResponse>>;
|
||||
|
||||
public class GetCampaignListHandler : IRequestHandler<GetCampaignListQuery, List<GetCampaignListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetCampaignListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetCampaignListResponse>> Handle(GetCampaignListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Campaign
|
||||
.AsNoTracking()
|
||||
.Include(x => x.SalesTeam)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetCampaignListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
SalesTeamName = x.SalesTeam != null ? x.SalesTeam.Name : string.Empty,
|
||||
CampaignDateStart = x.CampaignDateStart,
|
||||
Status = x.Status.GetDescription(),
|
||||
TargetRevenueAmount = x.TargetRevenueAmount,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
}).ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class CampaignLookupResponse
|
||||
{
|
||||
public List<LookupItem> SalesTeams { get; set; } = new();
|
||||
public List<LookupItem> Statuses { get; set; } = new();
|
||||
public List<LookupItem> BudgetStatuses { get; set; } = new();
|
||||
public List<LookupItem> ExpenseStatuses { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public record GetCampaignLookupQuery() : IRequest<CampaignLookupResponse>;
|
||||
|
||||
public class GetCampaignLookupHandler : IRequestHandler<GetCampaignLookupQuery, CampaignLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetCampaignLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CampaignLookupResponse> Handle(GetCampaignLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new CampaignLookupResponse();
|
||||
|
||||
response.SalesTeams = await _context.SalesTeam
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Statuses = Enum.GetValues(typeof(CampaignStatus))
|
||||
.Cast<CampaignStatus>()
|
||||
.Select(e => new LookupItem { Value = (int)e, Name = e.GetDescription() })
|
||||
.ToList();
|
||||
|
||||
response.BudgetStatuses = Enum.GetValues(typeof(BudgetStatus))
|
||||
.Cast<BudgetStatus>()
|
||||
.Select(e => new LookupItem { Value = (int)e, Name = e.GetDescription() })
|
||||
.ToList();
|
||||
|
||||
response.ExpenseStatuses = Enum.GetValues(typeof(ExpenseStatus))
|
||||
.Cast<ExpenseStatus>()
|
||||
.Select(e => new LookupItem { Value = (int)e, Name = e.GetDescription() })
|
||||
.ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class UpdateBudgetRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? BudgetDate { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public BudgetStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateBudgetResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateBudgetCommand(UpdateBudgetRequest Data) : IRequest<UpdateBudgetResponse>;
|
||||
|
||||
public class UpdateBudgetHandler : IRequestHandler<UpdateBudgetCommand, UpdateBudgetResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public UpdateBudgetHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateBudgetResponse> Handle(UpdateBudgetCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Budget
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateBudgetResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Title = request.Data.Title;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.BudgetDate = request.Data.BudgetDate;
|
||||
entity.Amount = request.Data.Amount;
|
||||
entity.Status = request.Data.Status;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateBudgetResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class UpdateCampaignRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public decimal? TargetRevenueAmount { get; set; }
|
||||
public DateTime? CampaignDateStart { get; set; }
|
||||
public DateTime? CampaignDateFinish { get; set; }
|
||||
public CampaignStatus Status { get; set; }
|
||||
public string? SalesTeamId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateCampaignResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateCampaignCommand(UpdateCampaignRequest Data) : IRequest<UpdateCampaignResponse>;
|
||||
|
||||
public class UpdateCampaignHandler : IRequestHandler<UpdateCampaignCommand, UpdateCampaignResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public UpdateCampaignHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateCampaignResponse> Handle(UpdateCampaignCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Campaign
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateCampaignResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Title = request.Data.Title;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.TargetRevenueAmount = request.Data.TargetRevenueAmount;
|
||||
entity.CampaignDateStart = request.Data.CampaignDateStart;
|
||||
entity.CampaignDateFinish = request.Data.CampaignDateFinish;
|
||||
entity.Status = request.Data.Status;
|
||||
entity.SalesTeamId = request.Data.SalesTeamId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateCampaignResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class UpdateCampaignValidator : AbstractValidator<UpdateCampaignRequest>
|
||||
{
|
||||
public UpdateCampaignValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Title).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
|
||||
RuleFor(x => x.SalesTeamId).NotEmpty().WithMessage("Sales Team is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Campaign.Cqrs;
|
||||
|
||||
public class UpdateExpenseRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? ExpenseDate { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public ExpenseStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateExpenseResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateExpenseCommand(UpdateExpenseRequest Data) : IRequest<UpdateExpenseResponse>;
|
||||
|
||||
public class UpdateExpenseHandler : IRequestHandler<UpdateExpenseCommand, UpdateExpenseResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public UpdateExpenseHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateExpenseResponse> Handle(UpdateExpenseCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Expense
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateExpenseResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Title = request.Data.Title;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.ExpenseDate = request.Data.ExpenseDate;
|
||||
entity.Amount = request.Data.Amount;
|
||||
entity.Status = request.Data.Status;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateExpenseResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
@page "/pipeline/expense"
|
||||
@using Indotalent.Features.Pipeline.Expense
|
||||
@using Indotalent.Features.Pipeline.Expense.Cqrs
|
||||
@using Indotalent.Features.Pipeline.Expense.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_ExpenseCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_ExpenseUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_ExpenseDataTable OnAdd="ShowCreate" OnEdit="(item) => ShowUpdate(item, false)" OnView="(item) => ShowUpdate(item, true)" />
|
||||
}
|
||||
|
||||
@code {
|
||||
private enum ViewMode { Table, Create, Update, View }
|
||||
private ViewMode _currentView = ViewMode.Table;
|
||||
private UpdateExpenseRequest? _selectedData;
|
||||
|
||||
private void ShowCreate() => _currentView = ViewMode.Create;
|
||||
private void ShowUpdate(UpdateExpenseRequest data, bool isReadOnly) { _selectedData = data; _currentView = isReadOnly ? ViewMode.View : ViewMode.Update; }
|
||||
private void BackToTable() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
private void HandleSuccess() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
@using Indotalent.Features.Pipeline.Expense
|
||||
@using Indotalent.Features.Pipeline.Expense.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject ExpenseService ExpenseService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center gap-4" Style="border: 1px solid #DCEBFA;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add New Expense</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Record actual spending for your campaign.</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title" For="@(() => _model.Title)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Campaign</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.CampaignId" For="@(() => _model.CampaignId)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Campaigns)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.ExpenseStatus" @bind-Value="_model.Status" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ExpenseStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Amount</MudText>
|
||||
<MudNumericField @bind-Value="_model.Amount" T="decimal?" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" HideSpinButtons="false" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Expense Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.ExpenseDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
<div class="d-flex justify-end gap-2 mt-8">
|
||||
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Style="border-radius: 4px; border: 1px solid #e0e0e0; text-transform: none; font-weight: 700;">Cancel</MudButton>
|
||||
<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;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<MudText>Create Expense</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
private MudForm _form = default!;
|
||||
private CreateExpenseValidator _validator = new();
|
||||
private CreateExpenseRequest _model = new();
|
||||
private ExpenseLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await ExpenseService.GetExpenseLookupAsync();
|
||||
if (res != null && res.IsSuccess) _lookup = res.Value ?? new();
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
var res = await ExpenseService.CreateExpenseAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (res != null && res.IsSuccess) { Snackbar.Add("Created successfully", Severity.Success); await OnSuccess.InvokeAsync(); }
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.Expense
|
||||
@using Indotalent.Features.Pipeline.Expense.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject ExpenseService ExpenseService
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Expense Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Manage and monitor actual spending for campaigns.</MudText>
|
||||
</div>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Pipeline</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Expense</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
|
||||
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<MudTextField @bind-Value="_searchString" Placeholder="Search..." Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Small" Class="mt-0" Variant="Variant.Outlined" Margin="Margin.Dense" Style="background-color: white; width: 280px; border-radius: 8px;" OnKeyDown="@HandleSearchKeyDown" />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OnSearchClick" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none;">Search</MudButton>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Success" OnClick="ExportToExcel" Size="Size.Small" Disabled="_isExporting" StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)" Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isExporting)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" OnClick="LoadData" Size="Size.Small" StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)" Disabled="_isRefreshing" Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isRefreshing)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
@if (_selectedExpense != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedExpense = null" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">Add New Expense</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Striped="true" Class="mud-table-styled" Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetExpenseListResponse" OnRowClick="@((args) => _selectedExpense = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Number</MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Expense Title</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Campaign</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Amount</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">Status</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
|
||||
<MudCheckBox T="bool" Value="@(_selectedExpense?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.AutoNumber</MudTd>
|
||||
<MudTd Style="font-weight: 600; color: #374151;">@context.Title</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.CampaignTitle</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.Amount?.ToString("N0")</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;"><MudChip T="string" Size="Size.Small" Color="Color.Info" Variant="Variant.Text" Style="border-radius:0px; font-weight:700;">@context.Status</MudChip></MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
|
||||
<div style="display: flex; align-items: center; gap: 12px;">
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
|
||||
<MudSelect T="int" Value="@_top" ValueChanged="OnPageSizeChanged" Dense="true" Margin="Margin.Dense" Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;" Variant="Variant.Outlined" Class="mt-0 custom-select-dense" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
<MudSelectItem Value="5" /><MudSelectItem Value="10" /><MudSelectItem Value="50" /><MudSelectItem Value="500" /><MudSelectItem Value="1000" />
|
||||
</MudSelect>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF; font-size: 0.75rem; font-weight: 500; margin-left: 12px;">
|
||||
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
|
||||
</MudText>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "background-color: #f1f5f9; color: #cbd5e1;" : "background-color: white; border: 1px solid #E5E7EB; color: #3B82F6;")" Class="rounded-0" />
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="text-transform: none; font-weight: 700;">Prev</MudButton>
|
||||
@{
|
||||
var totalPages = _totalPage == 0 ? 1 : _totalPage;
|
||||
var maxVisible = 5;
|
||||
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
|
||||
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
|
||||
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
|
||||
}
|
||||
@for (int i = startPage; i <= endPage; i++)
|
||||
{
|
||||
var pageNum = i;
|
||||
var isActive = pageNum == _currentPage;
|
||||
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
|
||||
Variant="Variant.Text" Size="Size.Small"
|
||||
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
|
||||
}
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="text-transform: none; font-weight: 700;">Next</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "background-color: #f1f5f9; color: #cbd5e1;" : "background-color: white; border: 1px solid #E5E7EB; color: #3B82F6;")" Class="rounded-0" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateExpenseRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateExpenseRequest> OnView { get; set; }
|
||||
|
||||
private List<GetExpenseListResponse> _expenses = new();
|
||||
private GetExpenseListResponse? _selectedExpense;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
|
||||
private int _skip = 0;
|
||||
private int _top = 5;
|
||||
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
|
||||
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedExpense = null;
|
||||
StateHasChanged();
|
||||
var response = await ExpenseService.GetExpenseListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_expenses = response.Value ?? new List<GetExpenseListResponse>();
|
||||
}
|
||||
_isRefreshing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private IEnumerable<GetExpenseListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _expenses;
|
||||
return _expenses.Where(x =>
|
||||
(x.Title?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.CampaignTitle?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetExpenseListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private void OnSearchClick() { _skip = 0; _selectedExpense = null; StateHasChanged(); }
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") OnSearchClick(); }
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
using var workbook = new XLWorkbook();
|
||||
var worksheet = workbook.Worksheets.Add("Expenses");
|
||||
var currentRow = 1;
|
||||
worksheet.Cell(currentRow, 1).Value = "Number";
|
||||
worksheet.Cell(currentRow, 2).Value = "Title";
|
||||
worksheet.Cell(currentRow, 3).Value = "Campaign";
|
||||
worksheet.Cell(currentRow, 4).Value = "Amount";
|
||||
|
||||
foreach (var item in GetFilteredData())
|
||||
{
|
||||
currentRow++;
|
||||
worksheet.Cell(currentRow, 1).Value = item.AutoNumber;
|
||||
worksheet.Cell(currentRow, 2).Value = item.Title;
|
||||
worksheet.Cell(currentRow, 3).Value = item.CampaignTitle;
|
||||
worksheet.Cell(currentRow, 4).Value = item.Amount;
|
||||
}
|
||||
worksheet.Columns().AdjustToContents();
|
||||
using var stream = new MemoryStream();
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "Expense_List.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
|
||||
_isExporting = false;
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page) { if (page >= 1 && page <= _totalPage) { _skip = (page - 1) * _top; _selectedExpense = null; } }
|
||||
private void OnPageSizeChanged(int size) { _top = size; _skip = 0; _selectedExpense = null; }
|
||||
|
||||
private async Task InvokeEdit() { if (_selectedExpense != null) { var req = await MapToRequest(_selectedExpense.Id!); if (req != null) await OnEdit.InvokeAsync(req); } }
|
||||
private async Task InvokeView() { if (_selectedExpense != null) { var req = await MapToRequest(_selectedExpense.Id!); if (req != null) await OnView.InvokeAsync(req); } }
|
||||
|
||||
private async Task<UpdateExpenseRequest?> MapToRequest(string id)
|
||||
{
|
||||
var res = await ExpenseService.GetExpenseByIdAsync(id);
|
||||
if (res != null && res.IsSuccess && res.Value != null)
|
||||
{
|
||||
var d = res.Value;
|
||||
return new UpdateExpenseRequest { Id = d.Id, Title = d.Title, Amount = d.Amount, ExpenseDate = d.ExpenseDate, Status = d.Status, CampaignId = d.CampaignId, Description = d.Description, CreatedAt = d.CreatedAt, CreatedBy = d.CreatedBy, UpdatedAt = d.UpdatedAt, UpdatedBy = d.UpdatedBy };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedExpense == null) return;
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedExpense.Title } };
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true });
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
if (await ExpenseService.DeleteExpenseByIdAsync(_selectedExpense.Id!)) { await LoadData(); Snackbar.Add("Deleted", Severity.Success); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.Expense
|
||||
@using Indotalent.Features.Pipeline.Expense.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject ExpenseService ExpenseService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center gap-4" Style="border: 1px solid #DCEBFA;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Expense Details" : "Edit Expense")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing actual expenditure." : "Modify existing expense record.")</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Title</MudText>
|
||||
<MudTextField @bind-Value="_model.Title"
|
||||
For="@(() => _model.Title)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Campaign</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.CampaignId"
|
||||
For="@(() => _model.CampaignId)"
|
||||
Validation="@(_validator.ValidateValue())"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
|
||||
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Campaigns)
|
||||
{
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Status</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.ExpenseStatus" @bind-Value="_model.Status"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true"
|
||||
AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Statuses)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ExpenseStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Amount</MudText>
|
||||
<MudNumericField @bind-Value="_model.Amount"
|
||||
T="decimal?"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true"
|
||||
HideSpinButtons="false" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Expense Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.ExpenseDate"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
|
||||
</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 UpdateExpenseRequest 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 UpdateExpenseValidator _validator = new();
|
||||
private UpdateExpenseRequest _model = new();
|
||||
private ExpenseLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await ExpenseService.GetExpenseLookupAsync();
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
_lookup = res.Value ?? new();
|
||||
}
|
||||
|
||||
_model = new UpdateExpenseRequest
|
||||
{
|
||||
Id = Data.Id,
|
||||
Title = Data.Title,
|
||||
Description = Data.Description,
|
||||
Amount = Data.Amount,
|
||||
ExpenseDate = Data.ExpenseDate,
|
||||
Status = Data.Status,
|
||||
CampaignId = Data.CampaignId,
|
||||
CreatedAt = Data.CreatedAt,
|
||||
CreatedBy = Data.CreatedBy,
|
||||
UpdatedAt = Data.UpdatedAt,
|
||||
UpdatedBy = Data.UpdatedBy
|
||||
};
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (ReadOnly) return;
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var res = await ExpenseService.UpdateExpenseAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Expense updated successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Error: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.Data.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
|
||||
public class CreateExpenseRequest
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? ExpenseDate { get; set; } = DateTime.Today;
|
||||
public ExpenseStatus Status { get; set; } = ExpenseStatus.Draft;
|
||||
public decimal? Amount { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateExpenseResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Code { get; set; }
|
||||
}
|
||||
|
||||
public record CreateExpenseCommand(CreateExpenseRequest Data) : IRequest<CreateExpenseResponse>;
|
||||
|
||||
public class CreateExpenseHandler : IRequestHandler<CreateExpenseCommand, CreateExpenseResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateExpenseHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateExpenseResponse> Handle(CreateExpenseCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.Expense);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.Expense
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
Title = request.Data.Title,
|
||||
Description = request.Data.Description,
|
||||
ExpenseDate = request.Data.ExpenseDate,
|
||||
Status = request.Data.Status,
|
||||
Amount = request.Data.Amount,
|
||||
CampaignId = request.Data.CampaignId
|
||||
};
|
||||
|
||||
_context.Expense.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateExpenseResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Code = entity.AutoNumber
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
|
||||
public class CreateExpenseValidator : AbstractValidator<CreateExpenseRequest>
|
||||
{
|
||||
public CreateExpenseValidator()
|
||||
{
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty().WithMessage("Expense Title is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.CampaignId)
|
||||
.NotEmpty().WithMessage("Campaign is required");
|
||||
|
||||
RuleFor(x => x.Amount)
|
||||
.NotNull().WithMessage("Amount is required");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue() => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CreateExpenseRequest>.CreateWithOptions((CreateExpenseRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid) return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
|
||||
public record DeleteExpenseByIdRequest(string Id);
|
||||
|
||||
public record DeleteExpenseByIdCommand(DeleteExpenseByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteExpenseByIdHandler : IRequestHandler<DeleteExpenseByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteExpenseByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteExpenseByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Expense
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Expense.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
|
||||
public class GetExpenseByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? ExpenseDate { get; set; }
|
||||
public Data.Enums.ExpenseStatus Status { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetExpenseByIdQuery(string Id) : IRequest<GetExpenseByIdResponse?>;
|
||||
|
||||
public class GetExpenseByIdHandler : IRequestHandler<GetExpenseByIdQuery, GetExpenseByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetExpenseByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetExpenseByIdResponse?> Handle(GetExpenseByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Expense
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetExpenseByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
Description = x.Description,
|
||||
ExpenseDate = x.ExpenseDate,
|
||||
Status = x.Status,
|
||||
Amount = x.Amount,
|
||||
CampaignId = x.CampaignId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
|
||||
public class GetExpenseListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? CampaignTitle { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public DateTime? ExpenseDate { get; set; }
|
||||
public Data.Enums.ExpenseStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public record GetExpenseListQuery() : IRequest<List<GetExpenseListResponse>>;
|
||||
|
||||
public class GetExpenseListHandler : IRequestHandler<GetExpenseListQuery, List<GetExpenseListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetExpenseListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetExpenseListResponse>> Handle(GetExpenseListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Expense
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Campaign)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetExpenseListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
CampaignTitle = x.Campaign != null ? x.Campaign.Title : string.Empty,
|
||||
Amount = x.Amount,
|
||||
ExpenseDate = x.ExpenseDate,
|
||||
Status = x.Status
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
|
||||
public class ExpenseLookupResponse
|
||||
{
|
||||
public List<LookupItem> Campaigns { get; set; } = new();
|
||||
public List<LookupItem> Statuses { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public record GetExpenseLookupQuery() : IRequest<ExpenseLookupResponse>;
|
||||
|
||||
public class GetExpenseLookupHandler : IRequestHandler<GetExpenseLookupQuery, ExpenseLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetExpenseLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<ExpenseLookupResponse> Handle(GetExpenseLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new ExpenseLookupResponse();
|
||||
|
||||
response.Campaigns = await _context.Campaign
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Title)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Title })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Statuses = Enum.GetValues(typeof(ExpenseStatus))
|
||||
.Cast<ExpenseStatus>()
|
||||
.Select(x => new LookupItem
|
||||
{
|
||||
Value = (int)x,
|
||||
Name = x.ToString()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
|
||||
public class UpdateExpenseRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? ExpenseDate { get; set; }
|
||||
public ExpenseStatus Status { get; set; }
|
||||
public decimal? Amount { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateExpenseResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateExpenseCommand(UpdateExpenseRequest Data) : IRequest<UpdateExpenseResponse>;
|
||||
|
||||
public class UpdateExpenseHandler : IRequestHandler<UpdateExpenseCommand, UpdateExpenseResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateExpenseHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateExpenseResponse> Handle(UpdateExpenseCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Expense
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateExpenseResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Title = request.Data.Title;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.ExpenseDate = request.Data.ExpenseDate;
|
||||
entity.Status = request.Data.Status;
|
||||
entity.Amount = request.Data.Amount;
|
||||
entity.CampaignId = request.Data.CampaignId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateExpenseResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
|
||||
public class UpdateExpenseValidator : AbstractValidator<UpdateExpenseRequest>
|
||||
{
|
||||
public UpdateExpenseValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required for update");
|
||||
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty().WithMessage("Expense Title is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.CampaignId)
|
||||
.NotEmpty().WithMessage("Campaign is required");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue() => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<UpdateExpenseRequest>.CreateWithOptions((UpdateExpenseRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid) return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense;
|
||||
|
||||
public static class ExpenseEndpoint
|
||||
{
|
||||
public static void MapExpenseEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/expense").WithTags("Expenses")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetExpenseListQuery());
|
||||
return result.ToApiResponse("Expenses retrieved successfully");
|
||||
})
|
||||
.WithName("GetExpenseList");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetExpenseByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Expense detail retrieved successfully"
|
||||
: $"Expense with ID {id} not found");
|
||||
})
|
||||
.WithName("GetExpenseById");
|
||||
|
||||
group.MapPost("/", async (CreateExpenseRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateExpenseCommand(request));
|
||||
return result.ToApiResponse("Expense has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateExpense");
|
||||
|
||||
group.MapPost("/update", async (UpdateExpenseRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateExpenseCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed.");
|
||||
}
|
||||
return result.ToApiResponse("Expense has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateExpense");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteExpenseByIdCommand(new DeleteExpenseByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed.");
|
||||
}
|
||||
return true.ToApiResponse("Expense has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteExpenseById");
|
||||
|
||||
group.MapGet("/lookup", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetExpenseLookupQuery());
|
||||
return result.ToApiResponse("Expense lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetExpenseLookup");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Pipeline.Expense.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Expense;
|
||||
|
||||
public class ExpenseService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public ExpenseService(
|
||||
IHttpClientFactory clientFactory,
|
||||
NavigationManager nav,
|
||||
ISnackbar snackbar,
|
||||
ICurrentUserService currentUserService,
|
||||
TokenProvider tokenProvider)
|
||||
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
|
||||
{
|
||||
_client = new RestClient(nav.BaseUri);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<List<GetExpenseListResponse>>?> GetExpenseListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/expense", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetExpenseListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetExpenseByIdResponse>?> GetExpenseByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/expense/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetExpenseByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateExpenseResponse>?> CreateExpenseAsync(CreateExpenseRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/expense", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateExpenseResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteExpenseByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/expense/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateExpenseResponse>?> UpdateExpenseAsync(UpdateExpenseRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/expense/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateExpenseResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<ExpenseLookupResponse>?> GetExpenseLookupAsync()
|
||||
{
|
||||
var request = new RestRequest("api/expense/lookup", Method.Get);
|
||||
return await ExecuteWithResponseAsync<ExpenseLookupResponse>(_client, request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
@page "/pipeline/lead"
|
||||
@using Indotalent.Features.Pipeline.Lead
|
||||
@using Indotalent.Features.Pipeline.Lead.Cqrs
|
||||
@using Indotalent.Features.Pipeline.Lead.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_LeadCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_LeadUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_LeadDataTable OnAdd="ShowCreate" OnEdit="(item) => ShowUpdate(item, false)" OnView="(item) => ShowUpdate(item, true)" />
|
||||
}
|
||||
|
||||
@code {
|
||||
private enum ViewMode { Table, Create, Update, View }
|
||||
private ViewMode _currentView = ViewMode.Table;
|
||||
private UpdateLeadRequest? _selectedData;
|
||||
|
||||
private void ShowCreate() => _currentView = ViewMode.Create;
|
||||
private void ShowUpdate(UpdateLeadRequest data, bool isReadOnly) { _selectedData = data; _currentView = isReadOnly ? ViewMode.View : ViewMode.Update; }
|
||||
private void BackToTable() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
private void HandleSuccess() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
@using Indotalent.Features.Pipeline.Lead
|
||||
@using Indotalent.Features.Pipeline.Lead.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject LeadService LeadService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center gap-4" Style="border: 1px solid #DCEBFA;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add New Lead</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Enter full lead profile and company details.</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Basic Information</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12"><MudText Typo="Typo.subtitle2" Class="mb-1">Lead Title</MudText><MudTextField @bind-Value="_model.Title" For="@(() => _model.Title)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12"><MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText><MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Campaign</MudText><MudSelect T="string" @bind-Value="_model.CampaignId" For="@(() => _model.CampaignId)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">@foreach (var item in _lookup.Campaigns) {
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Sales Team</MudText><MudSelect T="string" @bind-Value="_model.SalesTeamId" For="@(() => _model.SalesTeamId)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">@foreach (var item in _lookup.SalesTeams) {
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect></MudItem>
|
||||
|
||||
<MudItem xs="12" Class="mt-4"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Company Details</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Company Name</MudText><MudTextField @bind-Value="_model.CompanyName" For="@(() => _model.CompanyName)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Company Description</MudText><MudTextField @bind-Value="_model.CompanyDescription" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12"><MudText Typo="Typo.subtitle2" Class="mb-1">Street Address</MudText><MudTextField @bind-Value="_model.CompanyAddressStreet" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">City</MudText><MudTextField @bind-Value="_model.CompanyAddressCity" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">State</MudText><MudTextField @bind-Value="_model.CompanyAddressState" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Zip Code</MudText><MudTextField @bind-Value="_model.CompanyAddressZipCode" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Country</MudText><MudTextField @bind-Value="_model.CompanyAddressCountry" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Phone</MudText><MudTextField @bind-Value="_model.CompanyPhoneNumber" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Fax</MudText><MudTextField @bind-Value="_model.CompanyFaxNumber" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Email</MudText><MudTextField @bind-Value="_model.CompanyEmail" 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;">Digital Presence</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Website</MudText><MudTextField @bind-Value="_model.CompanyWebsite" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">WhatsApp</MudText><MudTextField @bind-Value="_model.CompanyWhatsApp" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">LinkedIn</MudText><MudTextField @bind-Value="_model.CompanyLinkedIn" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Facebook</MudText><MudTextField @bind-Value="_model.CompanyFacebook" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Instagram</MudText><MudTextField @bind-Value="_model.CompanyInstagram" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Twitter</MudText><MudTextField @bind-Value="_model.CompanyTwitter" 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;">Dates & Targeted Amount</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Prospecting Date</MudText><MudDatePicker @bind-Date="_model.DateProspecting" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Closing Estimation</MudText><MudDatePicker @bind-Date="_model.DateClosingEstimation" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Closing Actual</MudText><MudDatePicker @bind-Date="_model.DateClosingActual" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Amount Targeted</MudText><MudNumericField @bind-Value="_model.AmountTargeted" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Amount Closed</MudText><MudNumericField @bind-Value="_model.AmountClosed" 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;">BANT Scoring</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Budget Score</MudText><MudNumericField @bind-Value="_model.BudgetScore" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Authority Score</MudText><MudNumericField @bind-Value="_model.AuthorityScore" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Need Score</MudText><MudNumericField @bind-Value="_model.NeedScore" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Timeline Score</MudText><MudNumericField @bind-Value="_model.TimelineScore" 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;">Pipeline & Closing</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Pipeline Stage</MudText><MudSelect T="Indotalent.Data.Enums.PipelineStage" @bind-Value="_model.PipelineStage" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">@foreach (var item in _lookup.PipelineStages) {
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.PipelineStage)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Closing Status</MudText><MudSelect T="Indotalent.Data.Enums.ClosingStatus" @bind-Value="_model.ClosingStatus" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">@foreach (var item in _lookup.ClosingStatuses) {
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ClosingStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect></MudItem>
|
||||
<MudItem xs="12"><MudText Typo="Typo.subtitle2" Class="mb-1">Closing Note</MudText><MudTextField @bind-Value="_model.ClosingNote" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" /></MudItem>
|
||||
</MudGrid>
|
||||
<div class="d-flex justify-end gap-2 mt-8">
|
||||
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Style="border-radius: 4px; border: 1px solid #e0e0e0; text-transform: none; font-weight: 700;">Cancel</MudButton>
|
||||
<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;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<MudText>Create Lead</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
private MudForm _form = default!;
|
||||
private CreateLeadValidator _validator = new();
|
||||
private CreateLeadRequest _model = new();
|
||||
private LeadLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await LeadService.GetLeadLookupAsync();
|
||||
if (res != null && res.IsSuccess) _lookup = res.Value ?? new();
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var res = await LeadService.CreateLeadAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (res != null && res.IsSuccess) { Snackbar.Add("Created successfully", Severity.Success); await OnSuccess.InvokeAsync(); }
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.Lead
|
||||
@using Indotalent.Features.Pipeline.Lead.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject LeadService LeadService
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Lead Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Manage business opportunities and sales pipeline.</MudText>
|
||||
</div>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Pipeline</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Lead</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
|
||||
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<MudTextField @bind-Value="_searchString" Placeholder="Search..." Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Small" Class="mt-0" Variant="Variant.Outlined" Margin="Margin.Dense" Style="background-color: white; width: 280px; border-radius: 8px;" OnKeyDown="@HandleSearchKeyDown" />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OnSearchClick" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none;">Search</MudButton>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Success" OnClick="ExportToExcel" Size="Size.Small" Disabled="_isExporting" StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)" Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isExporting)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" OnClick="LoadData" Size="Size.Small" StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)" Disabled="_isRefreshing" Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isRefreshing)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
@if (_selectedLead != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedLead = null" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">Add New Lead</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Striped="true" Class="mud-table-styled" Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetLeadListResponse" OnRowClick="@((args) => _selectedLead = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadListResponse, object>(x => x.AutoNumber!)" Style="font-weight: 700; color: #111827;">Number</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadListResponse, object>(x => x.Title!)" Style="font-weight: 700; color: #111827;">Title</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadListResponse, object>(x => x.CompanyName!)" Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em;">Company</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadListResponse, object>(x => x.PipelineStage)" Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em;">Stage</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadListResponse, object>(x => x.ClosingStatus)" Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em;">Closing Status</MudTableSortLabel>
|
||||
</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd><MudCheckBox T="bool" Value="@(_selectedLead?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" /></MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.AutoNumber</MudTd>
|
||||
<MudTd Style="font-weight: 600; color: #374151;">@context.Title</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.CompanyName</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;"><MudChip T="string" Size="Size.Small" Color="Color.Primary" Variant="Variant.Text" Style="border-radius:0px; font-weight:700;">@context.PipelineStage</MudChip></MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;"><MudChip T="string" Size="Size.Small" Color="Color.Info" Variant="Variant.Text" Style="border-radius:0px; font-weight:700;">@context.ClosingStatus</MudChip></MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
|
||||
<div style="display: flex; align-items: center; gap: 12px;">
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
|
||||
<MudSelect T="int" Value="@_top" ValueChanged="OnPageSizeChanged" Dense="true" Margin="Margin.Dense" Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;" Variant="Variant.Outlined" Class="mt-0 custom-select-dense" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
<MudSelectItem Value="5" />
|
||||
<MudSelectItem Value="10" />
|
||||
<MudSelectItem Value="50" />
|
||||
<MudSelectItem Value="500" />
|
||||
<MudSelectItem Value="1000" />
|
||||
</MudSelect>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF; font-size: 0.75rem; font-weight: 500; margin-left: 12px;">
|
||||
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
|
||||
</MudText>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "background-color: #f1f5f9; color: #cbd5e1;" : "background-color: white; border: 1px solid #E5E7EB; color: #3B82F6;")" Class="rounded-0" />
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="text-transform: none; font-weight: 700;">Prev</MudButton>
|
||||
@{
|
||||
var totalPages = _totalPage == 0 ? 1 : _totalPage;
|
||||
var maxVisible = 5;
|
||||
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
|
||||
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
|
||||
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
|
||||
}
|
||||
@for (int i = startPage; i <= endPage; i++)
|
||||
{
|
||||
var pageNum = i;
|
||||
var isActive = pageNum == _currentPage;
|
||||
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
|
||||
Variant="Variant.Text" Size="Size.Small"
|
||||
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
|
||||
}
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="text-transform: none; font-weight: 700;">Next</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "background-color: #f1f5f9; color: #cbd5e1;" : "background-color: white; border: 1px solid #E5E7EB; color: #3B82F6;")" Class="rounded-0" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateLeadRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateLeadRequest> OnView { get; set; }
|
||||
|
||||
private List<GetLeadListResponse> _leads = new();
|
||||
private GetLeadListResponse? _selectedLead;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
|
||||
private int _skip = 0;
|
||||
private int _top = 5;
|
||||
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
|
||||
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedLead = null;
|
||||
StateHasChanged();
|
||||
var response = await LeadService.GetLeadListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_leads = response.Value ?? new List<GetLeadListResponse>();
|
||||
}
|
||||
_isRefreshing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private IEnumerable<GetLeadListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _leads;
|
||||
return _leads.Where(x =>
|
||||
(x.Title?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.CompanyName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetLeadListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private void OnSearchClick() { _skip = 0; _selectedLead = null; StateHasChanged(); }
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") OnSearchClick(); }
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
using var workbook = new XLWorkbook();
|
||||
var worksheet = workbook.Worksheets.Add("Leads");
|
||||
var currentRow = 1;
|
||||
worksheet.Cell(currentRow, 1).Value = "Number";
|
||||
worksheet.Cell(currentRow, 2).Value = "Title";
|
||||
worksheet.Cell(currentRow, 3).Value = "Company";
|
||||
worksheet.Cell(currentRow, 4).Value = "Stage";
|
||||
|
||||
foreach (var item in GetFilteredData())
|
||||
{
|
||||
currentRow++;
|
||||
worksheet.Cell(currentRow, 1).Value = item.AutoNumber;
|
||||
worksheet.Cell(currentRow, 2).Value = item.Title;
|
||||
worksheet.Cell(currentRow, 3).Value = item.CompanyName;
|
||||
worksheet.Cell(currentRow, 4).Value = item.PipelineStage.ToString();
|
||||
}
|
||||
worksheet.Columns().AdjustToContents();
|
||||
using var stream = new MemoryStream();
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "Lead_List.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
|
||||
_isExporting = false;
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page) { if (page >= 1 && page <= _totalPage) { _skip = (page - 1) * _top; _selectedLead = null; } }
|
||||
private void OnPageSizeChanged(int size) { _top = size; _skip = 0; _selectedLead = null; }
|
||||
|
||||
private async Task InvokeEdit() { if (_selectedLead != null) { var req = await MapToRequest(_selectedLead.Id!); if (req != null) await OnEdit.InvokeAsync(req); } }
|
||||
private async Task InvokeView() { if (_selectedLead != null) { var req = await MapToRequest(_selectedLead.Id!); if (req != null) await OnView.InvokeAsync(req); } }
|
||||
|
||||
private async Task<UpdateLeadRequest?> MapToRequest(string id)
|
||||
{
|
||||
var res = await LeadService.GetLeadByIdAsync(id);
|
||||
if (res != null && res.IsSuccess && res.Value != null)
|
||||
{
|
||||
var d = res.Value;
|
||||
return new UpdateLeadRequest { Id = d.Id, Title = d.Title, Description = d.Description, CompanyName = d.CompanyName, CompanyDescription = d.CompanyDescription, CompanyAddressStreet = d.CompanyAddressStreet, CompanyAddressCity = d.CompanyAddressCity, CompanyAddressState = d.CompanyAddressState, CompanyAddressZipCode = d.CompanyAddressZipCode, CompanyAddressCountry = d.CompanyAddressCountry, CompanyPhoneNumber = d.CompanyPhoneNumber, CompanyFaxNumber = d.CompanyFaxNumber, CompanyEmail = d.CompanyEmail, CompanyWebsite = d.CompanyWebsite, CompanyWhatsApp = d.CompanyWhatsApp, CompanyLinkedIn = d.CompanyLinkedIn, CompanyFacebook = d.CompanyFacebook, CompanyInstagram = d.CompanyInstagram, CompanyTwitter = d.CompanyTwitter, DateProspecting = d.DateProspecting, DateClosingEstimation = d.DateClosingEstimation, DateClosingActual = d.DateClosingActual, AmountTargeted = d.AmountTargeted, AmountClosed = d.AmountClosed, BudgetScore = d.BudgetScore, AuthorityScore = d.AuthorityScore, NeedScore = d.NeedScore, TimelineScore = d.TimelineScore, PipelineStage = d.PipelineStage, ClosingStatus = d.ClosingStatus, ClosingNote = d.ClosingNote, CampaignId = d.CampaignId, SalesTeamId = d.SalesTeamId, CreatedAt = d.CreatedAt, CreatedBy = d.CreatedBy, UpdatedAt = d.UpdatedAt, UpdatedBy = d.UpdatedBy };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedLead == null) return;
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedLead.Title } };
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true });
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
if (await LeadService.DeleteLeadByIdAsync(_selectedLead.Id!)) { await LoadData(); Snackbar.Add("Deleted", Severity.Success); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.Lead
|
||||
@using Indotalent.Features.Pipeline.Lead.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject LeadService LeadService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center gap-4" Style="border: 1px solid #DCEBFA;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Lead Details" : "Edit Lead")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing sales lead information." : "Modify existing lead profile.")</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Basic Information</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12"><MudText Typo="Typo.subtitle2" Class="mb-1">Lead Title</MudText><MudTextField @bind-Value="_model.Title" For="@(() => _model.Title)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12"><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" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Campaign</MudText><MudSelect T="string" @bind-Value="_model.CampaignId" For="@(() => _model.CampaignId)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">@foreach (var item in _lookup.Campaigns) {
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Sales Team</MudText><MudSelect T="string" @bind-Value="_model.SalesTeamId" For="@(() => _model.SalesTeamId)" Validation="@(_validator.ValidateValue())" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">@foreach (var item in _lookup.SalesTeams) {
|
||||
<MudSelectItem Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect></MudItem>
|
||||
|
||||
<MudItem xs="12" Class="mt-4"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Company Information</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Company Name</MudText><MudTextField @bind-Value="_model.CompanyName" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Company Description</MudText><MudTextField @bind-Value="_model.CompanyDescription" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12"><MudText Typo="Typo.subtitle2" Class="mb-1">Street Address</MudText><MudTextField @bind-Value="_model.CompanyAddressStreet" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">City</MudText><MudTextField @bind-Value="_model.CompanyAddressCity" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">State</MudText><MudTextField @bind-Value="_model.CompanyAddressState" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Zip Code</MudText><MudTextField @bind-Value="_model.CompanyAddressZipCode" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Country</MudText><MudTextField @bind-Value="_model.CompanyAddressCountry" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Phone</MudText><MudTextField @bind-Value="_model.CompanyPhoneNumber" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Fax</MudText><MudTextField @bind-Value="_model.CompanyFaxNumber" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Email</MudText><MudTextField @bind-Value="_model.CompanyEmail" 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;">Digital Presence</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Website</MudText><MudTextField @bind-Value="_model.CompanyWebsite" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">WhatsApp</MudText><MudTextField @bind-Value="_model.CompanyWhatsApp" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">LinkedIn</MudText><MudTextField @bind-Value="_model.CompanyLinkedIn" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Facebook</MudText><MudTextField @bind-Value="_model.CompanyFacebook" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Instagram</MudText><MudTextField @bind-Value="_model.CompanyInstagram" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Twitter</MudText><MudTextField @bind-Value="_model.CompanyTwitter" 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;">Dates & Targeted Amount</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Prospecting Date</MudText><MudDatePicker @bind-Date="_model.DateProspecting" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Closing Estimation</MudText><MudDatePicker @bind-Date="_model.DateClosingEstimation" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Closing Actual</MudText><MudDatePicker @bind-Date="_model.DateClosingActual" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Amount Targeted</MudText><MudNumericField @bind-Value="_model.AmountTargeted" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Amount Closed</MudText><MudNumericField @bind-Value="_model.AmountClosed" 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;">BANT Scoring</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Budget Score</MudText><MudNumericField @bind-Value="_model.BudgetScore" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Authority Score</MudText><MudNumericField @bind-Value="_model.AuthorityScore" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Need Score</MudText><MudNumericField @bind-Value="_model.NeedScore" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Timeline Score</MudText><MudNumericField @bind-Value="_model.TimelineScore" 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;">Pipeline & Closing</MudText><MudDivider /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Pipeline Stage</MudText><MudSelect T="Indotalent.Data.Enums.PipelineStage" @bind-Value="_model.PipelineStage" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">@foreach (var item in _lookup.PipelineStages) {
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.PipelineStage)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Closing Status</MudText><MudSelect T="Indotalent.Data.Enums.ClosingStatus" @bind-Value="_model.ClosingStatus" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">@foreach (var item in _lookup.ClosingStatuses) {
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.ClosingStatus)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect></MudItem>
|
||||
<MudItem xs="12"><MudText Typo="Typo.subtitle2" Class="mb-1">Closing Note</MudText><MudTextField @bind-Value="_model.ClosingNote" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" /></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="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="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="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="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" 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 UpdateLeadRequest 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 UpdateLeadValidator _validator = new();
|
||||
private UpdateLeadRequest _model = new();
|
||||
private LeadLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await LeadService.GetLeadLookupAsync();
|
||||
if (res != null && res.IsSuccess) _lookup = res.Value ?? new();
|
||||
|
||||
_model = new UpdateLeadRequest
|
||||
{
|
||||
Id = Data.Id,
|
||||
Title = Data.Title,
|
||||
Description = Data.Description,
|
||||
CompanyName = Data.CompanyName,
|
||||
CompanyDescription = Data.CompanyDescription,
|
||||
CompanyAddressStreet = Data.CompanyAddressStreet,
|
||||
CompanyAddressCity = Data.CompanyAddressCity,
|
||||
CompanyAddressState = Data.CompanyAddressState,
|
||||
CompanyAddressZipCode = Data.CompanyAddressZipCode,
|
||||
CompanyAddressCountry = Data.CompanyAddressCountry,
|
||||
CompanyPhoneNumber = Data.CompanyPhoneNumber,
|
||||
CompanyFaxNumber = Data.CompanyFaxNumber,
|
||||
CompanyEmail = Data.CompanyEmail,
|
||||
CompanyWebsite = Data.CompanyWebsite,
|
||||
CompanyWhatsApp = Data.CompanyWhatsApp,
|
||||
CompanyLinkedIn = Data.CompanyLinkedIn,
|
||||
CompanyFacebook = Data.CompanyFacebook,
|
||||
CompanyInstagram = Data.CompanyInstagram,
|
||||
CompanyTwitter = Data.CompanyTwitter,
|
||||
DateProspecting = Data.DateProspecting,
|
||||
DateClosingEstimation = Data.DateClosingEstimation,
|
||||
DateClosingActual = Data.DateClosingActual,
|
||||
AmountTargeted = Data.AmountTargeted,
|
||||
AmountClosed = Data.AmountClosed,
|
||||
BudgetScore = Data.BudgetScore,
|
||||
AuthorityScore = Data.AuthorityScore,
|
||||
NeedScore = Data.NeedScore,
|
||||
TimelineScore = Data.TimelineScore,
|
||||
PipelineStage = Data.PipelineStage,
|
||||
ClosingStatus = Data.ClosingStatus,
|
||||
ClosingNote = Data.ClosingNote,
|
||||
CampaignId = Data.CampaignId,
|
||||
SalesTeamId = Data.SalesTeamId,
|
||||
CreatedAt = Data.CreatedAt,
|
||||
CreatedBy = Data.CreatedBy,
|
||||
UpdatedAt = Data.UpdatedAt,
|
||||
UpdatedBy = Data.UpdatedBy
|
||||
};
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var res = await LeadService.UpdateLeadAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (res != null && res.IsSuccess) { Snackbar.Add("Updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); }
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.Data.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class CreateLeadRequest
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CompanyName { get; set; }
|
||||
public string? CompanyDescription { get; set; }
|
||||
public string? CompanyAddressStreet { get; set; }
|
||||
public string? CompanyAddressCity { get; set; }
|
||||
public string? CompanyAddressState { get; set; }
|
||||
public string? CompanyAddressZipCode { get; set; }
|
||||
public string? CompanyAddressCountry { get; set; }
|
||||
public string? CompanyPhoneNumber { get; set; }
|
||||
public string? CompanyFaxNumber { get; set; }
|
||||
public string? CompanyEmail { get; set; }
|
||||
public string? CompanyWebsite { get; set; }
|
||||
public string? CompanyWhatsApp { get; set; }
|
||||
public string? CompanyLinkedIn { get; set; }
|
||||
public string? CompanyFacebook { get; set; }
|
||||
public string? CompanyInstagram { get; set; }
|
||||
public string? CompanyTwitter { get; set; }
|
||||
public DateTime? DateProspecting { get; set; } = DateTime.Today;
|
||||
public DateTime? DateClosingEstimation { get; set; }
|
||||
public DateTime? DateClosingActual { get; set; }
|
||||
public decimal? AmountTargeted { get; set; }
|
||||
public decimal? AmountClosed { get; set; }
|
||||
public decimal? BudgetScore { get; set; }
|
||||
public decimal? AuthorityScore { get; set; }
|
||||
public decimal? NeedScore { get; set; }
|
||||
public decimal? TimelineScore { get; set; }
|
||||
public PipelineStage PipelineStage { get; set; } = PipelineStage.Prospecting;
|
||||
public ClosingStatus ClosingStatus { get; set; } = ClosingStatus.ClosedWon;
|
||||
public string? ClosingNote { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public string? SalesTeamId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateLeadResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Code { get; set; }
|
||||
}
|
||||
|
||||
public record CreateLeadCommand(CreateLeadRequest Data) : IRequest<CreateLeadResponse>;
|
||||
|
||||
public class CreateLeadHandler : IRequestHandler<CreateLeadCommand, CreateLeadResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateLeadHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateLeadResponse> Handle(CreateLeadCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.Lead);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.Lead
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
Title = request.Data.Title,
|
||||
Description = request.Data.Description,
|
||||
CompanyName = request.Data.CompanyName,
|
||||
CompanyDescription = request.Data.CompanyDescription,
|
||||
CompanyAddressStreet = request.Data.CompanyAddressStreet,
|
||||
CompanyAddressCity = request.Data.CompanyAddressCity,
|
||||
CompanyAddressState = request.Data.CompanyAddressState,
|
||||
CompanyAddressZipCode = request.Data.CompanyAddressZipCode,
|
||||
CompanyAddressCountry = request.Data.CompanyAddressCountry,
|
||||
CompanyPhoneNumber = request.Data.CompanyPhoneNumber,
|
||||
CompanyFaxNumber = request.Data.CompanyFaxNumber,
|
||||
CompanyEmail = request.Data.CompanyEmail,
|
||||
CompanyWebsite = request.Data.CompanyWebsite,
|
||||
CompanyWhatsApp = request.Data.CompanyWhatsApp,
|
||||
CompanyLinkedIn = request.Data.CompanyLinkedIn,
|
||||
CompanyFacebook = request.Data.CompanyFacebook,
|
||||
CompanyInstagram = request.Data.CompanyInstagram,
|
||||
CompanyTwitter = request.Data.CompanyTwitter,
|
||||
DateProspecting = request.Data.DateProspecting,
|
||||
DateClosingEstimation = request.Data.DateClosingEstimation,
|
||||
DateClosingActual = request.Data.DateClosingActual,
|
||||
AmountTargeted = request.Data.AmountTargeted,
|
||||
AmountClosed = request.Data.AmountClosed,
|
||||
BudgetScore = request.Data.BudgetScore,
|
||||
AuthorityScore = request.Data.AuthorityScore,
|
||||
NeedScore = request.Data.NeedScore,
|
||||
TimelineScore = request.Data.TimelineScore,
|
||||
PipelineStage = request.Data.PipelineStage,
|
||||
ClosingStatus = request.Data.ClosingStatus,
|
||||
ClosingNote = request.Data.ClosingNote,
|
||||
CampaignId = request.Data.CampaignId,
|
||||
SalesTeamId = request.Data.SalesTeamId
|
||||
};
|
||||
|
||||
_context.Lead.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateLeadResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Code = entity.AutoNumber
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class CreateLeadValidator : AbstractValidator<CreateLeadRequest>
|
||||
{
|
||||
public CreateLeadValidator()
|
||||
{
|
||||
RuleFor(x => x.Title)
|
||||
.NotEmpty().WithMessage("Lead Title is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.CompanyName)
|
||||
.NotEmpty().WithMessage("Company Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.CompanyEmail)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.CompanyEmail));
|
||||
|
||||
RuleFor(x => x.CampaignId)
|
||||
.NotEmpty().WithMessage("Campaign is required");
|
||||
|
||||
RuleFor(x => x.SalesTeamId)
|
||||
.NotEmpty().WithMessage("Sales Team is required");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue() => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CreateLeadRequest>.CreateWithOptions((CreateLeadRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid) return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public record DeleteLeadByIdRequest(string Id);
|
||||
|
||||
public record DeleteLeadByIdCommand(DeleteLeadByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteLeadByIdHandler : IRequestHandler<DeleteLeadByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteLeadByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteLeadByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Lead.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.Lead.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class GetLeadByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CompanyName { get; set; }
|
||||
public string? CompanyDescription { get; set; }
|
||||
public string? CompanyAddressStreet { get; set; }
|
||||
public string? CompanyAddressCity { get; set; }
|
||||
public string? CompanyAddressState { get; set; }
|
||||
public string? CompanyAddressZipCode { get; set; }
|
||||
public string? CompanyAddressCountry { get; set; }
|
||||
public string? CompanyPhoneNumber { get; set; }
|
||||
public string? CompanyFaxNumber { get; set; }
|
||||
public string? CompanyEmail { get; set; }
|
||||
public string? CompanyWebsite { get; set; }
|
||||
public string? CompanyWhatsApp { get; set; }
|
||||
public string? CompanyLinkedIn { get; set; }
|
||||
public string? CompanyFacebook { get; set; }
|
||||
public string? CompanyInstagram { get; set; }
|
||||
public string? CompanyTwitter { get; set; }
|
||||
public DateTime? DateProspecting { get; set; }
|
||||
public DateTime? DateClosingEstimation { get; set; }
|
||||
public DateTime? DateClosingActual { get; set; }
|
||||
public decimal? AmountTargeted { get; set; }
|
||||
public decimal? AmountClosed { get; set; }
|
||||
public decimal? BudgetScore { get; set; }
|
||||
public decimal? AuthorityScore { get; set; }
|
||||
public decimal? NeedScore { get; set; }
|
||||
public decimal? TimelineScore { get; set; }
|
||||
public PipelineStage PipelineStage { get; set; }
|
||||
public ClosingStatus ClosingStatus { get; set; }
|
||||
public string? ClosingNote { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public string? SalesTeamId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadByIdQuery(string Id) : IRequest<GetLeadByIdResponse?>;
|
||||
|
||||
public class GetLeadByIdHandler : IRequestHandler<GetLeadByIdQuery, GetLeadByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetLeadByIdResponse?> Handle(GetLeadByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Lead
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetLeadByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
Description = x.Description,
|
||||
CompanyName = x.CompanyName,
|
||||
CompanyDescription = x.CompanyDescription,
|
||||
CompanyAddressStreet = x.CompanyAddressStreet,
|
||||
CompanyAddressCity = x.CompanyAddressCity,
|
||||
CompanyAddressState = x.CompanyAddressState,
|
||||
CompanyAddressZipCode = x.CompanyAddressZipCode,
|
||||
CompanyAddressCountry = x.CompanyAddressCountry,
|
||||
CompanyPhoneNumber = x.CompanyPhoneNumber,
|
||||
CompanyFaxNumber = x.CompanyFaxNumber,
|
||||
CompanyEmail = x.CompanyEmail,
|
||||
CompanyWebsite = x.CompanyWebsite,
|
||||
CompanyWhatsApp = x.CompanyWhatsApp,
|
||||
CompanyLinkedIn = x.CompanyLinkedIn,
|
||||
CompanyFacebook = x.CompanyFacebook,
|
||||
CompanyInstagram = x.CompanyInstagram,
|
||||
CompanyTwitter = x.CompanyTwitter,
|
||||
DateProspecting = x.DateProspecting,
|
||||
DateClosingEstimation = x.DateClosingEstimation,
|
||||
DateClosingActual = x.DateClosingActual,
|
||||
AmountTargeted = x.AmountTargeted,
|
||||
AmountClosed = x.AmountClosed,
|
||||
BudgetScore = x.BudgetScore,
|
||||
AuthorityScore = x.AuthorityScore,
|
||||
NeedScore = x.NeedScore,
|
||||
TimelineScore = x.TimelineScore,
|
||||
PipelineStage = x.PipelineStage,
|
||||
ClosingStatus = x.ClosingStatus,
|
||||
ClosingNote = x.ClosingNote,
|
||||
CampaignId = x.CampaignId,
|
||||
SalesTeamId = x.SalesTeamId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class GetLeadListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? CompanyName { get; set; }
|
||||
public string? CampaignTitle { get; set; }
|
||||
public string? SalesTeamName { get; set; }
|
||||
public PipelineStage PipelineStage { get; set; }
|
||||
public ClosingStatus ClosingStatus { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadListQuery() : IRequest<List<GetLeadListResponse>>;
|
||||
|
||||
public class GetLeadListHandler : IRequestHandler<GetLeadListQuery, List<GetLeadListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetLeadListResponse>> Handle(GetLeadListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Lead
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Campaign)
|
||||
.Include(x => x.SalesTeam)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetLeadListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
CompanyName = x.CompanyName,
|
||||
CampaignTitle = x.Campaign != null ? x.Campaign.Title : string.Empty,
|
||||
SalesTeamName = x.SalesTeam != null ? x.SalesTeam.Name : string.Empty,
|
||||
PipelineStage = x.PipelineStage,
|
||||
ClosingStatus = x.ClosingStatus
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class LeadLookupResponse
|
||||
{
|
||||
public List<LookupItem> Campaigns { get; set; } = new();
|
||||
public List<LookupItem> SalesTeams { get; set; } = new();
|
||||
public List<LookupItem> PipelineStages { get; set; } = new();
|
||||
public List<LookupItem> ClosingStatuses { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadLookupQuery() : IRequest<LeadLookupResponse>;
|
||||
|
||||
public class GetLeadLookupHandler : IRequestHandler<GetLeadLookupQuery, LeadLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LeadLookupResponse> Handle(GetLeadLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new LeadLookupResponse();
|
||||
|
||||
response.Campaigns = await _context.Campaign.AsNoTracking()
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Title }).ToListAsync(cancellationToken);
|
||||
|
||||
response.SalesTeams = await _context.SalesTeam.AsNoTracking()
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name }).ToListAsync(cancellationToken);
|
||||
|
||||
response.PipelineStages = Enum.GetValues(typeof(PipelineStage)).Cast<PipelineStage>()
|
||||
.Select(x => new LookupItem { Value = (int)x, Name = x.ToString() }).ToList();
|
||||
|
||||
response.ClosingStatuses = Enum.GetValues(typeof(ClosingStatus)).Cast<ClosingStatus>()
|
||||
.Select(x => new LookupItem { Value = (int)x, Name = x.ToString() }).ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class UpdateLeadRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? CompanyName { get; set; }
|
||||
public string? CompanyDescription { get; set; }
|
||||
public string? CompanyAddressStreet { get; set; }
|
||||
public string? CompanyAddressCity { get; set; }
|
||||
public string? CompanyAddressState { get; set; }
|
||||
public string? CompanyAddressZipCode { get; set; }
|
||||
public string? CompanyAddressCountry { get; set; }
|
||||
public string? CompanyPhoneNumber { get; set; }
|
||||
public string? CompanyFaxNumber { get; set; }
|
||||
public string? CompanyEmail { get; set; }
|
||||
public string? CompanyWebsite { get; set; }
|
||||
public string? CompanyWhatsApp { get; set; }
|
||||
public string? CompanyLinkedIn { get; set; }
|
||||
public string? CompanyFacebook { get; set; }
|
||||
public string? CompanyInstagram { get; set; }
|
||||
public string? CompanyTwitter { get; set; }
|
||||
public DateTime? DateProspecting { get; set; }
|
||||
public DateTime? DateClosingEstimation { get; set; }
|
||||
public DateTime? DateClosingActual { get; set; }
|
||||
public decimal? AmountTargeted { get; set; }
|
||||
public decimal? AmountClosed { get; set; }
|
||||
public decimal? BudgetScore { get; set; }
|
||||
public decimal? AuthorityScore { get; set; }
|
||||
public decimal? NeedScore { get; set; }
|
||||
public decimal? TimelineScore { get; set; }
|
||||
public PipelineStage PipelineStage { get; set; }
|
||||
public ClosingStatus ClosingStatus { get; set; }
|
||||
public string? ClosingNote { get; set; }
|
||||
public string? CampaignId { get; set; }
|
||||
public string? SalesTeamId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateLeadResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateLeadCommand(UpdateLeadRequest Data) : IRequest<UpdateLeadResponse>;
|
||||
|
||||
public class UpdateLeadHandler : IRequestHandler<UpdateLeadCommand, UpdateLeadResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateLeadHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateLeadResponse> Handle(UpdateLeadCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Lead
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return new UpdateLeadResponse { Id = request.Data.Id, Success = false };
|
||||
|
||||
entity.Title = request.Data.Title;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.CompanyName = request.Data.CompanyName;
|
||||
entity.CompanyDescription = request.Data.CompanyDescription;
|
||||
entity.CompanyAddressStreet = request.Data.CompanyAddressStreet;
|
||||
entity.CompanyAddressCity = request.Data.CompanyAddressCity;
|
||||
entity.CompanyAddressState = request.Data.CompanyAddressState;
|
||||
entity.CompanyAddressZipCode = request.Data.CompanyAddressZipCode;
|
||||
entity.CompanyAddressCountry = request.Data.CompanyAddressCountry;
|
||||
entity.CompanyPhoneNumber = request.Data.CompanyPhoneNumber;
|
||||
entity.CompanyFaxNumber = request.Data.CompanyFaxNumber;
|
||||
entity.CompanyEmail = request.Data.CompanyEmail;
|
||||
entity.CompanyWebsite = request.Data.CompanyWebsite;
|
||||
entity.CompanyWhatsApp = request.Data.CompanyWhatsApp;
|
||||
entity.CompanyLinkedIn = request.Data.CompanyLinkedIn;
|
||||
entity.CompanyFacebook = request.Data.CompanyFacebook;
|
||||
entity.CompanyInstagram = request.Data.CompanyInstagram;
|
||||
entity.CompanyTwitter = request.Data.CompanyTwitter;
|
||||
entity.DateProspecting = request.Data.DateProspecting;
|
||||
entity.DateClosingEstimation = request.Data.DateClosingEstimation;
|
||||
entity.DateClosingActual = request.Data.DateClosingActual;
|
||||
entity.AmountTargeted = request.Data.AmountTargeted;
|
||||
entity.AmountClosed = request.Data.AmountClosed;
|
||||
entity.BudgetScore = request.Data.BudgetScore;
|
||||
entity.AuthorityScore = request.Data.AuthorityScore;
|
||||
entity.NeedScore = request.Data.NeedScore;
|
||||
entity.TimelineScore = request.Data.TimelineScore;
|
||||
entity.PipelineStage = request.Data.PipelineStage;
|
||||
entity.ClosingStatus = request.Data.ClosingStatus;
|
||||
entity.ClosingNote = request.Data.ClosingNote;
|
||||
entity.CampaignId = request.Data.CampaignId;
|
||||
entity.SalesTeamId = request.Data.SalesTeamId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateLeadResponse { Id = entity.Id, Success = true };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
|
||||
public class UpdateLeadValidator : AbstractValidator<UpdateLeadRequest>
|
||||
{
|
||||
public UpdateLeadValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Title).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
|
||||
RuleFor(x => x.CompanyName).NotEmpty().MaximumLength(GlobalConsts.StringLengthShort);
|
||||
RuleFor(x => x.CampaignId).NotEmpty();
|
||||
RuleFor(x => x.SalesTeamId).NotEmpty();
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue() => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<UpdateLeadRequest>.CreateWithOptions((UpdateLeadRequest)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid) return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead;
|
||||
|
||||
public static class LeadEndpoint
|
||||
{
|
||||
public static void MapLeadEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/lead").WithTags("Leads")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadListQuery());
|
||||
return result.ToApiResponse("Leads retrieved successfully");
|
||||
})
|
||||
.WithName("GetLeadList");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Lead detail retrieved successfully"
|
||||
: $"Lead with ID {id} not found");
|
||||
})
|
||||
.WithName("GetLeadById");
|
||||
|
||||
group.MapPost("/", async (CreateLeadRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateLeadCommand(request));
|
||||
return result.ToApiResponse("Lead has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateLead");
|
||||
|
||||
group.MapPost("/update", async (UpdateLeadRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateLeadCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. Lead not found.");
|
||||
}
|
||||
return result.ToApiResponse("Lead has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateLead");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteLeadByIdCommand(new DeleteLeadByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. Lead not found.");
|
||||
}
|
||||
return true.ToApiResponse("Lead has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteLeadById");
|
||||
|
||||
group.MapGet("/lookup", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadLookupQuery());
|
||||
return result.ToApiResponse("Lead lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetLeadLookup");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Pipeline.Lead.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.Lead;
|
||||
|
||||
public class LeadService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public LeadService(
|
||||
IHttpClientFactory clientFactory,
|
||||
NavigationManager nav,
|
||||
ISnackbar snackbar,
|
||||
ICurrentUserService currentUserService,
|
||||
TokenProvider tokenProvider)
|
||||
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
|
||||
{
|
||||
_client = new RestClient(nav.BaseUri);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<List<GetLeadListResponse>>?> GetLeadListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/lead", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetLeadListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetLeadByIdResponse>?> GetLeadByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/lead/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetLeadByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateLeadResponse>?> CreateLeadAsync(CreateLeadRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/lead", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateLeadResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteLeadByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/lead/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateLeadResponse>?> UpdateLeadAsync(UpdateLeadRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/lead/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateLeadResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<LeadLookupResponse>?> GetLeadLookupAsync()
|
||||
{
|
||||
var request = new RestRequest("api/lead/lookup", Method.Get);
|
||||
return await ExecuteWithResponseAsync<LeadLookupResponse>(_client, request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
@page "/pipeline/lead-activity"
|
||||
@using Indotalent.Features.Pipeline.LeadActivity.Cqrs
|
||||
@using Indotalent.Features.Pipeline.LeadActivity.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_LeadActivityCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_LeadActivityUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_LeadActivityDataTable OnAdd="ShowCreate" OnEdit="(item) => ShowUpdate(item, false)" OnView="(item) => ShowUpdate(item, true)" />
|
||||
}
|
||||
|
||||
@code {
|
||||
private enum ViewMode { Table, Create, Update, View }
|
||||
private ViewMode _currentView = ViewMode.Table;
|
||||
private UpdateLeadActivityRequest? _selectedData;
|
||||
private void ShowCreate() => _currentView = ViewMode.Create;
|
||||
private void ShowUpdate(UpdateLeadActivityRequest data, bool isReadOnly) { _selectedData = data; _currentView = isReadOnly ? ViewMode.View : ViewMode.Update; }
|
||||
private void BackToTable() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
private void HandleSuccess() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
@using Indotalent.Features.Pipeline.LeadActivity.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject LeadActivityService LeadActivityService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center gap-4" Style="border: 1px solid #DCEBFA;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">Add Lead Activity</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Log a new interaction with a lead.</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Basic Information</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Summary</MudText>
|
||||
<MudTextField @bind-Value="_model.Summary" For="@(() => _model.Summary)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-0">Lead</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.LeadId" For="@(() => _model.LeadId)" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Leads)
|
||||
{
|
||||
<MudSelectItem T="string" Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-0">Activity Type</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.LeadActivityType" @bind-Value="_model.Type" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.ActivityTypes)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.LeadActivityType)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="3" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" Class="mt-4"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Schedule</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-0">From Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.FromDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-0">To Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.ToDate" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
<div class="d-flex justify-end gap-2 mt-8">
|
||||
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Style="border-radius: 4px; border: 1px solid #e0e0e0; text-transform: none; font-weight: 700;">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Disabled="_processing" Style="border-radius: 4px; text-transform: none; font-weight: 700;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Create Activity</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
private MudForm _form = default!;
|
||||
private CreateLeadActivityValidator _validator = new();
|
||||
private CreateLeadActivityRequest _model = new();
|
||||
private LeadActivityLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
protected override async Task OnInitializedAsync() { var res = await LeadActivityService.GetLeadActivityLookupAsync(); if (res != null && res.IsSuccess) _lookup = res.Value ?? new(); }
|
||||
private async Task Submit() { await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var res = await LeadActivityService.CreateLeadActivityAsync(_model); await Task.Delay(500); if (res != null && res.IsSuccess) { Snackbar.Add("Created successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } finally { _processing = false; } }
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.LeadActivity
|
||||
@using Indotalent.Features.Pipeline.LeadActivity.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject LeadActivityService LeadActivityService
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Lead Activity Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Track and manage all interactions related to leads.</MudText>
|
||||
</div>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Pipeline</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Lead Activity</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
|
||||
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<MudTextField @bind-Value="_searchString"
|
||||
Placeholder="Search..."
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
IconSize="Size.Small"
|
||||
Class="mt-0"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
Style="background-color: white; width: 280px; border-radius: 8px;"
|
||||
OnKeyDown="@HandleSearchKeyDown" />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OnSearchClick" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none;">Search</MudButton>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Success" OnClick="ExportToExcel" Size="Size.Small" Disabled="_isExporting" StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)" Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isExporting)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" OnClick="LoadData" Size="Size.Small" StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)" Disabled="_isRefreshing" Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isRefreshing)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
@if (_selectedItem != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedItem = null" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">Add New Activity</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<MudTable Striped="true" Class="mud-table-styled" Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetLeadActivityListResponse" OnRowClick="@((args) => _selectedItem = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadActivityListResponse, object>(x => x.Summary!)">Summary</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadActivityListResponse, object>(x => x.AutoNumber!)">Number</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadActivityListResponse, object>(x => x.FromDate!)">Date</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">Type</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd><MudCheckBox T="bool" Value="@(_selectedItem?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" /></MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudAvatar Color="Color.Info" Variant="Variant.Filled" Size="Size.Small" Style="width: 32px; height: 32px; font-size: 10px; font-weight: 700;">@context.Summary.ToInitial()</MudAvatar>
|
||||
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.Summary</MudText>
|
||||
</div>
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;"><MudChip T="string" Size="Size.Small" Color="Color.Info" Variant="Variant.Text" Style="border-radius:0px; font-weight:700;">@context.AutoNumber</MudChip></MudTd>
|
||||
<MudTd>@DateTimeExtensions.ToString(context.FromDate)</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.Type.ToString()</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
|
||||
<div style="display: flex; align-items: center; gap: 12px;">
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
|
||||
<MudSelect T="int" Value="@_top" ValueChanged="OnPageSizeChanged" Dense="true" Margin="Margin.Dense" Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;" Variant="Variant.Outlined" Class="mt-0 custom-select-dense">
|
||||
<MudSelectItem Value="5" /><MudSelectItem Value="10" /><MudSelectItem Value="50" /><MudSelectItem Value="500" /><MudSelectItem Value="1000" />
|
||||
</MudSelect>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF; font-size: 0.75rem; font-weight: 500; margin-left: 12px;">
|
||||
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
|
||||
</MudText>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" />
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="text-transform: none; font-weight: 700; color: #3B82F6;">Prev</MudButton>
|
||||
@{
|
||||
var totalPages = _totalPage == 0 ? 1 : _totalPage;
|
||||
var maxVisible = 5;
|
||||
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
|
||||
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
|
||||
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
|
||||
}
|
||||
@for (int i = startPage; i <= endPage; i++)
|
||||
{
|
||||
var pageNum = i;
|
||||
var isActive = pageNum == _currentPage;
|
||||
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
|
||||
Variant="Variant.Text" Size="Size.Small"
|
||||
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
|
||||
}
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="text-transform: none; font-weight: 700; color: #3B82F6;">Next</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="background-color: white; border: 1px solid #E5E7EB; color: #3B82F6;" Class="rounded-0" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
<style>
|
||||
.mud-table-styled .mud-table-row:hover { background-color: #F9FAFB !important; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateLeadActivityRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateLeadActivityRequest> OnView { get; set; }
|
||||
private List<GetLeadActivityListResponse> _items = new();
|
||||
private GetLeadActivityListResponse? _selectedItem;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
private int _skip = 0;
|
||||
private int _top = 5;
|
||||
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
|
||||
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedItem = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var res = await LeadActivityService.GetLeadActivityListAsync();
|
||||
await Task.Delay(500);
|
||||
if (res != null && res.IsSuccess) _items = res.Value ?? new();
|
||||
}
|
||||
finally { _isRefreshing = false; StateHasChanged(); }
|
||||
}
|
||||
private IEnumerable<GetLeadActivityListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _items;
|
||||
return _items.Where(x => (x.Summary?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) || (x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false));
|
||||
}
|
||||
private IEnumerable<GetLeadActivityListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
private void OnSearchClick() { _skip = 0; _selectedItem = null; StateHasChanged(); }
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e) { if (e.Key == "Enter") OnSearchClick(); }
|
||||
private void OnPageChanged(int page) { if (page >= 1 && page <= _totalPage) { _skip = (page - 1) * _top; _selectedItem = null; StateHasChanged(); } }
|
||||
private void OnPageSizeChanged(int size) { _top = size; _skip = 0; _selectedItem = null; StateHasChanged(); }
|
||||
private async Task InvokeEdit() { if (_selectedItem == null) return; var req = await MapToUpdateRequest(_selectedItem.Id!); if (req != null) await OnEdit.InvokeAsync(req); }
|
||||
private async Task InvokeView() { if (_selectedItem == null) return; var req = await MapToUpdateRequest(_selectedItem.Id!); if (req != null) await OnView.InvokeAsync(req); }
|
||||
private async Task<UpdateLeadActivityRequest?> MapToUpdateRequest(string id)
|
||||
{
|
||||
var res = await LeadActivityService.GetLeadActivityByIdAsync(id);
|
||||
if (res != null && res.IsSuccess && res.Value != null)
|
||||
{
|
||||
var d = res.Value;
|
||||
return new UpdateLeadActivityRequest { Id = d.Id, LeadId = d.LeadId, Summary = d.Summary, Description = d.Description, FromDate = d.FromDate, ToDate = d.ToDate, Type = d.Type, CreatedAt = d.CreatedAt, CreatedBy = d.CreatedBy, UpdatedAt = d.UpdatedAt, UpdatedBy = d.UpdatedBy };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true; StateHasChanged();
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
using var workbook = new XLWorkbook();
|
||||
var worksheet = workbook.Worksheets.Add("LeadActivities");
|
||||
worksheet.Cell(1, 1).Value = "Summary"; worksheet.Cell(1, 2).Value = "Number"; worksheet.Cell(1, 3).Value = "Date"; worksheet.Cell(1, 4).Value = "Type";
|
||||
var headerRange = worksheet.Range(1, 1, 1, 4); headerRange.Style.Font.Bold = true; headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#0D47A1"); headerRange.Style.Font.FontColor = XLColor.White;
|
||||
var row = 2; foreach (var item in GetFilteredData()) { worksheet.Cell(row, 1).Value = item.Summary; worksheet.Cell(row, 2).Value = item.AutoNumber; worksheet.Cell(row, 3).Value = item.FromDate?.ToString("yyyy-MM-dd"); worksheet.Cell(row, 4).Value = item.Type.ToString(); row++; }
|
||||
worksheet.Columns().AdjustToContents();
|
||||
using var stream = new MemoryStream(); workbook.SaveAs(stream);
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "LeadActivity_List.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", Convert.ToBase64String(stream.ToArray()));
|
||||
Snackbar.Add("Excel exported successfully", Severity.Success);
|
||||
}
|
||||
catch (Exception ex) { Snackbar.Add($"Export failed: {ex.Message}", Severity.Error); }
|
||||
finally { _isExporting = false; StateHasChanged(); }
|
||||
}
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedItem.Summary } };
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, new DialogOptions { FullWidth = true, MaxWidth = MaxWidth.ExtraSmall });
|
||||
var result = await dialog.Result;
|
||||
if (result != null && !result.Canceled) { var success = await LeadActivityService.DeleteLeadActivityByIdAsync(_selectedItem.Id!); if (success) { _selectedItem = null; await LoadData(); Snackbar.Add("Deleted successfully", Severity.Success); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.LeadActivity.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject LeadActivityService LeadActivityService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center gap-4" Style="border: 1px solid #DCEBFA;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Activity Details" : "Edit Activity")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing activity log." : "Modify activity details.")</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Basic Information</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Summary</MudText>
|
||||
<MudTextField @bind-Value="_model.Summary" For="@(() => _model.Summary)" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-0">Lead</MudText>
|
||||
<MudSelect T="string" @bind-Value="_model.LeadId" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Leads)
|
||||
{
|
||||
<MudSelectItem T="string" Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-0">Activity Type</MudText>
|
||||
<MudSelect T="Indotalent.Data.Enums.LeadActivityType" @bind-Value="_model.Type" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" FullWidth="true" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.ActivityTypes)
|
||||
{
|
||||
<MudSelectItem Value="@((Indotalent.Data.Enums.LeadActivityType)item.Value)">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<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-4"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Schedule</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-0">From Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.FromDate" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-0">To Date</MudText>
|
||||
<MudDatePicker @bind-Date="_model.ToDate" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
</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="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="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="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="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" 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: 0px; font-weight: 700;">
|
||||
@if (_processing)
|
||||
{
|
||||
<MudProgressCircular 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 UpdateLeadActivityRequest 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 UpdateLeadActivityValidator _validator = new();
|
||||
private UpdateLeadActivityRequest _model = new();
|
||||
private LeadActivityLookupResponse _lookup = new();
|
||||
private bool _processing = false;
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await LeadActivityService.GetLeadActivityLookupAsync();
|
||||
if (res != null && res.IsSuccess) _lookup = res.Value ?? new();
|
||||
_model = new UpdateLeadActivityRequest
|
||||
{
|
||||
Id = Data.Id,
|
||||
LeadId = Data.LeadId,
|
||||
Summary = Data.Summary,
|
||||
Description = Data.Description,
|
||||
FromDate = Data.FromDate,
|
||||
ToDate = Data.ToDate,
|
||||
Type = Data.Type,
|
||||
CreatedAt = Data.CreatedAt,
|
||||
CreatedBy = Data.CreatedBy,
|
||||
UpdatedAt = Data.UpdatedAt,
|
||||
UpdatedBy = Data.UpdatedBy
|
||||
};
|
||||
StateHasChanged();
|
||||
}
|
||||
private async Task Submit() { await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var res = await LeadActivityService.UpdateLeadActivityAsync(_model); await Task.Delay(500); if (res != null && res.IsSuccess) { Snackbar.Add("Updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } finally { _processing = false; } }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class CreateLeadActivityRequest
|
||||
{
|
||||
public string? LeadId { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? FromDate { get; set; }
|
||||
public DateTime? ToDate { get; set; }
|
||||
public Data.Enums.LeadActivityType Type { get; set; }
|
||||
}
|
||||
|
||||
public class CreateLeadActivityResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
|
||||
public record CreateLeadActivityCommand(CreateLeadActivityRequest Data) : IRequest<CreateLeadActivityResponse>;
|
||||
|
||||
public class CreateLeadActivityHandler : IRequestHandler<CreateLeadActivityCommand, CreateLeadActivityResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateLeadActivityHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateLeadActivityResponse> Handle(CreateLeadActivityCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.LeadActivity);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.LeadActivity
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
LeadId = request.Data.LeadId,
|
||||
Summary = request.Data.Summary,
|
||||
Description = request.Data.Description,
|
||||
FromDate = request.Data.FromDate,
|
||||
ToDate = request.Data.ToDate,
|
||||
Type = request.Data.Type
|
||||
};
|
||||
|
||||
_context.LeadActivity.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateLeadActivityResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Summary = entity.Summary
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class CreateLeadActivityValidator : AbstractValidator<CreateLeadActivityRequest>
|
||||
{
|
||||
public CreateLeadActivityValidator()
|
||||
{
|
||||
RuleFor(x => x.Summary)
|
||||
.NotEmpty().WithMessage("Summary is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.LeadId)
|
||||
.NotEmpty().WithMessage("Lead association is required");
|
||||
|
||||
RuleFor(x => x.FromDate)
|
||||
.NotEmpty().WithMessage("From Date is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public record DeleteLeadActivityByIdRequest(string Id);
|
||||
public record DeleteLeadActivityByIdCommand(DeleteLeadActivityByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteLeadActivityByIdHandler : IRequestHandler<DeleteLeadActivityByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteLeadActivityByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteLeadActivityByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadActivity
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.LeadActivity.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class GetLeadActivityByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? FromDate { get; set; }
|
||||
public DateTime? ToDate { get; set; }
|
||||
public Data.Enums.LeadActivityType Type { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadActivityByIdQuery(string Id) : IRequest<GetLeadActivityByIdResponse?>;
|
||||
|
||||
public class GetLeadActivityByIdHandler : IRequestHandler<GetLeadActivityByIdQuery, GetLeadActivityByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadActivityByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetLeadActivityByIdResponse?> Handle(GetLeadActivityByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.LeadActivity
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetLeadActivityByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
LeadId = x.LeadId,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Summary = x.Summary,
|
||||
Description = x.Description,
|
||||
FromDate = x.FromDate,
|
||||
ToDate = x.ToDate,
|
||||
Type = x.Type,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class GetLeadActivityListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public DateTime? FromDate { get; set; }
|
||||
public Data.Enums.LeadActivityType Type { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadActivityListQuery() : IRequest<List<GetLeadActivityListResponse>>;
|
||||
|
||||
public class GetLeadActivityListHandler : IRequestHandler<GetLeadActivityListQuery, List<GetLeadActivityListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadActivityListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetLeadActivityListResponse>> Handle(GetLeadActivityListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.LeadActivity
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(x => x.FromDate)
|
||||
.Select(x => new GetLeadActivityListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Summary = x.Summary,
|
||||
FromDate = x.FromDate,
|
||||
Type = x.Type
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class LeadActivityLookupResponse
|
||||
{
|
||||
public List<LookupItem> Leads { get; set; } = new();
|
||||
public List<LookupItem> ActivityTypes { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadActivityLookupQuery() : IRequest<LeadActivityLookupResponse>;
|
||||
|
||||
public class GetLeadActivityLookupHandler : IRequestHandler<GetLeadActivityLookupQuery, LeadActivityLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadActivityLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LeadActivityLookupResponse> Handle(GetLeadActivityLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new LeadActivityLookupResponse();
|
||||
|
||||
response.Leads = await _context.Lead.AsNoTracking()
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Title }).ToListAsync(cancellationToken);
|
||||
|
||||
response.ActivityTypes = Enum.GetValues(typeof(LeadActivityType)).Cast<LeadActivityType>()
|
||||
.Select(x => new LookupItem { Value = (int)x, Name = x.ToString() }).ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class UpdateLeadActivityRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? FromDate { get; set; }
|
||||
public DateTime? ToDate { get; set; }
|
||||
public Data.Enums.LeadActivityType Type { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateLeadActivityResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateLeadActivityCommand(UpdateLeadActivityRequest Data) : IRequest<UpdateLeadActivityResponse>;
|
||||
|
||||
public class UpdateLeadActivityHandler : IRequestHandler<UpdateLeadActivityCommand, UpdateLeadActivityResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateLeadActivityHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateLeadActivityResponse> Handle(UpdateLeadActivityCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadActivity
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateLeadActivityResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.LeadId = request.Data.LeadId;
|
||||
entity.Summary = request.Data.Summary;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.FromDate = request.Data.FromDate;
|
||||
entity.ToDate = request.Data.ToDate;
|
||||
entity.Type = request.Data.Type;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateLeadActivityResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
|
||||
public class UpdateLeadActivityValidator : AbstractValidator<UpdateLeadActivityRequest>
|
||||
{
|
||||
public UpdateLeadActivityValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
|
||||
RuleFor(x => x.Summary)
|
||||
.NotEmpty().WithMessage("Summary is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.LeadId)
|
||||
.NotEmpty().WithMessage("Lead association is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity;
|
||||
|
||||
public static class LeadActivityEndpoint
|
||||
{
|
||||
public static void MapLeadActivityEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/lead-activity").WithTags("LeadActivities")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/lookup", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadActivityLookupQuery());
|
||||
return result.ToApiResponse("Lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetLeadActivityLookup");
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadActivityListQuery());
|
||||
return result.ToApiResponse("Lead activity list retrieved successfully");
|
||||
})
|
||||
.WithName("GetLeadActivityList");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadActivityByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Lead activity detail retrieved successfully"
|
||||
: $"Lead activity with ID {id} not found");
|
||||
})
|
||||
.WithName("GetLeadActivityById");
|
||||
|
||||
group.MapPost("/", async (CreateLeadActivityRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateLeadActivityCommand(request));
|
||||
return result.ToApiResponse("Lead activity has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateLeadActivity");
|
||||
|
||||
group.MapPost("/update", async (UpdateLeadActivityRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateLeadActivityCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The lead activity data could not be found.");
|
||||
}
|
||||
return result.ToApiResponse("Lead activity has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateLeadActivity");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteLeadActivityByIdCommand(new DeleteLeadActivityByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The lead activity data could not be found.");
|
||||
}
|
||||
return true.ToApiResponse("Lead activity has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteLeadActivityById");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Pipeline.LeadActivity.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadActivity;
|
||||
|
||||
public class LeadActivityService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public LeadActivityService(
|
||||
IHttpClientFactory clientFactory,
|
||||
NavigationManager nav,
|
||||
ISnackbar snackbar,
|
||||
ICurrentUserService currentUserService,
|
||||
TokenProvider tokenProvider)
|
||||
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
|
||||
{
|
||||
_client = new RestClient(nav.BaseUri);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<LeadActivityLookupResponse>?> GetLeadActivityLookupAsync()
|
||||
{
|
||||
var request = new RestRequest("api/lead-activity/lookup", Method.Get);
|
||||
return await ExecuteWithResponseAsync<LeadActivityLookupResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<List<GetLeadActivityListResponse>>?> GetLeadActivityListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/lead-activity", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetLeadActivityListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetLeadActivityByIdResponse>?> GetLeadActivityByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/lead-activity/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetLeadActivityByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateLeadActivityResponse>?> CreateLeadActivityAsync(CreateLeadActivityRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/lead-activity", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateLeadActivityResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateLeadActivityResponse>?> UpdateLeadActivityAsync(UpdateLeadActivityRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/lead-activity/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateLeadActivityResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteLeadActivityByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/lead-activity/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
@page "/pipeline/lead-contact"
|
||||
@using Indotalent.Features.Pipeline.LeadContact.Cqrs
|
||||
@using Indotalent.Features.Pipeline.LeadContact.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_LeadContactCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_LeadContactUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_LeadContactDataTable OnAdd="ShowCreate" OnEdit="(item) => ShowUpdate(item, false)" OnView="(item) => ShowUpdate(item, true)" />
|
||||
}
|
||||
|
||||
@code {
|
||||
private enum ViewMode { Table, Create, Update, View }
|
||||
private ViewMode _currentView = ViewMode.Table;
|
||||
private UpdateLeadContactRequest? _selectedData;
|
||||
|
||||
private void ShowCreate() => _currentView = ViewMode.Create;
|
||||
private void ShowUpdate(UpdateLeadContactRequest data, bool isReadOnly) { _selectedData = data; _currentView = isReadOnly ? ViewMode.View : ViewMode.Update; }
|
||||
private void BackToTable() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
private void HandleSuccess() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
@using Indotalent.Features.Pipeline.LeadContact.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject LeadContactService LeadContactService
|
||||
@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;">Add Lead Contact</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">Create a new contact entry for your pipeline.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
|
||||
<MudItem xs="12"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Basic Information</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Full Name</MudText>
|
||||
<MudTextField @bind-Value="_model.FullName" For="@(() => _model.FullName)" Validation="@(_validator.ValidateValue())" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Lead</MudText>
|
||||
<MudSelect T="string"
|
||||
@bind-Value="_model.LeadId"
|
||||
For="@(() => _model.LeadId)"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
Dense="true"
|
||||
FullWidth="true"
|
||||
AnchorOrigin="Origin.BottomCenter"
|
||||
TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Leads)
|
||||
{
|
||||
<MudSelectItem T="string" Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Description</MudText>
|
||||
<MudTextField @bind-Value="_model.Description" Variant="Variant.Outlined" Margin="Margin.Dense" Lines="2" FullWidth="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" Class="mt-4"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Address Info</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12"><MudText Typo="Typo.subtitle2" Class="mb-1">Street Address</MudText><MudTextField @bind-Value="_model.AddressStreet" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">City</MudText><MudTextField @bind-Value="_model.AddressCity" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">State</MudText><MudTextField @bind-Value="_model.AddressState" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Zip Code</MudText><MudTextField @bind-Value="_model.AddressZipCode" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Country</MudText><MudTextField @bind-Value="_model.AddressCountry" 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;">Contact Details</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Phone Number</MudText><MudTextField @bind-Value="_model.PhoneNumber" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Fax Number</MudText><MudTextField @bind-Value="_model.FaxNumber" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Mobile Number</MudText><MudTextField @bind-Value="_model.MobileNumber" 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.Email" 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" 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;">Digital Presence</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">WhatsApp</MudText><MudTextField @bind-Value="_model.WhatsApp" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">LinkedIn</MudText><MudTextField @bind-Value="_model.LinkedIn" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Facebook</MudText><MudTextField @bind-Value="_model.Facebook" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Twitter</MudText><MudTextField @bind-Value="_model.Twitter" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Instagram</MudText><MudTextField @bind-Value="_model.Instagram" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<div class="d-flex justify-end gap-2 mt-8">
|
||||
<MudButton OnClick="() => OnCancel.InvokeAsync()" Variant="Variant.Outlined" Style="border-radius: 4px; border: 1px solid #e0e0e0; text-transform: none; font-weight: 700;">Cancel</MudButton>
|
||||
<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;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Create Contact</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
[Parameter] public EventCallback OnSuccess { get; set; }
|
||||
|
||||
private MudForm _form = default!;
|
||||
private CreateLeadContactValidator _validator = new();
|
||||
private CreateLeadContactRequest _model = new();
|
||||
private bool _processing = false;
|
||||
private LeadContactLookupResponse _lookup = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await LeadContactService.GetLeadContactLookupAsync();
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
_lookup = res.Value ?? new();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var res = await LeadContactService.CreateLeadContactAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Created successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,397 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.LeadContact
|
||||
@using Indotalent.Features.Pipeline.LeadContact.Cqrs
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using Features.Root.Shared
|
||||
@using ClosedXML.Excel
|
||||
@using System.IO
|
||||
@inject LeadContactService LeadContactService
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center justify-space-between" Style="border: 1px solid #E5E7EB; border-radius: 12px;">
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 700; color: #111827;">Lead Contact Management</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #9CA3AF;">Manage pipeline contacts and communication details.</MudText>
|
||||
</div>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Home" Size="Size.Small" Color="Color.Default" />
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">Pipeline</MudText>
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF;">/</MudText>
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 600; color: #111827;">Lead Contact</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Style="border-radius: 12px; overflow: hidden; background-color: #ffffff; border: 1px solid #E5E7EB;">
|
||||
|
||||
<div style="padding: 20px 24px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center; background-color: #ffffff; min-height: 80px;">
|
||||
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<MudTextField @bind-Value="_searchString"
|
||||
Placeholder="Search..."
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
IconSize="Size.Small"
|
||||
Class="mt-0"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
Style="background-color: white; width: 280px; border-radius: 8px;"
|
||||
OnKeyDown="@HandleSearchKeyDown" />
|
||||
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
OnClick="OnSearchClick"
|
||||
Size="Size.Small"
|
||||
Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px; box-shadow: none;">
|
||||
Search
|
||||
</MudButton>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Success"
|
||||
OnClick="ExportToExcel"
|
||||
Size="Size.Small"
|
||||
Disabled="_isExporting"
|
||||
StartIcon="@(_isExporting ? null : Icons.Custom.FileFormats.FileExcel)"
|
||||
Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isExporting)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Processing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Excel</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Primary"
|
||||
OnClick="LoadData"
|
||||
Size="Size.Small"
|
||||
StartIcon="@(_isRefreshing ? null : Icons.Material.Filled.Refresh)"
|
||||
Disabled="_isRefreshing"
|
||||
Style="background: white; font-weight: 500; border-radius: 6px; text-transform: none; height: 34px; border: 1px solid #D1D5DB;">
|
||||
@if (_isRefreshing)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Refreshing...</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.button" Style="text-transform: none !important;">Refresh</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
|
||||
@if (_selectedItem != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Visibility" OnClick="InvokeView" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">View</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Edit" OnClick="InvokeEdit" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #D1D5DB;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; background: white; border: 1px solid #FCA5A5; color: #EF4444;">Remove</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Close" Size="Size.Small" OnClick="() => _selectedItem = null" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" OnClick="() => OnAdd.InvokeAsync()" Size="Size.Small" Style="text-transform: none; font-weight: 500; border-radius: 6px; height: 34px;">
|
||||
Add New Contact
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudTable Striped="true" Class="mud-table-styled" Items="@GetPagedData()" Hover="true" Elevation="0" CustomHeader="true" Dense="true" T="GetLeadContactListResponse" OnRowClick="@((args) => _selectedItem = args.Item)" Loading="@_isRefreshing">
|
||||
<HeaderContent>
|
||||
<MudTh Style="width: 50px; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB;"></MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadContactListResponse, object>(x => x.FullName!)">Contact Name</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 700; color: #111827; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadContactListResponse, object>(x => x.AutoNumber!)">Auto Number</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">Mobile</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; letter-spacing: 0.05em; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadContactListResponse, object>(x => x.Email!)">Email</MudTableSortLabel>
|
||||
</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
|
||||
<MudCheckBox T="bool" Value="@(_selectedItem?.Id == context.Id)" Color="Color.Primary" Dense="true" Size="Size.Small" ReadOnly="true" />
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem;">
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudAvatar Color="Color.Info" Variant="Variant.Filled" Size="Size.Small" Style="width: 32px; height: 32px; font-size: 10px; font-weight: 700;">
|
||||
@context.FullName.ToInitial()
|
||||
</MudAvatar>
|
||||
<MudText Typo="Typo.body2" Style="font-weight: 600; color: #374151;">@context.FullName</MudText>
|
||||
</div>
|
||||
</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;"><MudChip T="string" Size="Size.Small" Color="Color.Info" Variant="Variant.Text" Style="border-radius:0px; font-weight:700;">@context.AutoNumber</MudChip></MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.MobileNumber</MudTd>
|
||||
<MudTd Style="padding-top: 0.75rem; padding-bottom: 0.75rem; color: #6B7280; font-size: 0.875rem;">@context.Email</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: #F9FAFB; border-top: 1px solid #E5E7EB;">
|
||||
<div style="display: flex; align-items: center; gap: 12px;">
|
||||
<MudText Typo="Typo.caption" Style="font-weight: 500; color: #9CA3AF; font-size: 0.75rem;">Rows per page:</MudText>
|
||||
|
||||
<MudSelect T="int"
|
||||
Value="@_top"
|
||||
ValueChanged="OnPageSizeChanged"
|
||||
Dense="true"
|
||||
Margin="Margin.Dense"
|
||||
Style="width: 80px; background-color: white; font-size: 12px; font-weight: 600;"
|
||||
Variant="Variant.Outlined"
|
||||
Class="mt-0 custom-select-dense">
|
||||
<MudSelectItem Value="5" />
|
||||
<MudSelectItem Value="10" />
|
||||
<MudSelectItem Value="50" />
|
||||
<MudSelectItem Value="500" />
|
||||
<MudSelectItem Value="1000" />
|
||||
</MudSelect>
|
||||
|
||||
<MudText Typo="Typo.caption" Style="color: #9CA3AF; font-size: 0.75rem; font-weight: 500; margin-left: 12px;">
|
||||
Showing @(GetFilteredData().Count() == 0 ? 0 : _skip + 1)-@Math.Min(_skip + _top, GetFilteredData().Count()) of @GetFilteredData().Count()
|
||||
</MudText>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.FirstPage" Size="Size.Small" OnClick="@(() => OnPageChanged(1))" Disabled="@(_currentPage == 1)" Style="@(_currentPage == 1 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" />
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage - 1))" Disabled="@(_currentPage == 1)" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ChevronLeft" Size="Size.Small" Style="@(_currentPage == 1 ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #D1D5DB; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">Prev</MudButton>
|
||||
@{
|
||||
var totalPages = _totalPage == 0 ? 1 : _totalPage;
|
||||
var maxVisible = 5;
|
||||
var startPage = Math.Max(1, _currentPage - maxVisible / 2);
|
||||
var endPage = Math.Min(totalPages, startPage + maxVisible - 1);
|
||||
if (endPage - startPage < maxVisible - 1) { startPage = Math.Max(1, endPage - maxVisible + 1); }
|
||||
}
|
||||
@for (int i = startPage; i <= endPage; i++)
|
||||
{
|
||||
var pageNum = i;
|
||||
var isActive = pageNum == _currentPage;
|
||||
<MudButton OnClick="@(() => OnPageChanged(pageNum))"
|
||||
Variant="Variant.Text" Size="Size.Small"
|
||||
Style="@(isActive ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: #3B82F6; color: white; border: 1px solid #3B82F6; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #374151; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">@pageNum</MudButton>
|
||||
}
|
||||
<MudButton OnClick="@(() => OnPageChanged(_currentPage + 1))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Variant="Variant.Text" EndIcon="@Icons.Material.Filled.ChevronRight" Size="Size.Small" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #D1D5DB; border-radius: 6px; text-transform: none;" : "min-width: 34px; padding: 4px 8px; font-size: 0.75rem; font-weight: 500; color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px; text-transform: none;")">Next</MudButton>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.LastPage" Size="Size.Small" OnClick="@(() => OnPageChanged(_totalPage))" Disabled="@(_currentPage == _totalPage || _totalPage == 0)" Style="@(_currentPage == _totalPage || _totalPage == 0 ? "color: #D1D5DB; background: transparent;" : "color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")" />
|
||||
</div>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<script>
|
||||
function downloadFile(fileName, contentType, base64String) {
|
||||
const link = document.createElement('a');
|
||||
link.download = fileName;
|
||||
link.href = `data:${contentType};base64,${base64String}`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.mud-input-outlined-border { border-radius: 0px !important; }
|
||||
.custom-select-dense .mud-input-control { margin-top: 0 !important; }
|
||||
.custom-select-dense .mud-input-slot { padding-top: 4px !important; padding-bottom: 4px !important; padding-left: 8px !important; font-size: 12px !important; }
|
||||
</style>
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback OnAdd { get; set; }
|
||||
[Parameter] public EventCallback<UpdateLeadContactRequest> OnEdit { get; set; }
|
||||
[Parameter] public EventCallback<UpdateLeadContactRequest> OnView { get; set; }
|
||||
|
||||
private List<GetLeadContactListResponse> _items = new();
|
||||
private GetLeadContactListResponse? _selectedItem;
|
||||
private string _searchString = "";
|
||||
private bool _isRefreshing = false;
|
||||
private bool _isExporting = false;
|
||||
|
||||
private int _skip = 0;
|
||||
private int _top = 5;
|
||||
private int _totalPage => GetFilteredData().Count() == 0 ? 0 : (int)Math.Ceiling((double)GetFilteredData().Count() / (_top == 0 ? 1 : _top));
|
||||
private int _currentPage => (_top >= GetFilteredData().Count() || _top == 0) ? 1 : (_skip / _top) + 1;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadData();
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
_isRefreshing = true;
|
||||
_selectedItem = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var response = await LeadContactService.GetLeadContactListAsync();
|
||||
await Task.Delay(500);
|
||||
if (response != null && response.IsSuccess)
|
||||
{
|
||||
_items = response.Value ?? new List<GetLeadContactListResponse>();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRefreshing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GetLeadContactListResponse> GetFilteredData()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchString)) return _items;
|
||||
return _items.Where(x =>
|
||||
(x.FullName?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.AutoNumber?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
||||
(x.Email?.Contains(_searchString, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
private IEnumerable<GetLeadContactListResponse> GetPagedData() => GetFilteredData().Skip(_skip).Take(_top);
|
||||
|
||||
private void OnSearchClick()
|
||||
{
|
||||
_skip = 0;
|
||||
_selectedItem = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void HandleSearchKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Enter") OnSearchClick();
|
||||
}
|
||||
|
||||
private async Task ExportToExcel()
|
||||
{
|
||||
_isExporting = true;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
var worksheet = workbook.Worksheets.Add("LeadContacts");
|
||||
var currentRow = 1;
|
||||
|
||||
worksheet.Cell(currentRow, 1).Value = "Full Name";
|
||||
worksheet.Cell(currentRow, 2).Value = "Auto Number";
|
||||
worksheet.Cell(currentRow, 3).Value = "Mobile Number";
|
||||
worksheet.Cell(currentRow, 4).Value = "Email";
|
||||
|
||||
var headerRange = worksheet.Range(1, 1, 1, 4);
|
||||
headerRange.Style.Font.Bold = true;
|
||||
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#0D47A1");
|
||||
headerRange.Style.Font.FontColor = XLColor.White;
|
||||
|
||||
foreach (var item in GetFilteredData())
|
||||
{
|
||||
currentRow++;
|
||||
worksheet.Cell(currentRow, 1).Value = item.FullName;
|
||||
worksheet.Cell(currentRow, 2).Value = item.AutoNumber;
|
||||
worksheet.Cell(currentRow, 3).Value = item.MobileNumber;
|
||||
worksheet.Cell(currentRow, 4).Value = item.Email;
|
||||
}
|
||||
|
||||
worksheet.Columns().AdjustToContents();
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
workbook.SaveAs(stream);
|
||||
var content = Convert.ToBase64String(stream.ToArray());
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "LeadContact_List.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", content);
|
||||
Snackbar.Add("Excel exported successfully", Severity.Success);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Export failed: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isExporting = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageChanged(int page)
|
||||
{
|
||||
if (page >= 1 && page <= _totalPage)
|
||||
{
|
||||
_skip = (page - 1) * _top;
|
||||
_selectedItem = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageSizeChanged(int size)
|
||||
{
|
||||
_top = size;
|
||||
_skip = 0;
|
||||
_selectedItem = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task InvokeEdit()
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedItem.Id!);
|
||||
if (request != null) await OnEdit.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task InvokeView()
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
var request = await MapToUpdateRequest(_selectedItem.Id!);
|
||||
if (request != null) await OnView.InvokeAsync(request);
|
||||
}
|
||||
|
||||
private async Task<UpdateLeadContactRequest?> MapToUpdateRequest(string id)
|
||||
{
|
||||
var response = await LeadContactService.GetLeadContactByIdAsync(id);
|
||||
if (response != null && response.IsSuccess && response.Value != null)
|
||||
{
|
||||
var d = response.Value;
|
||||
return new UpdateLeadContactRequest
|
||||
{
|
||||
Id = d.Id, LeadId = d.LeadId, FullName = d.FullName, Description = d.Description,
|
||||
AddressStreet = d.AddressStreet, AddressCity = d.AddressCity, AddressState = d.AddressState,
|
||||
AddressZipCode = d.AddressZipCode, AddressCountry = d.AddressCountry, PhoneNumber = d.PhoneNumber,
|
||||
FaxNumber = d.FaxNumber, MobileNumber = d.MobileNumber, Email = d.Email, Website = d.Website,
|
||||
WhatsApp = d.WhatsApp, LinkedIn = d.LinkedIn, Facebook = d.Facebook, Twitter = d.Twitter,
|
||||
Instagram = d.Instagram, CreatedAt = d.CreatedAt, CreatedBy = d.CreatedBy,
|
||||
UpdatedAt = d.UpdatedAt, UpdatedBy = d.UpdatedBy
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task OnDelete()
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
|
||||
var parameters = new DialogParameters<_DeleteConfirmation> { { x => x.ContentText, _selectedItem.FullName } };
|
||||
var options = new DialogOptions { CloseButton = false, MaxWidth = MaxWidth.ExtraSmall, FullWidth = true };
|
||||
|
||||
var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("", parameters, options);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result != null && !result.Canceled)
|
||||
{
|
||||
var isSuccess = await LeadContactService.DeleteLeadContactByIdAsync(_selectedItem.Id!);
|
||||
if (isSuccess)
|
||||
{
|
||||
_selectedItem = null;
|
||||
await LoadData();
|
||||
Snackbar.Add("Deleted successfully", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Delete failed.", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
@using Indotalent.ConfigBackEnd.Extensions
|
||||
@using Indotalent.Features.Pipeline.LeadContact
|
||||
@using Indotalent.Features.Pipeline.LeadContact.Cqrs
|
||||
@using Indotalent.Shared.Utils
|
||||
@using MudBlazor
|
||||
@inject LeadContactService LeadContactService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudPaper Elevation="0" Square="true" Class="pa-6 mb-3 d-flex align-center gap-4" Style="border: 1px solid #DCEBFA;">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowBack" OnClick="() => OnCancel.InvokeAsync()" />
|
||||
<div>
|
||||
<MudText Typo="Typo.h5" Style="font-weight: 900; color: #1a1a1a;">@(ReadOnly ? "Lead Contact Details" : "Edit Lead Contact")</MudText>
|
||||
<MudText Typo="Typo.body2" Style="color: #64748b;">@(ReadOnly ? "Viewing pipeline contact specification." : "Modify existing contact information.")</MudText>
|
||||
</div>
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Elevation="0" Outlined="true" Class="pa-8" Style="border-radius: 0px; border: 1px solid #DCEBFA;">
|
||||
<MudForm @ref="_form" Model="_model">
|
||||
<MudGrid Spacing="3">
|
||||
|
||||
<MudItem xs="12"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Basic Information</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-1">Full Name</MudText>
|
||||
<MudTextField @bind-Value="_model.FullName" For="@(() => _model.FullName)" 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">Lead</MudText>
|
||||
<MudSelect T="string"
|
||||
@bind-Value="_model.LeadId"
|
||||
For="@(() => _model.LeadId)"
|
||||
ReadOnly="ReadOnly"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
Dense="true"
|
||||
FullWidth="true"
|
||||
AnchorOrigin="Origin.BottomCenter"
|
||||
TransformOrigin="Origin.TopCenter">
|
||||
@foreach (var item in _lookup.Leads)
|
||||
{
|
||||
<MudSelectItem T="string" Value="@item.Id">@item.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<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-4"><MudText Typo="Typo.button" Color="Color.Primary" Style="font-weight: 800;">Address Information</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12"><MudText Typo="Typo.subtitle2" Class="mb-1">Street Address</MudText><MudTextField @bind-Value="_model.AddressStreet" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">City</MudText><MudTextField @bind-Value="_model.AddressCity" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">State</MudText><MudTextField @bind-Value="_model.AddressState" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Zip Code</MudText><MudTextField @bind-Value="_model.AddressZipCode" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="3"><MudText Typo="Typo.subtitle2" Class="mb-1">Country</MudText><MudTextField @bind-Value="_model.AddressCountry" 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;">Contact & Communication</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="4"><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="4"><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="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Mobile Number</MudText><MudTextField @bind-Value="_model.MobileNumber" 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.Email" 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;">Digital Presence</MudText><MudDivider /></MudItem>
|
||||
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">WhatsApp</MudText><MudTextField @bind-Value="_model.WhatsApp" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">LinkedIn</MudText><MudTextField @bind-Value="_model.LinkedIn" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="4"><MudText Typo="Typo.subtitle2" Class="mb-1">Facebook</MudText><MudTextField @bind-Value="_model.Facebook" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Twitter</MudText><MudTextField @bind-Value="_model.Twitter" ReadOnly="ReadOnly" Variant="Variant.Outlined" Margin="Margin.Dense" FullWidth="true" /></MudItem>
|
||||
<MudItem xs="12" sm="6"><MudText Typo="Typo.subtitle2" Class="mb-1">Instagram</MudText><MudTextField @bind-Value="_model.Instagram" 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;">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="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="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="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="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" 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 UpdateLeadContactRequest 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 UpdateLeadContactValidator _validator = new();
|
||||
private UpdateLeadContactRequest _model = new();
|
||||
private bool _processing = false;
|
||||
private LeadContactLookupResponse _lookup = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var res = await LeadContactService.GetLeadContactLookupAsync();
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
_lookup = res.Value ?? new();
|
||||
}
|
||||
|
||||
_model = new UpdateLeadContactRequest
|
||||
{
|
||||
Id = Data.Id,
|
||||
LeadId = Data.LeadId,
|
||||
FullName = Data.FullName,
|
||||
Description = Data.Description,
|
||||
AddressStreet = Data.AddressStreet,
|
||||
AddressCity = Data.AddressCity,
|
||||
AddressState = Data.AddressState,
|
||||
AddressZipCode = Data.AddressZipCode,
|
||||
AddressCountry = Data.AddressCountry,
|
||||
PhoneNumber = Data.PhoneNumber,
|
||||
FaxNumber = Data.FaxNumber,
|
||||
MobileNumber = Data.MobileNumber,
|
||||
Email = Data.Email,
|
||||
Website = Data.Website,
|
||||
WhatsApp = Data.WhatsApp,
|
||||
LinkedIn = Data.LinkedIn,
|
||||
Facebook = Data.Facebook,
|
||||
Twitter = Data.Twitter,
|
||||
Instagram = Data.Instagram,
|
||||
CreatedAt = Data.CreatedAt,
|
||||
CreatedBy = Data.CreatedBy,
|
||||
UpdatedAt = Data.UpdatedAt,
|
||||
UpdatedBy = Data.UpdatedBy
|
||||
};
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid) return;
|
||||
_processing = true;
|
||||
try
|
||||
{
|
||||
var res = await LeadContactService.UpdateLeadContactAsync(_model);
|
||||
await Task.Delay(500);
|
||||
if (res != null && res.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Updated successfully", Severity.Success);
|
||||
await OnSuccess.InvokeAsync();
|
||||
}
|
||||
}
|
||||
finally { _processing = false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using Indotalent.Infrastructure.File;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class ChangeLeadContactAvatarRequest
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public byte[] FileData { get; set; } = Array.Empty<byte>();
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class ChangeLeadContactAvatarResponse
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public record ChangeLeadContactAvatarCommand(ChangeLeadContactAvatarRequest Data) : IRequest<ChangeLeadContactAvatarResponse>;
|
||||
|
||||
public class ChangeLeadContactAvatarHandler : IRequestHandler<ChangeLeadContactAvatarCommand, ChangeLeadContactAvatarResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
private readonly FileStorageService _fileStorage;
|
||||
|
||||
public ChangeLeadContactAvatarHandler(AppDbContext context, FileStorageService fileStorage)
|
||||
{
|
||||
_context = context;
|
||||
_fileStorage = fileStorage;
|
||||
}
|
||||
|
||||
public async Task<ChangeLeadContactAvatarResponse> Handle(ChangeLeadContactAvatarCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return new ChangeLeadContactAvatarResponse { IsSuccess = false, Message = "Lead Contact not found" };
|
||||
|
||||
try
|
||||
{
|
||||
var extension = Path.GetExtension(request.Data.FileName);
|
||||
|
||||
if (!string.IsNullOrEmpty(entity.AvatarName))
|
||||
{
|
||||
_fileStorage.DeleteOldAvatar(entity.AvatarName);
|
||||
}
|
||||
|
||||
var newFileName = await _fileStorage.SaveAvatarAsync(entity.Id, request.Data.FileData, extension);
|
||||
|
||||
entity.AvatarName = newFileName;
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new ChangeLeadContactAvatarResponse
|
||||
{
|
||||
IsSuccess = true,
|
||||
Message = "Lead Contact avatar updated successfully"
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ChangeLeadContactAvatarResponse { IsSuccess = false, Message = ex.Message };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class CreateLeadContactRequest
|
||||
{
|
||||
public string? LeadId { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? AddressStreet { get; set; }
|
||||
public string? AddressCity { get; set; }
|
||||
public string? AddressState { get; set; }
|
||||
public string? AddressZipCode { get; set; }
|
||||
public string? AddressCountry { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? MobileNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Twitter { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
}
|
||||
|
||||
public class CreateLeadContactResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
}
|
||||
|
||||
public record CreateLeadContactCommand(CreateLeadContactRequest Data) : IRequest<CreateLeadContactResponse>;
|
||||
|
||||
public class CreateLeadContactHandler : IRequestHandler<CreateLeadContactCommand, CreateLeadContactResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateLeadContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateLeadContactResponse> Handle(CreateLeadContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entityName = nameof(Data.Entities.LeadContact);
|
||||
|
||||
var autoNo = await _context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/",
|
||||
ct: cancellationToken
|
||||
);
|
||||
|
||||
var entity = new Data.Entities.LeadContact
|
||||
{
|
||||
AutoNumber = autoNo,
|
||||
LeadId = request.Data.LeadId,
|
||||
FullName = request.Data.FullName,
|
||||
Description = request.Data.Description,
|
||||
AddressStreet = request.Data.AddressStreet,
|
||||
AddressCity = request.Data.AddressCity,
|
||||
AddressState = request.Data.AddressState,
|
||||
AddressZipCode = request.Data.AddressZipCode,
|
||||
AddressCountry = request.Data.AddressCountry,
|
||||
PhoneNumber = request.Data.PhoneNumber,
|
||||
FaxNumber = request.Data.FaxNumber,
|
||||
MobileNumber = request.Data.MobileNumber,
|
||||
Email = request.Data.Email,
|
||||
Website = request.Data.Website,
|
||||
WhatsApp = request.Data.WhatsApp,
|
||||
LinkedIn = request.Data.LinkedIn,
|
||||
Facebook = request.Data.Facebook,
|
||||
Twitter = request.Data.Twitter,
|
||||
Instagram = request.Data.Instagram,
|
||||
AvatarName = request.Data.AvatarName
|
||||
};
|
||||
|
||||
_context.LeadContact.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateLeadContactResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
FullName = entity.FullName
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class CreateLeadContactValidator : AbstractValidator<CreateLeadContactRequest>
|
||||
{
|
||||
public CreateLeadContactValidator()
|
||||
{
|
||||
RuleFor(x => x.FullName)
|
||||
.NotEmpty().WithMessage("Full Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.Email)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.Email))
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.LeadId)
|
||||
.NotEmpty().WithMessage("Lead association is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public record DeleteLeadContactByIdRequest(string Id);
|
||||
|
||||
public record DeleteLeadContactByIdCommand(DeleteLeadContactByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteLeadContactByIdHandler : IRequestHandler<DeleteLeadContactByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteLeadContactByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteLeadContactByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.LeadContact.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class GetLeadContactAvatarInfoResponse
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string? FullName { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadContactAvatarInfoQuery(string Id) : IRequest<GetLeadContactAvatarInfoResponse?>;
|
||||
|
||||
public class GetLeadContactAvatarInfoHandler : IRequestHandler<GetLeadContactAvatarInfoQuery, GetLeadContactAvatarInfoResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadContactAvatarInfoHandler(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetLeadContactAvatarInfoResponse?> Handle(GetLeadContactAvatarInfoQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadContact
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return null;
|
||||
|
||||
return new GetLeadContactAvatarInfoResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
FullName = entity.FullName,
|
||||
AvatarName = entity.AvatarName
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class GetLeadContactByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? AddressStreet { get; set; }
|
||||
public string? AddressCity { get; set; }
|
||||
public string? AddressState { get; set; }
|
||||
public string? AddressZipCode { get; set; }
|
||||
public string? AddressCountry { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? MobileNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Twitter { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadContactByIdQuery(string Id) : IRequest<GetLeadContactByIdResponse?>;
|
||||
|
||||
public class GetLeadContactByIdHandler : IRequestHandler<GetLeadContactByIdQuery, GetLeadContactByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadContactByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetLeadContactByIdResponse?> Handle(GetLeadContactByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.LeadContact
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetLeadContactByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
LeadId = x.LeadId,
|
||||
AutoNumber = x.AutoNumber,
|
||||
FullName = x.FullName,
|
||||
Description = x.Description,
|
||||
AddressStreet = x.AddressStreet,
|
||||
AddressCity = x.AddressCity,
|
||||
AddressState = x.AddressState,
|
||||
AddressZipCode = x.AddressZipCode,
|
||||
AddressCountry = x.AddressCountry,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
FaxNumber = x.FaxNumber,
|
||||
MobileNumber = x.MobileNumber,
|
||||
Email = x.Email,
|
||||
Website = x.Website,
|
||||
WhatsApp = x.WhatsApp,
|
||||
LinkedIn = x.LinkedIn,
|
||||
Facebook = x.Facebook,
|
||||
Twitter = x.Twitter,
|
||||
Instagram = x.Instagram,
|
||||
AvatarName = x.AvatarName,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class GetLeadContactListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? MobileNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadContactListQuery() : IRequest<List<GetLeadContactListResponse>>;
|
||||
|
||||
public class GetLeadContactListHandler : IRequestHandler<GetLeadContactListQuery, List<GetLeadContactListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadContactListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetLeadContactListResponse>> Handle(GetLeadContactListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.LeadContact
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.FullName)
|
||||
.Select(x => new GetLeadContactListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
LeadId = x.LeadId,
|
||||
AutoNumber = x.AutoNumber,
|
||||
FullName = x.FullName,
|
||||
MobileNumber = x.MobileNumber,
|
||||
Email = x.Email,
|
||||
AvatarName = x.AvatarName,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class LeadContactLookupResponse
|
||||
{
|
||||
public List<LookupItem> Leads { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record GetLeadContactLookupQuery() : IRequest<LeadContactLookupResponse>;
|
||||
|
||||
public class GetLeadContactLookupHandler : IRequestHandler<GetLeadContactLookupQuery, LeadContactLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetLeadContactLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LeadContactLookupResponse> Handle(GetLeadContactLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new LeadContactLookupResponse();
|
||||
|
||||
response.Leads = await _context.Lead.AsNoTracking()
|
||||
.Select(x => new LookupItem
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Title
|
||||
}).ToListAsync(cancellationToken);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class UpdateLeadContactRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? LeadId { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? AddressStreet { get; set; }
|
||||
public string? AddressCity { get; set; }
|
||||
public string? AddressState { get; set; }
|
||||
public string? AddressZipCode { get; set; }
|
||||
public string? AddressCountry { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? FaxNumber { get; set; }
|
||||
public string? MobileNumber { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Website { get; set; }
|
||||
public string? WhatsApp { get; set; }
|
||||
public string? LinkedIn { get; set; }
|
||||
public string? Facebook { get; set; }
|
||||
public string? Twitter { get; set; }
|
||||
public string? Instagram { get; set; }
|
||||
public string? AvatarName { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateLeadContactResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateLeadContactCommand(UpdateLeadContactRequest Data) : IRequest<UpdateLeadContactResponse>;
|
||||
|
||||
public class UpdateLeadContactHandler : IRequestHandler<UpdateLeadContactCommand, UpdateLeadContactResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateLeadContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateLeadContactResponse> Handle(UpdateLeadContactCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.LeadContact
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateLeadContactResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.LeadId = request.Data.LeadId;
|
||||
entity.FullName = request.Data.FullName;
|
||||
entity.Description = request.Data.Description;
|
||||
entity.AddressStreet = request.Data.AddressStreet;
|
||||
entity.AddressCity = request.Data.AddressCity;
|
||||
entity.AddressState = request.Data.AddressState;
|
||||
entity.AddressZipCode = request.Data.AddressZipCode;
|
||||
entity.AddressCountry = request.Data.AddressCountry;
|
||||
entity.PhoneNumber = request.Data.PhoneNumber;
|
||||
entity.FaxNumber = request.Data.FaxNumber;
|
||||
entity.MobileNumber = request.Data.MobileNumber;
|
||||
entity.Email = request.Data.Email;
|
||||
entity.Website = request.Data.Website;
|
||||
entity.WhatsApp = request.Data.WhatsApp;
|
||||
entity.LinkedIn = request.Data.LinkedIn;
|
||||
entity.Facebook = request.Data.Facebook;
|
||||
entity.Twitter = request.Data.Twitter;
|
||||
entity.Instagram = request.Data.Instagram;
|
||||
entity.AvatarName = request.Data.AvatarName;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateLeadContactResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
|
||||
public class UpdateLeadContactValidator : AbstractValidator<UpdateLeadContactRequest>
|
||||
{
|
||||
public UpdateLeadContactValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("ID is required for update");
|
||||
|
||||
RuleFor(x => x.FullName)
|
||||
.NotEmpty().WithMessage("Full Name is required")
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.Email)
|
||||
.EmailAddress().When(x => !string.IsNullOrEmpty(x.Email))
|
||||
.MaximumLength(GlobalConsts.StringLengthShort);
|
||||
|
||||
RuleFor(x => x.LeadId)
|
||||
.NotEmpty().WithMessage("Lead association is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact;
|
||||
|
||||
public static class LeadContactEndpoint
|
||||
{
|
||||
public static void MapLeadContactEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/lead-contact").WithTags("LeadContacts")
|
||||
.RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser());
|
||||
|
||||
group.MapGet("/lookup", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadContactLookupQuery());
|
||||
return result.ToApiResponse("Lookup data retrieved successfully");
|
||||
})
|
||||
.WithName("GetLeadContactLookup");
|
||||
|
||||
group.MapGet("/", async (IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadContactListQuery());
|
||||
return result.ToApiResponse("Lead contact list retrieved successfully");
|
||||
})
|
||||
.WithName("GetLeadContactList");
|
||||
|
||||
group.MapGet("/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadContactByIdQuery(id));
|
||||
return result.ToApiResponse(result is not null
|
||||
? "Lead contact detail retrieved successfully"
|
||||
: $"Lead contact with ID {id} not found");
|
||||
})
|
||||
.WithName("GetLeadContactById");
|
||||
|
||||
group.MapPost("/", async (CreateLeadContactRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new CreateLeadContactCommand(request));
|
||||
return result.ToApiResponse("Lead contact has been created successfully", StatusCodes.Status201Created);
|
||||
})
|
||||
.WithName("CreateLeadContact");
|
||||
|
||||
group.MapPost("/update", async (UpdateLeadContactRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new UpdateLeadContactCommand(request));
|
||||
if (!result.Success)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Update failed. The lead contact data could not be found.");
|
||||
}
|
||||
return result.ToApiResponse("Lead contact has been updated successfully");
|
||||
})
|
||||
.WithName("UpdateLeadContact");
|
||||
|
||||
group.MapPost("/delete/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new DeleteLeadContactByIdCommand(new DeleteLeadContactByIdRequest(id)));
|
||||
if (!result)
|
||||
{
|
||||
return ((object?)null).ToApiResponse("Delete failed. The lead contact data could not be found.");
|
||||
}
|
||||
return true.ToApiResponse("Lead contact has been deleted successfully");
|
||||
})
|
||||
.WithName("DeleteLeadContactById");
|
||||
|
||||
group.MapPost("/change-avatar", async (ChangeLeadContactAvatarRequest request, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new ChangeLeadContactAvatarCommand(request));
|
||||
return result.ToApiResponse(result.Message);
|
||||
})
|
||||
.WithName("ChangeLeadContactAvatar");
|
||||
|
||||
group.MapGet("/avatar-info/{id}", async (string id, IMediator mediator) =>
|
||||
{
|
||||
var result = await mediator.Send(new GetLeadContactAvatarInfoQuery(id));
|
||||
return result.ToApiResponse(result is not null ? "Avatar info retrieved" : "Not found");
|
||||
})
|
||||
.WithName("GetLeadContactAvatarInfo");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Indotalent.ConfigBackEnd.Interfaces;
|
||||
using Indotalent.ConfigFrontEnd.Common;
|
||||
using Indotalent.Features.Pipeline.LeadContact.Cqrs;
|
||||
using Indotalent.Infrastructure.Authentication.Identity;
|
||||
using Indotalent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using RestSharp;
|
||||
|
||||
namespace Indotalent.Features.Pipeline.LeadContact;
|
||||
|
||||
public class LeadContactService : BaseService
|
||||
{
|
||||
private readonly RestClient _client;
|
||||
|
||||
public LeadContactService(
|
||||
IHttpClientFactory clientFactory,
|
||||
NavigationManager nav,
|
||||
ISnackbar snackbar,
|
||||
ICurrentUserService currentUserService,
|
||||
TokenProvider tokenProvider)
|
||||
: base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
|
||||
{
|
||||
_client = new RestClient(nav.BaseUri);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<LeadContactLookupResponse>?> GetLeadContactLookupAsync()
|
||||
{
|
||||
var request = new RestRequest("api/lead-contact/lookup", Method.Get);
|
||||
return await ExecuteWithResponseAsync<LeadContactLookupResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<List<GetLeadContactListResponse>>?> GetLeadContactListAsync()
|
||||
{
|
||||
var request = new RestRequest("api/lead-contact", Method.Get);
|
||||
return await ExecuteWithResponseAsync<List<GetLeadContactListResponse>>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetLeadContactByIdResponse>?> GetLeadContactByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/lead-contact/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetLeadContactByIdResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<CreateLeadContactResponse>?> CreateLeadContactAsync(CreateLeadContactRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/lead-contact", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<CreateLeadContactResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<UpdateLeadContactResponse>?> UpdateLeadContactAsync(UpdateLeadContactRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/lead-contact/update", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<UpdateLeadContactResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteLeadContactByIdAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/lead-contact/delete/{id}", Method.Post);
|
||||
var response = await ExecuteWithResponseAsync<object>(_client, request);
|
||||
return response?.IsSuccess ?? false;
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<ChangeLeadContactAvatarResponse>?> ChangeAvatarAsync(ChangeLeadContactAvatarRequest data)
|
||||
{
|
||||
var request = new RestRequest("api/lead-contact/change-avatar", Method.Post);
|
||||
request.AddJsonBody(data);
|
||||
return await ExecuteWithResponseAsync<ChangeLeadContactAvatarResponse>(_client, request);
|
||||
}
|
||||
|
||||
public async Task<ApiResponse<GetLeadContactAvatarInfoResponse>?> GetAvatarInfoAsync(string id)
|
||||
{
|
||||
var request = new RestRequest($"api/lead-contact/avatar-info/{id}", Method.Get);
|
||||
return await ExecuteWithResponseAsync<GetLeadContactAvatarInfoResponse>(_client, request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
@page "/pipeline"
|
||||
@using Indotalent.Features.Pipeline.Budget.Components
|
||||
@using Indotalent.Features.Pipeline.Campaign.Components
|
||||
@using Indotalent.Features.Pipeline.Expense.Components
|
||||
@using Indotalent.Features.Pipeline.Lead.Components
|
||||
@using Indotalent.Features.Pipeline.LeadActivity.Components
|
||||
@using Indotalent.Features.Pipeline.LeadContact.Components
|
||||
@using Indotalent.Features.Pipeline.SalesRepresentative.Components
|
||||
@using Indotalent.Features.Pipeline.SalesTeam.Components
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Indotalent.Infrastructure.Authorization.Identity
|
||||
@using MudBlazor
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
|
||||
@attribute [Authorize(Roles = $"{ApplicationRoles.Admin},{ApplicationRoles.Member}")]
|
||||
|
||||
<style>
|
||||
.clean-white-tabs .mud-tabs-toolbar {
|
||||
background-color: white !important;
|
||||
border-bottom: 2px solid #DCEBFA;
|
||||
border-radius: 0px !important;
|
||||
}
|
||||
|
||||
.clean-white-tabs .mud-tab {
|
||||
color: #94a3b8 !important;
|
||||
text-transform: none;
|
||||
font-weight: 500;
|
||||
min-width: 140px;
|
||||
border-radius: 0px !important;
|
||||
}
|
||||
|
||||
.clean-white-tabs .mud-tab-active {
|
||||
color: var(--mud-palette-primary) !important;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.clean-white-tabs .mud-tabs-slider {
|
||||
background-color: var(--mud-palette-primary) !important;
|
||||
height: 3px !important;
|
||||
bottom: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="mt-2 mb-8">
|
||||
<div class="clean-white-tabs">
|
||||
<MudTabs Elevation="0"
|
||||
ActivePanelIndex="@_activeTabIndex"
|
||||
ActivePanelIndexChanged="OnTabChanged"
|
||||
ApplyEffectsToContainer="true"
|
||||
TabPanelsClass="pt-4"
|
||||
ScrollButtons="ScrollButtons.Always">
|
||||
|
||||
<MudTabPanel Text="Campaign" Icon="@Icons.Material.Outlined.Campaign">
|
||||
<CampaignPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Budget" Icon="@Icons.Material.Outlined.Paid">
|
||||
<BudgetPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Expense" Icon="@Icons.Material.Outlined.ReceiptLong">
|
||||
<ExpensePage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Leads" Icon="@Icons.Material.Outlined.FilterAlt">
|
||||
<LeadPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Lead Contacts" Icon="@Icons.Material.Outlined.ContactPhone">
|
||||
<LeadContactPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Lead Activities" Icon="@Icons.Material.Outlined.EventNote">
|
||||
<LeadActivityPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Sales Team" Icon="@Icons.Material.Outlined.Groups">
|
||||
<SalesTeamPage />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Sales Rep" Icon="@Icons.Material.Outlined.Badge">
|
||||
<SalesRepresentativePage />
|
||||
</MudTabPanel>
|
||||
|
||||
</MudTabs>
|
||||
</div>
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
private int _activeTabIndex = 0;
|
||||
|
||||
private readonly Dictionary<int, string> _tabMapping = new()
|
||||
{
|
||||
{ 0, "campaign" },
|
||||
{ 1, "budget" },
|
||||
{ 2, "expense" },
|
||||
{ 3, "leads" },
|
||||
{ 4, "lead-contacts" },
|
||||
{ 5, "lead-activities" },
|
||||
{ 6, "sales-team" },
|
||||
{ 7, "sales-rep" }
|
||||
};
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
|
||||
if (Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query).TryGetValue("tab", out var tabValue))
|
||||
{
|
||||
var tabStr = tabValue.ToString().ToLower();
|
||||
var match = _tabMapping.FirstOrDefault(x => x.Value == tabStr);
|
||||
_activeTabIndex = match.Value != null ? match.Key : 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTabChanged(int index)
|
||||
{
|
||||
_activeTabIndex = index;
|
||||
_tabMapping.TryGetValue(index, out var tabName);
|
||||
|
||||
NavigationManager.NavigateTo($"/pipeline?tab={tabName ?? "campaign"}", replace: false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
@page "/pipeline/sales-representative"
|
||||
@using Indotalent.Features.Pipeline.SalesRepresentative
|
||||
@using Indotalent.Features.Pipeline.SalesRepresentative.Cqrs
|
||||
@using Indotalent.Features.Pipeline.SalesRepresentative.Components
|
||||
@using MudBlazor
|
||||
|
||||
@if (_currentView == ViewMode.Create)
|
||||
{
|
||||
<_SalesRepresentativeCreateForm OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else if (_currentView == ViewMode.Update || _currentView == ViewMode.View)
|
||||
{
|
||||
<_SalesRepresentativeUpdateForm Data="_selectedData!" ReadOnly="@(_currentView == ViewMode.View)" OnCancel="BackToTable" OnSuccess="HandleSuccess" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<_SalesRepresentativeDataTable OnAdd="() => ShowCreate()" OnEdit="(item) => ShowUpdate(item, false)" OnView="(item) => ShowUpdate(item, true)" />
|
||||
}
|
||||
|
||||
@code {
|
||||
private enum ViewMode { Table, Create, Update, View }
|
||||
private ViewMode _currentView = ViewMode.Table;
|
||||
private UpdateSalesRepresentativeRequest? _selectedData;
|
||||
private void ShowCreate() => _currentView = ViewMode.Create;
|
||||
private void ShowUpdate(UpdateSalesRepresentativeRequest data, bool isReadOnly) { _selectedData = data; _currentView = isReadOnly ? ViewMode.View : ViewMode.Update; }
|
||||
private void BackToTable() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
private void HandleSuccess() { _currentView = ViewMode.Table; _selectedData = null; }
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user