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

@@ -0,0 +1,68 @@
<script setup lang="ts">
import { useForm } from '@inertiajs/vue3';
import { Send } from 'lucide-vue-next';
import { ref } from 'vue';
import { Button } from '@/components/ui/button';
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover';
type Props = {
assigneeName: string | null;
nudgeUrl: string;
};
const props = defineProps<Props>();
const open = ref(false);
const form = useForm({});
function sendNudge() {
form.post(props.nudgeUrl, {
preserveScroll: true,
onSuccess: () => {
open.value = false;
},
});
}
</script>
<template>
<Popover v-model:open="open">
<PopoverTrigger as-child>
<Button
variant="ghost"
size="icon"
class="h-8 w-8"
@click.stop
>
<Send class="h-4 w-4" />
</Button>
</PopoverTrigger>
<PopoverContent
class="w-64"
align="end"
@click.stop
>
<div class="space-y-3">
<p class="text-sm">
Envoyer une relance à
<span class="font-medium">{{
assigneeName ?? 'Non assigné'
}}</span>
</p>
<Button
class="w-full"
size="sm"
:disabled="form.processing || !assigneeName"
@click="sendNudge"
>
<Send class="mr-2 h-4 w-4" />
Envoyer une relance
</Button>
</div>
</PopoverContent>
</Popover>
</template>

View File

@@ -0,0 +1,19 @@
<script setup lang="ts">
import type { PopoverRootEmits, PopoverRootProps } from "reka-ui"
import { PopoverRoot, useForwardPropsEmits } from "reka-ui"
const props = defineProps<PopoverRootProps>()
const emits = defineEmits<PopoverRootEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>
<template>
<PopoverRoot
v-slot="slotProps"
data-slot="popover"
v-bind="forwarded"
>
<slot v-bind="slotProps" />
</PopoverRoot>
</template>

View File

@@ -0,0 +1,15 @@
<script setup lang="ts">
import type { PopoverAnchorProps } from "reka-ui"
import { PopoverAnchor } from "reka-ui"
const props = defineProps<PopoverAnchorProps>()
</script>
<template>
<PopoverAnchor
data-slot="popover-anchor"
v-bind="props"
>
<slot />
</PopoverAnchor>
</template>

View File

@@ -0,0 +1,45 @@
<script setup lang="ts">
import type { PopoverContentEmits, PopoverContentProps } from "reka-ui"
import type { HTMLAttributes } from "vue"
import { reactiveOmit } from "@vueuse/core"
import {
PopoverContent,
PopoverPortal,
useForwardPropsEmits,
} from "reka-ui"
import { cn } from "@/lib/utils"
defineOptions({
inheritAttrs: false,
})
const props = withDefaults(
defineProps<PopoverContentProps & { class?: HTMLAttributes["class"] }>(),
{
align: "center",
sideOffset: 4,
},
)
const emits = defineEmits<PopoverContentEmits>()
const delegatedProps = reactiveOmit(props, "class")
const forwarded = useForwardPropsEmits(delegatedProps, emits)
</script>
<template>
<PopoverPortal>
<PopoverContent
data-slot="popover-content"
v-bind="{ ...$attrs, ...forwarded }"
:class="
cn(
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 rounded-md border p-4 shadow-md origin-(--reka-popover-content-transform-origin) outline-hidden',
props.class,
)
"
>
<slot />
</PopoverContent>
</PopoverPortal>
</template>

View File

@@ -0,0 +1,15 @@
<script setup lang="ts">
import type { PopoverTriggerProps } from "reka-ui"
import { PopoverTrigger } from "reka-ui"
const props = defineProps<PopoverTriggerProps>()
</script>
<template>
<PopoverTrigger
data-slot="popover-trigger"
v-bind="props"
>
<slot />
</PopoverTrigger>
</template>

View File

@@ -0,0 +1,4 @@
export { default as Popover } from "./Popover.vue"
export { default as PopoverAnchor } from "./PopoverAnchor.vue"
export { default as PopoverContent } from "./PopoverContent.vue"
export { default as PopoverTrigger } from "./PopoverTrigger.vue"

View File

@@ -62,6 +62,7 @@ const breadcrumbs: BreadcrumbItem[] = [
const hasWorkspace = computed(() => !!props.workspaceName);
const showFeed = ref(false);
const nudgingIds = ref(new Set<number>());
const isWorkerEmpty = computed(
() =>
@@ -347,7 +348,21 @@ function navigateToDeclaration(declaration: DashboardDeclaration): void {
Voir
</DropdownMenuItem>
<DropdownMenuItem
disabled
v-if="canNudge"
:disabled="nudgingIds.has(declaration.id)"
@click.stop="
if (!nudgingIds.has(declaration.id)) {
nudgingIds.add(declaration.id);
router.post(
declaration.nudgeUrl,
{},
{
preserveScroll: true,
onFinish: () => nudgingIds.delete(declaration.id),
},
);
}
"
>
<Send
class="mr-2 h-4 w-4"

View File

@@ -1,6 +1,7 @@
<script setup lang="ts">
import { Head, Link, router } from '@inertiajs/vue3';
import { FolderOpen } from 'lucide-vue-next';
import NudgePopover from '@/components/declarations/NudgePopover.vue';
import Heading from '@/components/Heading.vue';
import Pagination from '@/components/Pagination.vue';
import { Button } from '@/components/ui/button';
@@ -11,11 +12,13 @@ type Declaration = {
title: string;
type: string;
client_name: string;
assignee_name: string | null;
status: string;
due_date: string | null;
showUrl: string;
editUrl: string;
destroyUrl: string;
nudgeUrl: string | null;
};
type PaginatedData<T> = {
@@ -40,6 +43,7 @@ type Props = {
canCreate: boolean;
canEdit: boolean;
canDelete: boolean;
canNudge: boolean;
};
const props = defineProps<Props>();
@@ -167,7 +171,16 @@ const statusLabels: Record<string, string> = {
<td class="px-4 py-3 text-muted-foreground">
{{ declaration.due_date || '—' }}
</td>
<td class="space-x-2 px-4 py-3 text-right">
<td
class="flex items-center gap-2 px-4 py-3 text-right"
>
<NudgePopover
v-if="props.canNudge"
:assignee-name="
declaration.assignee_name
"
:nudge-url="declaration.nudgeUrl"
/>
<Button
variant="outline"
size="sm"

View File

@@ -16,6 +16,7 @@ export type DashboardDeclaration = {
statusLabel: string;
dueDate: string | null;
showUrl: string;
nudgeUrl: string | null;
};
export type StatCardLink = {
@@ -56,6 +57,7 @@ export type DashboardProps = {
workspaceName: string | null;
roleLabel: string | null;
isWorker: boolean;
canNudge: boolean;
declarationsUrl: string | null;
clientsUrl: string | null;
viewAllAlertsUrl: string | null;