import React from 'react'; import { bindActionCreators } from "redux"; import { connect } from "react-redux"; // Components import Checkbox from "./checkbox/Checkbox"; import ErrorIcon from "../graphics/ErrorIcon"; import Evaluation from "./Evaluation"; import FetchOrg from "./FetchOrg"; import Html from "../helper/Html"; import Image from "./Image"; import ImageComponent from "../helper/Image"; import Information from "./Information"; import Input from "./Input"; import Missing from "./Missing"; import Number from "./Number"; import Radio from "./radio/Radio"; import Select from "./select/Select"; import Signature from "./Signature"; import Sum from "./Sum"; import SummaryDetails from "./SummaryDetails"; import Table from "./Table"; import Text from "./Text"; import Textarea from "./Textarea"; // State deps import { setData } from "../../state/actions"; import { NAME } from "../../state"; // Primitives import { SpecificBlock as StyledBlock } from "../../primitives/Block"; import StyledErrorBlock from "../../primitives/ErrorBlock"; import { ErrorMessage } from "../../primitives/Errors"; import { RenderableNode, State } from "../../index"; /** * Determine which component to use based on the node type */ function getBlock(type: RenderableNode["type"]) { switch (type) { case "Radio": return Radio; case "Checkbox": return Checkbox; case "Number": return Number; case "Select": return Select; case "Image": return Image; case "Text": return Text; case "Input": return Input; case "Textarea": return Textarea; case "Evaluation": return Evaluation; case "FetchOrg": return FetchOrg; case "Table": return Table; case "Signature": return Signature; case "Sum": return Sum; case "Information": return Information; default: return null; } } export function PureBlock(props: any) { const SpecificBlock = getBlock(props.type); if (props.type === "ErrorOk") { return (
{props.children.map((block: any) => ( ))}
); } if (props.type === "Group") { return ( {props.children.map((block: any) => ( ))} {props.summary && ( )} ); } if (props.type === "Error") { return ( {props.children.map((block: any) => ( ))} ); } if (!SpecificBlock) { return ; } if ( props.type === "Image" || props.type === "Text" || props.type === "Signature" || props.type === "Sum" || props.type === "Summary" || props.type === "Information" || props.type === "Evaluation" ) { return ( ); } return ( {props.disabled && ( {props.errorDescription} )} {props.summary && ( )} ); } PureBlock.defaultProps = { children: [], currentValue: undefined, details: "", disabled: false, errorDescription: null, errorPages: [], errors: {}, grouped: false, heading: "", id: null, image: {}, pages: [], property: null, setPage: () => { }, simple: false, summary: "", text: "", validator: false, }; const ConnectedBlock = connect( (state: State, props: any) => ({ data: state[NAME], debug: !!window.location.search.match("debug"), disabled: props.errors && props.errors.disabled && ((Array.isArray(props.errors.disabled) && props.errors.disabled.length > 0) || (props.errors.disabled.errors && props.errors.disabled.errors.length > 0)), }), (dispatch) => bindActionCreators({ setData }, dispatch) )(PureBlock); export default ConnectedBlock;