Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,28 @@ export const handleCustomValue = (event, index, conftTmp, setConf) => {
setConf({ ...newConf })
}


export const handleAuthData = async (actionName, tokenDetails, userInfo, setAuthData) => {
const requestParams = {};
requestParams.actionName = actionName
requestParams.tokenDetails = tokenDetails
requestParams.userInfo = userInfo
await bitsFetch(requestParams, 'store/authData').then((resp) => {
const requestParams = {
actionName: actionName,
tokenDetails: tokenDetails,
userInfo: userInfo,
};

try {
const resp = await bitsFetch(requestParams, 'store/authData');

if (resp.success) {
if (resp.data.data.length > 0) {
setAuthData(resp.data.data);
}
// setSnackbar({ show: true, msg: 'Authorization Data Fetched Successfully' })
} else if (resp.success === false && resp.data?.error) {
throw new Error(resp.data.error);
} else {
throw new Error('Unknown error occurred while storing auth data.');
}
})
}
} catch (error) {
console.error('handleAuthData error:', error.message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setSnackbar to show the error to the user

throw error;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function GoogleSheetAuthorization({


const handleVerificationCode = async (authInfo) => {
await tokenHelper(authInfo, sheetConf, setSheetConf, selectedAuthType, authData, setAuthData, setIsLoading, setSnackbar);
await tokenHelper(authInfo, sheetConf, setSheetConf, selectedAuthType, setAuthData, setIsLoading, setSnackbar);
setAuthInfo(undefined)
getAuthData()
}
Expand Down Expand Up @@ -227,7 +227,7 @@ export default function GoogleSheetAuthorization({
</button>
)}
<br />
<button onClick={() => nextPage(2)} className="btn f-right btcd-btn-lg purple sh-sm flx" type="button" disabled={!selectedUserId || authData.length === 0}>
<button onClick={() => nextPage(2)} className="btn f-right btcd-btn-lg purple sh-sm flx" type="button" disabled={!selectedUserId || (authData.length === 0 && !isEdit && (sheetConf.tokenDetails == null))}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary bracket (sheetConf.tokenDetails == null)

{__('Next', 'bit-integrations')}
<BackIcn className="ml-1 rev-icn" />
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,9 @@ export const handleAuthorize = (confTmp, selectedAuthType, setError, setIsLoadin
}
}, 500)
}

}

