Merge branch 'dev'
This commit is contained in:
@@ -771,7 +771,38 @@ public class DashboardController : Controller
|
||||
}
|
||||
};
|
||||
|
||||
return new ShopProgressWidgetViewModel { Items = items.Where(i => i != null).Select(i => i!).ToList() };
|
||||
var vm = new ShopProgressWidgetViewModel { Items = items.Where(i => i != null).Select(i => i!).ToList() };
|
||||
|
||||
// Suppress widget if the user already dismissed it after completing all steps
|
||||
if (vm.AllDone && prefs.GuidedActivationDismissedAt.HasValue)
|
||||
return null;
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Persists the company admin's dismissal of the progress widget completion state.
|
||||
/// Sets <c>GuidedActivationDismissedAt</c> so the widget stays hidden across devices
|
||||
/// and browser sessions (localStorage alone wouldn't survive a cleared cache).
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DismissProgressWidget()
|
||||
{
|
||||
var companyId = _tenantContext.GetCurrentCompanyId();
|
||||
if (companyId == null)
|
||||
return Json(new { success = false });
|
||||
|
||||
var company = await _unitOfWork.Companies.GetByIdAsync(companyId.Value, false, c => c.Preferences!);
|
||||
if (company?.Preferences == null)
|
||||
return Json(new { success = false });
|
||||
|
||||
company.Preferences.GuidedActivationDismissedAt = DateTime.UtcNow;
|
||||
await _unitOfWork.CompleteAsync();
|
||||
|
||||
_logger.LogInformation("Progress widget dismissed for company {CompanyId}", companyId.Value);
|
||||
|
||||
return Json(new { success = true });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PowderCoating.Core.Entities;
|
||||
using PowderCoating.Core.Interfaces;
|
||||
using PowderCoating.Shared.Constants;
|
||||
using PowderCoating.Web.ViewModels.Platform;
|
||||
|
||||
namespace PowderCoating.Web.Controllers;
|
||||
|
||||
[Authorize(Policy = AppConstants.Policies.SuperAdminOnly)]
|
||||
public class OnboardingProgressController : Controller
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
|
||||
public OnboardingProgressController(IUnitOfWork unitOfWork, UserManager<ApplicationUser> userManager)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows onboarding and activation status for every tenant company. SuperAdmin-only.
|
||||
/// Reads <c>CompanyPreferences</c> fields written by the setup wizard, guided activation,
|
||||
/// and the jobs/quotes/invoices controllers to give a cross-tenant activation funnel view.
|
||||
/// </summary>
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var companies = (await _unitOfWork.Companies.GetAllAsync(
|
||||
ignoreQueryFilters: true,
|
||||
c => c.Preferences!))
|
||||
.Where(c => !c.IsDeleted)
|
||||
.OrderBy(c => c.CompanyName)
|
||||
.ToList();
|
||||
|
||||
var rows = companies.Select(c => BuildRow(c)).ToList();
|
||||
|
||||
return View(new OnboardingProgressIndexViewModel { Rows = rows });
|
||||
}
|
||||
|
||||
private static OnboardingProgressRowViewModel BuildRow(Company company)
|
||||
{
|
||||
var prefs = company.Preferences;
|
||||
var wizardDone = prefs?.SetupWizardCompleted ?? false;
|
||||
|
||||
// Mirror the same 6-step logic used in DashboardController.BuildShopProgressWidgetAsync
|
||||
// Steps: first job/quote, status history (unknown here — omit), first invoice,
|
||||
// team size (unknown here — omit), customized lookups (unknown — omit), payment defaults.
|
||||
// We track the 3 date-stamped milestones we can derive from prefs alone.
|
||||
int steps = 0;
|
||||
if (prefs?.FirstJobCreatedAt.HasValue == true || prefs?.FirstQuoteCreatedAt.HasValue == true) steps++;
|
||||
if (prefs?.FirstInvoiceCreatedAt.HasValue == true) steps++;
|
||||
if (prefs?.FirstWorkflowCompletedAt.HasValue == true) steps++;
|
||||
const int total = 3;
|
||||
|
||||
OnboardingStatus status;
|
||||
if (!wizardDone)
|
||||
status = OnboardingStatus.NotStarted;
|
||||
else if (prefs?.FirstWorkflowCompletedAt.HasValue == true && prefs.GuidedActivationDismissedAt.HasValue)
|
||||
status = OnboardingStatus.Dismissed;
|
||||
else if (prefs?.FirstWorkflowCompletedAt.HasValue == true)
|
||||
status = OnboardingStatus.Complete;
|
||||
else if (steps > 0)
|
||||
status = OnboardingStatus.InProgress;
|
||||
else
|
||||
status = OnboardingStatus.NotStarted;
|
||||
|
||||
return new OnboardingProgressRowViewModel
|
||||
{
|
||||
CompanyId = company.Id,
|
||||
CompanyName = company.CompanyName ?? "Unknown",
|
||||
WizardCompleted = wizardDone,
|
||||
OnboardingPath = prefs?.OnboardingPath,
|
||||
StepsCompleted = steps,
|
||||
TotalSteps = total,
|
||||
FirstJobCreatedAt = prefs?.FirstJobCreatedAt,
|
||||
FirstQuoteCreatedAt = prefs?.FirstQuoteCreatedAt,
|
||||
FirstInvoiceCreatedAt = prefs?.FirstInvoiceCreatedAt,
|
||||
FirstWorkflowCompletedAt = prefs?.FirstWorkflowCompletedAt,
|
||||
GuidedActivationDismissedAt = prefs?.GuidedActivationDismissedAt,
|
||||
Status = status
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace PowderCoating.Web.ViewModels.Platform;
|
||||
|
||||
public class OnboardingProgressIndexViewModel
|
||||
{
|
||||
public List<OnboardingProgressRowViewModel> Rows { get; set; } = new();
|
||||
public int TotalCompanies => Rows.Count;
|
||||
public int WizardCompleted => Rows.Count(r => r.WizardCompleted);
|
||||
public int FullyActivated => Rows.Count(r => r.Status == OnboardingStatus.Complete);
|
||||
public int InProgress => Rows.Count(r => r.Status == OnboardingStatus.InProgress);
|
||||
public int NotStarted => Rows.Count(r => r.Status == OnboardingStatus.NotStarted);
|
||||
}
|
||||
|
||||
public class OnboardingProgressRowViewModel
|
||||
{
|
||||
public int CompanyId { get; set; }
|
||||
public string CompanyName { get; set; } = string.Empty;
|
||||
public bool WizardCompleted { get; set; }
|
||||
public string? OnboardingPath { get; set; }
|
||||
public int StepsCompleted { get; set; }
|
||||
public int TotalSteps { get; set; }
|
||||
public DateTime? FirstJobCreatedAt { get; set; }
|
||||
public DateTime? FirstQuoteCreatedAt { get; set; }
|
||||
public DateTime? FirstInvoiceCreatedAt { get; set; }
|
||||
public DateTime? FirstWorkflowCompletedAt { get; set; }
|
||||
public DateTime? GuidedActivationDismissedAt { get; set; }
|
||||
public OnboardingStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public enum OnboardingStatus
|
||||
{
|
||||
NotStarted,
|
||||
InProgress,
|
||||
Complete,
|
||||
Dismissed
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
@model PowderCoating.Web.ViewModels.Platform.OnboardingProgressIndexViewModel
|
||||
@using PowderCoating.Web.ViewModels.Platform
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Onboarding Progress";
|
||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<div class="container-fluid px-4 py-3">
|
||||
<div class="d-flex align-items-center justify-content-between mb-3">
|
||||
<div>
|
||||
<h4 class="mb-0 fw-semibold">Onboarding Progress</h4>
|
||||
<p class="text-muted mb-0" style="font-size:.85rem;">Activation funnel across all tenant companies</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Summary KPI strip *@
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-6 col-md-3">
|
||||
<div class="card border-0 shadow-sm text-center py-3">
|
||||
<div class="fs-3 fw-bold">@Model.TotalCompanies</div>
|
||||
<div class="text-muted small">Total Companies</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6 col-md-3">
|
||||
<div class="card border-0 shadow-sm text-center py-3">
|
||||
<div class="fs-3 fw-bold text-primary">@Model.WizardCompleted</div>
|
||||
<div class="text-muted small">Wizard Completed</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6 col-md-3">
|
||||
<div class="card border-0 shadow-sm text-center py-3">
|
||||
<div class="fs-3 fw-bold text-success">@Model.FullyActivated</div>
|
||||
<div class="text-muted small">Fully Activated</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6 col-md-3">
|
||||
<div class="card border-0 shadow-sm text-center py-3">
|
||||
<div class="fs-3 fw-bold text-warning">@Model.InProgress</div>
|
||||
<div class="text-muted small">In Progress</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-body p-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0" id="onboardingTable">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Company</th>
|
||||
<th class="text-center">Wizard</th>
|
||||
<th>Path</th>
|
||||
<th class="text-center">Milestones</th>
|
||||
<th>First Job / Quote</th>
|
||||
<th>First Invoice</th>
|
||||
<th>Workflow Done</th>
|
||||
<th>Widget Dismissed</th>
|
||||
<th class="text-center">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var row in Model.Rows)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<a asp-controller="Companies" asp-action="Details" asp-route-id="@row.CompanyId"
|
||||
class="fw-medium text-decoration-none">@row.CompanyName</a>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@if (row.WizardCompleted)
|
||||
{
|
||||
<i class="bi bi-check-circle-fill text-success"></i>
|
||||
}
|
||||
else
|
||||
{
|
||||
<i class="bi bi-circle text-muted"></i>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (!string.IsNullOrEmpty(row.OnboardingPath))
|
||||
{
|
||||
<span class="badge bg-secondary bg-opacity-10 text-secondary">@row.OnboardingPath</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted small">—</span>
|
||||
}
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@{
|
||||
var pct = row.TotalSteps == 0 ? 0 : row.StepsCompleted * 100 / row.TotalSteps;
|
||||
var barColor = pct == 100 ? "bg-success" : "bg-primary";
|
||||
}
|
||||
<div class="d-flex align-items-center gap-2" style="min-width:80px;">
|
||||
<div class="progress flex-grow-1" style="height:5px;">
|
||||
<div class="progress-bar @barColor" style="width:@pct%"></div>
|
||||
</div>
|
||||
<span class="text-muted small" style="white-space:nowrap;">@row.StepsCompleted/@row.TotalSteps</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-muted small">
|
||||
@{
|
||||
var firstActivity = row.FirstJobCreatedAt ?? row.FirstQuoteCreatedAt;
|
||||
}
|
||||
@(firstActivity.HasValue ? firstActivity.Value.ToString("MMM d, yyyy") : "—")
|
||||
</td>
|
||||
<td class="text-muted small">
|
||||
@(row.FirstInvoiceCreatedAt.HasValue ? row.FirstInvoiceCreatedAt.Value.ToString("MMM d, yyyy") : "—")
|
||||
</td>
|
||||
<td class="text-muted small">
|
||||
@(row.FirstWorkflowCompletedAt.HasValue ? row.FirstWorkflowCompletedAt.Value.ToString("MMM d, yyyy") : "—")
|
||||
</td>
|
||||
<td class="text-muted small">
|
||||
@(row.GuidedActivationDismissedAt.HasValue ? row.GuidedActivationDismissedAt.Value.ToString("MMM d, yyyy") : "—")
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@switch (row.Status)
|
||||
{
|
||||
case OnboardingStatus.Complete:
|
||||
<span class="badge bg-success">Complete</span>
|
||||
break;
|
||||
case OnboardingStatus.InProgress:
|
||||
<span class="badge bg-warning text-dark">In Progress</span>
|
||||
break;
|
||||
case OnboardingStatus.Dismissed:
|
||||
<span class="badge bg-secondary">Dismissed</span>
|
||||
break;
|
||||
default:
|
||||
<span class="badge bg-light text-muted border">Not Started</span>
|
||||
break;
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@if (!Model.Rows.Any())
|
||||
{
|
||||
<tr>
|
||||
<td colspan="9" class="text-center text-muted py-4">No companies found.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1215,6 +1215,10 @@
|
||||
</a>
|
||||
|
||||
<div class="nav-section-title">Users & Activity</div>
|
||||
<a asp-controller="OnboardingProgress" asp-action="Index" class="nav-link">
|
||||
<i class="bi bi-rocket-takeoff"></i>
|
||||
<span>Onboarding Progress</span>
|
||||
</a>
|
||||
<a asp-controller="PlatformUsers" asp-action="Index" class="nav-link">
|
||||
<i class="bi bi-people-fill"></i>
|
||||
<span>Platform Users</span>
|
||||
|
||||
@@ -38,6 +38,14 @@
|
||||
dismiss.addEventListener('click', function () {
|
||||
widget.style.display = 'none';
|
||||
try { localStorage.setItem(DISMISSED_KEY, '1'); } catch (e) { }
|
||||
// Persist server-side so dismissal survives cache clears and other devices
|
||||
var token = document.querySelector('input[name="__RequestVerificationToken"]');
|
||||
if (token) {
|
||||
fetch('/Dashboard/DismissProgressWidget', {
|
||||
method: 'POST',
|
||||
headers: { 'RequestVerificationToken': token.value }
|
||||
}).catch(function () {});
|
||||
}
|
||||
});
|
||||
}
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user