import * as React from "react" ; import { OutputBlockData } from "@editorjs/editorjs" ; import { termsOfServiceEnabled } from "./../functions" ; import { FbFormModel , FbFormRenderComponentProps } from "../../../types" ; type CreateTermsOfServiceComponentArgs = { props : FbFormRenderComponentProps ; formData : FbFormModel ; setTermsOfServiceAccepted : ( value : boolean ) => void ; } ; type ChildrenFunction = ( params : { onChange : ( value : boolean ) => void ; errorMessage : String ; message : OutputBlockData [ ] ; } ) => React . ReactNode ; export type TermsOfServiceProps = { children : ChildrenFunction ; onChange ? : ( value : string ) => void ; onErrored ? : Function ; onExpired ? : Function ; } ; export type TermsOfServiceComponent = React . FC < TermsOfServiceProps > ; const createTermsOfServiceComponent = ( { formData , setTermsOfServiceAccepted } ) : TermsOfServiceComponent => function TermsOfService ( props ) { if ( ! termsOfServiceEnabled ( formData ) ) { return null ; } const { settings } = formData ; if ( typeof props . children === "function" ) { return props . children ( { errorMessage : settings . termsOfServiceMessage . errorMessage , message : settings . termsOfServiceMessage . message , onChange : setTermsOfServiceAccepted } ) ; } throw new Error ( "Please use a function for children prop of TermsOfService component." ) ; } ; export default createTermsOfServiceComponent ;