Skip to content

Commit

Permalink
Reapply site address question changes with some modifications (#7511)
Browse files Browse the repository at this point in the history
* Reapply site address question changes with some modifications

Reapplies PR #7486 (commit 382debc). Modifications include keeping the `actual_uk_regions` question and unnesting it.

* Remove superfluous return

* Test transformation of actual_uk_regions field
  • Loading branch information
oliverjwroberts authored and dredmonds committed Feb 10, 2025
1 parent 5a5c52e commit ddb1b78
Show file tree
Hide file tree
Showing 14 changed files with 457 additions and 194 deletions.
4 changes: 3 additions & 1 deletion src/client/components/MyInvestmentProjects/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const GET_REQUIRED_FIELDS_AFTER_STAGE = {
['non_fdi_r_and_d_budget']: STAGE.VERIFY_WIN_ID,
['new_tech_to_uk']: STAGE.VERIFY_WIN_ID,
['export_revenue']: STAGE.VERIFY_WIN_ID,
['site_decided']: STAGE.VERIFY_WIN_ID,
['site_address_is_company_address']: STAGE.VERIFY_WIN_ID,
['actual_uk_regions']: STAGE.VERIFY_WIN_ID,
['delivery_partners']: STAGE.VERIFY_WIN_ID,
['actual_land_date']: STAGE.VERIFY_WIN_ID,
Expand Down Expand Up @@ -136,6 +136,8 @@ export const INCOMPLETE_FIELDS = {
'Does the project bring ‘New To World’ Technology, IP or Business Model to the UK site?',
export_revenue:
'Will the UK company export a significant proportion of their products and services produced in the UK as a result of the FDI project?',
site_address_is_company_address:
"Is the site address the same as the UK recipient company's address?",
address_1: 'Street',
address_town: 'Town',
address_postcode: 'Postcode',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { H2 } from 'govuk-react'
import { LEVEL_SIZE } from '@govuk-react/constants'
import { useParams } from 'react-router-dom'
import InsetText from '@govuk-react/inset-text'

import {
FieldAddress,
Expand All @@ -28,6 +29,7 @@ import {
import {
OPTIONS_YES_NO,
OPTION_YES,
OPTION_NO,
UNITED_KINGDOM_ID,
} from '../../../../../common/constants'

Expand All @@ -38,7 +40,7 @@ import {
isFieldOptionalForStageLabel,
validateFieldForStage,
} from '../validators'
import { siteDecidedValidator } from './validators'
import { siteAddressIsCompanyAddressValidator } from './validators'

const ukObject = {
name: 'United Kingdom',
Expand Down Expand Up @@ -78,6 +80,7 @@ const EditProjectRequirements = () => {
transformProjectRequirementsForApi({
projectId,
values,
ukCompany: project.ukCompany,
})
}
>
Expand Down Expand Up @@ -177,60 +180,88 @@ const EditProjectRequirements = () => {
}}
/>
<FieldRadios
name="site_decided"
label="Has the UK location (site address) for this investment been decided yet?"
name="site_address_is_company_address"
label={
"Is the site address the same as the UK recipient company's address?" +
isFieldOptionalForStageLabel(
'site_address_is_company_address',
project
)
}
initialValue={transformBoolToRadioOptionWithNullCheck(
project.siteDecided
project.siteAddressIsCompanyAddress
)}
options={OPTIONS_YES_NO.map((option) => ({
...option,
...(option.value === OPTION_YES && {
children: (
<>
<FieldAddress
legend="Address"
name="address"
country={ukObject}
hideCountyField={true}
useStaticPostcodeField={true}
initialValue={{
address1: project.address1 || '',
address2: project.address2 || '',
town: project.addressTown || '',
postcode: project.addressPostcode || '',
}}
/>
<FieldUKRegionTypeahead
name="actual_uk_regions"
label={
'UK regions landed' +
isFieldOptionalForStageLabel(
'actual_uk_regions',
project
)
}
initialValue={transformArrayForTypeahead(
project.actualUkRegions
)}
placeholder="Select a UK region"
isMulti={true}
validate={(values, field, formFields) => {
return validateFieldForStage(
field,
formFields,
project,
'Select a UK region'
)
}}
/>
<InsetText className="govuk-!-margin-bottom-3">
The address will appear on this form once you have
selected the recipient company
</InsetText>
</>
),
}),
...(option.value === OPTION_YES &&
project.ukCompany && {
children: (
<>
<InsetText className="govuk-!-margin-bottom-3">
<p>{project.ukCompany.address1}</p>
<p>{project.ukCompany.address2}</p>
<p>{project.ukCompany.addressTown}</p>
<p>{project.ukCompany.addressPostcode}</p>
</InsetText>
</>
),
}),
...(option.value === OPTION_NO && {
children: (
<FieldAddress
legend="What is the site address?"
name="address"
country={ukObject}
hideCountyField={true}
useStaticPostcodeField={true}
initialValue={{
address1: project.address1 || '',
address2: project.address2 || '',
town: project.addressTown || '',
postcode: project.addressPostcode || '',
}}
/>
),
}),
}))}
validate={(values, field, formFields) => {
return siteDecidedValidator(field, formFields, project)
return siteAddressIsCompanyAddressValidator(
field,
formFields,
project
)
}}
/>
<FieldUKRegionTypeahead
name="actual_uk_regions"
label={
'UK regions landed' +
isFieldOptionalForStageLabel('actual_uk_regions', project)
}
initialValue={transformArrayForTypeahead(
project.actualUkRegions
)}
placeholder="Select a UK region"
isMulti={true}
validate={(values, field, formFields) =>
validateFieldForStage(
field,
formFields,
project,
'Select a UK region'
)
}
/>
<ResourceOptionsField
name="delivery_partners"
label={
Expand Down
63 changes: 38 additions & 25 deletions src/client/modules/Investments/Projects/Details/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,33 @@ const checkIfItemHasValueOrZero = (value) =>
const setConditionalArrayValue = (radioValue, array) =>
transformRadioOptionToBool(radioValue) ? array.map((x) => x.value) : []

const setSiteDecidedSubValues = (
site_decided,
const setSiteAddressValues = (
siteAddressIsCompanyAddress,
ukCompany,
address1,
address2,
city,
postcode
) => {
return transformRadioOptionToBool(site_decided)
? {
address_1: address1,
address_2: address2,
address_town: city,
address_postcode: postcode,
}
: {
address_1: '',
address_2: '',
address_town: '',
address_postcode: '',
}
const siteAddressIsCompanyAddressBool = transformRadioOptionToBool(
siteAddressIsCompanyAddress
)
if (siteAddressIsCompanyAddressBool === true && ukCompany) {
return {
address_1: ukCompany.address1,
address_2: ukCompany.address2,
address_town: ukCompany.addressTown,
address_postcode: ukCompany.addressPostcode,
}
} else {
// return entered/existing values if not empty to ensure data is NOT overwritten
return {
address_1: address1 ? address1 : null,
address_2: address2 ? address2 : null,
address_town: city ? city : null,
address_postcode: postcode ? postcode : null,
}
}
}

const checkLandDate = (estimatedLandDate) => {
Expand Down Expand Up @@ -73,7 +80,11 @@ export const transformBoolToRadioOptionWithNullCheck = (boolean) =>
export const transformBoolToInvertedRadioOptionWithNullCheck = (boolean) =>
boolean === null ? null : transformBoolToInvertedRadioOption(boolean)

export const transformProjectRequirementsForApi = ({ projectId, values }) => {
export const transformProjectRequirementsForApi = ({
projectId,
values,
ukCompany,
}) => {
const {
actual_uk_regions,
address1,
Expand All @@ -84,13 +95,14 @@ export const transformProjectRequirementsForApi = ({ projectId, values }) => {
competitor_countries,
delivery_partners,
postcode,
site_decided,
site_address_is_company_address,
strategic_drivers,
uk_region_locations,
} = values

const siteDecidedObject = setSiteDecidedSubValues(
site_decided,
const siteAddressObject = setSiteAddressValues(
site_address_is_company_address,
ukCompany,
address1,
address2,
city,
Expand All @@ -99,10 +111,9 @@ export const transformProjectRequirementsForApi = ({ projectId, values }) => {

const requirementsValues = {
id: projectId,
actual_uk_regions: setConditionalArrayValue(
site_decided,
actual_uk_regions
),
actual_uk_regions: actual_uk_regions
? actual_uk_regions.map((x) => x.value)
: [],
client_considering_other_countries: transformRadioOptionToBoolWithNullCheck(
client_considering_other_countries
),
Expand All @@ -114,7 +125,9 @@ export const transformProjectRequirementsForApi = ({ projectId, values }) => {
delivery_partners: delivery_partners
? delivery_partners.map((x) => x.value)
: [],
site_decided: transformRadioOptionToBoolWithNullCheck(site_decided),
site_address_is_company_address: transformRadioOptionToBoolWithNullCheck(
site_address_is_company_address
),
strategic_drivers: strategic_drivers
? strategic_drivers.map((x) => x.value)
: [],
Expand All @@ -123,7 +136,7 @@ export const transformProjectRequirementsForApi = ({ projectId, values }) => {
: [],
}

return { ...siteDecidedObject, ...requirementsValues }
return { ...siteAddressObject, ...requirementsValues }
}

export const transformProjectSummaryForApi = ({
Expand Down
15 changes: 7 additions & 8 deletions src/client/modules/Investments/Projects/Details/validators.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { STAGE } from '../../../../components/MyInvestmentProjects/constants'
import { isFieldRequiredForStage } from '../validators'

const { OPTION_YES } = require('../../../../../common/constants')

export const totalInvestmentValidator = (value, foreignEquityInvestment) => {
if (parseInt(value) < parseInt(foreignEquityInvestment)) {
return 'Total investment must be >= to capital expenditure'
Expand All @@ -18,13 +16,14 @@ export const capitalExpenditureValidator = (value) => {
return null
}

export const siteDecidedValidator = (field, formFields, project) => {
if (project?.stage?.id == STAGE.ACTIVE_ID && !formFields.values[field.name]) {
return 'Select a value for UK location decision'
}
export const siteAddressIsCompanyAddressValidator = (
field,
formFields,
project
) => {
return isFieldRequiredForStage(field.name, project) &&
formFields.values[field.name] != OPTION_YES
? 'A UK region is required'
!formFields.values[field.name]
? "Select if the site address the same as the UK recipient company's address?"
: null
}

Expand Down
1 change: 1 addition & 0 deletions src/client/modules/Investments/Projects/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const mapFieldToUrl = (field, projectId) => {
'Delivery partners',
'Strategic drivers behind this investment',
'Possible UK locations for this investment',
"Is the site address the same as the UK recipient company's address?",
'Street',
'Town',
'Postcode',
Expand Down
10 changes: 2 additions & 8 deletions test/api-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7506,7 +7506,7 @@
"type": "string",
"nullable": true
},
"site_decided": {
"site_address_is_company_address": {
"type": "boolean",
"nullable": true
},
Expand Down Expand Up @@ -9526,13 +9526,7 @@
"nullable": true
},
"hiring": {
"enum": [
"1-5",
"6-50",
"51-100",
"101+",
"NO_PLANS_TO_HIRE_YET"
],
"enum": ["1-5", "6-50", "51-100", "101+", "NO_PLANS_TO_HIRE_YET"],
"type": "string"
},
"spend": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ const activeIncompleteFields = [
'non_fdi_r_and_d_budget',
'new_tech_to_uk',
'export_revenue',
'address_1',
'address_town',
'address_postcode',
'actual_uk_regions',
'site_address_is_company_address',
'delivery_partners',
'actual_land_date',
'foreign_equity_investment',
Expand Down Expand Up @@ -226,10 +223,10 @@ describe('ProjectIncompleteFields', () => {
'Will the UK company export a significant proportion of their products and services produced in the UK as a result of the FDI project?',
valueLink
)
assertLink('Street', requirementsLink)
assertLink('Town', requirementsLink)
assertLink('Postcode', requirementsLink)
assertLink('UK regions landed', requirementsLink)
assertLink(
"Is the site address the same as the UK recipient company's address?",
requirementsLink
)
assertLink('Delivery partners', requirementsLink)
assertLink('Actual land date', detailsLink)
assertLink('Foreign equity investment', valueLink)
Expand Down
3 changes: 2 additions & 1 deletion test/functional/cypress/fakers/investment-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const investmentProjectFaker = (overrides = {}) => ({
sector_classification_gva_multiplier: 'labour',
id: faker.string.uuid(),
},
specific_programmes: [],
...overrides,
})

Expand Down Expand Up @@ -120,7 +121,7 @@ const investmentProjectEmptyFaker = (overrides = {}) =>
non_fdi_r_and_d_budget: null,
new_tech_to_uk: null,
export_revenue: null,
site_decided: null,
site_address_is_company_address: null,
address_1: null,
address_town: null,
address_postcode: null,
Expand Down
Loading

0 comments on commit ddb1b78

Please sign in to comment.