diff --git a/awx/ui_next/src/screens/Team/Team.jsx b/awx/ui_next/src/screens/Team/Team.jsx
index d0a385017e..7440bad624 100644
--- a/awx/ui_next/src/screens/Team/Team.jsx
+++ b/awx/ui_next/src/screens/Team/Team.jsx
@@ -37,7 +37,7 @@ function Team({ i18n, setBreadcrumb }) {
setHasContentLoading(false);
}
})();
- }, [id, setBreadcrumb]);
+ }, [id, setBreadcrumb, location]);
const tabsArray = [
{ name: i18n._(t`Details`), link: `/teams/${id}/details`, id: 0 },
diff --git a/awx/ui_next/src/screens/Team/TeamEdit/TeamEdit.jsx b/awx/ui_next/src/screens/Team/TeamEdit/TeamEdit.jsx
index 40c18376fa..e11a014018 100644
--- a/awx/ui_next/src/screens/Team/TeamEdit/TeamEdit.jsx
+++ b/awx/ui_next/src/screens/Team/TeamEdit/TeamEdit.jsx
@@ -1,6 +1,6 @@
-import React, { Component } from 'react';
+import React, { useState } from 'react';
import PropTypes from 'prop-types';
-import { withRouter } from 'react-router-dom';
+import { withRouter, useHistory } from 'react-router-dom';
import { CardBody } from '@components/Card';
import { TeamsAPI } from '@api';
@@ -8,65 +8,38 @@ import { Config } from '@contexts/Config';
import TeamForm from '../shared/TeamForm';
-class TeamEdit extends Component {
- constructor(props) {
- super(props);
+function TeamEdit({ team }) {
+ const history = useHistory();
+ const [error, setError] = useState(null);
- this.handleSubmit = this.handleSubmit.bind(this);
- this.handleCancel = this.handleCancel.bind(this);
- this.handleSuccess = this.handleSuccess.bind(this);
-
- this.state = {
- error: '',
- };
- }
-
- async handleSubmit(values) {
- const { team } = this.props;
+ const handleSubmit = async values => {
try {
await TeamsAPI.update(team.id, values);
- this.handleSuccess();
+ history.push(`/teams/${team.id}/details`);
} catch (err) {
- this.setState({ error: err });
+ setError(err);
}
- }
+ };
- handleCancel() {
- const {
- team: { id },
- history,
- } = this.props;
- history.push(`/teams/${id}/details`);
- }
+ const handleCancel = () => {
+ history.push(`/teams/${team.id}/details`);
+ };
- handleSuccess() {
- const {
- team: { id },
- history,
- } = this.props;
- history.push(`/teams/${id}/details`);
- }
-
- render() {
- const { team } = this.props;
- const { error } = this.state;
-
- return (
-
-
- {({ me }) => (
-
- )}
-
- {error ? error
: null}
-
- );
- }
+ return (
+
+
+ {({ me }) => (
+
+ )}
+
+ {error ? error
: null}
+
+ );
}
TeamEdit.propTypes = {
diff --git a/awx/ui_next/src/screens/Team/TeamEdit/TeamEdit.test.jsx b/awx/ui_next/src/screens/Team/TeamEdit/TeamEdit.test.jsx
index cb410405b1..529e57ed84 100644
--- a/awx/ui_next/src/screens/Team/TeamEdit/TeamEdit.test.jsx
+++ b/awx/ui_next/src/screens/Team/TeamEdit/TeamEdit.test.jsx
@@ -20,8 +20,12 @@ describe('', () => {
},
};
- test('handleSubmit should call api update', async () => {
- const wrapper = mountWithContexts();
+ test('handleSubmit should call api update and then navigate to the details page', async () => {
+ const history = createMemoryHistory({});
+
+ const wrapper = mountWithContexts(, {
+ context: { router: { history } },
+ });
const updatedTeamData = {
name: 'new name',
@@ -32,6 +36,7 @@ describe('', () => {
});
expect(TeamsAPI.update).toHaveBeenCalledWith(1, updatedTeamData);
+ expect(history.location.pathname).toEqual('/teams/1/details');
});
test('should navigate to team detail when cancel is clicked', async () => {