fleet/frontend/components/EmailTokenRedirect/EmailTokenRedirect.tsx
Martavis Parker 384c987389
Removed all traces of Redux from the app! (#5287)
* clean up routes and useless components

* component clean up

* removed redux from routes

* rename file

* moved useDeepEffect hook with others

* removed redux, fleet, app_constants dirs; added types to utilities

* style cleanup

* typo fix

* removed unused ts-ignore comments

* removed redux packages!!!

* formatting

* fixed typing for simple search function

* updated frontend readme
2022-04-22 09:45:35 -07:00

44 lines
1.2 KiB
TypeScript

import { useContext } from "react";
import { InjectedRouter } from "react-router";
import { Params } from "react-router/lib/Router";
import PATHS from "router/paths";
import { AppContext } from "context/app";
import { NotificationContext } from "context/notification";
import useDeepEffect from "hooks/useDeepEffect";
import usersAPI from "services/entities/users";
interface IEmailTokenRedirectProps {
router: InjectedRouter; // v3
params: Params;
}
const EmailTokenRedirect = ({
router,
params: { token },
}: IEmailTokenRedirectProps) => {
const { currentUser } = useContext(AppContext);
const { renderFlash } = useContext(NotificationContext);
useDeepEffect(() => {
const confirmEmailChange = async () => {
if (currentUser && token) {
try {
await usersAPI.confirmEmailChange(currentUser, token);
router.push(PATHS.USER_SETTINGS);
renderFlash("success", "Email updated successfully!");
} catch (error) {
console.log(error);
router.push(PATHS.LOGIN);
}
}
};
confirmEmailChange();
}, [currentUser, token]);
return null;
};
export default EmailTokenRedirect;