diff --git a/src/components/form/QuestionRenderingEngine.tsx b/src/components/form/QuestionRenderingEngine.tsx index 5bb8a3b5..985ff16c 100644 --- a/src/components/form/QuestionRenderingEngine.tsx +++ b/src/components/form/QuestionRenderingEngine.tsx @@ -9,6 +9,7 @@ import Rating from './components/Rating'; import TextArea from './components/TextArea'; import TextInput from './components/TextInput'; import Dropdown from './components/Dropdown'; +import Address from './components/Address'; const Component = { TextInput, @@ -18,7 +19,8 @@ const Component = { Checkbox, Rating, Dropdown, - CheckboxGroup + CheckboxGroup, + Address }; interface IQuestionRenderingEngine { diff --git a/src/components/form/components/Address.tsx b/src/components/form/components/Address.tsx new file mode 100644 index 00000000..8b4f506b --- /dev/null +++ b/src/components/form/components/Address.tsx @@ -0,0 +1,66 @@ +import {StyleSheet, View} from 'react-native'; +import React from 'react'; +import Text from '../../../../RN-UI-LIB/src/components/Text'; +import Heading from '../../../../RN-UI-LIB/src/components/Heading'; +import { COLORS } from '../../../../RN-UI-LIB/src/styles/colors'; +import { GenericStyles } from '../../../../RN-UI-LIB/src/styles'; +import { useAppSelector } from '../../../hooks'; +import { Address as IAddressType, TaskTitle } from '../../../screens/allCases/interface'; +import { Task } from '../../../screens/caseDetails/interface'; + +interface IAddress { + caseId: string; + questionId: string; +} + +const getAddress = (address: IAddressType) => { + if(!address) return ''; + return `${address.houseNumber} ${address.lineOne} ${address.lineTwo} ${address.locality} ${address.city} ${address.pinCode} ${address.state}` +} + +const Address: React.FC = props => { + const { caseId, questionId } = props; + + const template = useAppSelector(state => state.case.templateData); + const question = + template.questions[questionId as keyof typeof template.questions]; + + const { showCommunicationAddress = true, showPermanentAddress = true } = question?.metadata || {}; + + + const caseTaskList = useAppSelector( + state => state.allCases.caseDetails[caseId].tasks, + ); + + const permanentAddressMetaData = caseTaskList.find((task: Task) => task.taskType === TaskTitle.PERMANENT_ADDRESS_VERIFICATION_TASK)?.metadata; + const communicationAddressMetaData = caseTaskList.find((task: Task) => task.taskType === TaskTitle.COMMUNICATION_ADDRESS_VERIFICATION_TASK)?.metadata; + + return ( + <> + { + showCommunicationAddress && ( + + + Communication address + + {getAddress(communicationAddressMetaData?.address)} + + ) + } + { + showPermanentAddress && ( + + + Permanent address + + {getAddress(permanentAddressMetaData?.address)} + + ) + } + + ); +}; + +export default Address; + +const styles = StyleSheet.create({}); diff --git a/src/components/form/index.tsx b/src/components/form/index.tsx index 1d7124c0..a80ddf34 100644 --- a/src/components/form/index.tsx +++ b/src/components/form/index.tsx @@ -2,6 +2,7 @@ import React, {useState} from 'react'; import {useForm} from 'react-hook-form'; import {Pressable, ScrollView, StyleSheet, View} from 'react-native'; import {SafeAreaView} from 'react-native-safe-area-context'; +import { useNavigationState } from '@react-navigation/native'; import {useDispatch, useSelector} from 'react-redux'; import Button from '../../../RN-UI-LIB/src/components/Button'; import Heading from '../../../RN-UI-LIB/src/components/Heading'; @@ -22,6 +23,8 @@ import {goBack, navigateToScreen, popToScreen, pushToScreen} from '../utlis/navi import {ConditionType, IDecision, ILeaf} from './interface'; import RenderQuestion from './RenderQuestion'; +const CASE_DETAIL_SCREEN_NAME = 'caseDetail'; + interface IWidget { route: { name: string; @@ -29,17 +32,22 @@ interface IWidget { caseId: string; journey: string; }; - }; + } } const Widget: React.FC = props => { + const navigationRoutes = useNavigationState(state => state.routes); + const previousScreenRoute = navigationRoutes[navigationRoutes.length - 2]; + + const [isJourneyFirstScreen] = useState(previousScreenRoute.name === CASE_DETAIL_SCREEN_NAME); + const {name, params} = props.route; const {caseId, journey} = params; const templateData = useAppSelector(state => state.case.templateData); const caseData = useAppSelector( state => state.allCases.caseDetails[caseId], ); - const {sections, transitionRules, isLeaf, isRoot} = templateData.widget[name]; + const {sections, transitionRules, isLeaf} = templateData.widget[name]; const sectionMap = templateData.sections; const {actions, conditions} = transitionRules; const [error, setError] = useState(); @@ -284,7 +292,7 @@ const Widget: React.FC = props => { styles.borderTop, ]}> { - !isRoot && ( + !isJourneyFirstScreen && (