2021-03-20 16:51:34 +01:00
|
|
|
import React, { useState } from 'react';
|
2021-03-20 15:07:10 +01:00
|
|
|
import styled from 'styled-components';
|
2021-03-20 16:51:34 +01:00
|
|
|
import { useDispatch } from 'react-redux';
|
2021-03-20 15:07:10 +01:00
|
|
|
import { Button } from '@buffetjs/core';
|
2021-03-20 16:51:34 +01:00
|
|
|
import ConfirmModal from '../ConfirmModal';
|
|
|
|
import { exportAllConfig, importAllConfig } from '../../state/actions/Config';
|
|
|
|
|
|
|
|
const ActionButtons = ({ diff }) => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
|
|
|
const [actionType, setActionType] = useState('');
|
|
|
|
|
|
|
|
const closeModal = () => {
|
|
|
|
setActionType('');
|
|
|
|
setModalIsOpen(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
const openModal = (type) => {
|
|
|
|
setActionType(type);
|
|
|
|
setModalIsOpen(true);
|
|
|
|
};
|
2021-03-20 15:07:10 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ActionButtonsStyling>
|
2021-03-20 16:51:34 +01:00
|
|
|
<Button disabled={!diff} color="primary" label="Import" onClick={() => openModal('import')} />
|
|
|
|
<Button disabled={!diff} color="primary" label="Export" onClick={() => openModal('export')} />
|
|
|
|
<ConfirmModal
|
|
|
|
isOpen={modalIsOpen}
|
|
|
|
onClose={closeModal}
|
|
|
|
type={actionType}
|
|
|
|
onSubmit={() => actionType === 'import' ? dispatch(importAllConfig()) : dispatch(exportAllConfig())}
|
|
|
|
/>
|
2021-03-20 15:07:10 +01:00
|
|
|
</ActionButtonsStyling>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ActionButtonsStyling = styled.div`
|
|
|
|
padding: 10px 0 20px 0;
|
|
|
|
|
|
|
|
> button {
|
|
|
|
margin-right: 10px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default ActionButtons;
|