Add delete logic

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-02-25 14:35:48 +01:00
parent bfe923b1ee
commit 94e7a3f5fc
3 changed files with 30 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import isImageType from './utils/isImageType';
const EditForm = ({ const EditForm = ({
fileToEdit, fileToEdit,
onChange, onChange,
onClickDeleteFileToUpload,
onSubmitEditNewFile, onSubmitEditNewFile,
setCropResult, setCropResult,
}) => { }) => {
@ -123,6 +124,10 @@ const EditForm = ({
setIsCropping(false); setIsCropping(false);
}; };
const handleClickDelete = () => {
onClickDeleteFileToUpload(fileToEdit.originalIndex);
};
const handleSubmit = e => { const handleSubmit = e => {
e.preventDefault(); e.preventDefault();
@ -139,7 +144,11 @@ const EditForm = ({
<CardControlsWrapper className="card-control-wrapper"> <CardControlsWrapper className="card-control-wrapper">
{!isCropping ? ( {!isCropping ? (
<> <>
<CardControl color="#9EA7B8" type="trash-alt" /> <CardControl
color="#9EA7B8"
type="trash-alt"
onClick={handleClickDelete}
/>
{canCrop && ( {canCrop && (
<CardControl <CardControl
type="crop" type="crop"
@ -234,6 +243,7 @@ const EditForm = ({
EditForm.defaultProps = { EditForm.defaultProps = {
fileToEdit: null, fileToEdit: null,
onChange: () => {}, onChange: () => {},
onClickDeleteFileToUpload: () => {},
onSubmitEditNewFile: e => e.preventDefault(), onSubmitEditNewFile: e => e.preventDefault(),
setCropResult: () => {}, setCropResult: () => {},
}; };
@ -241,6 +251,7 @@ EditForm.defaultProps = {
EditForm.propTypes = { EditForm.propTypes = {
fileToEdit: PropTypes.object, fileToEdit: PropTypes.object,
onChange: PropTypes.func, onChange: PropTypes.func,
onClickDeleteFileToUpload: PropTypes.func,
onSubmitEditNewFile: PropTypes.func, onSubmitEditNewFile: PropTypes.func,
setCropResult: PropTypes.func, setCropResult: PropTypes.func,
}; };

View File

@ -55,6 +55,21 @@ const ModalStepper = ({ isOpen, onToggle }) => {
}); });
}; };
const handleClickDeleteFileToUpload = fileIndex => {
dispatch({
type: 'REMOVE_FILE_TO_UPLOAD',
fileIndex,
});
if (currentStep === 'edit-new') {
dispatch({
type: 'RESET_FILE_TO_EDIT',
});
goNext();
}
};
const handleClosed = () => { const handleClosed = () => {
dispatch({ dispatch({
type: 'RESET_PROPS', type: 'RESET_PROPS',
@ -198,6 +213,7 @@ const ModalStepper = ({ isOpen, onToggle }) => {
fileToEdit={fileToEdit} fileToEdit={fileToEdit}
filesToUpload={filesToUpload} filesToUpload={filesToUpload}
onClickCancelUpload={handleCancelFileToUpload} onClickCancelUpload={handleCancelFileToUpload}
onClickDeleteFileToUpload={handleClickDeleteFileToUpload}
onClickEditNewFile={handleGoToEditNewFile} onClickEditNewFile={handleGoToEditNewFile}
onGoToAddBrowseFiles={handleGoToAddBrowseFiles} onGoToAddBrowseFiles={handleGoToAddBrowseFiles}
onSubmitEditNewFile={handleSubmitEditNewFile} onSubmitEditNewFile={handleSubmitEditNewFile}

View File

@ -40,6 +40,8 @@ const reducer = (state, action) => {
data => data.get('originalIndex') !== action.fileIndex data => data.get('originalIndex') !== action.fileIndex
); );
}); });
case 'RESET_FILE_TO_EDIT':
return state.update('fileToEdit', () => null);
case 'RESET_PROPS': case 'RESET_PROPS':
return initialState; return initialState;
case 'SET_CROP_RESULT': { case 'SET_CROP_RESULT': {