import { Link, useOutletContext, useSearchParams } from 'react-router-dom' import { hasRole } from '../../shared/enums.ts' import { OverdueBadge } from '../components/Badges' import { ActionStatusControl } from '../components/incident/ActionsSection' import { Page } from '../components/Page' import { PageIntro } from '../components/PageIntro' import { Empty, ErrorMessage, Loading } from '../components/QueryState' import { panel } from '../components/styles' import { useI18n } from '../i18n' import { useActions, useUpdateAction, type Me } from '../lib/queries' const filters = [ { value: 'open', label: 'filterOpen' }, { value: 'overdue', label: 'filterOverdue' }, { value: 'done', label: 'filterDone' }, { value: 'all', label: 'filterAll' }, ] as const const tab = (active: boolean) => `rounded-[5px] px-3 py-1.5 text-2xs font-semibold ${active ? 'bg-forest-950 text-white' : 'text-muted hover:bg-white hover:text-ink'}` export function Actions() { const me = useOutletContext() const { t, formatDay } = useI18n() const [params, setParams] = useSearchParams() const canSeeAll = hasRole(me.user.role, 'supervisor') const scope = canSeeAll && params.get('scope') === 'all' ? 'all' : 'mine' const filter = filters.find((f) => f.value === params.get('filter'))?.value ?? 'open' const actions = useActions(scope, filter) const update = useUpdateAction() const set = (key: string, value: string) => { const next = new URLSearchParams(params) next.set(key, value) setParams(next, { replace: true }) } return (
{filters.map((f) => ( ))}
{canSeeAll && (
)}
{actions.isPending ? ( ) : !actions.data?.length ? ( {filter === 'open' ? t.actions.nothingOpen : t.actions.none} ) : (
    {actions.data.map((action) => (
  • {action.title}

    {action.incident.reference} {' '} {action.incident.title} {scope === 'all' && ` ยท ${action.assignee?.name ?? t.actions.unassigned}`}

    {action.overdue && } {action.dueDate ? t.actions.due(formatDay(action.dueDate)) : t.actions.noDueDate} update.mutate({ id: action.id, status })} />
  • ))}
)}
) }