1- import React , { useState } from 'react' ;
1+ import React from 'react' ;
22import styled from 'styled-components' ;
33import { useDispatch , useSelector } from 'react-redux' ;
44import { isEmpty } from 'lodash' ;
5- import { Button } from '@strapi/design-system' ;
5+ import { Button , Typography } from '@strapi/design-system' ;
66import { Map } from 'immutable' ;
77import { getFetchClient , useNotification } from '@strapi/strapi/admin' ;
88import { useIntl } from 'react-intl' ;
@@ -14,38 +14,32 @@ const ActionButtons = () => {
1414 const { post, get } = getFetchClient ( ) ;
1515 const dispatch = useDispatch ( ) ;
1616 const { toggleNotification } = useNotification ( ) ;
17- const [ modalIsOpen , setModalIsOpen ] = useState ( false ) ;
18- const [ actionType , setActionType ] = useState ( '' ) ;
1917 const partialDiff = useSelector ( ( state ) => state . getIn ( [ 'config' , 'partialDiff' ] , Map ( { } ) ) ) . toJS ( ) ;
2018 const { formatMessage } = useIntl ( ) ;
2119
22- const closeModal = ( ) => {
23- setActionType ( '' ) ;
24- setModalIsOpen ( false ) ;
25- } ;
26-
27- const openModal = ( type ) => {
28- setActionType ( type ) ;
29- setModalIsOpen ( true ) ;
30- } ;
31-
3220 return (
3321 < ActionButtonsStyling >
34- < Button disabled = { isEmpty ( partialDiff ) } onClick = { ( ) => openModal ( 'import' ) } >
35- { formatMessage ( { id : 'config-sync.Buttons.Import' } ) }
36- </ Button >
37- < Button disabled = { isEmpty ( partialDiff ) } onClick = { ( ) => openModal ( 'export' ) } >
38- { formatMessage ( { id : 'config-sync.Buttons.Export' } ) }
39- </ Button >
40- { ! isEmpty ( partialDiff ) && (
41- < h4 style = { { display : 'inline' } } > { Object . keys ( partialDiff ) . length } { Object . keys ( partialDiff ) . length === 1 ? "config change" : "config changes" } </ h4 >
42- ) }
4322 < ConfirmModal
44- isOpen = { modalIsOpen }
45- onClose = { closeModal }
46- type = { actionType }
47- onSubmit = { ( force ) => actionType === 'import' ? dispatch ( importAllConfig ( partialDiff , force , toggleNotification , formatMessage , post , get ) ) : dispatch ( exportAllConfig ( partialDiff , toggleNotification , formatMessage , post , get ) ) }
23+ type = "import"
24+ trigger = { (
25+ < Button disabled = { isEmpty ( partialDiff ) } >
26+ { formatMessage ( { id : 'config-sync.Buttons.Import' } ) }
27+ </ Button >
28+ ) }
29+ onSubmit = { ( force ) => dispatch ( importAllConfig ( partialDiff , force , toggleNotification , formatMessage , post , get ) ) }
4830 />
31+ < ConfirmModal
32+ type = "export"
33+ trigger = { (
34+ < Button disabled = { isEmpty ( partialDiff ) } >
35+ { formatMessage ( { id : 'config-sync.Buttons.Export' } ) }
36+ </ Button >
37+ ) }
38+ onSubmit = { ( force ) => dispatch ( exportAllConfig ( partialDiff , toggleNotification , formatMessage , post , get ) ) }
39+ />
40+ { ! isEmpty ( partialDiff ) && (
41+ < Typography variant = "epsilon" > { Object . keys ( partialDiff ) . length } { Object . keys ( partialDiff ) . length === 1 ? "config change" : "config changes" } </ Typography >
42+ ) }
4943 </ ActionButtonsStyling >
5044 ) ;
5145} ;
0 commit comments