initial commit
This commit is contained in:
@@ -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" 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;">
|
||||
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-color: 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-color: white; border: 1px solid #D1D5DB;">Edit</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="OnDelete" Size="Size.Small" Style="background: white; border: 1px solid #FCA5A5; color: #EF4444; text-transform: none; font-weight: 500; border-radius: 6px;">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 Class="mud-table-styled" Striped="true" 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; letter-spacing: 0.05em;"></MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap; letter-spacing: 0.05em;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadContactListResponse, object>(x => x.FullName!)">Contact Name</MudTableSortLabel>
|
||||
</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap; letter-spacing: 0.05em;">
|
||||
<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; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap; letter-spacing: 0.05em;">Mobile</MudTh>
|
||||
<MudTh Style="font-weight: 600; color: #6B7280; text-transform: uppercase; font-size: 0.6875rem; background-color: #F9FAFB; border-bottom: 1px solid #E5E7EB; white-space: nowrap; letter-spacing: 0.05em;">
|
||||
<MudTableSortLabel SortBy="new Func<GetLeadContactListResponse, object>(x => x.Email!)">Email</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>
|
||||
<div class="d-flex align-center gap-2">
|
||||
<MudAvatar Color="Color.Info" Variant="Variant.Filled" Size="Size.Small" Style="border-radius: 50%; font-size: 10px; font-weight: 600;">
|
||||
@context.FullName.ToInitial()
|
||||
</MudAvatar>
|
||||
<MudText Typo="Typo.body2" Style="font-weight: 500;">@context.FullName</MudText>
|
||||
</div>
|
||||
</MudTd>
|
||||
<MudTd><MudChip T="string" Size="Size.Small" Color="Color.Info" Variant="Variant.Text" Style="border-radius: 6px; font-weight: 500;">@context.AutoNumber</MudChip></MudTd>
|
||||
<MudTd>@context.MobileNumber</MudTd>
|
||||
<MudTd>@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="color: #9CA3AF; font-size: 0.75rem; font-weight: 500;">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 ? "background: transparent; color: #D1D5DB; border: none;" : "background-color: white; border: 1px solid #D1D5DB; color: #6B7280; 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 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")">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 ? "text-transform: none; font-weight: 500; color: #D1D5DB;" : "text-transform: none; font-weight: 500; color: #6B7280; background: white; border: 1px solid #D1D5DB; border-radius: 6px;")">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: transparent; color: #D1D5DB; border: none;" : "background-color: white; border: 1px solid #D1D5DB; color: #6B7280; 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user