From 8676889db183d2216bc4d29f6f29ca7c93bdb22e Mon Sep 17 00:00:00 2001 From: AlexisG Date: Wed, 6 Nov 2024 12:12:41 +0100 Subject: [PATCH 1/3] feat: Edit only Scan step in Modify action This action is used in the three-dot menu of each file. --- src/components/Actions/Items/modify.jsx | 7 +++- .../Contexts/StepperDialogProvider.jsx | 17 +++++++- .../ModelSteps/Scan/ScanWrapper.jsx | 9 ++++- .../ScanResult/ScanResultDialog.jsx | 40 ++++++++++++++++--- .../ScanResult/ScanResultDialog.spec.jsx | 15 ++++++- src/components/Views/Edit.jsx | 26 ++++++++++-- src/helpers/filterSteps.js | 11 ++++- 7 files changed, 106 insertions(+), 19 deletions(-) diff --git a/src/components/Actions/Items/modify.jsx b/src/components/Actions/Items/modify.jsx index 13c0b40b..7a4b18da 100644 --- a/src/components/Actions/Items/modify.jsx +++ b/src/components/Actions/Items/modify.jsx @@ -22,9 +22,14 @@ export const modify = ({ t, navigate }) => { getCreatedByApp(docs[0]) === 'mespapiers', action: docs => { const country = docs[0].metadata.country?.toLowerCase() + const searchParams = new URLSearchParams({ + model: 'scan', + ...(country && { country }) + }).toString() + navigate({ pathname: `edit/${docs[0]._id}`, - ...(country && { search: `?country=${country}` }) + search: searchParams }) }, // eslint-disable-next-line react/display-name diff --git a/src/components/Contexts/StepperDialogProvider.jsx b/src/components/Contexts/StepperDialogProvider.jsx index fc316bd6..6c341c47 100644 --- a/src/components/Contexts/StepperDialogProvider.jsx +++ b/src/components/Contexts/StepperDialogProvider.jsx @@ -18,7 +18,13 @@ import { useWebviewIntent } from 'cozy-intent' const StepperDialogContext = createContext() -export const StepperDialogProvider = ({ children, isEdit }) => { +/** + * @param {object} props + * @param {React.ReactNode} props.children + * @param {boolean} props.isEdit - True if the dialog is in edit mode + * @param {function} props.stepFilterFn - The filter function to apply on the steps + */ +export const StepperDialogProvider = ({ children, isEdit, stepFilterFn }) => { const [stepperDialogTitle, setStepperDialogTitle] = useState('') const [allCurrentSteps, setAllCurrentSteps] = useState([]) const [currentStepIndex, setCurrentStepIndex] = useState(-1) @@ -68,6 +74,7 @@ export const StepperDialogProvider = ({ children, isEdit }) => { steps: allCurrentStepsDefinitions, webviewIntent, isEdit, + stepFilterFn, fromFlagshipUpload }) setAllCurrentSteps(filteredSteps) @@ -75,7 +82,13 @@ export const StepperDialogProvider = ({ children, isEdit }) => { } buildAllCurrentSteps() } - }, [webviewIntent, currentDefinition, fromFlagshipUpload, isEdit]) + }, [ + webviewIntent, + currentDefinition, + fromFlagshipUpload, + isEdit, + stepFilterFn + ]) useEffect(() => { const loadCreatePaperDataBackup = async () => { diff --git a/src/components/ModelSteps/Scan/ScanWrapper.jsx b/src/components/ModelSteps/Scan/ScanWrapper.jsx index 45e11ac2..c8219811 100644 --- a/src/components/ModelSteps/Scan/ScanWrapper.jsx +++ b/src/components/ModelSteps/Scan/ScanWrapper.jsx @@ -1,4 +1,5 @@ import { PDFDocument } from 'pdf-lib' +import propTypes from 'prop-types' import React, { useEffect, useState } from 'react' import { useParams, useSearchParams } from 'react-router-dom' import { PaperDefinitionsStepPropTypes } from 'src/PaperDefinitionsPropTypes' @@ -37,7 +38,7 @@ const isFileEncryptedPDF = async file => { return pdf.isEncrypted } -const ScanWrapper = ({ currentStep, onClose, onBack }) => { +const ScanWrapper = ({ currentStep, onClose, onBack, onSubmit }) => { const client = useClient() const [searchParams] = useSearchParams() const { qualificationLabel } = useParams() @@ -153,6 +154,7 @@ const ScanWrapper = ({ currentStep, onClose, onBack }) => { onChangeFile={onChangeFile} onClose={onClose} onBack={onBack} + onSubmit={onSubmit} /> ) } @@ -180,7 +182,10 @@ const ScanWrapper = ({ currentStep, onClose, onBack }) => { } ScanWrapper.propTypes = { - currentStep: PaperDefinitionsStepPropTypes + currentStep: PaperDefinitionsStepPropTypes, + onClose: propTypes.func.isRequired, + onBack: propTypes.func.isRequired, + onSubmit: propTypes.func.isRequired } export default ScanWrapper diff --git a/src/components/ModelSteps/ScanResult/ScanResultDialog.jsx b/src/components/ModelSteps/ScanResult/ScanResultDialog.jsx index 1ae4f02d..2e12ebb8 100644 --- a/src/components/ModelSteps/ScanResult/ScanResultDialog.jsx +++ b/src/components/ModelSteps/ScanResult/ScanResultDialog.jsx @@ -1,4 +1,5 @@ import cx from 'classnames' +import propTypes from 'prop-types' import React, { useRef, useState } from 'react' import { useSearchParams } from 'react-router-dom' import CompositeHeaderImage from 'src/components/CompositeHeader/CompositeHeaderImage' @@ -8,6 +9,7 @@ import OcrProcessingDialog from 'src/components/ModelSteps/ScanResult/OcrProcess import ScanResultCard from 'src/components/ModelSteps/ScanResult/ScanResultCard/ScanResultCard' import ScanResultTitle from 'src/components/ModelSteps/ScanResult/ScanResultTitle' import { makeFileFromBase64 } from 'src/components/ModelSteps/helpers' +import SubmitButton from 'src/components/ModelSteps/widgets/SubmitButton' import StepperDialogTitle from 'src/components/StepperDialog/StepperDialogTitle' import { FLAGSHIP_SCAN_TEMP_FILENAME, KEYS } from 'src/constants' import { isFlagshipOCRAvailable } from 'src/helpers/isFlagshipOCRAvailable' @@ -22,11 +24,22 @@ import useEventListener from 'cozy-ui/transpiled/react/hooks/useEventListener' import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints' import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' +/** + * @param {object} props + * @param {object} props.currentStep + * @param {Function} props.onClose + * @param {Function} props.onBack + * @param {Function} props.onChangeFile + * @param {Function} props.onSubmit + * @param {object} props.currentFile + * @param {Function} props.setCurrentFile + */ const ScanResultDialog = ({ currentStep, onClose, onBack, onChangeFile, + onSubmit, currentFile, setCurrentFile }) => { @@ -96,6 +109,7 @@ const ScanResultDialog = ({ ) } + const SubmitButtonComponent = isLastStep() ? SubmitButton : null return ( -