handle error when saving to DB

This commit is contained in:
Jan Prochazka 2020-05-13 20:09:17 +02:00
parent 66b870f23e
commit 2a0437e8b5
2 changed files with 44 additions and 4 deletions

View File

@ -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 = () => {

View 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>
);
}