Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 3x 3x 3x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 1x 1x 1x 1x 1x 21x 21x 21x 21x 21x 21x 21x 21x 1x 1x 1x 1x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 21x 21x 21x 21x 21x 21x 21x | import { useMemo } from 'react';
import { useAuth } from '@/contexts/AuthContext';
import type { AdminParticipationFilters } from '@/models/admin';
import { listAdminParticipations } from '@/services/adminService';
import { useAdminListViewModel } from '@/viewmodels/admin/useAdminListViewModel';
import { useAdminParticipationActionsViewModel } from '@/viewmodels/admin/useAdminParticipationActionsViewModel';
import { BackofficeIdCell, BackofficePageShell, BackofficePagination, BackofficeStatusPill, BackofficeTableState, formatAdminDate } from './BackofficeListParts';
const INITIAL_FILTERS: AdminParticipationFilters = {
q: '',
status: undefined,
event_id: '',
user_id: '',
created_from: '',
created_to: '',
};
export default function ParticipationsAdminPage() {
const { token } = useAuth();
const initialFilters = useMemo(() => INITIAL_FILTERS, []);
const vm = useAdminListViewModel({ token, initialFilters, fetchPage: listAdminParticipations });
const actions = useAdminParticipationActionsViewModel(token, vm.retry);
return (
<BackofficePageShell
title="Participations"
subtitle="Review user-event participation rows and current lifecycle status."
filters={(
<>
<input aria-label="Search participations" placeholder="Search event or user" value={vm.filters.q ?? ''} onChange={(event) => vm.setFilter('q', event.target.value)} />
<select aria-label="Participation status" value={vm.filters.status ?? ''} onChange={(event) => vm.setFilter('status', event.target.value === '' ? undefined : event.target.value as AdminParticipationFilters['status'])}>
<option value="">Any status</option>
<option value="APPROVED">APPROVED</option>
<option value="PENDING">PENDING</option>
<option value="CANCELED">CANCELED</option>
<option value="LEAVED">LEAVED</option>
</select>
<input aria-label="Event ID" placeholder="Event ID" value={vm.filters.event_id ?? ''} onChange={(event) => vm.setFilter('event_id', event.target.value)} />
<input aria-label="User ID" placeholder="User ID" value={vm.filters.user_id ?? ''} onChange={(event) => vm.setFilter('user_id', event.target.value)} />
<input aria-label="Created from" type="datetime-local" value={vm.filters.created_from ?? ''} onChange={(event) => vm.setFilter('created_from', event.target.value)} />
<input aria-label="Created to" type="datetime-local" value={vm.filters.created_to ?? ''} onChange={(event) => vm.setFilter('created_to', event.target.value)} />
<button type="button" onClick={vm.applyFilters}>Apply</button>
<button type="button" className="bo-secondary-button" onClick={vm.clearFilters}>Clear</button>
</>
)}
>
<form
className="bo-action-form bo-participation-form"
onSubmit={(event) => {
event.preventDefault();
void actions.submitCreate();
}}
>
<label className="bo-field">
<span>Event ID</span>
<input
aria-label="Manual event ID"
value={actions.createForm.eventId}
onChange={(event) => actions.setCreateField('eventId', event.target.value)}
/>
{actions.createErrors.eventId && <strong>{actions.createErrors.eventId}</strong>}
</label>
<label className="bo-field">
<span>User ID</span>
<input
aria-label="Manual user ID"
value={actions.createForm.userId}
onChange={(event) => actions.setCreateField('userId', event.target.value)}
/>
{actions.createErrors.userId && <strong>{actions.createErrors.userId}</strong>}
</label>
<label className="bo-field bo-field-wide">
<span>Reason</span>
<input
aria-label="Manual participation reason"
value={actions.createForm.reason}
onChange={(event) => actions.setCreateField('reason', event.target.value)}
placeholder="Optional admin note"
/>
</label>
{actions.createError && <div className="bo-state bo-state-error bo-inline-state">{actions.createError}</div>}
{actions.createResult && (
<div className="bo-result" role="status">
<span>Created participation: {actions.createResult.participation_id}</span>
<span>Status: {actions.createResult.status}</span>
{actions.createResult.ticket_status && <span>Ticket: {actions.createResult.ticket_status}</span>}
</div>
)}
<div className="bo-form-actions">
<button type="submit" disabled={actions.isCreating}>
{actions.isCreating ? 'Creating...' : 'Create approved participation'}
</button>
</div>
</form>
{actions.cancelError && <div className="bo-state bo-state-error">{actions.cancelError}</div>}
{actions.cancelResult && (
<div className="bo-result" role="status">
<span>Canceled participation: {actions.cancelResult.participation_id}</span>
<span>{actions.cancelResult.already_canceled ? 'Already canceled' : 'Status updated'}</span>
</div>
)}
<BackofficeTableState isLoading={vm.isLoading} error={vm.error} empty={vm.items.length === 0} onRetry={vm.retry} />
<div className="bo-table-wrap">
<table className="bo-table">
<thead>
<tr>
<th>ID</th>
<th>Event</th>
<th>User</th>
<th>Email</th>
<th>Status</th>
<th>Reconfirmed</th>
<th>Created</th>
<th>Updated</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{vm.items.map((participation) => {
const cancelable = participation.status === 'APPROVED' || participation.status === 'PENDING';
return (
<tr key={participation.id}>
<td><BackofficeIdCell id={participation.id} /></td>
<td>{participation.event_title}</td>
<td>{participation.username}</td>
<td>{participation.user_email}</td>
<td><BackofficeStatusPill status={participation.status} /></td>
<td>{formatAdminDate(participation.reconfirmed_at)}</td>
<td>{formatAdminDate(participation.created_at)}</td>
<td>{formatAdminDate(participation.updated_at)}</td>
<td>
<button
type="button"
className="bo-row-action"
disabled={!cancelable || actions.cancelingId === participation.id}
onClick={() => void actions.cancelParticipation(participation.id)}
>
{actions.cancelingId === participation.id ? 'Canceling...' : 'Cancel'}
</button>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
<BackofficePagination {...vm} onPrevious={vm.previousPage} onNext={vm.nextPage} onLimitChange={vm.changeLimit} />
</BackofficePageShell>
);
}
|