accounts-frontend/packages/app/containers/AuthFlowRouteContents.tsx

35 lines
1.1 KiB
TypeScript
Raw Normal View History

import React, { FC, ReactElement, ComponentType, useEffect, useState } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { useIsMounted } from 'app/hooks';
import authFlow from 'app/services/authFlow';
interface Props extends RouteComponentProps {
component: ComponentType<RouteComponentProps>;
2019-12-10 13:17:32 +05:30
}
const AuthFlowRouteContents: FC<Props> = ({ component: WantedComponent, location, match, history }) => {
const isMounted = useIsMounted();
const [component, setComponent] = useState<ReactElement | null>(null);
2020-05-24 04:38:24 +05:30
useEffect(() => {
2020-05-24 04:38:24 +05:30
authFlow.handleRequest(
{
path: location.pathname,
params: match.params,
query: new URLSearchParams(location.search),
},
history.push,
() => {
if (isMounted()) {
setComponent(<WantedComponent history={history} location={location} match={match} />);
}
2020-05-24 04:38:24 +05:30
},
);
}, [location.pathname, location.search]);
2020-05-24 04:38:24 +05:30
return component;
};
2020-05-24 04:38:24 +05:30
export default AuthFlowRouteContents;