diff --git a/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/add-drug.tsx b/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/add-drug.tsx index 9ec474ad5..f35ed3db5 100644 --- a/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/add-drug.tsx +++ b/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/add-drug.tsx @@ -18,6 +18,7 @@ type props = { amountUsed: string; amountUsedErrorMessage: string; amountDiscarded: string; + amountDiscardedErrorMessage: string; reactions: string; remainingUse: string; @@ -42,6 +43,7 @@ export const AddDrug: FC = ({ injectionMethodErrorMessage, discardMethod, amountDiscarded, + amountDiscardedErrorMessage, reactions, remainingUse, remove, @@ -262,6 +264,7 @@ export const AddDrug: FC = ({ placeholder="Example" inputClass="comp-form-control" value={amountDiscarded} + error={amountDiscardedErrorMessage} onChange={(evt: any) => { const { target: { value }, diff --git a/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/drug-item.tsx b/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/drug-item.tsx index 1358a88b3..d6a061eb9 100644 --- a/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/drug-item.tsx +++ b/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/drug-item.tsx @@ -104,12 +104,12 @@ export const DrugItem: FC = ({ - Fate of remaining drug in vial {remaining} + Fate of remaining drug in vial {remaining} {remainingUse === "DISC" && ( <> - Amount discarded {amountDiscarded}ml + Amount discarded {amountDiscarded} {amountDiscarded ? "ml" : ""} )} diff --git a/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/edit-animal-outcome.tsx b/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/edit-animal-outcome.tsx index f274a64fc..0310c3ca6 100644 --- a/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/edit-animal-outcome.tsx +++ b/frontend/src/app/components/containers/complaints/outcomes/animal-outcomes/edit-animal-outcome.tsx @@ -239,6 +239,7 @@ export const EditAnimalOutcome: FC = ({ amountUsed: "", amountUsedErrorMessage: "", amountDiscarded: "", + amountDiscardedErrorMessage: "", reactions: "", remainingUse: "", injectionMethod: "", @@ -279,19 +280,11 @@ export const EditAnimalOutcome: FC = ({ switch (type) { case "vial": currentDrug.vial = drug.vial; - if (!drug.vial) { - currentDrug.vialErrorMessage = "Required"; - } else { - currentDrug.vialErrorMessage = ""; - } + setErrorMessage(currentDrug, "vial"); break; case "drug": currentDrug.drug = drug.drug; - if (!drug.drug) { - currentDrug.drugErrorMessage = "Required"; - } else { - currentDrug.drugErrorMessage = ""; - } + setErrorMessage(currentDrug, "drug"); break; case "amountUsed": @@ -306,12 +299,26 @@ export const EditAnimalOutcome: FC = ({ break; case "injectionMethod": currentDrug.injectionMethod = drug.injectionMethod; - if (!drug.injectionMethod) { - currentDrug.injectionMethodErrorMessage = "Required"; + setErrorMessage(currentDrug, "injectionMethod"); + break; + case "reactions": + currentDrug.reactions = drug.reactions; + break; + case "amountDiscarded": + currentDrug.amountDiscarded = drug.amountDiscarded; + if (drug.amountDiscarded && !isPositiveNum(drug.amountDiscarded)) { + currentDrug.amountDiscardedErrorMessage = "Must be a positive number"; } else { - currentDrug.injectionMethodErrorMessage = ""; + currentDrug.amountDiscardedErrorMessage = ""; } break; + case "discardMethod": + currentDrug.discardMethod = drug.discardMethod; + break; + case "remainingUse": + currentDrug.remainingUse = drug.remainingUse; + break; + default: } const update = [...otherDrugs, currentDrug]; @@ -319,6 +326,12 @@ export const EditAnimalOutcome: FC = ({ setDrugs(update); }; + const setErrorMessage = (drug: any, field: string) => { + const dataField = field as keyof DrugUsed; + const errorField = (field + "ErrorMessage") as keyof DrugUsed; + drug[errorField] = drug[dataField] ? "" : "Required"; + }; + //update all input validation const updateDrug = (drug: DrugUsed) => { if (!drug.vial) { @@ -343,6 +356,12 @@ export const EditAnimalOutcome: FC = ({ } else { drug.injectionMethodErrorMessage = ""; } + if (drug.amountDiscarded && !isPositiveNum(drug.amountDiscarded)) { + drug.amountDiscardedErrorMessage = "Must be a positive number"; + } else { + drug.amountDiscardedErrorMessage = ""; + } + const items = drugs.filter(({ id }) => id !== drug.id); const update = [...items, drug]; diff --git a/frontend/src/app/types/app/complaints/outcomes/wildlife/drug-used.ts b/frontend/src/app/types/app/complaints/outcomes/wildlife/drug-used.ts index 5d277ee9b..06e2110ee 100644 --- a/frontend/src/app/types/app/complaints/outcomes/wildlife/drug-used.ts +++ b/frontend/src/app/types/app/complaints/outcomes/wildlife/drug-used.ts @@ -8,6 +8,7 @@ export interface DrugUsed { amountUsed: string; amountUsedErrorMessage: string; amountDiscarded: string; + amountDiscardedErrorMessage: string; injectionMethod: string; injectionMethodErrorMessage: string;