Skip to content

Commit

Permalink
fix: replace usage of useHistory and Redirect with useNavigate and Na…
Browse files Browse the repository at this point in the history
…vigate (react-router-dom)
  • Loading branch information
JamieSlome committed Jan 9, 2024
1 parent 20c9061 commit 1a6d113
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/ui/views/PushDetails/PushDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import moment from 'moment';
import { useHistory } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import Icon from '@material-ui/core/Icon';
import GridItem from '../../components/Grid/GridItem';
import GridContainer from '../../components/Grid/GridContainer';
Expand Down Expand Up @@ -31,7 +31,7 @@ export default function Dashboard(props) {
const [isError, setIsError] = useState(false);
const [message, setMessage] = useState('');
const [attestation, setAttestation] = useState(false);
const history = useHistory();
const navigate = useNavigate();
let isUserAllowedToApprove = true;
let isUserAllowedToReject = true;
function setUserAllowedToApprove(userAllowedToApprove) {
Expand All @@ -48,20 +48,20 @@ export default function Dashboard(props) {
const authorise = async (attestationData) => {
await authorisePush(id, setMessage, setUserAllowedToApprove, attestationData);
if (isUserAllowedToApprove) {
history.push('/admin/push/');
navigate('/admin/push/');
}
};

const reject = async () => {
await rejectPush(id, setMessage, setUserAllowedToReject);
if (isUserAllowedToReject) {
history.push('/admin/push/');
navigate('/admin/push/');
}
};

const cancel = async () => {
await cancelPush(id, setAuth, setIsError);
history.push(`/admin/push/`);
navigate(`/admin/push/`);
};

if (isLoading) return <div>Loading...</div>;
Expand Down
8 changes: 4 additions & 4 deletions src/ui/views/User/User.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import { Redirect, useHistory } from 'react-router-dom';
import { Navigate, useNavigate } from 'react-router-dom';
import GridItem from '../../components/Grid/GridItem';
import GridContainer from '../../components/Grid/GridContainer';
import Card from '../../components/Card/Card';
Expand Down Expand Up @@ -32,7 +32,7 @@ export default function Dashboard(props) {
const [isProfile, setIsProfile] = useState(false);
const [isAdmin, setIsAdmin] = useState(false);
const [gitAccount, setGitAccount] = useState('');
const history = useHistory();
const navigate = useNavigate();

useEffect(() => {
const id = props.match.params.id;
Expand All @@ -53,14 +53,14 @@ export default function Dashboard(props) {
if (isLoading) return <div>Loading...</div>;
if (isError) return <div>Something went wrong ...</div>;
if (!auth && window.location.pathname === '/admin/profile') {
return <Redirect to={{ pathname: '/login' }} />;
return <Navigate to='/login' />;
}

const updateProfile = async () => {
try {
data.gitAccount = gitAccount;
await updateUser(data);
history.push(`/admin/user/${data.username}`);
navigate(`/admin/user/${data.username}`);
} catch {
setIsError(true);
}
Expand Down

0 comments on commit 1a6d113

Please sign in to comment.