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

62 lines
2.1 KiB
React
Raw Normal View History

import React from 'react';
2021-03-20 15:07:10 +01:00
import styled from 'styled-components';
2021-11-20 19:06:01 +01:00
import { useDispatch, useSelector } from 'react-redux';
2021-03-21 17:55:14 +01:00
import { isEmpty } from 'lodash';
import { Button, Typography } from '@strapi/design-system';
2021-11-20 19:06:01 +01:00
import { Map } from 'immutable';
2024-05-08 20:46:09 +02:00
import { getFetchClient, useNotification } from '@strapi/strapi/admin';
2023-10-11 20:46:51 +02:00
import { useIntl } from 'react-intl';
2021-10-14 17:13:12 +02:00
2021-03-20 16:51:34 +01:00
import ConfirmModal from '../ConfirmModal';
2024-10-14 21:07:17 +02:00
import { exportAllConfig, importAllConfig, downloadZip } from '../../state/actions/Config';
2021-03-20 16:51:34 +01:00
2021-11-20 19:06:01 +01:00
const ActionButtons = () => {
2024-05-08 20:46:09 +02:00
const { post, get } = getFetchClient();
2021-03-20 16:51:34 +01:00
const dispatch = useDispatch();
2024-05-08 20:46:09 +02:00
const { toggleNotification } = useNotification();
2021-11-20 19:06:01 +01:00
const partialDiff = useSelector((state) => state.getIn(['config', 'partialDiff'], Map({}))).toJS();
2023-10-11 20:46:51 +02:00
const { formatMessage } = useIntl();
2021-03-20 16:51:34 +01:00
2021-03-20 15:07:10 +01:00
return (
<ActionButtonsStyling>
2021-03-20 16:51:34 +01:00
<ConfirmModal
type="import"
trigger={(
<Button disabled={isEmpty(partialDiff)}>
{formatMessage({ id: 'config-sync.Buttons.Import' })}
</Button>
)}
onSubmit={(force) => dispatch(importAllConfig(partialDiff, force, toggleNotification, formatMessage, post, get))}
2021-03-20 16:51:34 +01:00
/>
<ConfirmModal
type="export"
trigger={(
<Button disabled={isEmpty(partialDiff)}>
{formatMessage({ id: 'config-sync.Buttons.Export' })}
</Button>
)}
onSubmit={(force) => dispatch(exportAllConfig(partialDiff, toggleNotification, formatMessage, post, get))}
/>
{!isEmpty(partialDiff) && (
<Typography variant="epsilon">{Object.keys(partialDiff).length} {Object.keys(partialDiff).length === 1 ? "config change" : "config changes"}</Typography>
)}
<Button onClick={() => dispatch(downloadZip(toggleNotification, formatMessage, post, get))}>{formatMessage({ id: 'config-sync.Buttons.DownloadConfig' })}</Button>
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;
display: flex;
align-items: center;
2021-03-20 15:07:10 +01:00
> button {
margin-right: 10px;
}
> button:last-of-type {
margin-left: auto;
}
2021-03-20 15:07:10 +01:00
`;
2021-10-14 17:13:12 +02:00
export default ActionButtons;