import * as React from 'react' ; import { RouteComponentProps } from 'react-router' ; import { RegisterForm , IFormProps , FullProps } from '@opencrvs/client/src/views/RegisterForm/RegisterForm' ; import { DRAFT_BIRTH_PARENT_FORM_PAGE_GROUP , DRAFT_DEATH_FORM_PAGE_GROUP } from '@opencrvs/client/src/navigation/routes' ; import { getRegisterForm } from '@opencrvs/client/src/forms/register/application-selectors' ; import { IStoreState } from '@opencrvs/client/src/store' ; import { connect } from 'react-redux' ; import { Event , IForm } from '@client/forms' ; import { IApplication } from '@client/applications' ; const pageRoute = { birth : DRAFT_BIRTH_PARENT_FORM_PAGE_GROUP , death : DRAFT_DEATH_FORM_PAGE_GROUP } ; export class ApplicationFormView extends React . Component < FullProps > { render ( ) { return < RegisterForm { ... this . props } / > ; } } interface StateProps { application : IApplication ; registerForm : IForm ; pageRoute : string ; } function mapStatetoProps ( state , props ) { const { match } = props ; const application = state . applicationsState . applications . find ( ( { id } ) => id === match . params . applicationId ) ; if ( ! application ) { throw new Error ( `Draft "${ match . params . applicationId }" missing!` ) ; } const event = application . event ; if ( ! event ) { throw new Error ( `Event is not specified in Draft` ) ; } const registerForm = getRegisterForm ( state ) [ event ] ; return { application , registerForm , pageRoute : pageRoute [ event ] } ; } export const ApplicationForm = connect < StateProps , { } , IFormProps & RouteComponentProps < { pageId : string ; groupId : string ; applicationId : string ; } > , IStoreState > ( mapStatetoProps ) ( ApplicationFormView ) ;