mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 06:53:12 +00:00
Populate location dropdown from API in work order form
- Fetch locations from /api/Contact/GetLocations on mount - Replace hardcoded dropdown options with dynamic list - Switch form field from location (string) to locationId (int) - Include locationId in API response mapping
This commit is contained in:
parent
62d2b3103e
commit
0ccf8bdbbc
2 changed files with 18 additions and 8 deletions
|
|
@ -19,6 +19,7 @@ export const getWorkOrderById = async (id) => {
|
||||||
workOrderNumber: wo.workerOrderNumber ?? wo.workOrderNumber ?? "",
|
workOrderNumber: wo.workerOrderNumber ?? wo.workOrderNumber ?? "",
|
||||||
title: wo.title ?? wo.workerOrderTitle ?? "",
|
title: wo.title ?? wo.workerOrderTitle ?? "",
|
||||||
location: wo.location ?? "",
|
location: wo.location ?? "",
|
||||||
|
locationId: wo.locationId != null ? String(wo.locationId) : "",
|
||||||
assignedTo: wo.assignee ?? wo.assignedTo ?? "",
|
assignedTo: wo.assignee ?? wo.assignedTo ?? "",
|
||||||
dueDate: wo.dueDate ? wo.dueDate.split("T")[0] : "",
|
dueDate: wo.dueDate ? wo.dueDate.split("T")[0] : "",
|
||||||
createdDate: wo.createdDate ? wo.createdDate.split("T")[0] : "",
|
createdDate: wo.createdDate ? wo.createdDate.split("T")[0] : "",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import React, { useState, useEffect } from "react";
|
||||||
import { useParams, useNavigate } from "react-router";
|
import { useParams, useNavigate } from "react-router";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import { getWorkOrderById, addWorkOrder, editWorkOrder } from "../api";
|
import { getWorkOrderById, addWorkOrder, editWorkOrder } from "../api";
|
||||||
|
import { get } from "../../../apiUtil";
|
||||||
|
import { API_URL } from "../../../constants";
|
||||||
import "./WorkOrderFormPage.css";
|
import "./WorkOrderFormPage.css";
|
||||||
|
|
||||||
export default function WorkOrderFormPage() {
|
export default function WorkOrderFormPage() {
|
||||||
|
|
@ -12,7 +14,7 @@ export default function WorkOrderFormPage() {
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
workOrderNumber: "",
|
workOrderNumber: "",
|
||||||
title: "",
|
title: "",
|
||||||
location: "",
|
locationId: "",
|
||||||
priority: "Medium",
|
priority: "Medium",
|
||||||
status: "Open",
|
status: "Open",
|
||||||
createdDate: new Date().toISOString().split("T")[0],
|
createdDate: new Date().toISOString().split("T")[0],
|
||||||
|
|
@ -23,6 +25,13 @@ export default function WorkOrderFormPage() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [locations, setLocations] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
get(`${API_URL}/Contact/GetLocations`)
|
||||||
|
.then((data) => setLocations(data || []))
|
||||||
|
.catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isEdit && id) {
|
if (isEdit && id) {
|
||||||
|
|
@ -151,19 +160,19 @@ export default function WorkOrderFormPage() {
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-sm-6">
|
<div className="col-sm-6">
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label className="required-field" htmlFor="location">Location</label>
|
<label className="required-field" htmlFor="locationId">Location</label>
|
||||||
<select
|
<select
|
||||||
className="form-control"
|
className="form-control"
|
||||||
id="location"
|
id="locationId"
|
||||||
name="location"
|
name="locationId"
|
||||||
value={formData.location}
|
value={formData.locationId}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
<option value="">Select Location</option>
|
<option value="">Select Location</option>
|
||||||
<option value="Springfield Office">Springfield Office</option>
|
{locations.map((loc) => (
|
||||||
<option value="Chicago Distribution Center">Chicago Distribution Center</option>
|
<option key={loc.id} value={loc.id}>{loc.name}</option>
|
||||||
<option value="Indianapolis Warehouse">Indianapolis Warehouse</option>
|
))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue