feat: add one-click nudge system with popover, throttling, and email notifications (Story 3.2)

Add NudgeController with 1-hour throttling per declaration, NudgePopover component
on declarations index and dashboard, shadcn-vue popover primitives, and per-declaration
nudge tracking. Owners/managers can nudge assigned workers with one click.
Includes 10 feature tests covering authorization, throttling, and cache invalidation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 11:26:22 +01:00
parent 1ab3cfc445
commit c7ecbd0ee7
15 changed files with 808 additions and 6 deletions

View File

@@ -34,6 +34,7 @@ class DashboardController extends Controller
'workspaceName' => null,
'roleLabel' => null,
'isWorker' => false,
'canNudge' => false,
'declarationsUrl' => null,
'clientsUrl' => null,
'viewAllAlertsUrl' => null,
@@ -50,6 +51,7 @@ class DashboardController extends Controller
abort(404);
}
$isWorker = $workspaceUser->role->is(WorkspaceUserRole::Worker);
$cacheKey = "dashboard:{$workspace->id}:{$user->id}";
$dashboardData = Cache::remember($cacheKey, 300, function () use ($workspace, $user, $workspaceUser) {
@@ -106,11 +108,11 @@ class DashboardController extends Controller
'statusLabel' => DeclarationStatus::labels()[$d->status->value] ?? $d->status->value,
'dueDate' => $d->due_date?->format('Y-m-d'),
'showUrl' => route('declarations.show', $d),
'nudgeUrl' => ! $isWorker ? route('declarations.nudge', $d) : null,
])
->all();
$roleLabel = $this->roleLabels()[$workspaceUser->role->value] ?? $workspaceUser->role->value;
$isWorker = $workspaceUser->role->is(WorkspaceUserRole::Worker);
$assigneeParam = $isWorker ? ['assignee' => $user->id] : [];
@@ -150,6 +152,7 @@ class DashboardController extends Controller
'workspaceName' => $workspace->name,
'roleLabel' => $roleLabel,
'isWorker' => $isWorker,
'canNudge' => ! $isWorker,
'declarationsUrl' => route('declarations.index'),
'clientsUrl' => route('clients.index'),
'viewAllAlertsUrl' => route('declarations.index', ['filter' => 'alerts']),

View File

@@ -76,11 +76,13 @@ class DeclarationController extends Controller
'title' => $declaration->title,
'type' => $declaration->type->value,
'client_name' => $declaration->client->company_name,
'assignee_name' => $declaration->assignee?->name,
'status' => $declaration->status->value,
'due_date' => $declaration->due_date?->format('Y-m-d'),
'showUrl' => route('declarations.show', $declaration),
'editUrl' => route('declarations.edit', $declaration),
'destroyUrl' => route('declarations.destroy', $declaration),
'nudgeUrl' => ! $isWorker ? route('declarations.nudge', $declaration) : null,
]);
return Inertia::render('declarations/Index', [
@@ -90,6 +92,7 @@ class DeclarationController extends Controller
'canCreate' => ! $isWorker,
'canEdit' => ! $isWorker,
'canDelete' => ! $isWorker,
'canNudge' => ! $isWorker,
]);
}

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Http\Controllers;
use App\Concerns\HasWorkspaceScope;
use App\Models\Declaration;
use App\Notifications\NudgeNotification;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class NudgeController extends Controller
{
use HasWorkspaceScope;
public function store(Request $request, Declaration $declaration): RedirectResponse
{
$this->authorizeWorkspaceAccess($declaration);
$workspace = $this->currentWorkspace();
$userRole = $workspace->users()
->where('users.id', $request->user()->id)
->first()
?->pivot
?->role
?->value;
if (! in_array($userRole, ['owner', 'manager'])) {
abort(404);
}
$assignee = $declaration->assignee;
if (! $assignee) {
return back()->with('flash', ['type' => 'warning', 'message' => 'Cette déclaration n\'a pas de collaborateur assigné.']);
}
$recentNudge = $assignee
->notifications()
->where('type', NudgeNotification::class)
->where('data->declaration_id', $declaration->id)
->where('created_at', '>=', now()->subHour())
->exists();
if ($recentNudge) {
return back()->with('flash', ['type' => 'warning', 'message' => 'Relance déjà envoyée récemment']);
}
$assignee->notify(new NudgeNotification($declaration, $request->user()));
activity()
->performedOn($declaration)
->causedBy($request->user())
->log('nudged');
Cache::forget("user:{$assignee->id}:workspace:{$workspace->id}:unread_notifications");
return back()->with('flash', ['type' => 'success', 'message' => 'Relance envoyée à '.$assignee->name]);
}
}