Skip to content

Commit

Permalink
bug/CE-610-Unable-to-enter-text-into-outcome-by-animal-drug-text-fiel…
Browse files Browse the repository at this point in the history
…ds (#381)

Co-authored-by: Mike <100624415+marqueone-ps@users.noreply.github.com>
Co-authored-by: afwilcox <alecwilcox@gmail.com>
  • Loading branch information
3 people authored Apr 26, 2024
1 parent 4c9fb57 commit d17148e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type props = {
amountUsed: string;
amountUsedErrorMessage: string;
amountDiscarded: string;
amountDiscardedErrorMessage: string;

reactions: string;
remainingUse: string;
Expand All @@ -42,6 +43,7 @@ export const AddDrug: FC<props> = ({
injectionMethodErrorMessage,
discardMethod,
amountDiscarded,
amountDiscardedErrorMessage,
reactions,
remainingUse,
remove,
Expand Down Expand Up @@ -262,6 +264,7 @@ export const AddDrug: FC<props> = ({
placeholder="Example"
inputClass="comp-form-control"
value={amountDiscarded}
error={amountDiscardedErrorMessage}
onChange={(evt: any) => {
const {
target: { value },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ export const DrugItem: FC<props> = ({
</Row>
<Row>
<Col md={6}>
<span className="comp-fake-label">Fate of remaining drug in vial</span> {remaining}
<span className="comp-fake-label">Fate of remaining drug in vial </span> {remaining}
</Col>
<Col md={3}>
{remainingUse === "DISC" && (
<>
<span className="comp-fake-label">Amount discarded</span> {amountDiscarded}ml
<span className="comp-fake-label">Amount discarded</span> {amountDiscarded} {amountDiscarded ? "ml" : ""}
</>
)}
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export const EditAnimalOutcome: FC<EditAnimalOutcomeProps> = ({
amountUsed: "",
amountUsedErrorMessage: "",
amountDiscarded: "",
amountDiscardedErrorMessage: "",
reactions: "",
remainingUse: "",
injectionMethod: "",
Expand Down Expand Up @@ -279,19 +280,11 @@ export const EditAnimalOutcome: FC<EditAnimalOutcomeProps> = ({
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":
Expand All @@ -306,19 +299,39 @@ export const EditAnimalOutcome: FC<EditAnimalOutcomeProps> = ({
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];

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) {
Expand All @@ -343,6 +356,12 @@ export const EditAnimalOutcome: FC<EditAnimalOutcomeProps> = ({
} 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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface DrugUsed {
amountUsed: string;
amountUsedErrorMessage: string;
amountDiscarded: string;
amountDiscardedErrorMessage: string;

injectionMethod: string;
injectionMethodErrorMessage: string;
Expand Down

0 comments on commit d17148e

Please sign in to comment.