diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee435b8e26d70..2c81faf524495 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2800,9 +2800,6 @@ importers: '@wordpress/icons': specifier: 9.38.0 version: 9.38.0(react@18.2.0) - axios: - specifier: 1.6.2 - version: 1.6.2 classnames: specifier: 2.3.2 version: 2.3.2 diff --git a/projects/plugins/crm/changelog/fix-crm-3389-remove_axios_dependencies b/projects/plugins/crm/changelog/fix-crm-3389-remove_axios_dependencies new file mode 100644 index 0000000000000..8af4d78d57439 --- /dev/null +++ b/projects/plugins/crm/changelog/fix-crm-3389-remove_axios_dependencies @@ -0,0 +1,5 @@ +Significance: patch +Type: removed +Comment: Replaced axios with native fetch. + + diff --git a/projects/plugins/crm/package.json b/projects/plugins/crm/package.json index 0297aa4e319f7..f58d1500123f3 100644 --- a/projects/plugins/crm/package.json +++ b/projects/plugins/crm/package.json @@ -29,7 +29,6 @@ "@wordpress/element": "5.24.0", "@wordpress/i18n": "4.47.0", "@wordpress/icons": "9.38.0", - "axios": "1.6.2", "classnames": "2.3.2", "prop-types": "15.8.1", "react": "18.2.0", diff --git a/projects/plugins/crm/src/js/components/automations-admin/components/workflow-row/index.tsx b/projects/plugins/crm/src/js/components/automations-admin/components/workflow-row/index.tsx index 6819ec2e77489..2b72f17930c66 100644 --- a/projects/plugins/crm/src/js/components/automations-admin/components/workflow-row/index.tsx +++ b/projects/plugins/crm/src/js/components/automations-admin/components/workflow-row/index.tsx @@ -70,7 +70,7 @@ export const WorkflowRow: React.FC< WorkflowRowProps > = props => {
{ workflow.triggers.map( ( trigger: Trigger ) => { return ( -
+
{ trigger.title } = props => { const getSortableWorkflowTableHeader = ( column: SortableWorkflowTableColumn ) => { return ( = props => { return (
- - - { sortableColumns.map( column => getSortableWorkflowTableHeader( column ) ) } - - - { sortedWorkflows.map( workflow => ( - - ) ) } + + + + { sortableColumns.map( column => getSortableWorkflowTableHeader( column ) ) } + + + + + { sortedWorkflows.map( workflow => ( + + ) ) } +
); diff --git a/projects/plugins/crm/src/js/data/query-functions.ts b/projects/plugins/crm/src/js/data/query-functions.ts index 0c66bf4d53afe..38a2def8fcc55 100644 --- a/projects/plugins/crm/src/js/data/query-functions.ts +++ b/projects/plugins/crm/src/js/data/query-functions.ts @@ -1,4 +1,3 @@ -import axios from 'axios'; import { Workflow, ServerPreparedWorkflow } from 'crm/state/automations-admin/types'; import { getServerPreparedWorkflow } from 'crm/state/automations-admin/util'; @@ -7,24 +6,43 @@ declare let jpcrmAutomationsInitialState: any; const v4ApiRoot = `${ jpcrmAutomationsInitialState.apiRoot }jetpack-crm/v4`; -const api = axios.create( { - baseURL: v4ApiRoot, - headers: { 'X-WP-Nonce': jpcrmAutomationsInitialState.apiNonce }, -} ); +type fetchAutomationsAPIOptions = { + headers: HeadersInit; + method: string; + body?: string; +}; + +const callAutomationsAPI = async ( relative_url: string, payload?: object ) => { + const options: fetchAutomationsAPIOptions = { + headers: { + 'X-WP-Nonce': jpcrmAutomationsInitialState.apiNonce, + 'Content-Type': 'application/json', + }, + method: 'GET', + }; + if ( payload ) { + options.method = 'POST'; + options.body = JSON.stringify( payload ); + } + const response = await fetch( v4ApiRoot + relative_url, options ); + return await response.json(); +}; // /wp-json/jetpack-crm/v4/automation/workflows export const getAutomationWorkflows = ( hydrate: ( workflows: Workflow[] ) => void ) => async () => { - const result = await api.get< Workflow[] >( '/automation/workflows' ); - result.data && hydrate( result.data ); + const result: Workflow[] = await callAutomationsAPI( '/automation/workflows' ); + result && hydrate( result ); return result; }; // /wp-json/jetpack-crm/v4/automation/workflows/:id export const postAutomationWorkflow = async ( workflow: Workflow ) => { const serverPreparedWorkflow = getServerPreparedWorkflow( workflow ); - return await api.post< ServerPreparedWorkflow >( + + const result: ServerPreparedWorkflow = await callAutomationsAPI( `/automation/workflows/${ workflow.id }`, serverPreparedWorkflow ); + return result; };