mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 06:53:24 +00:00
- Click the status badge to open a dropdown with all status options - Status change calls ChangeStatus API and updates locally - Color-coded status dots in the dropdown menu - Closes on outside click - Also logged in audit trail via backend ChangeStatus endpoint
93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
import { workOrderApi } from "../../services/api";
|
|
import { post } from "../../apiUtil";
|
|
import { API_URL } from "../../constants";
|
|
|
|
export const getWorkOrders = async (params = {}) => {
|
|
try {
|
|
const response = await workOrderApi.getAll(params);
|
|
const workOrders = response.data || response;
|
|
return Array.isArray(workOrders) ? workOrders : [];
|
|
} catch (error) {
|
|
console.error("Error fetching work orders:", error);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const getWorkOrderById = async (id) => {
|
|
try {
|
|
const wo = await workOrderApi.getById(id);
|
|
return {
|
|
id: wo.id,
|
|
workOrderNumber: wo.workerOrderNumber ?? wo.workOrderNumber ?? "",
|
|
title: wo.title ?? wo.workerOrderTitle ?? "",
|
|
location: wo.location ?? "",
|
|
locationId: wo.locationId != null ? String(wo.locationId) : "",
|
|
assignedTo: wo.assignee ?? wo.assignedTo ?? "",
|
|
dueDate: wo.dueDate ? wo.dueDate.split("T")[0] : "",
|
|
createdDate: wo.createdDate ? wo.createdDate.split("T")[0] : "",
|
|
createdDateFull: wo.createdDate ?? "",
|
|
description: wo.description ?? "",
|
|
priority: wo.priority ?? "",
|
|
status: wo.status ?? "Open",
|
|
po: wo.po ?? "",
|
|
tt: wo.tt ?? "",
|
|
comments: wo.comments ?? [],
|
|
auditLog: wo.auditLog ?? [],
|
|
};
|
|
} catch (error) {
|
|
console.error("Error fetching work order:", error);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const addWorkOrder = async (workOrder) => {
|
|
try {
|
|
return await workOrderApi.create(workOrder);
|
|
} catch (error) {
|
|
console.error("Error creating work order:", error);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const editWorkOrder = async (workOrder) => {
|
|
try {
|
|
return await workOrderApi.update(workOrder.id, {
|
|
Id: workOrder.id,
|
|
WorkerOrderNumber: workOrder.workOrderNumber,
|
|
WorkerOrderTitle: workOrder.title,
|
|
Description: workOrder.description,
|
|
PO: workOrder.po,
|
|
TT: workOrder.tt,
|
|
AssignTo: workOrder.assignedTo || null,
|
|
DueDate: workOrder.dueDate || null,
|
|
Priority: workOrder.priority || null,
|
|
Status: workOrder.status,
|
|
LocationId: workOrder.locationId ? parseInt(workOrder.locationId) : null,
|
|
});
|
|
} catch (error) {
|
|
console.error("Error updating work order:", error);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const addComment = async (workOrderId, text, commentType = "internal") => {
|
|
return post(`${API_URL}/WorkOrder/AddCommentJson`, {
|
|
WorkorderId: workOrderId,
|
|
Text: text,
|
|
CommentType: commentType,
|
|
});
|
|
};
|
|
|
|
export const changeWorkOrderStatus = async (id, status) => {
|
|
return post(`${API_URL}/WorkOrder/ChangeStatus?id=${id}&status=${encodeURIComponent(status)}`);
|
|
};
|
|
|
|
export const deleteWorkOrder = async (id) => {
|
|
try {
|
|
await workOrderApi.delete(id);
|
|
return true;
|
|
} catch (error) {
|
|
console.error("Error deleting work order:", error);
|
|
throw error;
|
|
}
|
|
};
|