import React, { useState } from 'react' import { router, usePage } from '@inertiajs/react' import StudioLayout from '../../Layouts/StudioLayout' import { studioSurface, trackStudioEvent } from '../../utils/studioEvents' async function requestJson(url, method = 'POST') { const response = await fetch(url, { method, credentials: 'same-origin', headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || '', 'X-Requested-With': 'XMLHttpRequest', }, }) const payload = await response.json().catch(() => ({})) if (!response.ok) { throw new Error(payload?.message || 'Request failed') } return payload } function formatDate(value) { if (!value) return 'Unknown' const date = new Date(value) if (Number.isNaN(date.getTime())) return 'Unknown' return date.toLocaleString(undefined, { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) } export default function StudioActivity() { const { props } = usePage() const listing = props.listing || {} const filters = listing.filters || {} const items = listing.items || [] const meta = listing.meta || {} const summary = listing.summary || {} const typeOptions = listing.type_options || [] const moduleOptions = listing.module_options || [] const endpoints = props.endpoints || {} const [marking, setMarking] = useState(false) const updateFilters = (patch) => { const next = { ...filters, ...patch } if (patch.page == null) next.page = 1 trackStudioEvent('studio_activity_opened', { surface: studioSurface(), module: 'activity', meta: patch, }) router.get(window.location.pathname, next, { preserveScroll: true, preserveState: true, replace: true, }) } const markAllRead = async () => { setMarking(true) try { await requestJson(endpoints.markAllRead) router.reload({ only: ['listing'] }) } catch (error) { window.alert(error?.message || 'Unable to mark activity as read.') } finally { setMarking(false) } } return ( {marking ? 'Updating...' : 'Mark all read'} } >
New since last read
{Number(summary.new_items || 0).toLocaleString()}
Unread notifications
{Number(summary.unread_notifications || 0).toLocaleString()}
Last inbox reset
{summary.last_read_at ? formatDate(summary.last_read_at) : 'Not yet'}
{items.length > 0 ? items.map((item) => (
{item.actor?.avatar_url ? ( {item.actor.name ) : (
)}
{item.module_label} {formatDate(item.created_at)} {item.is_new && New}

{item.title}

{item.body}

{item.actor?.name && {item.actor.name}} Open
)) :
No activity matches this filter.
}
Page {meta.current_page || 1} of {meta.last_page || 1}
) }