Skip to content

Commit

Permalink
(feat) O3-2782: Show an inline notification for camera access errors …
Browse files Browse the repository at this point in the history
…in the add attachment modal (#1631)

(feat) Show inline notification for camera access error

Co-authored-by: Dennis Kigen <[email protected]>
  • Loading branch information
usamaidrsk and denniskigen authored Feb 2, 2024
1 parent 5c71287 commit 9f3f1cd
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
import React, { useState, useCallback, useMemo, useEffect, useRef, useContext } from 'react';
import { type UploadedFile, type FetchResponse, showSnackbar } from '@openmrs/esm-framework';
import CameraMediaUploaderContext from './camera-media-uploader-context.resources';
import { useTranslation } from 'react-i18next';
import { Tabs, Tab, TabList, TabPanels, TabPanel, ModalHeader, ModalBody, InlineNotification } from '@carbon/react';
import { type FetchResponse, type UploadedFile } from '@openmrs/esm-framework';
import CameraComponent from './camera.component';
import styles from './camera-media-uploader.scss';
import { Tabs, Tab, TabList, TabPanels, TabPanel, ModalHeader, ModalBody } from '@carbon/react';
import MediaUploaderComponent from './media-uploader.component';
import CameraMediaUploaderContext from './camera-media-uploader-context.resources';
import FileReviewContainer from './file-review.component';
import MediaUploaderComponent from './media-uploader.component';
import UploadingStatusComponent from './uploading-status.component';
import styles from './camera-media-uploader.scss';

interface CameraMediaUploaderModalProps {
multipleFiles?: boolean;
allowedExtensions: Array<string> | null;
cameraOnly?: boolean;
collectDescription?: boolean;
saveFile: (file: UploadedFile) => Promise<FetchResponse<any>>;
closeModal: () => void;
collectDescription?: boolean;
multipleFiles?: boolean;
onCompletion?: () => void;
allowedExtensions: Array<string> | null;
saveFile: (file: UploadedFile) => Promise<FetchResponse<any>>;
}

const CameraMediaUploaderModal: React.FC<CameraMediaUploaderModalProps> = ({
allowedExtensions,
cameraOnly,
multipleFiles,
collectDescription,
saveFile,
closeModal,
collectDescription,
multipleFiles,
onCompletion,
allowedExtensions,
saveFile,
}) => {
const [error, setError] = useState<Error>(undefined);
const [error, setError] = useState<Error>(null);
const [filesToUpload, setFilesToUpload] = useState<Array<UploadedFile>>([]);
const [uploadFilesToServer, setUploadFilesToServer] = useState(false);
const { t } = useTranslation();

useEffect(() => {
if (error) {
showSnackbar({
subtitle: error.message,
kind: 'error',
title: t('cameraError', 'Camera Error'),
});
}
}, [error, t]);

const handleTakePhoto = useCallback((file: string) => {
setFilesToUpload([
Expand Down Expand Up @@ -106,7 +95,7 @@ const CameraMediaUploaderModal: React.FC<CameraMediaUploaderModalProps> = ({
const CameraMediaUploadTabs = () => {
const { t } = useTranslation();
const [view, setView] = useState('upload');
const { cameraOnly, closeModal } = useContext(CameraMediaUploaderContext);
const { cameraOnly, closeModal, error } = useContext(CameraMediaUploaderContext);
const mediaStream = useRef<MediaStream | undefined>();

const stopCameraStream = useCallback(() => {
Expand Down Expand Up @@ -134,6 +123,15 @@ const CameraMediaUploadTabs = () => {
</TabList>
<TabPanels>
<TabPanel>
{error ? (
<InlineNotification
subtitle={t(
'cameraAccessErrorMessage',
'Please enable camera access in your browser settings and try again.',
)}
title={t('cameraError', 'Camera error')}
/>
) : null}
{view === 'camera' && <CameraComponent mediaStream={mediaStream} stopCameraStream={stopCameraStream} />}
</TabPanel>
<TabPanel>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useCallback, useEffect, useContext, type MutableRefObject } from 'react';
import React, { useCallback, useEffect, useContext, type MutableRefObject } from 'react';
import Camera from 'react-html5-camera-photo';
import CameraMediaUploaderContext from './camera-media-uploader-context.resources';
import 'react-html5-camera-photo/build/css/index.css';
Expand Down Expand Up @@ -29,6 +29,7 @@ const CameraComponent: React.FC<CameraComponentProps> = ({ mediaStream, stopCame
onCameraStart={setMediaStream}
onCameraStop={stopCameraStream}
onCameraError={setError}
isDisplayStartCameraError={false}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-attachments-app/translations/am.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Attachments": "Attachments",
"attachmentsInLowerCase": "attachments",
"attachmentsInProperFormat": "Attachments",
"cameraAccessErrorMessage": "Please enable camera access in your browser settings and try again.",
"cameraError": "Camera Error",
"cancel": "Cancel",
"changeImage": "Change image",
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-attachments-app/translations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Attachments": "المرفقات",
"attachmentsInLowerCase": "attachments",
"attachmentsInProperFormat": "Attachments",
"cameraAccessErrorMessage": "Please enable camera access in your browser settings and try again.",
"cameraError": "خطأ في الكاميرا",
"cancel": "إلغاء",
"changeImage": "غير الصورة",
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-attachments-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Attachments": "Attachments",
"attachmentsInLowerCase": "attachments",
"attachmentsInProperFormat": "Attachments",
"cameraAccessErrorMessage": "Please enable camera access in your browser settings and try again.",
"cameraError": "Camera Error",
"cancel": "Cancel",
"changeImage": "Change image",
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-attachments-app/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Attachments": "Archivos adjuntos",
"attachmentsInLowerCase": "attachments",
"attachmentsInProperFormat": "Attachments",
"cameraAccessErrorMessage": "Please enable camera access in your browser settings and try again.",
"cameraError": "Error de cámara",
"cancel": "Cancelar",
"changeImage": "Cambiar imagen",
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-attachments-app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Attachments": "Pièces jointes",
"attachmentsInLowerCase": "attachments",
"attachmentsInProperFormat": "Attachments",
"cameraAccessErrorMessage": "Please enable camera access in your browser settings and try again.",
"cameraError": "Erreur avec l'appareil photo",
"cancel": "Annuller",
"changeImage": "Changer l'image",
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-attachments-app/translations/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Attachments": "קבצים מצורפים",
"attachmentsInLowerCase": "קבצים מצורפים",
"attachmentsInProperFormat": "קבצים מצורפים",
"cameraAccessErrorMessage": "Please enable camera access in your browser settings and try again.",
"cameraError": "שגיאת מצלמה",
"cancel": "ביטול",
"changeImage": "שנה תמונה",
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-attachments-app/translations/km.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Attachments": "ឯកសារភ្ជាប់",
"attachmentsInLowerCase": "ឯកសារភ្ជាប់",
"attachmentsInProperFormat": "ឯកសារភ្ជាប់",
"cameraAccessErrorMessage": "Please enable camera access in your browser settings and try again.",
"cameraError": "កំហុសកាមេរ៉ា",
"cancel": "បោះបង់",
"changeImage": "ផ្លាស់ប្តូររូបភាព",
Expand Down
1 change: 1 addition & 0 deletions packages/esm-patient-attachments-app/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Attachments": "附件",
"attachmentsInLowerCase": "附件",
"attachmentsInProperFormat": "附件",
"cameraAccessErrorMessage": "Please enable camera access in your browser settings and try again.",
"cameraError": "相机错误",
"cancel": "取消",
"changeImage": "更改图像",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Attachments": "附件",
"attachmentsInLowerCase": "附件",
"attachmentsInProperFormat": "附件",
"cameraAccessErrorMessage": "Please enable camera access in your browser settings and try again.",
"cameraError": "相机错误",
"cancel": "取消",
"changeImage": "更改图像",
Expand Down

0 comments on commit 9f3f1cd

Please sign in to comment.