From 806370e116c39ee4212c0b58468978ca3147c70e Mon Sep 17 00:00:00 2001 From: deepakglobant Date: Tue, 23 Apr 2024 13:32:44 +0530 Subject: [PATCH] feat: onNavigateToNextSight callback (MN-504) --- packages/camera/src/components/Capture/capture.js | 11 ++++++++++- packages/camera/src/components/Controls/index.js | 2 -- website/docs/js/api/components/Capture.md | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/camera/src/components/Capture/capture.js b/packages/camera/src/components/Capture/capture.js index f274e91aa..b9e6c5c44 100644 --- a/packages/camera/src/components/Capture/capture.js +++ b/packages/camera/src/components/Capture/capture.js @@ -133,6 +133,7 @@ const Capture = forwardRef(({ onReady, onStartUploadPicture, onFinishUploadPicture, + onNavigateToNextSight, orientationBlockerProps, overlayPathStyles, primaryColor, @@ -353,6 +354,12 @@ const Capture = forwardRef(({ } }, [setAddDamageStatus, lastAddDamageHelpTimestamp]); + const handleOnFinishUploadPicture = useCallback(async () => { + await onNavigateToNextSight(); + api.goNextSight(); + onFinishUploadPicture(); + }, [api]); + const handleResetDamageStatus = useCallback(() => { setAddDamageStatus(AddDamageStatus.IDLE); setAddDamageParts([]); @@ -611,7 +618,7 @@ const Capture = forwardRef(({ onCloseEarly={handleCloseEarlyClick} onAddDamagePressed={handleAddDamagePressed} onStartUploadPicture={onStartUploadPicture} - onFinishUploadPicture={onFinishUploadPicture} + onFinishUploadPicture={handleOnFinishUploadPicture} addDamageParts={addDamageParts} onResetAddDamageStatus={handleResetDamageStatus} hideAddDamage={hideAddDamage} @@ -858,6 +865,7 @@ Capture.propTypes = { onComplianceCheckFinish: PropTypes.func, onComplianceCheckStart: PropTypes.func, onFinishUploadPicture: PropTypes.func, + onNavigateToNextSight: PropTypes.func, onPictureTaken: PropTypes.func, onPictureUploaded: PropTypes.func, onReady: PropTypes.func, @@ -979,6 +987,7 @@ Capture.defaultProps = { onComplianceCheckFinish: () => { }, onComplianceCheckStart: () => { }, onFinishUploadPicture: () => { }, + onNavigateToNextSight: () => { }, onWarningMessage: () => { }, onReady: () => { }, onStartUploadPicture: () => { }, diff --git a/packages/camera/src/components/Controls/index.js b/packages/camera/src/components/Controls/index.js index 74ce9c2bc..9f1e05fe8 100644 --- a/packages/camera/src/components/Controls/index.js +++ b/packages/camera/src/components/Controls/index.js @@ -156,12 +156,10 @@ export default function Controls({ if (action === Actions.sights.ADD_PROCESS_TO_QUEUE) { if (noOfProcesses < MAX_LIMIT_FOR_PROCESSES && current.index !== (ids.length - 1)) { onFinishUploadPicture(state, api); - api.goNextSight(); } } else if (action === Actions.sights.REMOVE_PROCESS_FROM_QUEUE) { if (noOfProcesses === (MAX_LIMIT_FOR_PROCESSES - 1) && current.index !== (ids.length - 1)) { onFinishUploadPicture(state, api); - api.goNextSight(); } } }, [state.sights.state.process]); diff --git a/website/docs/js/api/components/Capture.md b/website/docs/js/api/components/Capture.md index 2a4ecef3e..a104a2d74 100644 --- a/website/docs/js/api/components/Capture.md +++ b/website/docs/js/api/components/Capture.md @@ -46,6 +46,7 @@ export default function Inspector({ inspectionId }) { onReady={() => setLoading(false)} onStartUploadPicture={() => setLoading(true)} onFinishUploadPicture={() => setLoading(false)} + onNavigateToNextSight={onNavigateToNextSight} onChange={handleChange} sightIds={Constants.defaultSightIds} /> @@ -93,6 +94,7 @@ export default function Inspector({ inspectionId }) { onReady={() => setLoading(false)} onStartUploadPicture={() => setLoading(true)} onFinishUploadPicture={() => setLoading(false)} + onNavigateToNextSight={onNavigateToNextSight} onChange={handleChange} sightIds={Constants.defaultSightIds} /> @@ -468,6 +470,11 @@ const handleStartUploadPicture = (state, api) => console.log('Started uploading Will call a function when the uploading is finished for every picture. +## onNavigateToNextSight +`PropTypes.func` + +Will call a function before navigating to next sight. + ```js const handleFinishUploadPicture = (state, api) => console.log('Finished uploading a picture'); ```