strapi-plugin-config-sync/admin/src/components/ActionButtons/index.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

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-21 17:55:14 +01:00
import { isEmpty } from 'lodash';
2021-10-14 17:13:12 +02:00
import { Button } from '@strapi/parts/Button';
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-10-14 17:33:21 +02:00
<Button disabled={isEmpty(diff.diff)} onClick={() => openModal('import')}>Import</Button>
<Button disabled={isEmpty(diff.diff)} onClick={() => openModal('export')}>Export</Button>
2021-03-26 19:53:18 +01:00
{!isEmpty(diff.diff) && (
<h4 style={{ display: 'inline' }}>{Object.keys(diff.diff).length} {Object.keys(diff.diff).length === 1 ? "config change" : "config changes"}</h4>
)}
2021-03-20 16:51:34 +01:00
<ConfirmModal
isOpen={modalIsOpen}
onClose={closeModal}
2021-10-14 17:13:12 +02:00
type={actionType}
2021-10-14 17:33:21 +02:00
onSubmit={() => actionType === 'import' ? dispatch(importAllConfig()) : dispatch(exportAllConfig())}
2021-03-20 16:51:34 +01:00
/>
2021-03-20 15:07:10 +01:00
</ActionButtonsStyling>
);
2021-10-14 17:13:12 +02:00
};
2021-03-20 15:07:10 +01:00
const ActionButtonsStyling = styled.div`
padding: 10px 0 20px 0;
> button {
margin-right: 10px;
}
`;
2021-10-14 17:13:12 +02:00
export default ActionButtons;