@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
116 lines (114 loc) • 3.82 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-2023 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 { EnhancedDialog } from '../../EnhancedDialog';
import { DialogBody } from '../../DialogBody';
import { RepoStatus } from '../RepoStatus';
import { FormattedMessage } from 'react-intl';
import React, { useEffect, useState } from 'react';
import SecondaryButton from '../../SecondaryButton';
export function RepoStatusConflictDialog(props) {
const {
status,
onCommitSuccess,
onRevertSuccess: onRevertSuccessProp,
onConflictResolved,
onFailedPullCancelled,
...dialogProps
} = props;
const isRepoClean = status?.clean ?? false;
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
useEffect(() => {
if (dialogProps.open && !isRepoClean) {
window.onbeforeunload = (event) => {
event.preventDefault();
return (event.returnValue = '');
};
} else {
window.onbeforeunload = null;
}
return () => {
window.onbeforeunload = null;
};
}, [dialogProps.open, isRepoClean]);
const onRevertSuccess = () => {
setOpenConfirmDialog(false);
onRevertSuccessProp?.();
};
const onConfirmDialogOk = () => {
setOpenConfirmDialog(false);
};
const onClose = (e) => {
if (!isRepoClean) {
setOpenConfirmDialog(true);
} else {
props.onClose?.(e, null);
}
};
return React.createElement(
React.Fragment,
null,
React.createElement(
EnhancedDialog,
{
maxWidth: 'lg',
...dialogProps,
onClose: onClose,
title: React.createElement(FormattedMessage, { defaultMessage: 'Resolve conflicts' })
},
React.createElement(
DialogBody,
{
sx: {
minHeight: '40vh',
justifyContent: isRepoClean ? 'center' : null,
alignItems: isRepoClean ? 'center' : null
}
},
React.createElement(RepoStatus, {
status: status,
openConfirmDialog: openConfirmDialog,
onCommitSuccess: onCommitSuccess,
onConflictResolved: onConflictResolved,
onFailedPullCancelled: onFailedPullCancelled,
onConfirmDialogOk: onConfirmDialogOk,
onRevertSuccess: onRevertSuccess
}),
isRepoClean &&
React.createElement(
SecondaryButton,
{ onClick: onClose },
React.createElement(FormattedMessage, { defaultMessage: 'Close' })
)
)
)
);
}
export default RepoStatusConflictDialog;