webpack/scenes/ContentViews/Copy/CopyContentViewForm.js in katello-4.3.0.rc3 vs webpack/scenes/ContentViews/Copy/CopyContentViewForm.js in katello-4.3.0.rc4

- old
+ new

@@ -1,11 +1,11 @@ import { STATUS } from 'foremanReact/constants'; import React, { useState } from 'react'; import useDeepCompareEffect from 'use-deep-compare-effect'; import PropTypes from 'prop-types'; import { useDispatch, useSelector } from 'react-redux'; -import { Redirect } from 'react-router-dom'; +import { useHistory } from 'react-router-dom'; import { translate as __ } from 'foremanReact/common/I18n'; import { Form, FormGroup, TextInput, ActionGroup, Button } from '@patternfly/react-core'; import { selectCopyContentViewError, selectCopyContentViews, selectCopyContentViewStatus, @@ -13,39 +13,35 @@ import { copyContentView } from '../ContentViewsActions'; const CopyContentViewForm = ({ cvId, setModalOpen }) => { const dispatch = useDispatch(); const [name, setName] = useState(''); - const [redirect, setRedirect] = useState(false); const [saving, setSaving] = useState(false); const response = useSelector(selectCopyContentViews); const status = useSelector(selectCopyContentViewStatus); const error = useSelector(selectCopyContentViewError); + const { push } = useHistory(); useDeepCompareEffect(() => { const { id } = response; - if (id && status === STATUS.RESOLVED) { + if (saving && id && status === STATUS.RESOLVED) { setSaving(false); - setRedirect(true); + setModalOpen(false); + push(`/content_views/${id}`); } else if (status === STATUS.ERROR) { setSaving(false); } - }, [response, status, error]); + }, [response, status, error, saving, setSaving, setModalOpen, push]); const onSubmit = () => { setSaving(true); dispatch(copyContentView({ id: cvId, name, })); }; - if (redirect) { - const { id } = response; - return (<Redirect to={`/content_views/${id}`} />); - } - return ( <Form onSubmit={(e) => { e.preventDefault(); onSubmit(); }} @@ -75,10 +71,10 @@ </Form > ); }; CopyContentViewForm.propTypes = { - cvId: PropTypes.string, + cvId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), setModalOpen: PropTypes.func, }; CopyContentViewForm.defaultProps = { cvId: null,