Skip to content

Commit

Permalink
fix: prevent duplicate requests to api on forms
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstefanequilobe committed Apr 21, 2022
1 parent 30529e0 commit d4291b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/components/forms/CreateUnitsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const StyledFormContainer = styled('div')`
`;

const CreateUnitsForm = ({ onClose, modalSizeAndPosition }) => {
const { notification } = useSelector(state => state.app);
const { notification, showProgressOverlay } = useSelector(state => state.app);
const [tabValue, setTabValue] = useState(0);
const dispatch = useDispatch();
const intl = useIntl();
Expand Down Expand Up @@ -82,10 +82,12 @@ const CreateUnitsForm = ({ onClose, modalSizeAndPosition }) => {
isMandatoryIssuanceChecked
) {
dispatch(setValidateForm(false));
if (desiredStep >= stepperStepsTranslationIds.length) {
if (
desiredStep >= stepperStepsTranslationIds.length &&
!showProgressOverlay
) {
handleSubmitUnit();
} else {
dispatch(setValidateForm(false));
setTabValue(desiredStep);
dispatch(setForm(stepperStepsTranslationIds[desiredStep]));
}
Expand Down
7 changes: 5 additions & 2 deletions src/components/forms/EditUnitsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const StyledFormContainer = styled('div')`
const EditUnitsForm = ({ onClose, record, modalSizeAndPosition }) => {
const { organizations } = useSelector(store => store.climateWarehouse);
const myOrgUid = getMyOrgUid(organizations);
const { notification } = useSelector(state => state.app);
const { notification, showProgressOverlay } = useSelector(state => state.app);
const [unit, setUnit] = useState([]);
const [tabValue, setTabValue] = useState(0);
const dispatch = useDispatch();
Expand Down Expand Up @@ -80,7 +80,10 @@ const EditUnitsForm = ({ onClose, record, modalSizeAndPosition }) => {
isMandatoryIssuanceChecked
) {
dispatch(setValidateForm(false));
if (desiredStep >= stepperStepsTranslationIds.length) {
if (
desiredStep >= stepperStepsTranslationIds.length &&
!showProgressOverlay
) {
handleUpdateUnit();
} else {
dispatch(setValidateForm(false));
Expand Down

0 comments on commit d4291b8

Please sign in to comment.