Map API response fields to form state in getWorkOrderById

- workerOrderNumber → workOrderNumber
- assignee → assignedTo
- Format dates for date input fields
- Default empty strings for null fields
This commit is contained in:
Adam Moussa 2026-04-16 17:37:21 -04:00
parent fad2b7d661
commit cdf7477059

View file

@ -13,7 +13,22 @@ export const getWorkOrders = async (params = {}) => {
export const getWorkOrderById = async (id) => {
try {
return await workOrderApi.getById(id);
const wo = await workOrderApi.getById(id);
return {
id: wo.id,
workOrderNumber: wo.workerOrderNumber ?? wo.workOrderNumber ?? "",
title: wo.title ?? wo.workerOrderTitle ?? "",
location: wo.location ?? "",
assignedTo: wo.assignee ?? wo.assignedTo ?? "",
dueDate: wo.dueDate ? wo.dueDate.split("T")[0] : "",
createdDate: wo.createdDate ? wo.createdDate.split("T")[0] : "",
description: wo.description ?? "",
priority: wo.priority ?? "",
status: wo.status ?? "Open",
estimatedHours: wo.estimatedHours ?? "",
po: wo.po ?? "",
tt: wo.tt ?? "",
};
} catch (error) {
console.error("Error fetching work order:", error);
throw error;