|
| 1 | +/* eslint-disable max-len */ |
| 2 | +/* eslint-disable no-param-reassign */ |
| 3 | + |
| 4 | +import { create } from 'mutative' |
| 5 | +import { useState } from 'react' |
| 6 | +import MultiSelect from 'react-multiple-select-dropdown-lite' |
| 7 | +import 'react-multiple-select-dropdown-lite/dist/index.css' |
| 8 | +import { useRecoilValue } from 'recoil' |
| 9 | +import { $btcbi } from '../../../GlobalStates' |
| 10 | +import { __ } from '../../../Utils/i18nwrap' |
| 11 | +import Loader from '../../Loaders/Loader' |
| 12 | +import ConfirmModal from '../../Utilities/ConfirmModal' |
| 13 | +import TableCheckBox from '../../Utilities/TableCheckBox' |
| 14 | +import { ProFeatureTitle } from '../IntegrationHelpers/ActionProFeatureLabels' |
| 15 | +import { getAllTags } from './BentoCommonFunc' |
| 16 | + |
| 17 | +export default function BentoActions({ |
| 18 | + bentoConf, |
| 19 | + setBentoConf, |
| 20 | + loading, |
| 21 | + setLoading, |
| 22 | + isLoading, |
| 23 | + setIsLoading, |
| 24 | + setSnackbar |
| 25 | +}) { |
| 26 | + const [actionMdl, setActionMdl] = useState({ show: false }) |
| 27 | + const btcbi = useRecoilValue($btcbi) |
| 28 | + const { isPro } = btcbi |
| 29 | + |
| 30 | + const actionHandler = (e, type) => { |
| 31 | + if (type === 'add_tags' || type === 'add_tags_via_event') { |
| 32 | + getAllTags(bentoConf, setBentoConf, setLoading) |
| 33 | + } else if (type === 'subscribe') { |
| 34 | + setBentoConf(prevConf => |
| 35 | + create(prevConf, draftConf => { |
| 36 | + draftConf[type] = Boolean(e.target.checked) |
| 37 | + }) |
| 38 | + ) |
| 39 | + } |
| 40 | + |
| 41 | + setActionMdl({ show: type }) |
| 42 | + } |
| 43 | + |
| 44 | + const clsActionMdl = () => { |
| 45 | + setActionMdl({ show: false }) |
| 46 | + } |
| 47 | + |
| 48 | + const setChanges = (val, type) => { |
| 49 | + setBentoConf(prevConf => |
| 50 | + create(prevConf, draftConf => { |
| 51 | + draftConf[type] = val |
| 52 | + }) |
| 53 | + ) |
| 54 | + } |
| 55 | + |
| 56 | + return ( |
| 57 | + <> |
| 58 | + <div className="pos-rel d-flx w-8"> |
| 59 | + {'add_people' === bentoConf.action && ( |
| 60 | + <> |
| 61 | + <TableCheckBox |
| 62 | + onChange={e => actionHandler(e, 'add_tags')} |
| 63 | + checked={bentoConf?.selected_tags?.length > 0 || false} |
| 64 | + className="wdt-200 mt-4 mr-2" |
| 65 | + value="add_tags" |
| 66 | + isInfo={!isPro} |
| 67 | + title={<ProFeatureTitle title={__('Add Tags', 'bit-integrations')} />} |
| 68 | + subTitle={'Add Tags'} |
| 69 | + /> |
| 70 | + <TableCheckBox |
| 71 | + onChange={e => actionHandler(e, 'add_tags_via_event')} |
| 72 | + checked={bentoConf?.selected_tags_via_event?.length > 0 || false} |
| 73 | + className="wdt-200 mt-4 mr-2" |
| 74 | + value="add_tags_via_event" |
| 75 | + isInfo={!isPro} |
| 76 | + title={<ProFeatureTitle title={__('Add Tags via Event', 'bit-integrations')} />} |
| 77 | + subTitle={'Add Tags via Event'} |
| 78 | + /> |
| 79 | + <TableCheckBox |
| 80 | + onChange={e => actionHandler(e, 'subscribe')} |
| 81 | + checked={bentoConf?.subscribe || false} |
| 82 | + className="wdt-200 mt-4 mr-2" |
| 83 | + value="subscribe" |
| 84 | + isInfo={!isPro} |
| 85 | + title={<ProFeatureTitle title={__('Subscribe', 'bit-integrations')} />} |
| 86 | + subTitle={'Subscribe User'} |
| 87 | + /> |
| 88 | + </> |
| 89 | + )} |
| 90 | + |
| 91 | + {isPro && ( |
| 92 | + <> |
| 93 | + <ConfirmModal |
| 94 | + className="custom-conf-mdl" |
| 95 | + mainMdlCls="o-v" |
| 96 | + btnClass="purple" |
| 97 | + btnTxt={__('Ok', 'bit-integrations')} |
| 98 | + show={actionMdl.show === 'add_tags'} |
| 99 | + close={clsActionMdl} |
| 100 | + action={clsActionMdl} |
| 101 | + title={__('Add Tags', 'bit-integrations')}> |
| 102 | + <div className="btcd-hr mt-2 mb-2" /> |
| 103 | + {loading?.tags ? ( |
| 104 | + <Loader |
| 105 | + style={{ |
| 106 | + display: 'flex', |
| 107 | + justifyContent: 'center', |
| 108 | + alignItems: 'center', |
| 109 | + height: 45, |
| 110 | + transform: 'scale(0.5)' |
| 111 | + }} |
| 112 | + /> |
| 113 | + ) : ( |
| 114 | + <div className="flx mt-2"> |
| 115 | + <MultiSelect |
| 116 | + className="msl-wrp-options" |
| 117 | + defaultValue={bentoConf?.selected_tags} |
| 118 | + options={bentoConf.tags} |
| 119 | + onChange={val => setChanges(val, 'selected_tags')} |
| 120 | + /> |
| 121 | + <button |
| 122 | + onClick={() => getAllTags(bentoConf, setBentoConf, setLoading)} |
| 123 | + className="icn-btn sh-sm ml-2 mr-2 tooltip" |
| 124 | + style={{ '--tooltip-txt': `'${__('Refresh Tags', 'bit-integrations')}'` }} |
| 125 | + type="button"> |
| 126 | + ↻ |
| 127 | + </button> |
| 128 | + </div> |
| 129 | + )} |
| 130 | + </ConfirmModal> |
| 131 | + <ConfirmModal |
| 132 | + className="custom-conf-mdl" |
| 133 | + mainMdlCls="o-v" |
| 134 | + btnClass="purple" |
| 135 | + btnTxt={__('Ok', 'bit-integrations')} |
| 136 | + show={actionMdl.show === 'add_tags_via_event'} |
| 137 | + close={clsActionMdl} |
| 138 | + action={clsActionMdl} |
| 139 | + title={__('Add Tags via Event', 'bit-integrations')}> |
| 140 | + <div className="btcd-hr mt-2 mb-2" /> |
| 141 | + {loading?.tags ? ( |
| 142 | + <Loader |
| 143 | + style={{ |
| 144 | + display: 'flex', |
| 145 | + justifyContent: 'center', |
| 146 | + alignItems: 'center', |
| 147 | + height: 45, |
| 148 | + transform: 'scale(0.5)' |
| 149 | + }} |
| 150 | + /> |
| 151 | + ) : ( |
| 152 | + <div className="flx mt-2"> |
| 153 | + <MultiSelect |
| 154 | + className="msl-wrp-options" |
| 155 | + defaultValue={bentoConf?.selected_tags_via_event} |
| 156 | + options={bentoConf.tags} |
| 157 | + onChange={val => setChanges(val, 'selected_tags_via_event')} |
| 158 | + /> |
| 159 | + <button |
| 160 | + onClick={() => getAllTags(bentoConf, setBentoConf, setLoading)} |
| 161 | + className="icn-btn sh-sm ml-2 mr-2 tooltip" |
| 162 | + style={{ '--tooltip-txt': `'${__('Refresh Tags', 'bit-integrations')}'` }} |
| 163 | + type="button"> |
| 164 | + ↻ |
| 165 | + </button> |
| 166 | + </div> |
| 167 | + )} |
| 168 | + </ConfirmModal> |
| 169 | + </> |
| 170 | + )} |
| 171 | + </div> |
| 172 | + </> |
| 173 | + ) |
| 174 | +} |
0 commit comments