Skip to content

Commit

Permalink
Move all submission logic to Redux
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsunkel committed Jan 17, 2025
1 parent 7b50f77 commit 6ace295
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
8 changes: 3 additions & 5 deletions src/client/modules/Companies/MatchCompany/CannotFindMatch.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import { connect } from 'react-redux'
import { useParams } from 'react-router-dom'
import { H4 } from '@govuk-react/heading'
import InsetText from '@govuk-react/inset-text'
Expand All @@ -12,7 +11,6 @@ import Form from '../../../components/Form'
import { buildCompanyBreadcrumbs } from '../utils'
import { CompanyResource } from '../../../components/Resource/index'
import { CompanyName } from '../Referrals/SendReferralForm/SendReferralForm'
import { state2props } from './state'

const requiredWebsiteOrPhoneValidator = (
value,
Expand All @@ -26,7 +24,7 @@ const websiteValidator = (value) => {
WEBSITE_REGEX.test(value) ? null : 'Enter a valid website URL'
}

function CannotFindMatch({ csrfToken }) {
function CannotFindMatch() {
const { companyId } = useParams()
return (
<DefaultLayout
Expand All @@ -53,7 +51,7 @@ function CannotFindMatch({ csrfToken }) {
submissionTaskName="Cannot find match"
analyticsFormName="cannotFindMatchForm"
redirectTo={() => urls.companies.detail(companyId)}
transformPayload={(values) => ({ values, company, csrfToken })}
transformPayload={(values) => ({ values, company })}
flashMessage={() =>
'Verification request sent for third party review'
}
Expand Down Expand Up @@ -119,4 +117,4 @@ function CannotFindMatch({ csrfToken }) {
)
}

export default connect(state2props)(CannotFindMatch)
export default CannotFindMatch
3 changes: 0 additions & 3 deletions src/client/modules/Companies/MatchCompany/state.js

This file was deleted.

30 changes: 21 additions & 9 deletions src/client/modules/Companies/MatchCompany/tasks.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import axios from 'axios'
import { isEmpty, omit } from 'lodash'

import urls from '../../../../lib/urls'
import { apiProxyAxios } from '../../../components/Task/utils'

export const cannotFindMatchSubmit = ({ csrfToken, values, company }) =>
axios
.post(urls.companies.match.cannotFind(company.id), {
_csrf: csrfToken,
website: values.website,
telephone_number: values.telephoneNumber,
})
export const cannotFindMatchSubmit = ({ values, company }) => {
const { address } = company
const dnbInvestigation = {
company: company.id,
name: company.name,
website: values.website,
telephone_number: values.telephoneNumber,
address: {
...omit(address, ['country', 'area']),
country: address.country.id,
},
}
if (!isEmpty(address.area)) {
dnbInvestigation.address.area = address.area
}

return apiProxyAxios
.post('v4/dnb/company-investigation', dnbInvestigation)
.catch((e) => {
return Promise.reject(e.message)
})
.then((response) => {
return response.data
})
}
1 change: 1 addition & 0 deletions src/middleware/api-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const ALLOWLIST = [
'/v3/investment/:projectId/proposition/:propositionId/document/upload-callback',
'/v4/investment-lead/eyb/:eybLeadId',
'/v4/investment-lead/eyb',
'/v4/dnb/company-investigation',
]

module.exports = (app) => {
Expand Down

0 comments on commit 6ace295

Please sign in to comment.