Skip to content

Commit

Permalink
Prepare for react-router-dom v6 upgrade (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
entrotech authored Nov 4, 2023
1 parent 35d7618 commit 33bbcd1
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 197 deletions.
36 changes: 14 additions & 22 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"react-jss": "^10.8.2",
"react-loader": "^2.4.7",
"react-quill": "^2.0.0",
"react-router-dom": "^5.3.0",
"react-router-dom": "5.3",
"react-select": "^5.2.2",
"react-string-replace": "^1.1.0",
"react-to-print": "^2.14.12",
Expand Down
23 changes: 14 additions & 9 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const App = ({
<Switch>
{/* These routes either have no sidebar or use a custom sidebar */}
<Route
isAuthorized={account && !!account.email}
path="/projects"
render={() => (
<RequireAuth
Expand Down Expand Up @@ -103,15 +102,21 @@ const App = ({
/>
</Route>

<Route exact path="/calculation">
<Redirect to="/calculation/1" />
</Route>
<Route
exact
path="/calculation"
render={() => <Redirect to="/calculation/1" />}
/>

<Route exact path="/">
<Redirect
to={account && account.email ? "/calculation/1" : "/login"}
/>
</Route>
<Route
exact
path="/"
render={() => (
<Redirect
to={account && account.email ? "/calculation/1" : "/login"}
/>
)}
/>

{/* These routes use the same sidebar component */}
<Route>
Expand Down
23 changes: 6 additions & 17 deletions client/src/components/Authorization/ConfirmEmail.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";
import { Redirect, withRouter } from "react-router-dom";
import { Redirect, useParams, useHistory } from "react-router-dom";
import * as accountService from "../../services/account.service";
import { useToast } from "../../contexts/Toast";
import SendEmailForm from "./SendEmailForm";
import ContentContainer from "../Layout/ContentContainer";

const ConfirmEmail = props => {
const { history, match } = props;
const token = match.params.token;
const ConfirmEmail = () => {
const params = useParams();
const history = useHistory();
const token = params.token;
const [submitted, setSubmitted] = useState(false);
const [confirmResult, setConfirmResult] = useState(false);
const toast = useToast();
Expand Down Expand Up @@ -54,15 +54,4 @@ const ConfirmEmail = props => {
);
};

ConfirmEmail.propTypes = {
match: PropTypes.shape({
params: PropTypes.shape({
token: PropTypes.string
})
}),
history: PropTypes.shape({
push: PropTypes.func.isRequired
})
};

export default withRouter(ConfirmEmail);
export default ConfirmEmail;
3 changes: 1 addition & 2 deletions client/src/components/Authorization/ForgotPassword.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState } from "react";
import { withRouter } from "react-router-dom";
import * as accountService from "../../services/account.service";
import ContentContainer from "../Layout/ContentContainer";
import SendEmailForm from "./SendEmailForm";
Expand Down Expand Up @@ -32,4 +31,4 @@ const ForgotPassword = () => {
);
};

export default withRouter(ForgotPassword);
export default ForgotPassword;
26 changes: 7 additions & 19 deletions client/src/components/Authorization/Login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useRef, useContext } from "react";
import UserContext from "../../contexts/UserContext";
import PropTypes from "prop-types";
import { Link, withRouter, useHistory, useLocation } from "react-router-dom";
import { Link, useParams, useHistory, useLocation } from "react-router-dom";
import { createUseStyles, useTheme } from "react-jss";
import { Formik, Form, Field, ErrorMessage } from "formik";
import * as Yup from "yup";
Expand Down Expand Up @@ -31,10 +30,9 @@ const useStyles = createUseStyles(theme => ({
}
}));

const Login = props => {
const Login = () => {
const focusRef = useRef(null);
const userContext = useContext(UserContext);
const { match } = props;
const { search } = useLocation();
const searchParams = new URLSearchParams(search);
const projectId = searchParams.get("projectId");
Expand All @@ -44,8 +42,9 @@ const Login = props => {
useState(false);
const classes = useStyles();
const theme = useTheme();
const params = useParams();
const initialValues = {
email: match.params.email ? decodeURIComponent(match.params.email) : "",
email: params.email ? decodeURIComponent(params.email) : "",
password: ""
};

Expand All @@ -64,11 +63,7 @@ const Login = props => {
const trackLogin = useTrackEvent(appInsights, "Login");
const trackLoginFail = useTrackEvent(appInsights, "Login Failed");

const handleSubmit = async (
{ email, password },
{ setSubmitting },
{ history }
) => {
const handleSubmit = async ({ email, password }, { setSubmitting }) => {
try {
const loginResponse = await accountService.login(email, password);

Expand Down Expand Up @@ -164,7 +159,7 @@ const Login = props => {
<Formik
initialValues={initialValues}
validationSchema={loginSchema}
onSubmit={(values, actions) => handleSubmit(values, actions, props)}
onSubmit={(values, actions) => handleSubmit(values, actions)}
>
{({ touched, errors, isSubmitting, values }) => {
const isDisabled = !!(
Expand Down Expand Up @@ -271,12 +266,5 @@ const Login = props => {
</ContentContainer>
);
};
Login.propTypes = {
match: PropTypes.shape({
params: PropTypes.shape({
email: PropTypes.string
})
})
};

export default withRouter(Login);
export default Login;
17 changes: 5 additions & 12 deletions client/src/components/Authorization/Register.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState, useRef } from "react";
import PropTypes from "prop-types";
import { useParams } from "react-router-dom";
import * as accountService from "../../services/account.service";
import { createUseStyles } from "react-jss";
import { Formik, Form, Field, ErrorMessage } from "formik";
import { Link, withRouter } from "react-router-dom";
import { Link } from "react-router-dom";
import * as Yup from "yup";
import Button from "../Button/Button";
import ContentContainer from "../Layout/ContentContainer";
Expand All @@ -20,11 +20,11 @@ const useStyles = createUseStyles({
const Register = props => {
const focusRef = useRef(null);
const classes = useStyles();
const { match } = props;
const params = useParams();
const initialValues = {
firstName: "",
lastName: "",
email: match.params.email || "",
email: params.email || "",
password: "",
passwordConfirm: ""
};
Expand Down Expand Up @@ -227,12 +227,5 @@ const Register = props => {
</ContentContainer>
);
};
Register.propTypes = {
match: PropTypes.shape({
params: PropTypes.shape({
email: PropTypes.string
})
})
};

export default withRouter(Register);
export default Register;
24 changes: 7 additions & 17 deletions client/src/components/Authorization/ResetPassword.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState, useEffect, useRef } from "react";
import PropTypes from "prop-types";
import { withRouter } from "react-router-dom";
import { useHistory, useParams } from "react-router-dom";
import * as accountService from "../../services/account.service";
import { Formik, Form, Field, ErrorMessage } from "formik";
import * as Yup from "yup";
Expand All @@ -26,10 +25,12 @@ const validationSchema = Yup.object().shape({
.oneOf([Yup.ref("password")], "Password does not match")
});

const ResetPassword = props => {
const ResetPassword = () => {
const history = useHistory();
const focusRef = useRef(null);
const [success, setSuccess] = useState(false);
const { token } = props.match.params;
const params = useParams();
const token = params.token;
const classes = useStyles();
const toast = useToast();

Expand Down Expand Up @@ -119,7 +120,7 @@ const ResetPassword = props => {
<h3>Redirecting to login</h3>
<div className="hide">
{setTimeout(() => {
props.history.push(`/login/${success}`);
history.push(`/login/${success}`);
}, 2000)}
</div>
</>
Expand All @@ -128,15 +129,4 @@ const ResetPassword = props => {
);
};

ResetPassword.propTypes = {
match: PropTypes.shape({
params: PropTypes.shape({
token: PropTypes.string
})
}),
history: PropTypes.shape({
push: PropTypes.func.isRequired
})
};

export default withRouter(ResetPassword);
export default ResetPassword;
8 changes: 2 additions & 6 deletions client/src/components/Authorization/SendEmailForm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useRef } from "react";
import PropTypes from "prop-types";
import { Link, withRouter } from "react-router-dom";
import { Link } from "react-router-dom";
import Button from "../Button/Button";
import { createUseStyles } from "react-jss";
import { Formik, Form, Field, ErrorMessage } from "formik";
Expand Down Expand Up @@ -52,10 +52,6 @@ const SendEmailForm = ({ label, submitted, handleSubmit }) => {
const focusRef = useRef(null);
const classes = useStyles();

// useEffect(() => {
// focusRef.current.focus();
// });

return !submitted ? (
<>
<h1 className={classes.pageTitle}>Send {label} Email</h1>
Expand Down Expand Up @@ -124,4 +120,4 @@ SendEmailForm.propTypes = {
submitted: PropTypes.bool.isRequired
};

export default withRouter(SendEmailForm);
export default SendEmailForm;
Loading

0 comments on commit 33bbcd1

Please sign in to comment.