mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
384c987389
* 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
44 lines
1.2 KiB
TypeScript
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;
|