Skip to content

Commit 045400e

Browse files
authored
Comp 766 3 All changes except linking fix (#721)
1 parent a965cf8 commit 045400e

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

compliance-web/src/components/App/Inspections/Profile/Enforcements/Orders/OrderCreateModal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ const OrderCreateModal: FC<OrderCreateModalProps> = ({
101101
const formData = methods.getValues();
102102
const requirementIds = (data.requirements as InspectionRequirement[]).map((requirement) => requirement.id);
103103

104+
// Not historical - default to 'create_new'
105+
if (!inspectionData.is_history) {
106+
formData.orderCreationMethod = "create_new";
107+
}
108+
104109
if (!formData.orderCreationMethod) {
105110
methods.setError("orderCreationMethod", {
106111
type: "required",
@@ -166,7 +171,7 @@ const OrderCreateModal: FC<OrderCreateModalProps> = ({
166171
title="Create Order"
167172
onSubmit={handleBaseSubmit}
168173
isLoading={isPendingOrder || isPendingLink}
169-
additionalFormFields={
174+
additionalFormFields={ inspectionData.is_history &&
170175
<FormProvider {...methods}>
171176
<OrderCreationOptions
172177
inspectionData={inspectionData}

compliance-web/src/components/App/Inspections/Profile/Enforcements/Orders/OrderCreationOptions.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, useState, useEffect } from "react";
1+
import { FC, useState } from "react";
22
import {
33
Box,
44
FormControl,
@@ -29,26 +29,16 @@ const OrderCreationOptions: FC<OrderCreationOptionsProps> = ({
2929
isHistorical,
3030
}) => {
3131
const { setValue, clearErrors, formState: { errors } } = useFormContext();
32-
const [creationMethod, setCreationMethod] = useState<OrderCreationMethod>("create_new");
32+
const [creationMethod, setCreationMethod] = useState<OrderCreationMethod | ""> ("");
3333
const { data: openOrders } = useOrdersByCaseFileData(inspectionData.case_file_id, {
3434
isStaleInfinate: false,
3535
});
3636

37-
38-
39-
useEffect(() => {
40-
const defaultMethod = isHistorical ? "manual_entry" : "create_new";
41-
setCreationMethod(defaultMethod);
42-
setValue("orderCreationMethod", defaultMethod);
43-
}, [isHistorical, setValue]);
44-
4537
const handleCreationMethodChange = (event: React.ChangeEvent<HTMLInputElement>) => {
4638
const method = event.target.value as OrderCreationMethod;
4739
setCreationMethod(method);
4840
setValue("orderCreationMethod", method);
4941
clearErrors("orderCreationMethod");
50-
clearErrors("manualOrderNumber");
51-
clearErrors("existingOrderId");
5242

5343
if (method !== "manual_entry") {
5444
setValue("manualOrderNumber", "");
@@ -110,7 +100,7 @@ const OrderCreationOptions: FC<OrderCreationOptionsProps> = ({
110100
)}
111101
{/* Manual Order Number Entry */}
112102
{creationMethod === "manual_entry" && (
113-
<Box sx={{ mt: 1.5, ml: 2 }}>
103+
<Box sx={{ mt: 0, ml: 2 }}>
114104
<ControlledTextField
115105
name="manualOrderNumber"
116106
fullWidth

0 commit comments

Comments
 (0)