mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-25 06:30:00 +05:30
af59cc033f
Convert more components from class components to functional. Fix invalid finish state when client was auto approved
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
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>;
|
|
}
|
|
|
|
const AuthFlowRouteContents: FC<Props> = ({ component: WantedComponent, location, match, history }) => {
|
|
const isMounted = useIsMounted();
|
|
const [component, setComponent] = useState<ReactElement | null>(null);
|
|
|
|
useEffect(() => {
|
|
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} />);
|
|
}
|
|
},
|
|
);
|
|
}, [location.pathname, location.search]);
|
|
|
|
return component;
|
|
};
|
|
|
|
export default AuthFlowRouteContents;
|