'use client'; import { useCallback } from 'react'; import { useRouter } from 'next/navigation'; import { useAction } from 'next-safe-action/hooks'; import { formatDate } from '@kit/shared/dates'; import { Badge } from '@kit/ui/badge'; import { Button } from '@kit/ui/button'; import { toast } from '@kit/ui/sonner'; import { APPLICATION_STATUS_VARIANT, APPLICATION_STATUS_LABEL, } from '../lib/member-utils'; import { approveApplication, rejectApplication, } from '../server/actions/member-actions'; interface ApplicationWorkflowProps { applications: Array>; accountId: string; account: string; } export function ApplicationWorkflow({ applications, accountId, account, }: ApplicationWorkflowProps) { const router = useRouter(); const { execute: executeApprove, isPending: isApproving } = useAction( approveApplication, { onSuccess: ({ data }) => { if (data?.success) { toast.success('Antrag genehmigt – Mitglied wurde erstellt'); router.refresh(); } }, onError: ({ error }) => { toast.error(error.serverError ?? 'Fehler beim Genehmigen'); }, }, ); const { execute: executeReject, isPending: isRejecting } = useAction( rejectApplication, { onSuccess: ({ data }) => { if (data?.success) { toast.success('Antrag wurde abgelehnt'); router.refresh(); } }, onError: ({ error }) => { toast.error(error.serverError ?? 'Fehler beim Ablehnen'); }, }, ); const handleApprove = useCallback( (applicationId: string) => { if (!window.confirm('Mitglied wird automatisch erstellt. Fortfahren?')) { return; } executeApprove({ applicationId, accountId }); }, [executeApprove, accountId], ); const handleReject = useCallback( (applicationId: string) => { const reason = window.prompt( 'Bitte geben Sie einen Ablehnungsgrund ein:', ); if (reason === null) return; // cancelled executeReject({ applicationId, accountId, reviewNotes: reason, }); }, [executeReject, accountId], ); const isPending = isApproving || isRejecting; return (

Aufnahmeanträge

{applications.length} Antrag{applications.length !== 1 ? 'e' : ''}

{applications.length === 0 ? ( ) : ( applications.map((app) => { const appId = String(app.id ?? ''); const appStatus = String(app.status ?? 'submitted'); const isActionable = appStatus === 'submitted' || appStatus === 'review'; return ( ); }) )}
Name E-Mail Datum Status Aktionen
Keine Aufnahmeanträge vorhanden.
{String(app.last_name ?? '')},{' '} {String(app.first_name ?? '')} {String(app.email ?? '—')} {formatDate(app.created_at as string)} {APPLICATION_STATUS_LABEL[appStatus] ?? appStatus} {isActionable && (
)}
); }