diff options
Diffstat (limited to 'packages/anastasis-webui/src/pages/home/SolveScreen.tsx')
-rw-r--r-- | packages/anastasis-webui/src/pages/home/SolveScreen.tsx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/packages/anastasis-webui/src/pages/home/SolveScreen.tsx b/packages/anastasis-webui/src/pages/home/SolveScreen.tsx new file mode 100644 index 000000000..46ff8227d --- /dev/null +++ b/packages/anastasis-webui/src/pages/home/SolveScreen.tsx @@ -0,0 +1,41 @@ +import { h, VNode } from "preact"; +import { AnastasisReducerApi, ChallengeFeedback, ChallengeInfo } from "../../hooks/use-anastasis-reducer"; +import { SolveEmailEntry } from "./SolveEmailEntry"; +import { SolvePostEntry } from "./SolvePostEntry"; +import { SolveQuestionEntry } from "./SolveQuestionEntry"; +import { SolveSmsEntry } from "./SolveSmsEntry"; +import { SolveUnsupportedEntry } from "./SolveUnsupportedEntry"; +import { RecoveryReducerProps } from "./index"; + +export function SolveScreen(props: RecoveryReducerProps): VNode { + const chArr = props.recoveryState.recovery_information!.challenges; + const challengeFeedback = props.recoveryState.challenge_feedback ?? {}; + const selectedUuid = props.recoveryState.selected_challenge_uuid!; + const challenges: { + [uuid: string]: ChallengeInfo; + } = {}; + for (const ch of chArr) { + challenges[ch.uuid] = ch; + } + const selectedChallenge = challenges[selectedUuid]; + const dialogMap: Record<string, (p: SolveEntryProps) => h.JSX.Element> = { + question: SolveQuestionEntry, + sms: SolveSmsEntry, + email: SolveEmailEntry, + post: SolvePostEntry, + }; + const SolveDialog = dialogMap[selectedChallenge.type] ?? SolveUnsupportedEntry; + return ( + <SolveDialog + challenge={selectedChallenge} + reducer={props.reducer} + feedback={challengeFeedback[selectedUuid]} /> + ); +} + +export interface SolveEntryProps { + reducer: AnastasisReducerApi; + challenge: ChallengeInfo; + feedback?: ChallengeFeedback; +} + |