import React, { useState } from 'react' import { p as P, BottomDialog, pInput as PInput } from 'web-components' import { trpc } from '@/lib/trpc-client' import { TriangleAlert, Info, Plus, Calendar, User, ShoppingCart, CircleCheck } from 'lucide-react' import dayjs from 'dayjs' function UserIncidentDialog({ userId, orderId, open, onClose, onSuccess }: { userId: number orderId: number | null open: boolean onClose: () => void onSuccess?: () => void }) { const [adminComment, setAdminComment] = useState('') const [negativityScore, setNegativityScore] = useState('') const addIncidentMutation = trpc.admin.user.addUserIncident.useMutation({ onSuccess: () => { window.alert('Success: Incident added successfully') setAdminComment('') setNegativityScore('') onClose() onSuccess?.() }, onError: (error: any) => { window.alert(`Error: ${error.message || 'Failed to add incident'}`) }, }) const handleAddIncident = () => { const score = negativityScore ? parseInt(negativityScore) : undefined if (!adminComment.trim() && !negativityScore) { window.alert('Error: Please enter a comment or negativity score') return } addIncidentMutation.mutate({ userId, orderId: orderId || undefined, adminComment: adminComment || undefined, negativityScore: score, }) } return (

Add User Incident

Record an incident for this user. This will be visible in their profile.

setAdminComment(e.target.value)} placeholder="Enter details about the incident..." multiline className="h-24" /> setNegativityScore(e.target.value)} placeholder="0" type="number" inputMode="numeric" className="mt-4" />

Higher negativity scores indicate more serious incidents (e.g., repeated cancellations, abusive behavior).

) } export function UserIncidentsView({ userId, orderId }: { userId: number; orderId: number | null }) { const [incidentDialogOpen, setIncidentDialogOpen] = useState(false) const { data: incidentsData, refetch: refetchIncidents } = trpc.admin.user.getUserIncidents.useQuery( { userId }, { enabled: !!userId } ) return ( <>

User Incidents

{incidentsData?.incidents && incidentsData.incidents.length > 0 ? (
{incidentsData.incidents.map((incident: any, index: number) => (

{dayjs(incident.dateAdded).format('MMM DD, YYYY • h:mm A')}

{incident.negativityScore && (

Score: {incident.negativityScore}

)}
{incident.adminComment && (

{incident.adminComment}

)}

Added by {incident.addedBy}

{incident.orderId && ( <>

Order #{incident.orderId}

)}
))}
) : (

No incidents recorded for this user

)}
setIncidentDialogOpen(false)} onSuccess={refetchIncidents} /> ) }