diff --git a/src/app/components/ActionUIA.tsx b/src/app/components/ActionUIA.tsx new file mode 100644 index 00000000..88f0fe0e --- /dev/null +++ b/src/app/components/ActionUIA.tsx @@ -0,0 +1,64 @@ +import React, { ReactNode } from 'react'; +import { AuthDict, AuthType, IAuthData, UIAFlow } from 'matrix-js-sdk'; +import { getUIAFlowForStages } from '../utils/matrix-uia'; +import { useSupportedUIAFlows, useUIACompleted, useUIAFlow } from '../hooks/useUIAFlows'; +import { UIAFlowOverlay } from './UIAFlowOverlay'; +import { PasswordStage } from './uia-stages'; + +export const SUPPORTED_IN_APP_UIA_STAGES = [AuthType.Password, AuthType.Sso]; + +export const pickUIAFlow = (uiaFlows: UIAFlow[]): UIAFlow | undefined => { + const passwordFlow = getUIAFlowForStages(uiaFlows, [AuthType.Password]); + if (passwordFlow) return passwordFlow; + return getUIAFlowForStages(uiaFlows, [AuthType.Sso]); +}; + +type ActionUIAProps = { + userId: string; + authData: IAuthData; + ongoingFlow: UIAFlow; + action: (authDict: AuthDict) => void; + onCancel: () => void; +}; +export function ActionUIA({ userId, authData, ongoingFlow, action, onCancel }: ActionUIAProps) { + const completed = useUIACompleted(authData); + const { getStageToComplete } = useUIAFlow(authData, ongoingFlow); + + const stageToComplete = getStageToComplete(); + + if (!stageToComplete) return null; + return ( + + {stageToComplete.type === AuthType.Password && ( + + )} + + ); +} + +type ActionUIAFlowsLoaderProps = { + authData: IAuthData; + unsupported: () => ReactNode; + children: (ongoingFlow: UIAFlow) => ReactNode; +}; +export function ActionUIAFlowsLoader({ + authData, + unsupported, + children, +}: ActionUIAFlowsLoaderProps) { + const supportedFlows = useSupportedUIAFlows(authData.flows ?? [], SUPPORTED_IN_APP_UIA_STAGES); + const ongoingFlow = supportedFlows.length > 0 ? supportedFlows[0] : undefined; + + if (!ongoingFlow) return unsupported(); + + return children(ongoingFlow); +} diff --git a/src/app/components/UIAFlowOverlay.tsx b/src/app/components/UIAFlowOverlay.tsx index dc517b48..a2bdd1b8 100644 --- a/src/app/components/UIAFlowOverlay.tsx +++ b/src/app/components/UIAFlowOverlay.tsx @@ -13,7 +13,6 @@ import { IconButton, } from 'folds'; import FocusTrap from 'focus-trap-react'; -import { stopPropagation } from '../utils/keyboard'; export type UIAFlowOverlayProps = { currentStep: number; @@ -29,7 +28,7 @@ export function UIAFlowOverlay({ }: UIAFlowOverlayProps) { return ( }> - + {children} diff --git a/src/app/components/uia-stages/index.ts b/src/app/components/uia-stages/index.ts index 95c19a79..9b158989 100644 --- a/src/app/components/uia-stages/index.ts +++ b/src/app/components/uia-stages/index.ts @@ -1,6 +1,7 @@ export * from './types'; export * from './DummyStage'; export * from './EmailStage'; +export * from './PasswordStage'; export * from './ReCaptchaStage'; export * from './RegistrationTokenStage'; export * from './TermsStage';