feat: Add InterestDuplicateNotificationBanner for sales/admin users and implement duplicate detection logic
This commit is contained in:
96
components/InterestDuplicateNotificationBanner.vue
Normal file
96
components/InterestDuplicateNotificationBanner.vue
Normal file
@@ -0,0 +1,96 @@
|
||||
<template>
|
||||
<v-alert
|
||||
v-if="showBanner && duplicateCount > 0"
|
||||
type="warning"
|
||||
variant="tonal"
|
||||
closable
|
||||
@click:close="dismissBanner"
|
||||
class="ma-4"
|
||||
>
|
||||
<template #prepend>
|
||||
<v-icon>mdi-content-duplicate</v-icon>
|
||||
</template>
|
||||
|
||||
<div class="d-flex align-center justify-space-between">
|
||||
<div>
|
||||
<div class="text-subtitle-1 font-weight-medium">
|
||||
{{ duplicateCount }} duplicate interest record{{ duplicateCount > 1 ? 's' : '' }} detected
|
||||
</div>
|
||||
<div class="text-body-2">
|
||||
Duplicate interest records can affect data integrity and client communication.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<v-btn
|
||||
color="warning"
|
||||
variant="elevated"
|
||||
size="small"
|
||||
:to="'/dashboard/admin/duplicates'"
|
||||
prepend-icon="mdi-wrench"
|
||||
>
|
||||
Clean Up Duplicates
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-alert>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const { hasRole } = useAuthorization();
|
||||
|
||||
const showBanner = ref(true);
|
||||
const duplicateCount = ref(0);
|
||||
const loading = ref(false);
|
||||
|
||||
// Check for duplicates on mount (sales/admin users)
|
||||
const checkForDuplicates = async () => {
|
||||
if (loading.value) return;
|
||||
|
||||
// Only check for users with sales or admin role
|
||||
const canViewDuplicates = await hasRole(['sales', 'admin']);
|
||||
if (!canViewDuplicates) return;
|
||||
|
||||
try {
|
||||
loading.value = true;
|
||||
const response = await $fetch('/api/interests/duplicates/find', {
|
||||
method: 'GET',
|
||||
query: {
|
||||
threshold: 0.8,
|
||||
dateRange: 365 // Check last year
|
||||
}
|
||||
});
|
||||
|
||||
if (response.success && response.data?.duplicateGroups) {
|
||||
duplicateCount.value = response.data.duplicateGroups.length;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[InterestDuplicateNotification] Failed to check for duplicates:', error);
|
||||
// Silently fail - this is just a notification banner
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Dismiss the banner for this session
|
||||
const dismissBanner = () => {
|
||||
showBanner.value = false;
|
||||
// Store dismissal in session storage
|
||||
if (process.client) {
|
||||
sessionStorage.setItem('interest-duplicates-banner-dismissed', 'true');
|
||||
}
|
||||
};
|
||||
|
||||
// Check if banner was already dismissed this session
|
||||
onMounted(() => {
|
||||
if (process.client) {
|
||||
const dismissed = sessionStorage.getItem('interest-duplicates-banner-dismissed');
|
||||
if (dismissed === 'true') {
|
||||
showBanner.value = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for duplicates for sales/admin users
|
||||
// Small delay to let other components load first
|
||||
setTimeout(checkForDuplicates, 2000);
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user