notifications fixed
This commit is contained in:
parent
5f879c9436
commit
ad8e0d5cee
|
|
@ -36,6 +36,6 @@ public function __invoke(Request $request)
|
|||
]
|
||||
);
|
||||
|
||||
return response()->json(['status' => 'ok']);
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,15 @@ public function unread(Request $request)
|
|||
->select(['id', 'due_date', 'amount', 'contract_id', 'client_case_id', 'created_at'])
|
||||
->whereNotNull('due_date')
|
||||
->whereDate('due_date', '<=', $today)
|
||||
// Removed per-user unread filter: show notifications regardless of individual reads
|
||||
// Exclude activities that have been marked as read by this user
|
||||
->whereNotExists(function ($q) use ($user, $today) {
|
||||
$q->select(\DB::raw(1))
|
||||
->from('activity_notification_reads')
|
||||
->whereColumn('activity_notification_reads.activity_id', 'activities.id')
|
||||
->where('activity_notification_reads.user_id', $user->id)
|
||||
->whereDate('activity_notification_reads.due_date', '<=', $today)
|
||||
->whereNotNull('activity_notification_reads.read_at');
|
||||
})
|
||||
->when($clientCaseIdsForFilter->isNotEmpty(), function ($q) use ($clientCaseIdsForFilter) {
|
||||
// Filter by clients: activities directly on any of the client's cases OR via contracts under those cases
|
||||
$q->where(function ($qq) use ($clientCaseIdsForFilter) {
|
||||
|
|
@ -108,7 +116,15 @@ public function unread(Request $request)
|
|||
->select(['contract_id', 'client_case_id'])
|
||||
->whereNotNull('due_date')
|
||||
->whereDate('due_date', '<=', $today)
|
||||
// Removed per-user unread filter for client list base
|
||||
// Exclude activities that have been marked as read by this user
|
||||
->whereNotExists(function ($q) use ($user, $today) {
|
||||
$q->select(\DB::raw(1))
|
||||
->from('activity_notification_reads')
|
||||
->whereColumn('activity_notification_reads.activity_id', 'activities.id')
|
||||
->where('activity_notification_reads.user_id', $user->id)
|
||||
->whereDate('activity_notification_reads.due_date', '<=', $today)
|
||||
->whereNotNull('activity_notification_reads.read_at');
|
||||
})
|
||||
->when($clientCaseIdsForFilter->isNotEmpty(), function ($q) use ($clientCaseIdsForFilter) {
|
||||
$q->where(function ($qq) use ($clientCaseIdsForFilter) {
|
||||
$qq->whereIn('activities.client_case_id', $clientCaseIdsForFilter)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script setup>
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { usePage, Link } from "@inertiajs/vue3";
|
||||
import { usePage, Link, router } from "@inertiajs/vue3";
|
||||
import Dropdown from "@/Components/Dropdown.vue";
|
||||
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
||||
import { faBell } from "@fortawesome/free-solid-svg-icons";
|
||||
|
|
@ -53,7 +53,7 @@ watch(
|
|||
}
|
||||
);
|
||||
|
||||
async function markRead(item) {
|
||||
function markRead(item) {
|
||||
const idx = items.value.findIndex((i) => i.id === item.id);
|
||||
if (idx === -1) {
|
||||
return;
|
||||
|
|
@ -62,14 +62,20 @@ async function markRead(item) {
|
|||
// Optimistically remove
|
||||
const removed = items.value.splice(idx, 1)[0];
|
||||
|
||||
try {
|
||||
await window.axios.post(route("notifications.activity.read"), {
|
||||
activity_id: item.id,
|
||||
});
|
||||
} catch (e) {
|
||||
router.patch(
|
||||
route("notifications.activity.read"),
|
||||
{ activity_id: item.id },
|
||||
{
|
||||
onSuccess: () => {
|
||||
// Item successfully marked as read
|
||||
},
|
||||
onError: () => {
|
||||
// Rollback on failure
|
||||
items.value.splice(idx, 0, removed);
|
||||
},
|
||||
preserveScroll: true
|
||||
}
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -67,11 +67,14 @@ watch(selectedClient, (val) => {
|
|||
});
|
||||
});
|
||||
|
||||
async function markRead(id) {
|
||||
try {
|
||||
await window.axios.post(route("notifications.activity.read"), { activity_id: id });
|
||||
router.reload({ only: ["activities"] });
|
||||
} catch (e) {}
|
||||
function markRead(id) {
|
||||
router.patch(route("notifications.activity.read"),
|
||||
{ activity_id: id },
|
||||
{
|
||||
only: ["activities"],
|
||||
preserveScroll: true
|
||||
}
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -358,7 +358,7 @@
|
|||
|
||||
// Notifications: unread list and mark one activity as read (today)
|
||||
Route::get('notifications/unread', [NotificationController::class, 'unread'])->name('notifications.unread');
|
||||
Route::post('notifications/activity/read', ActivityNotificationController::class)->name('notifications.activity.read');
|
||||
Route::patch('notifications/activity/read', ActivityNotificationController::class)->name('notifications.activity.read');
|
||||
Route::delete('contracts/{contract:uuid}/documents/{document:uuid}', [ClientCaseContoller::class, 'deleteContractDocument'])->name('contract.document.delete');
|
||||
// settings
|
||||
Route::get('settings', [SettingController::class, 'index'])->name('settings');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user