mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
handle error when saving to DB
This commit is contained in:
parent
66b870f23e
commit
2a0437e8b5
@ -40,6 +40,8 @@ import DataGridContextMenu from './DataGridContextMenu';
|
||||
import useSocket from '../utility/SocketProvider';
|
||||
import LoadingInfo from '../widgets/LoadingInfo';
|
||||
import ErrorInfo from '../widgets/ErrorInfo';
|
||||
import showModal from '../modals/showModal';
|
||||
import ErrorMessageModal from '../modals/ErrorMessageModal';
|
||||
|
||||
const GridContainer = styled.div`
|
||||
position: absolute;
|
||||
@ -817,7 +819,7 @@ export default function DataGridCore(props) {
|
||||
}
|
||||
|
||||
async function handleConfirmSql() {
|
||||
await axios.request({
|
||||
const resp = await axios.request({
|
||||
url: 'database-connections/query-data',
|
||||
method: 'post',
|
||||
params: {
|
||||
@ -827,9 +829,14 @@ export default function DataGridCore(props) {
|
||||
data: { sql: confirmSql },
|
||||
});
|
||||
|
||||
dispatchChangeSet({ type: 'reset', value: createChangeSet() });
|
||||
setConfirmSql(null);
|
||||
display.reload();
|
||||
const { errorMessage } = resp.data || {};
|
||||
if (errorMessage) {
|
||||
showModal((modalState) => <ErrorMessageModal modalState={modalState} message={errorMessage} title='Error when saving' />);
|
||||
} else {
|
||||
dispatchChangeSet({ type: 'reset', value: createChangeSet() });
|
||||
setConfirmSql(null);
|
||||
display.reload();
|
||||
}
|
||||
}
|
||||
|
||||
const insertNewRow = () => {
|
||||
|
33
packages/web/src/modals/ErrorMessageModal.js
Normal file
33
packages/web/src/modals/ErrorMessageModal.js
Normal file
@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
import ModalBase from './ModalBase';
|
||||
import FormStyledButton from '../widgets/FormStyledButton';
|
||||
import styled from 'styled-components';
|
||||
import { FontIcon } from '../icons';
|
||||
import { FormButtonRow } from '../utility/forms';
|
||||
|
||||
const Wrapper = styled.div`
|
||||
display:flex
|
||||
align-items:center
|
||||
`;
|
||||
|
||||
const IconWrapper = styled.div`
|
||||
margin-right: 10px;
|
||||
font-size: 20pt;
|
||||
`;
|
||||
|
||||
export default function ErrorMessageModal({ modalState, title = 'Error', message }) {
|
||||
return (
|
||||
<ModalBase modalState={modalState}>
|
||||
<h2>{title}</h2>
|
||||
<Wrapper>
|
||||
<IconWrapper>
|
||||
<FontIcon icon="fas fa-times-circle red" />
|
||||
</IconWrapper>
|
||||
{message}
|
||||
</Wrapper>
|
||||
<FormButtonRow>
|
||||
<FormStyledButton type="button" value="Close" onClick={modalState.close} />
|
||||
</FormButtonRow>
|
||||
</ModalBase>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user