From e9408bc8e5958040c7f981a6ad92f4593930288c Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Fri, 24 May 2024 16:34:52 +0100 Subject: [PATCH] refactor: add snackbar warning if not mobile on odk redirect --- .../src/components/DialogTaskActions.jsx | 19 +++++++++++++----- .../FeatureSelectionPopup.tsx | 20 +++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/components/DialogTaskActions.jsx b/src/frontend/src/components/DialogTaskActions.jsx index 606b67c149..194c1fe385 100755 --- a/src/frontend/src/components/DialogTaskActions.jsx +++ b/src/frontend/src/components/DialogTaskActions.jsx @@ -206,12 +206,21 @@ export default function Dialog({ taskId, feature, map, view }) { type="submit" className="fmtm-font-bold !fmtm-rounded fmtm-text-sm !fmtm-py-2 !fmtm-w-full fmtm-flex fmtm-justify-center" onClick={() => { - const xformId = projectInfo.xform_id; + const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( + navigator.userAgent, + ); - try { - document.location.href = `odkcollect://form/${xformId}?task_id=${taskId}`; - } catch (error) { - document.location.href = 'https://play.google.com/store/apps/details?id=org.odk.collect.android'; + if (isMobile) { + document.location.href = `odkcollect://form/${projectInfo.xform_id}?task_id=${taskId}`; + } else { + dispatch( + CommonActions.SetSnackBar({ + open: true, + message: 'Requires a mobile phone with ODK Collect.', + variant: 'warning', + duration: 3000, + }), + ); } }} /> diff --git a/src/frontend/src/components/ProjectDetailsV2/FeatureSelectionPopup.tsx b/src/frontend/src/components/ProjectDetailsV2/FeatureSelectionPopup.tsx index b5034290ef..e7a6411334 100644 --- a/src/frontend/src/components/ProjectDetailsV2/FeatureSelectionPopup.tsx +++ b/src/frontend/src/components/ProjectDetailsV2/FeatureSelectionPopup.tsx @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react'; import CoreModules from '@/shared/CoreModules'; import AssetModules from '@/shared/AssetModules'; +import { CommonActions } from '@/store/slices/CommonSlice'; import Button from '@/components/common/Button'; import { ProjectActions } from '@/store/slices/ProjectSlice'; import environment from '@/environment'; @@ -15,7 +16,6 @@ import MapStyles from '@/hooks/MapStyles'; type TaskFeatureSelectionPopupPropType = { taskId: number; featureProperties: TaskFeatureSelectionProperties | null; - taskId: number; taskFeature: Record; map: any; view: any; @@ -162,10 +162,22 @@ const TaskFeatureSelectionPopup = ({ ); } - try { + const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( + navigator.userAgent, + ); + + if (isMobile) { + // Load entity in ODK Collect by intent document.location.href = `odkcollect://form/${xformId}?task_id=${taskId}&existing=${entityUuid}`; - } catch (error) { - document.location.href = 'https://play.google.com/store/apps/details?id=org.odk.collect.android'; + } else { + dispatch( + CommonActions.SetSnackBar({ + open: true, + message: 'Requires a mobile phone with ODK Collect.', + variant: 'warning', + duration: 3000, + }), + ); } }} />