feat: add bulk client notifications and email enhancements with review fixes (Stories 3.4 & 3.5)

Story 3-4: Bulk client notification scheduling — BulkNotificationController,
BulkActionBar component, checkbox selection on declarations index.

Story 3-5: Email notification enhancement — observer-driven email on
en_attente_client, cache invalidation on ferme, workspace branding on
all email templates, 11 feature tests.

Code review fixes:
- Move bulk-notify route above resource wildcard to prevent shadowing
- Add static $suppressEmail flag to prevent observer double-sending
  when DeclarationMessageController already sends the email
- Fix canBulkNotify logic (was granting workers access)
- Add WorkspaceUserRole check to BulkNotifyRequest::authorize()
- Replace firstOrCreate with explicit invitation lookup that syncs
  client email and handles used/expired invitations correctly
- Watch declarations.data instead of current_page to clear selection
  on filter/sort changes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 14:31:36 +01:00
parent 32e11db2b5
commit 1d4f3bcd0f
17 changed files with 1384 additions and 7 deletions

View File

@@ -1,10 +1,13 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { Head, Link, router } from '@inertiajs/vue3';
import { FolderOpen } from 'lucide-vue-next';
import BulkActionBar from '@/components/declarations/BulkActionBar.vue';
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';
import { Checkbox } from '@/components/ui/checkbox';
import AppLayout from '@/layouts/AppLayout.vue';
type Declaration = {
@@ -44,10 +47,61 @@ type Props = {
canEdit: boolean;
canDelete: boolean;
canNudge: boolean;
bulkNotifyUrl?: string;
canBulkNotify?: boolean;
};
const props = defineProps<Props>();
const selectedIds = ref<number[]>([]);
watch(() => props.declarations.data, () => {
selectedIds.value = [];
});
const eligibleDeclarations = computed(() =>
props.declarations.data.filter(
(d) => d.status === 'en_attente_client',
),
);
const allEligibleSelected = computed(
() =>
eligibleDeclarations.value.length > 0 &&
eligibleDeclarations.value.every((d) =>
selectedIds.value.includes(d.id),
),
);
function toggleSelectAll(checked: boolean | 'indeterminate') {
if (checked === true) {
const eligibleIds = eligibleDeclarations.value.map((d) => d.id);
const merged = new Set([...selectedIds.value, ...eligibleIds]);
selectedIds.value = [...merged];
} else {
const eligibleIds = new Set(
eligibleDeclarations.value.map((d) => d.id),
);
selectedIds.value = selectedIds.value.filter(
(id) => !eligibleIds.has(id),
);
}
}
function toggleRow(id: number, checked: boolean | 'indeterminate') {
if (checked === true) {
if (!selectedIds.value.includes(id)) {
selectedIds.value = [...selectedIds.value, id];
}
} else {
selectedIds.value = selectedIds.value.filter((i) => i !== id);
}
}
function clearSelection() {
selectedIds.value = [];
}
function destroy(declaration: Declaration) {
if (
window.confirm(
@@ -80,6 +134,8 @@ const statusLabels: Record<string, string> = {
closed: 'Clôturé',
cancelled: 'Annulé',
};
const columnCount = computed(() => (props.canBulkNotify ? 7 : 6));
</script>
<template>
@@ -107,6 +163,18 @@ const statusLabels: Record<string, string> = {
class="border-b border-sidebar-border/70 bg-muted/50"
>
<tr>
<th
v-if="props.canBulkNotify"
class="h-10 w-10 px-4 text-center align-middle"
>
<Checkbox
:checked="allEligibleSelected"
:disabled="
eligibleDeclarations.length === 0
"
@update:checked="toggleSelectAll"
/>
</th>
<th
class="h-10 px-4 text-left align-middle font-medium"
>
@@ -145,6 +213,26 @@ const statusLabels: Record<string, string> = {
:key="declaration.id"
class="border-b border-sidebar-border/50 last:border-0"
>
<td
v-if="props.canBulkNotify"
class="px-4 py-3 text-center"
>
<Checkbox
v-if="
declaration.status ===
'en_attente_client'
"
:checked="
selectedIds.includes(
declaration.id,
)
"
@update:checked="
(v: boolean | 'indeterminate') =>
toggleRow(declaration.id, v)
"
/>
</td>
<td class="px-4 py-3 font-medium">
<Link
:href="declaration.showUrl"
@@ -212,7 +300,7 @@ const statusLabels: Record<string, string> = {
</tr>
<tr v-if="!declarations.data.length">
<td
colspan="6"
:colspan="columnCount"
class="px-4 py-8 text-center text-muted-foreground"
>
<div
@@ -246,5 +334,12 @@ const statusLabels: Record<string, string> = {
}"
/>
</div>
<BulkActionBar
v-if="props.canBulkNotify && props.bulkNotifyUrl"
:selected-ids="selectedIds"
:bulk-notify-url="props.bulkNotifyUrl"
@clear="clearSelection"
/>
</AppLayout>
</template>