import { IRegisterFormState } from '@client/forms/register/reducer' ; import { IStoreState } from '@opencrvs/client/src/store' ; import { Section , IFormSection , Event , DeathSection , BirthSection } from '@client/forms' ; const getPartialState = ( state ) : IRegisterFormState => state . registerForm ; function getKey < K extends keyof IRegisterFormState > ( state , key ) { return getPartialState ( state ) [ key ] ; } export const getRegisterForm = ( state ) => { const form = getKey ( state , 'registerForm' ) ; if ( ! form ) { throw new Error ( 'Selector called before data was ready. This should never happen' ) ; } return form ; } ; export const isRegisterFormReady = ( state ) => { const form = getKey ( state , 'registerForm' ) ; return Boolean ( form ) ; } ; export const getEventRegisterForm = ( state , event ) => { return getRegisterForm ( state ) [ event ] ; } ; export const getRegisterFormSection = ( state , key , event ) : IFormSection => { const eventRegisterForm = getEventRegisterForm ( state , event ) ; const section = eventRegisterForm . sections . find ( ( section ) => section . id === key ) ! ; if ( ! section ) { throw new Error ( 'Selector called with an unknown section. This should never happen' ) ; } return section ; } ; export const getBirthSection = ( state , section ) => { return getRegisterFormSection ( state , section , Event . BIRTH ) ; } ; export const getDeathSection = ( state , section ) => { return getRegisterFormSection ( state , section , Event . DEATH ) ; } ;