diff --git a/ProtectedRouter.tsx b/ProtectedRouter.tsx index afe03ffb..998cac6e 100644 --- a/ProtectedRouter.tsx +++ b/ProtectedRouter.tsx @@ -16,6 +16,7 @@ import OtpInput from './src/screens/login/OtpInput'; import TodoList from './src/screens/todoList/TodoList'; import { RootState } from './src/store/store'; import Profile from './src/screens/Profile'; +import interactionsHandler from './src/screens/caseDetails/interactionsHandler'; const Stack = createNativeStackNavigator(); @@ -28,7 +29,7 @@ const ProtectedRouter = () => { // for setting user token in global.ts for api calling's setGlobalUserData(sessionDetails?.sessionToken); - + const d = interactionsHandler() const dispatch = useAppDispatch(); if (!deviceId) { @@ -68,6 +69,7 @@ const ProtectedRouter = () => { component={Widget} options={{ header: () => null, + animation: 'slide_from_right' }} /> ))} diff --git a/RN-UI-LIB b/RN-UI-LIB index ba5a756a..a6ebb528 160000 --- a/RN-UI-LIB +++ b/RN-UI-LIB @@ -1 +1 @@ -Subproject commit ba5a756af9744e4f52bbc9e2aae20fe81f3d6da2 +Subproject commit a6ebb5280b0348a7b819f5f361f021e50615c23b diff --git a/src/action/dataActions.ts b/src/action/dataActions.ts index 5b7edca7..2f97263b 100644 --- a/src/action/dataActions.ts +++ b/src/action/dataActions.ts @@ -1,5 +1,5 @@ import axiosInstance, {ApiKeys, getApiUrl} from '../components/utlis/apiHelper'; -import { navigateToScreen } from '../components/utlis/navigationUtlis'; +import {navigateToScreen} from '../components/utlis/navigationUtlis'; import { resetTodoList, setCasesListData, @@ -52,3 +52,17 @@ export const postPinnedList = dispatch(setTodoListOffline(updatedCaseList)); }); }; + +export const syncCaseDetail = (data: any) => (dispatch: AppDispatch) => { + const url = getApiUrl(ApiKeys.FEEDBACK); + + console.log(data); + axiosInstance + .post(url, { + id: data.id, + ...data, + }) + .then(res => console.log(res.data)) + .catch(err => console.log(err, 'error')); + console.log(data); +}; diff --git a/src/common/IconLabel.tsx b/src/common/IconLabel.tsx index d679fbf3..fa0612af 100644 --- a/src/common/IconLabel.tsx +++ b/src/common/IconLabel.tsx @@ -24,7 +24,7 @@ const IconLabel: React.FC = props => { {icon ? icon : } - {text} + {text} ); }; diff --git a/src/components/form/components/CheckboxGroup.tsx b/src/components/form/components/CheckboxGroup.tsx index 3455caa2..5bde858e 100644 --- a/src/components/form/components/CheckboxGroup.tsx +++ b/src/components/form/components/CheckboxGroup.tsx @@ -1,20 +1,18 @@ -import React, { useEffect } from 'react'; -import { View } from 'react-native'; +import React, {useEffect} from 'react'; +import {View} from 'react-native'; -import { useState } from 'react'; -import { Control, Controller } from 'react-hook-form'; -import { useSelector } from 'react-redux'; -import RNDropDown from '../../../../RN-UI-LIB/src/components/dropdown/Dropdown'; -import RNOptions from '../../../../RN-UI-LIB/src/components/dropdown/Options'; +import {useState} from 'react'; +import {Control, Controller} from 'react-hook-form'; +import {useSelector} from 'react-redux'; +import RNCheckboxGroup from '../../../../RN-UI-LIB/src/components/chechbox/CheckboxGroup'; +import {ICheckboxOption} from '../../../../RN-UI-LIB/src/components/chechbox/types'; import Text from '../../../../RN-UI-LIB/src/components/Text'; -import { GenericStyles } from '../../../../RN-UI-LIB/src/styles'; -import template from '../../../data/RealTemplateData.json'; -import { RootState } from '../../../store/store'; +import {GenericStyles} from '../../../../RN-UI-LIB/src/styles'; +import {RootState} from '../../../store/store'; +import {AnswerType} from '../interface'; import QuestionRenderingEngine from '../QuestionRenderingEngine'; import ErrorMessage from './ErrorMessage'; -import RNCheckboxGroup from '../../../../RN-UI-LIB/src/components/chechbox/CheckboxGroup'; -import { ICheckboxOption } from '../../../../RN-UI-LIB/src/components/chechbox/types'; -import { AnswerType } from '../interface'; +import {useAppSelector } from '../../../hooks'; interface ICheckBoxGroup { questionType: string; @@ -29,6 +27,7 @@ interface ICheckBoxGroup { const CheckBoxGroup: React.FC = props => { const {questionId, widgetId, journeyId, caseId, sectionId, error} = props; + const template = useAppSelector(state => state.case.templateData) const question = template.questions[questionId as keyof typeof template.questions]; const options = template.options; @@ -38,9 +37,7 @@ const CheckBoxGroup: React.FC = props => { const dataFromRedux = useSelector( (state: RootState) => - state.case.caseForm?.[caseId]?.[journeyId]?.[widgetId]?.[ - sectionId - ]?.[questionId], + state.case.caseForm?.[caseId]?.[journeyId]?.widgetContext?.[widgetId]?.sectionContext?.[sectionId]?.questionContext?.[questionId] ); useEffect(() => { @@ -50,7 +47,6 @@ const CheckBoxGroup: React.FC = props => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [dataFromRedux]); - const computeNextQuestion = (optionId: keyof typeof options) => { if (options[optionId]?.associateQuestions.length < 1) { setAssociatedQuestions([]); @@ -59,38 +55,52 @@ const CheckBoxGroup: React.FC = props => { setAssociatedQuestions(options[optionId]?.associateQuestions); }; - const optiosList = question.options.map(option =>({label: options[option].text, value: option})); + const optiosList = question.options.map((option: any) => ({ + label: options[option].text, + value: option, + })); - const handleChange = (change : Array | null, onChange : (...event: any[]) => void) => { - const values = change?.map(item=>item.value) + const handleChange = ( + change: Array | null, + onChange: (...event: any[]) => void, + ) => { + const values = change?.map(item => item.value); onChange({ answer: values, - type: AnswerType.array - }) - } + type: AnswerType.array, + }); + }; return ( - {question.text ? - {question.text}{' '} - {question.type === 'mandatory' && ( - * - )} - : null} + {question.text ? ( + + {question.text}{' '} + {question.type === 'mandatory' && ( + * + )} + + ) : null} { - console.log(value) - return( - handleChange(change, onChange))} defaultValue={value?.answer} options={optiosList} /> - ) + console.log(value); + return ( + + handleChange(change, onChange) + } + defaultValue={value?.answer} + options={optiosList} + /> + ); }} - name={`${sectionId}.${questionId}`} + name={`widgetContext.${widgetId}.sectionContext.${props.sectionId}.questionContext.${questionId}`} /> - + {associatedQuestions?.map((nextQuestion: string, index) => { if ( template.questions[ diff --git a/src/components/form/components/Dropdown.tsx b/src/components/form/components/Dropdown.tsx index 786ca778..66f58875 100644 --- a/src/components/form/components/Dropdown.tsx +++ b/src/components/form/components/Dropdown.tsx @@ -8,11 +8,11 @@ import RNDropDown from '../../../../RN-UI-LIB/src/components/dropdown/Dropdown'; import RNOptions from '../../../../RN-UI-LIB/src/components/dropdown/Options'; import Text from '../../../../RN-UI-LIB/src/components/Text'; import {GenericStyles} from '../../../../RN-UI-LIB/src/styles'; -import template from '../../../data/RealTemplateData.json'; import {RootState} from '../../../store/store'; import QuestionRenderingEngine from '../QuestionRenderingEngine'; import ErrorMessage from './ErrorMessage'; -import {AnswerType} from '../interface'; +import {AnswerType, Options} from '../interface'; +import { useAppSelector } from '../../../hooks'; interface IDropDown { questionType: string; @@ -27,6 +27,7 @@ interface IDropDown { const DropDown: React.FC = props => { const {questionId, widgetId, journeyId, caseId, sectionId, error} = props; + const template = useAppSelector(state => state.case.templateData); const question = template.questions[questionId as keyof typeof template.questions]; const options = template.options; @@ -36,9 +37,7 @@ const DropDown: React.FC = props => { const dataFromRedux = useSelector( (state: RootState) => - state.case.caseForm?.[caseId]?.[journeyId]?.[widgetId]?.[ - sectionId - ]?.[questionId], + state.case.caseForm?.[caseId]?.[journeyId]?.widgetContext?.[widgetId]?.sectionContext?.[sectionId]?.questionContext?.[questionId] ); useEffect(() => { @@ -48,27 +47,6 @@ const DropDown: React.FC = props => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [dataFromRedux]); - // const dispatch = useDispatch(); - // const answer = useSelector( - // (state: RootState) => - // state.counter.caseForm?.[caseId]?.[journeyId]?.[widgetId]?.[ - // sectionId - // ]?.[questionId] || 'not_found', - // ); - - // const registerValue = (id: string) => { - // dispatch( - // updateInteraction({ - // caseId, - // journeyId, - // widgetId, - // questionId, - // answer: id, - // sectionId, - // }), - // ); - // }; - const computeNextQuestion = (optionId: keyof typeof options) => { if (options[optionId]?.associateQuestions.length < 1) { setAssociatedQuestions([]); @@ -105,22 +83,21 @@ const DropDown: React.FC = props => { bottomSheetHeight={question.options.length - 1 * 10} onValueChange={change => handleChange(change, onChange)} value={value?.answer}> - {question.options.map(option => { + {question.options.map((option: keyof typeof options) => { return ( ); })} )} - name={`${sectionId}.${questionId}`} + name={`widgetContext.${widgetId}.sectionContext.${props.sectionId}.questionContext.${questionId}`} /> - + {associatedQuestions?.map((nextQuestion: string, index) => { if ( template.questions[ diff --git a/src/components/form/components/ImageUpload.tsx b/src/components/form/components/ImageUpload.tsx index e94c733d..03de9924 100644 --- a/src/components/form/components/ImageUpload.tsx +++ b/src/components/form/components/ImageUpload.tsx @@ -1,24 +1,23 @@ +import React, { useEffect } from 'react'; +import { Control, Controller } from 'react-hook-form'; import { - Image, ImageBackground, Pressable, StyleSheet, - View, + View } from 'react-native'; -import React, {useEffect} from 'react'; -import {Control, Controller} from 'react-hook-form'; import CameraClickPicture from '../../../../RN-UI-LIB/src/components/camera_click_picture/CameraClickPicture'; -import template from '../../../data/RealTemplateData.json'; -import {GenericStyles} from '../../../../RN-UI-LIB/src/styles'; -import {useState} from 'react'; -import {useSelector} from 'react-redux'; -import {RootState} from '../../../store/store'; -import ErrorMessage from './ErrorMessage'; -import DeleteIcon from '../../../../RN-UI-LIB/src/Icons/DeleteIcon'; -import {COLORS} from '../../../../RN-UI-LIB/src/styles/colors'; +import { useState } from 'react'; +import { useSelector } from 'react-redux'; import Text from '../../../../RN-UI-LIB/src/components/Text'; +import DeleteIcon from '../../../../RN-UI-LIB/src/Icons/DeleteIcon'; +import { GenericStyles } from '../../../../RN-UI-LIB/src/styles'; +import { COLORS } from '../../../../RN-UI-LIB/src/styles/colors'; +import { useAppSelector } from '../../../hooks'; +import { RootState } from '../../../store/store'; import { AnswerType } from '../interface'; +import ErrorMessage from './ErrorMessage'; interface IImageUpload { questionType: string; @@ -34,13 +33,12 @@ interface IImageUpload { const ImageUpload: React.FC = props => { const {questionId, error, sectionId, caseId, journeyId, widgetId} = props; const [image, setImage] = useState(''); + const template = useAppSelector(state => state.case.templateData); const question = template.questions[questionId as keyof typeof template.questions]; const dataFromRedux = useSelector( (state: RootState) => - state.case.caseForm?.[caseId]?.[journeyId]?.[widgetId]?.[ - sectionId - ]?.[questionId], + state.case.caseForm?.[caseId]?.[journeyId]?.widgetContext?.[widgetId]?.sectionContext?.[sectionId]?.questionContext?.[questionId] ); useEffect(() => { @@ -84,7 +82,7 @@ const ImageUpload: React.FC = props => { onPictureClickSuccess={clickedImage => handleChange(clickedImage, onChange)} /> )} - name={`${props.sectionId}.${questionId}`} + name={`widgetContext.${widgetId}.sectionContext.${props.sectionId}.questionContext.${questionId}`} /> ) : ( @@ -97,7 +95,7 @@ const ImageUpload: React.FC = props => { )} - + ); }; diff --git a/src/components/form/components/RadioButton.tsx b/src/components/form/components/RadioButton.tsx index bc7b7c45..9c1f1b68 100644 --- a/src/components/form/components/RadioButton.tsx +++ b/src/components/form/components/RadioButton.tsx @@ -9,11 +9,11 @@ import RadioChip from '../../../../RN-UI-LIB/src/components/radio_button/RadioCh import RadioGroup from '../../../../RN-UI-LIB/src/components/radio_button/RadioGroup'; import Text from '../../../../RN-UI-LIB/src/components/Text'; import {GenericStyles} from '../../../../RN-UI-LIB/src/styles'; -import template from '../../../data/RealTemplateData.json'; import {RootState} from '../../../store/store'; import QuestionRenderingEngine from '../QuestionRenderingEngine'; import ErrorMessage from './ErrorMessage'; -import { AnswerType } from '../interface'; +import {AnswerType} from '../interface'; +import {useAppSelector} from '../../../hooks'; interface IRadioButton { questionType: string; @@ -28,8 +28,8 @@ interface IRadioButton { const RadioButton: React.FC = props => { const {questionId, widgetId, journeyId, caseId, sectionId, error} = props; - const question = - template.questions[questionId as keyof typeof template.questions]; + const template = useAppSelector(state => state.case.templateData); + const question = template.questions[questionId]; const options = template.options; const [associatedQuestions, setAssociatedQuestions] = useState< Array @@ -37,9 +37,9 @@ const RadioButton: React.FC = props => { const dataFromRedux = useSelector( (state: RootState) => - state.case.caseForm?.[caseId]?.[journeyId]?.[widgetId]?.[ - sectionId - ]?.[questionId], + state.case.caseForm?.[caseId]?.[journeyId]?.widgetContext?.[ + widgetId + ]?.sectionContext?.[sectionId]?.questionContext?.[questionId], ); useEffect(() => { @@ -49,27 +49,6 @@ const RadioButton: React.FC = props => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [dataFromRedux]); - // const dispatch = useDispatch(); - // const answer = useSelector( - // (state: RootState) => - // state.counter.caseForm?.[caseId]?.[journeyId]?.[widgetId]?.[ - // sectionId - // ]?.[questionId] || 'not_found', - // ); - - // const registerValue = (id: string) => { - // dispatch( - // updateInteraction({ - // caseId, - // journeyId, - // widgetId, - // questionId, - // answer: id, - // sectionId, - // }), - // ); - // }; - const computeNextQuestion = (optionId: keyof typeof options) => { if (options[optionId]?.associateQuestions.length < 1) { setAssociatedQuestions([]); @@ -78,16 +57,16 @@ const RadioButton: React.FC = props => { setAssociatedQuestions(options[optionId]?.associateQuestions); }; - - const handleChange = (change : string | null, onChange : (...event: any[]) => void) => { + const handleChange = ( + change: string | null, + onChange: (...event: any[]) => void, + ) => { computeNextQuestion(change as keyof typeof options); onChange({ answer: change, - type: AnswerType.option - }) - } - - + type: AnswerType.option, + }); + }; return ( @@ -110,32 +89,35 @@ const RadioButton: React.FC = props => { question.metadata.orientation || 'verticle' }> {question?.metadata.buttonType === 'button' - ? question.options.map(option => { - return( - - )}) - : question.options.map(option => ( + ? question.options.map((option: keyof typeof options) => { + return ( + + ); + }) + : question.options.map((option: keyof typeof options) => ( ))} )} - name={`${sectionId}.${questionId}`} + name={`widgetContext.${widgetId}.sectionContext.${props.sectionId}.questionContext.${questionId}`} + /> + - {associatedQuestions?.map((nextQuestion: string, index) => { if ( template.questions[ @@ -148,7 +130,7 @@ const RadioButton: React.FC = props => { questionType={ template.questions[ nextQuestion as keyof typeof template.questions - ].input_type + ].inputType } questionId={nextQuestion} name={widgetId} diff --git a/src/components/form/components/Rating.tsx b/src/components/form/components/Rating.tsx index 59a05209..a8b8509e 100644 --- a/src/components/form/components/Rating.tsx +++ b/src/components/form/components/Rating.tsx @@ -3,10 +3,10 @@ import React from 'react'; import {Control, Controller} from 'react-hook-form'; import {GenericStyles} from '../../../../RN-UI-LIB/src/styles'; import StarRating from '../../../../RN-UI-LIB/src/components/star_rating/StarRating'; -import template from '../../../data/RealTemplateData.json'; import ErrorMessage from './ErrorMessage'; import Text from '../../../../RN-UI-LIB/src/components/Text'; import { AnswerType } from '../interface'; +import { useAppSelector } from '../../../hooks'; interface IRating { questionType: string; questionId: string; @@ -19,8 +19,8 @@ interface IRating { } const Rating: React.FC = props => { - const {questionId, error, sectionId} = props; - + const {questionId, error, sectionId, widgetId} = props; + const template = useAppSelector(state => state.case.templateData); const question = template.questions[questionId as keyof typeof template.questions]; if (!question) { @@ -55,9 +55,9 @@ const Rating: React.FC = props => { maxRating={5} /> )} - name={`${props.sectionId}.${questionId}`} + name={`widgetContext.${widgetId}.sectionContext.${props.sectionId}.questionContext.${questionId}`} /> - + ); }; diff --git a/src/components/form/components/TextArea.tsx b/src/components/form/components/TextArea.tsx index b094fd84..44139df9 100644 --- a/src/components/form/components/TextArea.tsx +++ b/src/components/form/components/TextArea.tsx @@ -2,12 +2,12 @@ import {View} from 'react-native'; import React from 'react'; import {Control, Controller} from 'react-hook-form'; -import template from '../../../data/RealTemplateData.json'; import RNTextArea from '../../../../RN-UI-LIB/src/components/TextArea'; import Text from '../../../../RN-UI-LIB/src/components/Text'; import {GenericStyles} from '../../../../RN-UI-LIB/src/styles'; import ErrorMessage from './ErrorMessage'; import { AnswerType } from '../interface'; +import { useAppSelector } from '../../../hooks'; interface ITextArea { questionType: string; @@ -21,8 +21,8 @@ interface ITextArea { } const TextArea: React.FC = props => { - const {questionId, error, sectionId} = props; - + const {questionId, error, sectionId, widgetId} = props; + const template = useAppSelector(state => state.case.templateData); const question = template.questions[questionId as keyof typeof template.questions]; if (!question) { @@ -58,9 +58,9 @@ const TextArea: React.FC = props => { title="" /> )} - name={`${props.sectionId}.${questionId}`} + name={`widgetContext.${widgetId}.sectionContext.${props.sectionId}.questionContext.${questionId}`} /> - + ); }; diff --git a/src/components/form/components/TextInput.tsx b/src/components/form/components/TextInput.tsx index 63ffb5d1..7378fe97 100644 --- a/src/components/form/components/TextInput.tsx +++ b/src/components/form/components/TextInput.tsx @@ -4,10 +4,10 @@ import RNTextInput from '../../../../RN-UI-LIB/src/components/TextInput'; import {GenericStyles} from '../../../../RN-UI-LIB/src/styles'; import {Control, Controller} from 'react-hook-form'; -import template from '../../../data/RealTemplateData.json'; import Text from '../../../../RN-UI-LIB/src/components/Text'; import ErrorMessage from './ErrorMessage'; import { AnswerType } from '../interface'; +import { useAppSelector } from '../../../hooks'; interface ITextInput { questionType: string; @@ -21,8 +21,8 @@ interface ITextInput { } const TextInput: React.FC = props => { - const {questionId, error, sectionId} = props; - + const {questionId, error, sectionId, widgetId} = props; + const template = useAppSelector(state => state.case.templateData); const question = template.questions[questionId as keyof typeof template.questions]; if (!question) { @@ -56,9 +56,9 @@ const TextInput: React.FC = props => { containerStyle={[GenericStyles.mt12]} /> )} - name={`${props.sectionId}.${questionId}`} + name={`widgetContext.${widgetId}.sectionContext.${props.sectionId}.questionContext.${questionId}`} /> - + ); }; diff --git a/src/components/form/index.tsx b/src/components/form/index.tsx index 2ab23adc..df784c79 100644 --- a/src/components/form/index.tsx +++ b/src/components/form/index.tsx @@ -1,22 +1,21 @@ -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 { useDispatch, useSelector } from 'react-redux'; +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 {useDispatch, useSelector} from 'react-redux'; import Button from '../../../RN-UI-LIB/src/components/Button'; import Heading from '../../../RN-UI-LIB/src/components/Heading'; import Text from '../../../RN-UI-LIB/src/components/Text'; +import BackArrowIcon from '../../../RN-UI-LIB/src/Icons/BackArrowIcon'; import CloseIcon from '../../../RN-UI-LIB/src/Icons/CloseIcon'; -import { GenericStyles, getShadowStyle } from '../../../RN-UI-LIB/src/styles'; -import { COLORS } from '../../../RN-UI-LIB/src/styles/colors'; -import Realjson from '../../data/RealTemplateData.json'; -import { updateInteraction } from '../../reducer/caseReducre'; -import { RootState } from '../../store/store'; -import { goBack, navigateToScreen } from '../utlis/navigationUtlis'; -import { - ConditionType, - IDecision, ILeaf -} from './interface'; +import {GenericStyles, getShadowStyle} from '../../../RN-UI-LIB/src/styles'; +import {COLORS} from '../../../RN-UI-LIB/src/styles/colors'; +import {useAppSelector} from '../../hooks'; +import { updateCaseDetail } from '../../reducer/allCasesSlice'; +import {deleteInteraction, updateInteraction} from '../../reducer/caseReducre'; +import {RootState} from '../../store/store'; +import {goBack, navigateToScreen} from '../utlis/navigationUtlis'; +import {ConditionType, IDecision, ILeaf} from './interface'; import RenderQuestion from './RenderQuestion'; interface IWidget { @@ -32,21 +31,25 @@ interface IWidget { const Widget: React.FC = props => { const {name, params} = props.route; const {caseId, journey} = params; - const {sections, transitionRules, isLeaf} = - Realjson.widget[name as keyof typeof Realjson.widget]; - const sectionMap = Realjson.sections; + const templateData = useAppSelector(state => state.case.templateData); + const caseData = useAppSelector(state => state.allCases.caseDetails[caseId]); + const {sections, transitionRules, isLeaf} = templateData.widget[name]; + const sectionMap = templateData.sections; const {actions, conditions} = transitionRules; const [error, setError] = useState(); const dispatch = useDispatch(); - const dataToBeValidated = useSelector( - (state: RootState) => state.case.caseForm?.[caseId]?.[journey]?.[name], + const dataToBeValidated = useAppSelector( + state => state.case.caseForm?.[caseId]?.[journey], ); + console.log(dataToBeValidated); + const journeyData = useSelector( (state: RootState) => state.case.caseForm?.[caseId]?.[journey], ); + console.log(journeyData); const {control, handleSubmit} = useForm({ defaultValues: dataToBeValidated, @@ -55,7 +58,11 @@ const Widget: React.FC = props => { const evaluateLeaf = (leaf: ILeaf, data: any): boolean => { switch (leaf.operator) { case 'MATCHES': - return leaf.right === data[leaf.section][leaf.left]?.answer; + return ( + leaf.right === + data?.widgetContext?.[name]?.sectionContext?.[leaf.section] + ?.questionContext?.[leaf.left]?.answer + ); default: return false; } @@ -66,7 +73,9 @@ const Widget: React.FC = props => { case 'MATCHES': return ( leaf.right === - journeyData[leaf.widgetId][leaf.section][leaf.left] + journeyData.widgetContext[leaf.widgetId]?.sectionContext?.[ + leaf.section + ]?.questionContext?.[leaf.left] ); default: return false; @@ -114,7 +123,7 @@ const Widget: React.FC = props => { }; const onSubmit = (data: any) => { - console.log(data) + console.log(data, 'submit'); dispatch( updateInteraction({ caseId, @@ -139,16 +148,31 @@ const Widget: React.FC = props => { answer: data, }), ); - const rules = Realjson.journey[journey].transitionRules.conditions; - const screeenAction = Realjson.journey[journey].transitionRules.actions; - let nextScreenName = ''; + const rules = + templateData.journey[journey as keyof typeof templateData.journey] + .transitionRules.conditions; + const screeenAction = + templateData.journey[journey as keyof typeof templateData.journey] + .transitionRules.actions; + let nextActions = ''; if (rules.condition_type === 'LEAF_NODE') { - nextScreenName = screeenAction[evaluateLeafJourney(rules)]; + nextActions = screeenAction[String(evaluateLeafJourney(rules as ILeaf))]; } else { - const answer = String(evaluateComposite(rules)); - nextScreenName = screeenAction[answer]; + const answer = String(evaluateComposite(rules as IDecision, data)); + nextActions = screeenAction[answer]; } + + console.log(nextActions); // dispatch some actions to redux store + dispatch(updateCaseDetail({ + caseId, + journeyId: journey, + widgetId: name, + answer: data, + caseData: caseData, + nextActions + })) + navigateToScreen('Home', { journey: journey, caseId, @@ -185,7 +209,7 @@ const Widget: React.FC = props => { GenericStyles.p16, GenericStyles.whiteBackground, ]}> - {sections.map((section, index: number) => ( + {sections.map((section: any, index: number) => ( = props => { variant={'secondary'} style={styles.fb45} title={'Back'} - onPress={goBack} + onPress={() => { + dispatch( + deleteInteraction({ + caseId, + journeyId: journey, + widgetId: name, + }), + ); + goBack(); + }} + leftIcon={} />