Skip to content

Commit

Permalink
Revert "Replace site decided with new site address question (#7486)" (#…
Browse files Browse the repository at this point in the history
…7501)

This reverts commit 382debc.
  • Loading branch information
oliverjwroberts authored Jan 30, 2025
1 parent 382debc commit e4b0ea2
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 398 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,7 +48,8 @@ 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_address_is_company_address']: STAGE.VERIFY_WIN_ID,
['site_decided']: STAGE.VERIFY_WIN_ID,
['actual_uk_regions']: 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 @@ -135,11 +136,10 @@ 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,7 +2,6 @@ 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 @@ -29,7 +28,6 @@ import {
import {
OPTIONS_YES_NO,
OPTION_YES,
OPTION_NO,
UNITED_KINGDOM_ID,
} from '../../../../../common/constants'

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

const ukObject = {
name: 'United Kingdom',
Expand Down Expand Up @@ -80,7 +78,6 @@ const EditProjectRequirements = () => {
transformProjectRequirementsForApi({
projectId,
values,
ukCompany: project.ukCompany,
})
}
>
Expand Down Expand Up @@ -180,60 +177,58 @@ const EditProjectRequirements = () => {
}}
/>
<FieldRadios
name="site_address_is_company_address"
label="Is the site address the same as the UK recipient company's address?"
name="site_decided"
label="Has the UK location (site address) for this investment been decided yet?"
initialValue={transformBoolToRadioOptionWithNullCheck(
project.siteAddressIsCompanyAddress
project.siteDecided
)}
options={OPTIONS_YES_NO.map((option) => ({
...option,
...(option.value === OPTION_YES && {
children: (
<>
<InsetText className="govuk-!-margin-bottom-3">
The address will appear on this form once you have
selected the recipient company
</InsetText>
<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'
)
}}
/>
</>
),
}),
...(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 siteAddressIsCompanyAddressValidator(
field,
formFields,
project
)
return siteDecidedValidator(field, formFields, project)
}}
/>
<ResourceOptionsField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import InvestmentName from '../InvestmentName'

const checkIfRequirementsStarted = (project) => {
const requirementsArrays = [
project.actualUkRegions,
project.competitorCountries,
project.deliveryPartners,
project.strategicDrivers,
Expand Down Expand Up @@ -239,6 +240,13 @@ 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: 26 additions & 46 deletions src/client/modules/Investments/Projects/Details/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,26 @@ const checkIfItemHasValueOrZero = (value) =>
const setConditionalArrayValue = (radioValue, array) =>
transformRadioOptionToBool(radioValue) ? array.map((x) => x.value) : []

const setSiteAddressValues = (
siteAddressIsCompanyAddress,
ukCompany,
const setSiteDecidedSubValues = (
site_decided,
address1,
address2,
city,
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,
}
}
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 checkLandDate = (estimatedLandDate) => {
Expand Down Expand Up @@ -91,12 +73,9 @@ export const transformBoolToRadioOptionWithNullCheck = (boolean) =>
export const transformBoolToInvertedRadioOptionWithNullCheck = (boolean) =>
boolean === null ? null : transformBoolToInvertedRadioOption(boolean)

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

const siteAddressObject = setSiteAddressValues(
site_address_is_company_address,
ukCompany,
const siteDecidedObject = setSiteDecidedSubValues(
site_decided,
address1,
address2,
city,
Expand All @@ -121,6 +99,10 @@ export const transformProjectRequirementsForApi = ({

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

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

export const transformProjectSummaryForApi = ({
Expand Down
15 changes: 8 additions & 7 deletions src/client/modules/Investments/Projects/Details/validators.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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 @@ -16,14 +18,13 @@ export const capitalExpenditureValidator = (value) => {
return null
}

export const siteAddressIsCompanyAddressValidator = (
field,
formFields,
project
) => {
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'
}
return isFieldRequiredForStage(field.name, project) &&
!formFields.values[field.name]
? "Select if the site address the same as the UK recipient company's address?"
formFields.values[field.name] != OPTION_YES
? 'A UK region is required'
: 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: 14 additions & 2 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_address_is_company_address": {
"site_decided": {
"type": "boolean",
"nullable": true
},
Expand Down Expand Up @@ -7547,6 +7547,12 @@
"type": "string"
}
},
"actual_uk_regions": {
"type": "array",
"items": {
"type": "string"
}
},
"delivery_partners": {
"type": "array",
"items": {
Expand Down Expand Up @@ -9520,7 +9526,13 @@
"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 e4b0ea2

Please sign in to comment.