diff options
author | Sebastian <sebasjm@gmail.com> | 2021-10-22 01:31:46 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-10-22 01:31:46 -0300 |
commit | 2ec2161a7e1c0787b5e9ea14311f19c6b6a52d63 (patch) | |
tree | ef06a4edcb6b35f1743878f3a4cd77edc752a76f /packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx | |
parent | 3740010117df56c0ab8cfa97c983d9cf0143daf1 (diff) | |
download | wallet-core-2ec2161a7e1c0787b5e9ea14311f19c6b6a52d63.tar.xz |
some storybook exmaples
Diffstat (limited to 'packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx')
-rw-r--r-- | packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx b/packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx index 6f87a3358..2f804f940 100644 --- a/packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx +++ b/packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx @@ -1,15 +1,24 @@ /* eslint-disable @typescript-eslint/camelcase */ import { h, VNode } from "preact"; import { useState } from "preact/hooks"; -import { ReducerStateRecovery, ReducerStateBackup } from "../../../../anastasis-core/lib"; +import { ReducerStateRecovery, ReducerStateBackup, UserAttributeSpec } from "anastasis-core/lib"; +import { useAnastasisContext } from "../../context/anastasis"; import { AnastasisReducerApi } from "../../hooks/use-anastasis-reducer"; import { AnastasisClientFrame, withProcessLabel, LabeledInput } from "./index"; -export function AttributeEntryScreen(props: AttributeEntryProps): VNode { - const { reducer, reducerState: backupState } = props; - const [attrs, setAttrs] = useState<Record<string, string>>( - props.reducerState.identity_attributes ?? {} - ); +export function AttributeEntryScreen(): VNode { + const reducer = useAnastasisContext() + const state = reducer?.currentReducerState + const currentIdentityAttributes = state && "identity_attributes" in state ? (state.identity_attributes || {}) : {} + const [attrs, setAttrs] = useState<Record<string, string>>(currentIdentityAttributes); + + if (!reducer) { + return <div>no reducer in context</div> + } + if (!reducer.currentReducerState || !("required_attributes" in reducer.currentReducerState)) { + return <div>invalid state</div> + } + return ( <AnastasisClientFrame title={withProcessLabel(reducer, "Select Country")} @@ -17,7 +26,7 @@ export function AttributeEntryScreen(props: AttributeEntryProps): VNode { identity_attributes: attrs, })} > - {backupState.required_attributes.map((x: any, i: number) => { + {reducer.currentReducerState.required_attributes?.map((x, i: number) => { return ( <AttributeEntryField key={i} @@ -40,7 +49,7 @@ export interface AttributeEntryFieldProps { isFirst: boolean; value: string; setValue: (newValue: string) => void; - spec: any; + spec: UserAttributeSpec; } export function AttributeEntryField(props: AttributeEntryFieldProps): VNode { |