Skip to content

Commit

Permalink
Instrumentation input validation (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lehats authored Jan 15, 2024
2 parents 420c8fb + 80d5d1e commit a6657ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/client/cypress/e2e/viewer/displayLayer.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ describe("Test for the borehole form.", () => {

cy.wait("@borehole");
cy.wait("@get-layers-by-profileId");
cy.wait(5000);

// Click on layer
cy.get('[data-cy="stratigraphy-layer-0"]').scrollIntoView().click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const Instrumentation = ({ isEditable, completionId }) => {
{displayedInstrumentations?.length === 0 && (
<Stack alignItems="center" justifyContent="center" sx={{ flexGrow: 1 }}>
<Typography variant="fullPageMessage">
{t("msgInstrumentationEmpty")}
{t("msgInstrumentsEmpty")}
</Typography>
</Stack>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useContext } from "react";
import React, { useEffect } from "react";
import { useForm, Controller } from "react-hook-form";
import {
Box,
Expand All @@ -13,7 +13,6 @@ import {
import CheckIcon from "@mui/icons-material/Check";
import { useTranslation } from "react-i18next";
import { useDomains } from "../../../../api/fetchApiV2";
import { AlertContext } from "../../../alert/alertContext";
import { completionSchemaConstants } from "./completionSchemaConstants";
import {
TextfieldWithMarginRight,
Expand All @@ -29,26 +28,15 @@ const InstrumentationInput = ({
}) => {
const domains = useDomains();
const { t, i18n } = useTranslation();
const { handleSubmit, register, control, formState, getValues, trigger } =
useForm();
const alertContext = useContext(AlertContext);
const { handleSubmit, register, control, formState, trigger } = useForm();

// trigger form validation on mount
useEffect(() => {
trigger();
}, [trigger]);

const closeFormIfCompleted = () => {
const formValues = getValues();
if (
!formValues.fromDepth ||
!formValues.toDepth ||
!formValues.kindId ||
!formValues.statusId ||
!formValues.name
) {
alertContext.error(t("instrumentationRequiredFieldsAlert"));
} else {
if (formState.isValid) {
handleSubmit(submitForm)();
setSelectedInstrumentation(null);
}
Expand Down

0 comments on commit a6657ff

Please sign in to comment.