fix(tickets): refresh status and resources in detail panel after update
Status update was returning only new_status (string) and the parent list's onStatusUpdated only set status_name. The <select> was bound to status_id, which never changed — so it visually reverted to the old status even though the PATCH succeeded. - Backend: include new_status_id in the status-update response. - Panel: own currentStatusId/currentStatusName state so the select reflects the change immediately and survives stale parent snapshots. - Parent list: update status_id on both the row and selectedTicket so the list row stays in sync when the panel stays open. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,11 +6,13 @@ import type { PSATicketStatusUpdate } from '@/types/tickets'
|
||||
|
||||
interface Props {
|
||||
ticket: PSATicketSearchResult
|
||||
currentStatusId: number | null
|
||||
currentStatusName: string | null
|
||||
statuses: PSATicketStatusItem[]
|
||||
onStatusUpdated: (ticketId: number, newStatus: string) => void
|
||||
onStatusUpdated: (ticketId: number, newStatus: string, newStatusId: number) => void
|
||||
}
|
||||
|
||||
export function TicketDetailHeader({ ticket, statuses, onStatusUpdated }: Props) {
|
||||
export function TicketDetailHeader({ ticket, currentStatusId, currentStatusName, statuses, onStatusUpdated }: Props) {
|
||||
const [updating, setUpdating] = useState(false)
|
||||
|
||||
async function handleStatusChange(statusId: number) {
|
||||
@@ -18,7 +20,7 @@ export function TicketDetailHeader({ ticket, statuses, onStatusUpdated }: Props)
|
||||
setUpdating(true)
|
||||
try {
|
||||
const result: PSATicketStatusUpdate = await ticketsApi.updateStatus(Number(ticket.id), statusId)
|
||||
onStatusUpdated(result.ticket_id, result.new_status)
|
||||
onStatusUpdated(result.ticket_id, result.new_status, result.new_status_id)
|
||||
toast.success(`Status updated to ${result.new_status}`)
|
||||
} catch {
|
||||
toast.error('Failed to update status')
|
||||
@@ -48,7 +50,7 @@ export function TicketDetailHeader({ ticket, statuses, onStatusUpdated }: Props)
|
||||
{statuses.length > 0 ? (
|
||||
<select
|
||||
disabled={updating}
|
||||
value={ticket.status_id ?? ''}
|
||||
value={currentStatusId ?? ''}
|
||||
onChange={e => handleStatusChange(Number(e.target.value))}
|
||||
className="bg-input border border-default rounded-[5px] px-2 py-1 text-xs text-primary focus:border-accent focus:outline-none"
|
||||
>
|
||||
@@ -57,9 +59,9 @@ export function TicketDetailHeader({ ticket, statuses, onStatusUpdated }: Props)
|
||||
))}
|
||||
</select>
|
||||
) : (
|
||||
ticket.status_name && (
|
||||
currentStatusName && (
|
||||
<span className="px-2 py-0.5 bg-elevated rounded text-xs text-muted-foreground">
|
||||
{ticket.status_name}
|
||||
{currentStatusName}
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user