Skip to content

Commit

Permalink
Replace site decided with new site address question (#7486)
Browse files Browse the repository at this point in the history
Co-authored-by: Stuart Mindt <stuart.mindt@madetech.com>
  • Loading branch information
oliverjwroberts and stuart-mindt authored Jan 30, 2025
1 parent 4c418b4 commit 382debc
Show file tree
Hide file tree
Showing 17 changed files with 398 additions and 227 deletions.
6 changes: 3 additions & 3 deletions src/client/components/MyInvestmentProjects/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +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,
['actual_uk_regions']: STAGE.VERIFY_WIN_ID,
['site_address_is_company_address']: STAGE.VERIFY_WIN_ID,
['delivery_partners']: STAGE.VERIFY_WIN_ID,
['actual_land_date']: STAGE.VERIFY_WIN_ID,
['specific_programmes']: STAGE.VERIFY_WIN_ID,
Expand Down Expand Up @@ -136,10 +135,11 @@ 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',
actual_uk_regions: 'UK regions landed',
actual_land_date: 'Actual land date',
average_salary: 'Average salary of new jobs',
client_cannot_provide_foreign_investment:
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,58 +180,60 @@ 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?"
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
)
}}
/>
<ResourceOptionsField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import InvestmentName from '../InvestmentName'

const checkIfRequirementsStarted = (project) => {
const requirementsArrays = [
project.actualUkRegions,
project.competitorCountries,
project.deliveryPartners,
project.strategicDrivers,
Expand Down Expand Up @@ -240,13 +239,6 @@ const ProjectDetails = ({ currentAdviserId }) => {
value={transformArray(project.ukRegionLocations)}
/>
)}
{project.actualUkRegions &&
project.actualUkRegions.length > 0 && (
<SummaryTable.TextRow
heading="UK regions landed"
value={transformArray(project.actualUkRegions)}
/>
)}
<SummaryTable.TextRow
heading="UK recipient company"
value={
Expand Down
72 changes: 46 additions & 26 deletions src/client/modules/Investments/Projects/Details/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,44 @@ 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 === null ||
(siteAddressIsCompanyAddressBool === true && !ukCompany)
) {
return {
address_1: '',
address_2: '',
address_town: '',
address_postcode: '',
}
}
if (siteAddressIsCompanyAddressBool === true && ukCompany) {
return {
address_1: ukCompany.address1,
address_2: ukCompany.address2,
address_town: ukCompany.addressTown,
address_postcode: ukCompany.addressPostcode,
}
}
if (siteAddressIsCompanyAddressBool === false) {
return {
address_1: address1,
address_2: address2,
address_town: city,
address_postcode: postcode,
}
}
}

const checkLandDate = (estimatedLandDate) => {
Expand Down Expand Up @@ -73,9 +91,12 @@ 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,
address2,
city,
Expand All @@ -84,13 +105,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 +121,6 @@ export const transformProjectRequirementsForApi = ({ projectId, values }) => {

const requirementsValues = {
id: projectId,
actual_uk_regions: setConditionalArrayValue(
site_decided,
actual_uk_regions
),
client_considering_other_countries: transformRadioOptionToBoolWithNullCheck(
client_considering_other_countries
),
Expand All @@ -114,7 +132,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 +143,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
2 changes: 1 addition & 1 deletion src/client/modules/Investments/Projects/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ export const mapFieldToUrl = (field, projectId) => {
'Foreign equity investment',
]
const requirementsFields = [
'UK regions landed',
'Is the client considering other countries?',
'Client requirements',
'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
16 changes: 2 additions & 14 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 @@ -7547,12 +7547,6 @@
"type": "string"
}
},
"actual_uk_regions": {
"type": "array",
"items": {
"type": "string"
}
},
"delivery_partners": {
"type": "array",
"items": {
Expand Down Expand Up @@ -9526,13 +9520,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
Loading

0 comments on commit 382debc

Please sign in to comment.