export const tokenHelper = async (authInfo, confTmp, setConf, selectedAuthType, authData, setAuthData, setIsLoading, setSnackbar) => {
export const tokenHelper = async (authInfo, confTmp, setConf, selectedAuthType, setAuthData, setIsLoading, setSnackbar) => {
if (!selectedAuthType) {
return
}
Expand Down
16 changes: 7 additions & 9 deletions frontend-dev/src/components/AllIntegrations/IntegInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const ZohoMarketingHubAuthorization = lazy(
)
const ZohoRecruitAuthorization = lazy(() => import('./ZohoRecruit/ZohoRecruitAuthorization'))
const GoogleSheetInfo = lazy(() => import('./GoogleSheet/GoogleSheetInfo'))
const ZohoCRMInfo = lazy(() => import('./ZohoCRM/ZohoCRMInfo'))
const MailChimpAuthorization = lazy(() => import('./MailChimp/MailChimpAuthorization'))
const MailPoetAuthorization = lazy(() => import('./MailPoet/MailPoetAuthorization'))
const SendinblueAuthorization = lazy(() => import('./SendinBlue/SendinBlueAuthorization'))
Expand Down Expand Up @@ -226,15 +227,6 @@ export default function IntegInfo() {

const IntegrationInfo = () => {
switch (integrationConf.type) {
case 'Zoho CRM':
return (
<ZohoCRMAuthorization
crmConf={integrationConf}
step={1}
redirectLocation={location}
isInfo
/>
)
case 'Autonami':
return <AutonamiAuthorization autonamiConf={integrationConf} step={1} isInfo />
case 'Dropbox':
Expand Down Expand Up @@ -304,6 +296,12 @@ export default function IntegInfo() {
isInfo
/>
)
case 'Zoho CRM':
return (
<ZohoCRMInfo crmConf={integrationConf}
isInfo
/>
)
case 'Mail Chimp':
return (
<MailChimpAuthorization
Expand Down
95 changes: 58 additions & 37 deletions frontend-dev/src/components/AllIntegrations/ZohoCRM/EditZohoCRM.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ import EditWebhookInteg from '../EditWebhookInteg'
import IntegrationStepThree from '../IntegrationHelpers/IntegrationStepThree'
import { checkMappedFields, handleInput } from './ZohoCRMCommonFunc'
import ZohoCRMIntegLayout from './ZohoCRMIntegLayout'
import ZohoCRMAuthorization from './ZohoCRMAuthorization'

function EditZohoCRM({ allIntegURL }) {
const navigate = useNavigate()
const { id } = useParams()
const { id, formID } = useParams()
const [crmConf, setCrmConf] = useRecoilState($actionConf)
const [flow, setFlow] = useRecoilState($newFlow)
const [isLoading, setIsLoading] = useState(false)
const [snack, setSnackbar] = useState({ show: false })
const [tab, settab] = useState(0)
const [step, setStep] = useState(1);
const formFields = useRecoilValue($formFields)
const saveConfig = () => {
if (!checkMappedFields(crmConf)) {
Expand All @@ -41,50 +43,69 @@ function EditZohoCRM({ allIntegURL }) {
setSnackbar
})
}
return (
<div style={{ width: 900 }}>
<SnackMsg snack={snack} setSnackbar={setSnackbar} />

<div className="flx mt-3">
<b className="wdt-200 ">{__('Integration Name:', 'bit-integrations')}</b>
<input
className="btcd-paper-inp w-5"
onChange={(e) => handleInput(e, tab, crmConf, setCrmConf)}
name="name"
value={crmConf.name}
type="text"
placeholder={__('Integration Name...', 'bit-integrations')}
/>
</div>
<br />

<SetEditIntegComponents entity={flow.triggered_entity} setSnackbar={setSnackbar} />

<ZohoCRMIntegLayout
tab={tab}
settab={settab}
formID={flow.triggered_entity_id}
formFields={formFields}
handleInput={(e) => handleInput(e, tab, crmConf, setCrmConf, setIsLoading, setSnackbar)}
if (step == 1) {
return (
<ZohoCRMAuthorization
formID={formID}
crmConf={crmConf}
setCrmConf={setCrmConf}
step={step}
setstep={setStep}
isLoading={isLoading}
setIsLoading={setIsLoading}
setSnackbar={setSnackbar}
/>
)
}

if (step == 2) {
return (
<div style={{ width: 900 }}>
<SnackMsg snack={snack} setSnackbar={setSnackbar} />

<div className="flx mt-3">
<b className="wdt-200 ">{__('Integration Name:', 'bit-integrations')}</b>
<input
className="btcd-paper-inp w-5"
onChange={(e) => handleInput(e, tab, crmConf, setCrmConf)}
name="name"
value={crmConf.name}
type="text"
placeholder={__('Integration Name...', 'bit-integrations')}
/>
</div>
<br />

<SetEditIntegComponents entity={flow.triggered_entity} setSnackbar={setSnackbar} />

<ZohoCRMIntegLayout
tab={tab}
settab={settab}
formID={flow.triggered_entity_id}
formFields={formFields}
handleInput={(e) => handleInput(e, tab, crmConf, setCrmConf, setIsLoading, setSnackbar)}
crmConf={crmConf}
setCrmConf={setCrmConf}
isLoading={isLoading}
setIsLoading={setIsLoading}
setSnackbar={setSnackbar}
/>

<IntegrationStepThree
edit
saveConfig={saveConfig}
disabled={crmConf.module === '' || crmConf.layout === '' || crmConf.field_map.length < 1}
isLoading={isLoading}
dataConf={crmConf}
setDataConf={setCrmConf}
formFields={formFields}
/>
<br />
</div>
)
}

<IntegrationStepThree
edit
saveConfig={saveConfig}
disabled={crmConf.module === '' || crmConf.layout === '' || crmConf.field_map.length < 1}
isLoading={isLoading}
dataConf={crmConf}
setDataConf={setCrmConf}
formFields={formFields}
/>
<br />
</div>
)
}

export default EditZohoCRM
24 changes: 22 additions & 2 deletions frontend-dev/src/components/AllIntegrations/ZohoCRM/ZohoCRM.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import IntegrationStepThree from '../IntegrationHelpers/IntegrationStepThree'
import ZohoCRMAuthorization from './ZohoCRMAuthorization'
import { checkMappedFields, handleInput } from './ZohoCRMCommonFunc'
import ZohoCRMIntegLayout from './ZohoCRMIntegLayout'
import bitsFetch from '../../../Utils/bitsFetch'

function ZohoCRM({ formFields, setFlow, flow, allIntegURL }) {
const navigate = useNavigate()
Expand All @@ -32,9 +33,28 @@ function ZohoCRM({ formFields, setFlow, flow, allIntegURL }) {
actions: {}
})


useEffect(() => {
window.opener && setGrantTokenResponse('zohoCRM')
}, [])
const fetchCredentials = async () => {
if (crmConf.oneClickAuthCredentials === undefined) {
const actionName = "zohoCrm";

try {
const userInfoResponse = await fetch('https://auth-apps.bitapps.pro/apps/' + actionName);
const userInfo = await userInfoResponse.json();
setCrmConf((prevConf) => {
return { ...prevConf, oneClickAuthCredentials: userInfo };
});
} catch (error) {
console.error('Error fetching Credentials:', error);
}
}
};

fetchCredentials();
}, []);



const saveConfig = () => {
saveActionConf({
Expand Down
Loading