/* eslint-disable @typescript-eslint/camelcase */ import { UserAttributeSpec, validators } from "anastasis-core"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { useAnastasisContext } from "../../context/anastasis"; import { AnastasisClientFrame, withProcessLabel } from "./index"; import { LabeledInput } from "../../components/fields/LabeledInput"; import { DateInput } from "../../components/fields/DateInput"; 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>(currentIdentityAttributes); if (!reducer) { return
no reducer in context
} if (!reducer.currentReducerState || !("required_attributes" in reducer.currentReducerState)) { return
invalid state
} return ( reducer.transition("enter_user_attributes", { identity_attributes: attrs, })} >
{reducer.currentReducerState.required_attributes?.map((x, i: number) => { const value = attrs[x.name] function checkIfValid(): string | undefined { const pattern = x['validation-regex'] if (pattern) { const re = new RegExp(pattern) if (!re.test(value)) return 'The value is invalid' } const logic = x['validation-logic'] if (logic) { const func = (validators as any)[logic]; if (func && typeof func === 'function' && !func(value)) return 'Please check the value' } const optional = x.optional console.log('optiona', optional) if (!optional && !value) { return 'This value is required' } return undefined } return ( setAttrs({ ...attrs, [x.name]: v })} spec={x} isValid={checkIfValid} value={value} /> ); })}

This stay private

The information you have entered here:

  • Will be hashed, and therefore unreadable
  • The non-hashed version is not shared
); } interface AttributeEntryFieldProps { isFirst: boolean; value: string; setValue: (newValue: string) => void; spec: UserAttributeSpec; isValid: () => string | undefined; } function AttributeEntryField(props: AttributeEntryFieldProps): VNode { const errorMessage = props.isValid() return (
{props.spec.type === 'date' ? : } This stay private
); }