Skip to content

Commit 37d091b

Browse files
committed
feat: copperCRM assign tags to person module added
1 parent 89105d4 commit 37d091b

File tree

5 files changed

+91
-20
lines changed

5 files changed

+91
-20
lines changed

frontend-dev/src/components/AllIntegrations/CopperCRM/CopperCRMActions.jsx

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
getAllOpportunities,
1212
getAllOwners,
1313
getAllCompanies,
14-
getAllPipelineStages
14+
getAllPipelineStages,
15+
getAllTags
1516
} from './CopperCRMCommonFunc'
1617

1718
export default function CopperCRMActions({ copperCRMConf, setCopperCRMConf, loading, setLoading }) {
@@ -54,6 +55,14 @@ export default function CopperCRMActions({ copperCRMConf, setCopperCRMConf, load
5455
setActionMdl({ show: false })
5556
delete newConf.actions.company
5657
}
58+
} else if (type === 'tag') {
59+
if (e.target?.checked) {
60+
getAllTags(copperCRMConf, setCopperCRMConf, setLoading)
61+
newConf.actions.tag = true
62+
} else {
63+
setActionMdl({ show: false })
64+
delete newConf.actions.tag
65+
}
5766
} else if (type === 'pipelineStage') {
5867
if (e.target?.checked) {
5968
getAllPipelineStages(copperCRMConf, setCopperCRMConf, setLoading)
@@ -95,14 +104,24 @@ export default function CopperCRMActions({ copperCRMConf, setCopperCRMConf, load
95104
return (
96105
<div className="pos-rel d-flx flx-wrp">
97106
{copperCRMConf.actionName === 'person' && (
98-
<TableCheckBox
99-
checked={copperCRMConf?.selectedCompany?.length || false}
100-
onChange={e => actionHandler(e, 'company')}
101-
className="wdt-200 mt-4 mr-2"
102-
value="company"
103-
title={__('Add Company', 'bit-integrations')}
104-
subTitle={__('Add an company')}
105-
/>
107+
<>
108+
<TableCheckBox
109+
checked={copperCRMConf?.selectedCompany?.length || false}
110+
onChange={e => actionHandler(e, 'company')}
111+
className="wdt-200 mt-4 mr-2"
112+
value="company"
113+
title={__('Add Company', 'bit-integrations')}
114+
subTitle={__('Add an company')}
115+
/>
116+
<TableCheckBox
117+
checked={copperCRMConf?.selectedTags?.length || false}
118+
onChange={e => actionHandler(e, 'tag')}
119+
className="wdt-200 mt-4 mr-2"
120+
value="tag"
121+
title={__('Add Tags', 'bit-integrations')}
122+
subTitle={__('Add tags')}
123+
/>
124+
</>
106125
)}
107126
{(copperCRMConf.actionName === 'person' ||
108127
copperCRMConf.actionName === 'company' ||
@@ -274,13 +293,13 @@ export default function CopperCRMActions({ copperCRMConf, setCopperCRMConf, load
274293
mainMdlCls="o-v"
275294
btnClass="purple"
276295
btnTxt={__('Ok', 'bit-integrations')}
277-
show={actionMdl.show === 'company'}
296+
show={actionMdl.show === 'tag'}
278297
close={clsActionMdl}
279298
action={clsActionMdl}
280299
title={__('Companies', 'bit-integrations')}>
281300
<div className="btcd-hr mt-2 mb-2" />
282-
<div className="mt-2">{__('Select Company', 'bit-integrations')}</div>
283-
{loading.companies ? (
301+
<div className="mt-2">{__('Select tags', 'bit-integrations')}</div>
302+
{loading.tags ? (
284303
<Loader
285304
style={{
286305
display: 'flex',
@@ -293,19 +312,18 @@ export default function CopperCRMActions({ copperCRMConf, setCopperCRMConf, load
293312
) : (
294313
<div className="flx flx-between mt-2">
295314
<MultiSelect
296-
options={copperCRMConf?.companies?.map(company => ({
297-
label: company.name,
298-
value: company.id
315+
options={copperCRMConf?.tags?.map(tag => ({
316+
label: tag,
317+
value: tag
299318
}))}
300319
className="msl-wrp-options"
301-
defaultValue={copperCRMConf?.selectedCompany}
302-
onChange={val => setChanges(val, 'selectedCompany')}
303-
singleSelect
320+
defaultValue={copperCRMConf?.selectedTags}
321+
onChange={val => setChanges(val, 'selectedTags')}
304322
/>
305323
<button
306-
onClick={() => getAllCompanies(copperCRMConf, setCopperCRMConf, setLoading)}
324+
onClick={() => getAllTags(copperCRMConf, setCopperCRMConf, setLoading)}
307325
className="icn-btn sh-sm ml-2 mr-2 tooltip"
308-
style={{ '--tooltip-txt': `${__('Refresh Companies', 'bit-integrations')}'` }}
326+
style={{ '--tooltip-txt': `${__('Refresh Tags', 'bit-integrations')}'` }}
309327
type="button">
310328
&#x21BB;
311329
</button>

frontend-dev/src/components/AllIntegrations/CopperCRM/CopperCRMCommonFunc.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,31 @@ export const getAllCompanies = (confTmp, setConf, setLoading) => {
191191
})
192192
}
193193

194+
export const getAllTags = (confTmp, setConf, setLoading) => {
195+
setLoading({ ...setLoading, tags: true })
196+
197+
const requestParams = {
198+
api_key: confTmp.api_key,
199+
api_email: confTmp.api_email
200+
}
201+
202+
bitsFetch(requestParams, 'coppercrm_fetch_all_tags').then(result => {
203+
if (result && result.success) {
204+
const newConf = { ...confTmp }
205+
if (result.data) {
206+
newConf.tags = result.data
207+
}
208+
setConf(newConf)
209+
setLoading({ ...setLoading, tags: false })
210+
211+
toast.success(__('Tags fetched successfully', 'bit-integrations'))
212+
return
213+
}
214+
setLoading({ ...setLoading, tags: false })
215+
toast.error(__('Tags fetching failed', 'bit-integrations'))
216+
})
217+
}
218+
194219
export const getAllPipelineStages = (confTmp, setConf, setLoading) => {
195220
setLoading({ ...setLoading, pipelineStages: true })
196221

includes/Actions/CopperCRM/CopperCRMController.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,30 @@ public function getAllCompanies($fieldsRequestParams)
176176
}
177177
}
178178

179+
public function getAllTags($fieldsRequestParams)
180+
{
181+
if (empty($fieldsRequestParams->api_key)) {
182+
wp_send_json_error(__('Requested parameter is empty', 'bit-integrations'), 400);
183+
}
184+
$apiKey = $fieldsRequestParams->api_key;
185+
$apiEmail = $fieldsRequestParams->api_email;
186+
$apiEndpoint = $this->apiEndpoint . '/tags';
187+
$headers = [
188+
'X-PW-AccessToken' => $apiKey,
189+
'X-PW-Application' => 'developer_api',
190+
'X-PW-UserEmail' => $apiEmail,
191+
'Content-Type' => 'application/json'
192+
];
193+
194+
$response = HttpHelper::get($apiEndpoint, null, $headers);
195+
196+
if (isset($response->error)) {
197+
wp_send_json_error($response->error ?? __('Unknown error', 'bit-integrations'), 400);
198+
}
199+
200+
wp_send_json_success(array_column((array) $response, 'name'), 200);
201+
}
202+
179203
public function getAllPipelineStages($fieldsRequestParams)
180204
{
181205
if (empty($fieldsRequestParams->api_key)) {

includes/Actions/CopperCRM/RecordApiHelper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public function addPerson($finalData)
127127
if (!empty($this->integrationDetails->selectedCompany)) {
128128
$requestParams['company_id'] = (int) ($this->integrationDetails->selectedCompany);
129129
}
130+
if (!empty($this->integrationDetails->selectedTags)) {
131+
$requestParams['tags'] = explode(',', $this->integrationDetails->selectedTags);
132+
}
130133

131134
$this->type = 'Person';
132135
$this->typeName = 'Person created';

includes/Actions/CopperCRM/Routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Route::post('coppercrm_fetch_all_opportunities', [CopperCRMController::class, 'getAllOpportunities']);
1313
Route::post('coppercrm_fetch_all_owners', [CopperCRMController::class, 'getAllOwners']);
1414
Route::post('coppercrm_fetch_all_companies', [CopperCRMController::class, 'getAllCompanies']);
15+
Route::post('coppercrm_fetch_all_tags', [CopperCRMController::class, 'getAllTags']);
1516
Route::post('coppercrm_fetch_all_pipelineStages', [CopperCRMController::class, 'getAllPipelineStages']);
1617
Route::post('coppercrm_fetch_all_CRMPeoples', [CopperCRMController::class, 'getAllCRMPeoples']);
1718
Route::post('coppercrm_fetch_all_CRMPipelines', [CopperCRMController::class, 'getAllCRMPipelines']);

0 commit comments

Comments
 (0)