@@ -9,26 +9,30 @@ import ConfirmModal from '../../Utilities/ConfirmModal'
99import TableCheckBox from '../../Utilities/TableCheckBox'
1010import 'react-multiple-select-dropdown-lite/dist/index.css'
1111import { getAllGroups } from './MailerLiteCommonFunc'
12+ import { create } from 'mutative'
1213
1314export default function MailerLiteActions ( { mailerLiteConf, setMailerLiteConf, loading, setLoading } ) {
1415 const [ actionMdl , setActionMdl ] = useState ( { show : false , action : ( ) => { } } )
1516
1617 const actionHandler = ( e , type ) => {
17- const newConf = { ...mailerLiteConf }
18-
1918 if ( type === 'group' ) {
2019 getAllGroups ( mailerLiteConf , setMailerLiteConf , loading , setLoading )
2120 }
2221
23- if ( e . target . checked ) {
24- newConf . actions [ type ] = true
25- } else {
26- delete newConf . actions [ type ]
27- }
28-
2922 setActionMdl ( { show : type } )
30- setMailerLiteConf ( { ...newConf } )
23+ setMailerLiteConf ( prevConf =>
24+ create ( prevConf , draftConf => {
25+ draftConf . actions = { ...( draftConf . actions || { } ) }
26+
27+ if ( e . target . checked ) {
28+ draftConf . actions [ type ] = true
29+ } else {
30+ delete draftConf . actions [ type ]
31+ }
32+ } )
33+ )
3134 }
35+
3236 const clsActionMdl = ( ) => {
3337 setActionMdl ( { show : false } )
3438 }
0 commit comments