diff --git a/src/main/ui/src/components/motorcycleStock/MotorcycleStockAddModal.jsx b/src/main/ui/src/components/motorcycleStock/MotorcycleStockAddModal.jsx
index c68a2e2..96c9275 100644
--- a/src/main/ui/src/components/motorcycleStock/MotorcycleStockAddModal.jsx
+++ b/src/main/ui/src/components/motorcycleStock/MotorcycleStockAddModal.jsx
@@ -6,6 +6,7 @@ import Button from "react-bootstrap/Button";
import CrudModal from "../shared/CrudModal";
import {fetchData} from "../../util/fetchData";
+import {identifyMotorcycleModelObject} from "../../util/identifyMotorcycleModelObject";
import {getJwtToken} from "../../security/authService";
// Imports related to form validation
@@ -35,8 +36,10 @@ const AddForm = (props) => {
async function handleSubmit(values) {
const url = "/service/motorcycle/stock/add";
+ const motorcycleModel = identifyMotorcycleModelObject(motorcycleModels, values.motorcycleModel);
+
const requestBody = {
- "motorcycleModel": motorcycleModels.find(motorcycleModel => motorcycleModel.modelName === values.motorcycleModel),
+ "motorcycleModel": motorcycleModel,
"mileage": values.mileage,
"purchasingPrice": values.purchasingPrice,
"profitMargin": values.profitMargin,
@@ -107,10 +110,15 @@ const AddForm = (props) => {
-
- {motorcycleModels.map(m => (
-
- ))}
+
+ {motorcycleModels.map(m => {
+ if (m.manufacturer.name + " - " + m.modelName !== values.motorcycleModel) {
+ return
+ }
+
+ return "Click to select Motorcycle model";
+ })}
{incompleteMotorcycleModelAlert ? "Choose a Motorcycle model!" : null}
diff --git a/src/main/ui/src/components/motorcycleStock/MotorcycleStockDeleteModal.jsx b/src/main/ui/src/components/motorcycleStock/MotorcycleStockDeleteModal.jsx
index d1319dd..df7fba0 100644
--- a/src/main/ui/src/components/motorcycleStock/MotorcycleStockDeleteModal.jsx
+++ b/src/main/ui/src/components/motorcycleStock/MotorcycleStockDeleteModal.jsx
@@ -54,7 +54,7 @@ const DeleteItemInformation = (props) => {
return (
{camelCaseToSentenceCase(key)}
-
{value.modelName}
+ {value.manufacturer.name + " - " + value.modelName}
)
} else {
diff --git a/src/main/ui/src/components/motorcycleStock/MotorcycleStockUpdateModal.jsx b/src/main/ui/src/components/motorcycleStock/MotorcycleStockUpdateModal.jsx
index 06e4d86..932aa3e 100644
--- a/src/main/ui/src/components/motorcycleStock/MotorcycleStockUpdateModal.jsx
+++ b/src/main/ui/src/components/motorcycleStock/MotorcycleStockUpdateModal.jsx
@@ -6,6 +6,7 @@ import Button from "react-bootstrap/Button";
import CrudModal from "../shared/CrudModal";
import {fetchData} from "../../util/fetchData";
+import {identifyMotorcycleModelObject} from "../../util/identifyMotorcycleModelObject";
import {getJwtToken} from "../../security/authService";
// Imports related to form validation
@@ -28,6 +29,7 @@ const UpdateForm = (props) => {
const [currentRecord, setCurrentRecord] = useState({});
const [currentMotorcycleModel, setCurrentMotorcycleModel] = useState({});
+ const [currentManufacturer, setCurrentManufacturer] = useState({});
useEffect(() => {
@@ -38,15 +40,18 @@ const UpdateForm = (props) => {
setCurrentRecord(currentRecord);
setCurrentMotorcycleModel(currentRecord.motorcycleModel);
+ setCurrentManufacturer(currentRecord.motorcycleModel.manufacturer);
}, [props.motorcycleStocks, props.recordId])
async function handleSubmit(values) {
const url = "/service/motorcycle/stock/update";
+ const motorcycleModel = identifyMotorcycleModelObject(motorcycleModels, values.motorcycleModel);
+
const requestBody = {
"id": currentRecord.id,
- "motorcycleModel": values.motorcycleModel ? motorcycleModels.find(motorcycleModel => motorcycleModel.modelName === values.motorcycleModel) : currentMotorcycleModel,
+ "motorcycleModel": values.motorcycleModel ? motorcycleModel : currentMotorcycleModel,
"mileage": values.mileage ? values.mileage : currentRecord.mileage,
"purchasingPrice": values.purchasingPrice ? values.purchasingPrice : currentRecord.purchasingPrice,
"profitMargin": values.profitMargin ? values.profitMargin : currentRecord.profitMargin,
@@ -79,7 +84,7 @@ const UpdateForm = (props) => {
{
>
{motorcycleModels.map(m => {
- if (m.modelName !== values.motorcycleModel) {
- return
+ if (m.manufacturer.name + " - " + m.modelName !== values.motorcycleModel) {
+ return
}
return "Click to select Motorcycle model";
diff --git a/src/main/ui/src/util/identifyMotorcycleModelObject.js b/src/main/ui/src/util/identifyMotorcycleModelObject.js
new file mode 100644
index 0000000..3570a07
--- /dev/null
+++ b/src/main/ui/src/util/identifyMotorcycleModelObject.js
@@ -0,0 +1,21 @@
+/**
+ * Identifies an object of type motorcycleModel from a collection, based on a given String expression by checking the
+ * expression against the names of the objects.
+ *
+ * Dropdown (