From c925e3fe93c20ffb7bd614f1478e2ec780f7cfde Mon Sep 17 00:00:00 2001 From: Aman Chaturvedi Date: Wed, 7 Aug 2024 18:56:03 +0530 Subject: [PATCH] TP-74667 | fix --- .../com/avapp/photoModule/PhotoModule.java | 41 +++++++++-------- src/common/TrackingComponent.tsx | 3 +- src/components/form/AnswerRender.tsx | 1 + .../form/QuestionRenderingEngine.tsx | 45 ++----------------- src/components/form/index.tsx | 2 +- src/components/form/services/forms.service.ts | 37 +++++++++++++++ src/components/utlis/deeplinkingUtils.ts | 25 ++++++++++- src/constants/Global.ts | 1 - src/reducer/feedbackImagesSlice.ts | 5 ++- src/screens/auth/AuthRouter.tsx | 9 ---- src/screens/auth/ProtectedRouter.tsx | 11 +++++ .../caseDetails/interactionsHandler.tsx | 6 +-- src/wmDB/const.ts | 2 +- src/wmDB/model/OfflineImage.ts | 2 + src/wmDB/schema.ts | 2 + 15 files changed, 111 insertions(+), 81 deletions(-) diff --git a/android/app/src/main/java/com/avapp/photoModule/PhotoModule.java b/android/app/src/main/java/com/avapp/photoModule/PhotoModule.java index 23e70cab..e03db6cd 100644 --- a/android/app/src/main/java/com/avapp/photoModule/PhotoModule.java +++ b/android/app/src/main/java/com/avapp/photoModule/PhotoModule.java @@ -44,6 +44,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.text.DateFormatSymbols; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; @@ -129,9 +130,11 @@ public class PhotoModule extends ReactContextBaseJavaModule { // Get time in the format "DD MMM YYYY, HH:mm A" private String getTime() { - SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy, HH:mm a", Locale.getDefault()); - Log.d("PhotoModule", "getTime: " + sdf.format(new Date())); - return sdf.format(new Date()); + DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault()); + symbols.setAmPmStrings(new String[] { "AM", "PM" }); + SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy, h:mm a", symbols); + String formattedDate = sdf.format(new Date()); + return formattedDate; } private Bitmap addTextToBottom(Bitmap img, Context context) { @@ -375,22 +378,18 @@ public class PhotoModule extends ReactContextBaseJavaModule { // Add a method to fetch location private void fetchLocationAndManipulatePhoto(Activity currentActivity) { Log.d("PhotoModule", "fetchLocationAndManipulatePhoto"); - // Create a HandlerThread - HandlerThread handlerThread = new HandlerThread("LocationThread"); - handlerThread.start(); - // Create a Handler attached to the HandlerThread's Looper - Handler locationHandler = new Handler(handlerThread.getLooper()); - - locationHandler.post(() -> { - // If geolocation passed down by the app is not old, then proceed with that - if (!photoText.isEmpty()) { - currentActivity.runOnUiThread(() -> { - continueEditingPhoto(currentActivity); - // Consider stopping the HandlerThread when done - handlerThread.quitSafely(); - }); - } else { - // If geolocation is old, then capture a newer one and use that + // If geolocation passed down by the app is not old, then proceed with that + if (!photoText.isEmpty()) { + currentActivity.runOnUiThread(() -> { + continueEditingPhoto(currentActivity); + }); + } else { + // If geolocation is old, then capture a newer one and use that + HandlerThread handlerThread = new HandlerThread("LocationThread"); + handlerThread.start(); + // Create a Handler attached to the HandlerThread's Looper + Handler locationHandler = new Handler(handlerThread.getLooper()); + locationHandler.post(() -> { GeolocationModule geolocationModule = new GeolocationModule(getReactApplicationContext()); geolocationModule.fetchLocation(new GeolocationModule.LocationCallbackInterface() { @Override @@ -418,8 +417,8 @@ public class PhotoModule extends ReactContextBaseJavaModule { }); } }); - } - }); + }); + } } @ReactMethod diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index 581466c5..1854268c 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -73,6 +73,7 @@ import { sendVideosToServer } from '@services/videoSyncService'; import { getSyncUrl } from '@services/syncJsonDataToBe'; import { handleCheckAndUpdatePullToRefreshStateForNearbyCases } from '@screens/allCases/utils'; import { initialize } from 'react-native-clarity'; +import { updateImageUploadComponent } from '@components/form/services/forms.service'; export enum FOREGROUND_TASKS { GEOLOCATION = 'GEOLOCATION', @@ -396,7 +397,7 @@ const TrackingComponent: React.FC = ({ children }) => { LitmusExperimentNameMap[LitmusExperimentName.ENABLE_IMAGE_GEO_TAGGING], { 'x-customer-id': GLOBAL.AGENT_ID } ); - GLOBAL.ENABLE_IMAGE_GEOTAGGING = enableFeedbackImageGeotagging; + updateImageUploadComponent(enableFeedbackImageGeotagging); if ( MS_CLARITY_PROJECT_ID && !GLOBAL.MS_CLARITY_INITIALIZED && diff --git a/src/components/form/AnswerRender.tsx b/src/components/form/AnswerRender.tsx index 2ef4adc1..b523a09c 100644 --- a/src/components/form/AnswerRender.tsx +++ b/src/components/form/AnswerRender.tsx @@ -126,6 +126,7 @@ const AnswerRender: React.FC = (props) => { } return ; case AnswerType.image: + if(!image?.imageData) return null; return ( = (props) => { - if (props.questionType === 'ImageUpload' && GLOBAL.ENABLE_IMAGE_GEOTAGGING) { - return ( - - - - ); - } - // todo write proper schema // @ts-ignore - const Comp = Component[props.questionType]; - if (!Comp) { + const QuestionComponent = FormComponentList[props.questionType]; + if (!QuestionComponent) { return null; } return ( - + ); }; diff --git a/src/components/form/index.tsx b/src/components/form/index.tsx index c6525a4c..2b1a2759 100644 --- a/src/components/form/index.tsx +++ b/src/components/form/index.tsx @@ -204,7 +204,7 @@ const Widget: React.FC = (props) => { if (!docs) { return; } - dispatch(setDocumentInteractionId({ caseKey: caseKey.current, interactionId })); + dispatch(setDocumentInteractionId({ caseId, caseKey: caseKey.current, interactionId })); dispatch(uploadImages(caseKey.current, docs, interactionId)); }; diff --git a/src/components/form/services/forms.service.ts b/src/components/form/services/forms.service.ts index a7d6d87d..f221a2a9 100644 --- a/src/components/form/services/forms.service.ts +++ b/src/components/form/services/forms.service.ts @@ -7,6 +7,35 @@ import { ConditionAction, FormTemplateV1, } from '../../../types/template.types'; +import Checkbox from '../components/Checkbox'; +import CheckboxGroup from '../components/CheckboxGroup'; +import ImageUploadV2 from '../components/imageUpload/ImageUploadV2'; +import RadioButton from '../components/RadioButton'; +import Rating from '../components/Rating'; +import TextArea from '../components/TextArea'; +import TextInput from '../components/TextInput'; +import Dropdown from '../components/Dropdown'; +import AddressSelection from '../components/AddressSelection'; +import PhoneNumberSelection from '../components/PhoneNumberSelection'; +import DateInput from '../components/DateInput'; +import TimeInput from '../components/TimeInput'; +import ImageUpload from '../components/ImageUpload'; + +export const FormComponentList = { + TextInput, + TextArea, + RadioButton, + ImageUpload, + Checkbox, + Rating, + Dropdown, + CheckboxGroup, + AddressSelection, + PhoneNumberSelection, + DateInput, + TimeInput, + Amount: TextInput, +}; export const getVisitedWidgetsNodeList = ( templateData: FormTemplateV1, @@ -63,3 +92,11 @@ export function getNextJourneyActions(conditionActions: ConditionAction[], conte } return nextActions; } + +export const updateImageUploadComponent = (enableImageGeoTagging: boolean) => { + if (enableImageGeoTagging) { + FormComponentList.ImageUpload = ImageUploadV2; + } else { + FormComponentList.ImageUpload = ImageUpload; + } +}; diff --git a/src/components/utlis/deeplinkingUtils.ts b/src/components/utlis/deeplinkingUtils.ts index e26a3cfa..d909c6fe 100644 --- a/src/components/utlis/deeplinkingUtils.ts +++ b/src/components/utlis/deeplinkingUtils.ts @@ -2,7 +2,6 @@ import { LinkingOptions, getStateFromPath as getDefaultStateFromPath, } from '@react-navigation/native'; -import { CaseDetailStackEnum } from '@screens/caseDetails/CaseDetailStack'; import { Linking } from 'react-native'; import notifee, { InitialNotification } from '@notifee/react-native'; import { GenericType } from '@common/GenericTypes'; @@ -14,6 +13,30 @@ import { AgentRevivalNotificationTemplateActionMap } from '@hooks/useFCM/notific export const LAST_INITIAL_NOTIFICATION_ID = 'LAST_INITIAL_NOTIFICATION_ID'; +enum CaseDetailStackEnum { + COLLECTION_CASE_DETAIL = 'collectionCaseDetail', + CUSTOMER_PROFILE = 'customerProfile', + VKYC_FULL = 'vkycFull', + PDF_FULL = 'pdfFull', + IMAGE_FULL = 'imageFull', + PAYMENTS = 'registerPayments', + ADDRESS_GEO = 'addressGeolocation', + NEW_ADDRESS = 'newAddress', + ADDITIONAL_ADDRESSES = 'additionalAddresses', + GEOLOCATION_OLD_FEEDBACKS = 'geolocationOldFeedbacks', + PAST_FEEDBACK_DETAIL = 'pastFeedbackDetail', + EMI_SCHEDULE = 'EmiSchedule', + ADD_NEW_NUMBER = 'AddNewNumber', + VIEW_RequestHistory = 'viewRequestHistory', + VIEW_REQUEST_DETAIL = 'viewRequestDetail', + RAISE_REQUEST = 'raiseRequest', + SIMILAR_GEOLOCATIONS = 'SimilarGeolocations', + ADDITIONAL_GEOLOCATIONS = 'AdditionalGeolocations', + FEE_WAIVER = 'FeeWaiver', + FEE_WAIVER_HISTORY = 'FeeWaiverHistory', + CALL_CUSTOMER = 'CallCustomer', +} + // Define a type for the Route object for better type checking type Route = { name: string; diff --git a/src/constants/Global.ts b/src/constants/Global.ts index 656e1106..6dd1e0e4 100644 --- a/src/constants/Global.ts +++ b/src/constants/Global.ts @@ -17,7 +17,6 @@ export const GLOBAL = { SELECTED_AGENT_ID: '', BUILD_FLAVOUR: '', MS_CLARITY_INITIALIZED: false, - ENABLE_IMAGE_GEOTAGGING: false, }; interface IGlobalUserData { diff --git a/src/reducer/feedbackImagesSlice.ts b/src/reducer/feedbackImagesSlice.ts index 8f39760d..0068581d 100644 --- a/src/reducer/feedbackImagesSlice.ts +++ b/src/reducer/feedbackImagesSlice.ts @@ -60,14 +60,15 @@ const feedbackImagesSlice = createSlice({ state.docsToBeUploaded[caseKey] = { ...state.intermediateDocsToBeUploaded[caseId], }; - delete state.intermediateDocsToBeUploaded?.[caseId]; } }, setDocumentInteractionId: (state, action) => { - const { caseKey, interactionId } = action.payload; + const { caseId, caseKey, interactionId } = action.payload; if (state.docsToBeUploaded[caseKey]) { state.docsToBeUploaded[caseKey].interactionId = interactionId; } + // delete intermediate docs once the interaction id is set + delete state.intermediateDocsToBeUploaded?.[caseId]; }, removeDocumentByQuestionKey: (state, action) => { const { caseKey, questionKey } = action.payload; diff --git a/src/screens/auth/AuthRouter.tsx b/src/screens/auth/AuthRouter.tsx index 67c5c979..056a45ab 100644 --- a/src/screens/auth/AuthRouter.tsx +++ b/src/screens/auth/AuthRouter.tsx @@ -153,15 +153,6 @@ function AuthRouter() { GLOBAL.MS_CLARITY_INITIALIZED = true; } }); - - getLitmusExperimentResult( - LitmusExperimentNameMap[LitmusExperimentName.ENABLE_IMAGE_GEO_TAGGING], - { - 'x-customer-id': GLOBAL.AGENT_ID, - } - ).then((response) => { - GLOBAL.ENABLE_IMAGE_GEOTAGGING = response; - }); } }, [deviceId]); diff --git a/src/screens/auth/ProtectedRouter.tsx b/src/screens/auth/ProtectedRouter.tsx index 3fed20a1..7d3e3313 100644 --- a/src/screens/auth/ProtectedRouter.tsx +++ b/src/screens/auth/ProtectedRouter.tsx @@ -24,6 +24,9 @@ import useResyncFirebase from '@hooks/useResyncFirebase'; import CaseDetailStack from '@screens/caseDetails/CaseDetailStack'; import { getFirestoreResyncIntervalInMinutes } from '@common/AgentActivityConfigurableConstants'; import { getSelfieDocument } from '@actions/profileActions'; +import getLitmusExperimentResult, { LitmusExperimentName, LitmusExperimentNameMap } from '@services/litmusExperiments.service'; +import { GLOBAL } from '@constants/Global'; +import { updateImageUploadComponent } from '@components/form/services/forms.service'; const Stack = createNativeStackNavigator(); @@ -57,6 +60,14 @@ const ProtectedRouter = () => { useEffect(() => { if (isOnline) { dispatch(getNotifications()); + getLitmusExperimentResult( + LitmusExperimentNameMap[LitmusExperimentName.ENABLE_IMAGE_GEO_TAGGING], + { + 'x-customer-id': GLOBAL.AGENT_ID, + } + ).then((response) => { + updateImageUploadComponent(response); + }); } }, [isOnline]); diff --git a/src/screens/caseDetails/interactionsHandler.tsx b/src/screens/caseDetails/interactionsHandler.tsx index bf3dd4e1..ee00eada 100644 --- a/src/screens/caseDetails/interactionsHandler.tsx +++ b/src/screens/caseDetails/interactionsHandler.tsx @@ -36,12 +36,12 @@ const interactionsHandler = () => { const inProgressCaseIds = useRef([]); - const handleSuccessSubmit = (caseKey: string, interactionId: string) => { + const handleSuccessSubmit = (caseKey: string, interactionId: string, caseId: string) => { const docs = docsToBeUploaded?.[caseKey]?.documents; if (!docs) { return; } - dispatch(setDocumentInteractionId({ caseKey, interactionId })); + dispatch(setDocumentInteractionId({ caseKey, interactionId, caseId })); dispatch(uploadImages(caseKey, docs, interactionId)); }; @@ -73,7 +73,7 @@ const interactionsHandler = () => { } dispatch( syncCaseDetail(modifiedCaseItem, { - onSuccessCB: (_, interactionId) => handleSuccessSubmit(caseKey, interactionId), + onSuccessCB: (_, interactionId) => handleSuccessSubmit(caseKey, interactionId, caseItem.caseId), }) ); } diff --git a/src/wmDB/const.ts b/src/wmDB/const.ts index 107a9193..42973a62 100644 --- a/src/wmDB/const.ts +++ b/src/wmDB/const.ts @@ -4,6 +4,6 @@ export enum TableName { CLICKSTREAM_EVENTS = 'clickstream_events', } -export const DB_VERSION = 5; +export const DB_VERSION = 7; export const DB_NAME = 'AVAPP'; diff --git a/src/wmDB/model/OfflineImage.ts b/src/wmDB/model/OfflineImage.ts index 1bf3aa7a..d3726c5f 100644 --- a/src/wmDB/model/OfflineImage.ts +++ b/src/wmDB/model/OfflineImage.ts @@ -8,6 +8,8 @@ export default class OfflineImage extends Model { @field('idx') idx!: string; @field('image_data') imageData!: string; @field('original_image_uri') originalImageUri!: string; + @field('image_width') imageWidth!: string; + @field('image_height') imageHeight!: string; @readonly @date('created_at') createdAt!: any; @readonly @date('updated_at') updatedAt!: any; } diff --git a/src/wmDB/schema.ts b/src/wmDB/schema.ts index 1b27e451..ded3a4d7 100644 --- a/src/wmDB/schema.ts +++ b/src/wmDB/schema.ts @@ -10,6 +10,8 @@ export default appSchema({ { name: 'idx', type: 'string' }, { name: 'image_data', type: 'string' }, { name: 'original_image_uri', type: 'string' }, + { name: 'image_width', type: 'string' }, + { name: 'image_height', type: 'string' }, ], }), tableSchema({