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 = ({
fileToEdit,
onChange,
onClickDeleteFileToUpload,
onSubmitEditNewFile,
setCropResult,
}) => {
@ -123,6 +124,10 @@ const EditForm = ({
setIsCropping(false);
};
const handleClickDelete = () => {
onClickDeleteFileToUpload(fileToEdit.originalIndex);
};
const handleSubmit = e => {
e.preventDefault();
@ -139,7 +144,11 @@ const EditForm = ({
<CardControlsWrapper className="card-control-wrapper">
{!isCropping ? (
<>
<CardControl color="#9EA7B8" type="trash-alt" />
<CardControl
color="#9EA7B8"
type="trash-alt"
onClick={handleClickDelete}
/>
{canCrop && (
<CardControl
type="crop"
@ -234,6 +243,7 @@ const EditForm = ({
EditForm.defaultProps = {
fileToEdit: null,
onChange: () => {},
onClickDeleteFileToUpload: () => {},
onSubmitEditNewFile: e => e.preventDefault(),
setCropResult: () => {},
};
@ -241,6 +251,7 @@ EditForm.defaultProps = {
EditForm.propTypes = {
fileToEdit: PropTypes.object,
onChange: PropTypes.func,
onClickDeleteFileToUpload: PropTypes.func,
onSubmitEditNewFile: 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 = () => {
dispatch({
type: 'RESET_PROPS',
@ -198,6 +213,7 @@ const ModalStepper = ({ isOpen, onToggle }) => {
fileToEdit={fileToEdit}
filesToUpload={filesToUpload}
onClickCancelUpload={handleCancelFileToUpload}
onClickDeleteFileToUpload={handleClickDeleteFileToUpload}
onClickEditNewFile={handleGoToEditNewFile}
onGoToAddBrowseFiles={handleGoToAddBrowseFiles}
onSubmitEditNewFile={handleSubmitEditNewFile}

View File

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