fix(ui,db): align status with backend enum
Add mapping to convert dashboard status 'submitted', 'in_progress',
'fixed' to backend values 'New', 'In Progress', 'Fixed' before sending
PATCH to /api/tickets/{id}/status.
Keep dashboard format in local state when the API returns no body.
Add debug logging for visibility during updates.
Also update fixmate.db contents; no schema changes.
This commit is contained in:
Binary file not shown.
@@ -332,12 +332,24 @@ function App(){
|
|||||||
return Array.from(s);
|
return Array.from(s);
|
||||||
}, [rawData]);
|
}, [rawData]);
|
||||||
|
|
||||||
|
// Map dashboard status format to backend enum format
|
||||||
|
const mapStatusToBackend = (dashboardStatus) => {
|
||||||
|
const statusMapping = {
|
||||||
|
'submitted': 'New',
|
||||||
|
'in_progress': 'In Progress',
|
||||||
|
'fixed': 'Fixed'
|
||||||
|
};
|
||||||
|
return statusMapping[dashboardStatus] || dashboardStatus;
|
||||||
|
};
|
||||||
|
|
||||||
const updateTicketStatus = async (reportId, newStatus) => {
|
const updateTicketStatus = async (reportId, newStatus) => {
|
||||||
try {
|
try {
|
||||||
|
const backendStatus = mapStatusToBackend(newStatus);
|
||||||
|
console.log('Updating status:', newStatus, '->', backendStatus);
|
||||||
const res = await fetch(`${BACKEND_BASE}/api/tickets/${reportId}/status`, {
|
const res = await fetch(`${BACKEND_BASE}/api/tickets/${reportId}/status`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ status: newStatus })
|
body: JSON.stringify({ status: backendStatus })
|
||||||
});
|
});
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
// Prefer using returned updated ticket if provided
|
// Prefer using returned updated ticket if provided
|
||||||
@@ -348,7 +360,7 @@ const updateTicketStatus = async (reportId, newStatus) => {
|
|||||||
setRawData(prev => prev.map(r => r.id === reportId ? normalized : r));
|
setRawData(prev => prev.map(r => r.id === reportId ? normalized : r));
|
||||||
if (selected && selected.id === reportId) setSelected(normalized);
|
if (selected && selected.id === reportId) setSelected(normalized);
|
||||||
} else {
|
} else {
|
||||||
// No body returned - update local state
|
// No body returned - update local state (keep dashboard format)
|
||||||
setRawData(prev=> prev.map(r=> r.id === reportId ? {...r, status: newStatus, updatedAt: new Date().toISOString()} : r));
|
setRawData(prev=> prev.map(r=> r.id === reportId ? {...r, status: newStatus, updatedAt: new Date().toISOString()} : r));
|
||||||
if(selected && selected.id === reportId) setSelected(prev => ({...prev, status: newStatus, updatedAt: new Date().toISOString()}));
|
if(selected && selected.id === reportId) setSelected(prev => ({...prev, status: newStatus, updatedAt: new Date().toISOString()}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user