Skip to content

Commit

Permalink
#1289 | fix: navigation with useHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
vedfordev committed Dec 24, 2024
1 parent fb0985d commit 50d0936
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/adminApp/Organisation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import {
BooleanField,
Datagrid,
Expand Down Expand Up @@ -32,7 +32,7 @@ import { AvniSelect } from "../common/components/AvniSelect";
import MenuItem from "@material-ui/core/MenuItem";
import useGetData from "../custom-hooks/useGetData";
import httpClient from "../common/utils/httpClient";
import { Redirect } from "react-router-dom";
import { useHistory } from "react-router-dom";
import { connect } from "react-redux";
import PropTypes from "prop-types";

Expand Down Expand Up @@ -209,14 +209,21 @@ export const OrganisationCreateComponent = ({ showNotification }) => {
categoryId: null,
statusId: null
});

//todo clear errors
const [errors, setErrors] = useState({});
const [redirect, setRedirect] = useState(false);

const [category, categoryError] = useGetData("/organisationCategory");
const [status, statusError] = useGetData("/organisationStatus");
const categoryList = category ? category._embedded.organisationCategory.map(ele => ele) : [];
const statusList = status ? status._embedded.organisationStatus.map(ele => ele) : [];
const history = useHistory();

useEffect(() => {
if (redirect) {
history.push("/admin/organisation");
}
}, [redirect]);

const handleChange = (property, value) => {
setData(currentData => ({ ...currentData, [property]: value }));
Expand Down Expand Up @@ -290,10 +297,6 @@ export const OrganisationCreateComponent = ({ showNotification }) => {
);
}

if (redirect) {
return <Redirect to={"/admin/organisation"} />;
}

return (
<>
<Box boxShadow={2} p={2} bgcolor="background.paper">
Expand Down

0 comments on commit 50d0936

Please sign in to comment.