@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
109 lines (107 loc) • 4.09 kB
JavaScript
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (C) 2007-2025 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React, { createElement, useState } from 'react';
import EnhancedDialog from '../EnhancedDialog/EnhancedDialog';
import FolderMoveAlert from './FolderMoveAlert';
import { batchActions } from '../../state/actions/misc';
import { setClipboard } from '../../state/actions/content';
import { emitSystemEvent, itemCut, showCutItemSuccessNotification } from '../../state/actions/system';
import { FormattedMessage } from 'react-intl';
import SecondaryButton from '../SecondaryButton';
import PrimaryButton from '../PrimaryButton';
import DialogFooter from '../DialogFooter';
import { useDispatch } from 'react-redux';
import { closeFolderMoveAlertDialog } from '../../state/actions/dialogs';
import Tooltip from '@mui/material/Tooltip';
export function FolderMoveAlertDialog(props) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Need `item` removed to pass down props to EnhancedDialog
const { item, ...rest } = props;
return React.createElement(
EnhancedDialog,
{ maxWidth: 'sm', title: React.createElement(FormattedMessage, { defaultMessage: 'Warning' }), ...rest },
createElement(Body, props)
);
}
function Body({ item, onClose }) {
const [moveAck, setMoveAck] = useState(false);
const dispatch = useDispatch();
const onContinue = () => {
dispatch(
batchActions([
setClipboard({ type: 'CUT', paths: [item.path], sourcePath: item.path }),
emitSystemEvent(itemCut({ target: item.path })),
closeFolderMoveAlertDialog(),
showCutItemSuccessNotification()
])
);
};
return React.createElement(
React.Fragment,
null,
React.createElement(FolderMoveAlert, {
autoFocus: true,
initialExpanded: true,
checked: moveAck,
action: 'move',
onChange: (e) => setMoveAck(e.target.checked),
sx: { border: 'none', borderRadius: 0 }
}),
React.createElement(
DialogFooter,
null,
React.createElement(
SecondaryButton,
{ onClick: (e) => onClose?.(e, null) },
React.createElement(FormattedMessage, { defaultMessage: 'Cancel' })
),
React.createElement(
Tooltip,
{
title: moveAck
? ''
: React.createElement(FormattedMessage, {
defaultMessage: 'Please click the warning checkbox above to confirm and continue.'
})
},
React.createElement(
'span',
null,
React.createElement(
PrimaryButton,
{ onClick: onContinue, disabled: !moveAck },
React.createElement(FormattedMessage, { defaultMessage: 'Continue' })
)
)
)
)
);
}
export default FolderMoveAlertDialog;