From b9daa26b1640c88d31ae535b8a0c626402dc2923 Mon Sep 17 00:00:00 2001 From: Christopher Sunkel Date: Fri, 5 Jan 2024 18:37:08 +0000 Subject: [PATCH 1/5] Migrate business details page to React Router --- .../client/CompanyBusinessDetails.jsx | 310 ++++++++++-------- .../client/SectionHierarchy.jsx | 6 +- .../apps/business-details/client/reducer.js | 23 +- .../apps/business-details/client/state.js | 3 + .../apps/business-details/client/tasks.js | 8 + src/apps/routers.js | 1 + src/client/actions.js | 3 + src/client/routes.js | 6 + src/client/tasks.js | 2 + src/lib/urls.js | 1 + .../BusinessDetails/SectionAbout.cy.jsx | 2 +- .../BusinessDetails/SectionAddresses.cy.jsx | 2 +- .../BusinessDetails/SectionHierarchy.cy.jsx | 2 +- .../BusinessDetails/SectionOneList.cy.jsx | 2 +- .../BusinessDetails/SectionRegion.cy.jsx | 2 +- .../BusinessDetails/SectionSector.cy.jsx | 2 +- .../specs/DIT/business-hierarchy-spec.js | 28 +- 17 files changed, 226 insertions(+), 177 deletions(-) diff --git a/src/apps/companies/apps/business-details/client/CompanyBusinessDetails.jsx b/src/apps/companies/apps/business-details/client/CompanyBusinessDetails.jsx index 7456ed6d08c..db160a18371 100644 --- a/src/apps/companies/apps/business-details/client/CompanyBusinessDetails.jsx +++ b/src/apps/companies/apps/business-details/client/CompanyBusinessDetails.jsx @@ -6,6 +6,7 @@ import Link from '@govuk-react/link' import styled from 'styled-components' import Button from '@govuk-react/button' import { SPACING_POINTS } from '@govuk-react/constants' +import { useParams } from 'react-router-dom' import SectionAbout from './SectionAbout' import SectionAddresses from './SectionAddresses' @@ -16,16 +17,23 @@ import SectionOneList from './SectionOneList' import ArchiveForm from '../../../../../client/components/ArchiveForm' import { StatusMessage } from '../../../../../client/components/' import { COMPANY_DISSOLVED_OPTION } from '../../../constants' -import { CompanyResource } from '../../../../../client/components/Resource' -import CompanyLayout from '../../../../../client/components/Layout/CompanyLayout' +import { + CompanyResource, + RelatedCompaniesCountResource, +} from '../../../../../client/components/Resource' +import CompanyLayoutNew from '../../../../../client/components/Layout/CompanyLayoutNew' import urls from '../../../../../lib/urls' import { ID as CHECK_PENDING_REQUEST_ID, TASK_ARCHIVE_COMPANY, + TASK_GET_GLOBAL_ULTIMATE, state2props, } from './state' -import { DNB__CHECK_PENDING_REQUEST } from '../../../../../client/actions' +import { + COMPANIES__GLOBAL_ULTIMATE_LOADED, + DNB__CHECK_PENDING_REQUEST, +} from '../../../../../client/actions' import Task from '../../../../../client/components/Task' const { format } = require('../../../../../client/utils/date') @@ -52,150 +60,178 @@ const canEditOneList = (permissions) => ) const CompanyBusinessDetails = ({ - subsidiariesCount, - dnbRelatedCompaniesCount, globalUltimate, isDnbPending, - companyId, flashMessages, csrfToken, - permissions, -}) => ( - - {(company) => ( - - -
- This page shows information about this business and how it is - related to other businesses. -
-
- Changes made to this information can be found on the{' '} - - Edit history page - - . -
- {lastUpdated(company) && ( -
Last updated on: {format(lastUpdated(company))}
- )} - - {() => - isDnbPending && ( - <> -
- - Changes to these business details are currently being - reviewed. - - - ) - } -
- {isDnbCompany(company.dunsNumber) && ( -
{ + const { companyId } = useParams() + return ( + + {(company) => ( + + +
+ This page shows information about this business and how it is + related to other businesses. +
+
+ Changes made to this information can be found on the{' '} + + Edit history page + + . +
+ {lastUpdated(company) && ( +
Last updated on: {format(lastUpdated(company))}
+ )} + -

- Most business details have been verified by trusted - third-parties to keep them updated automatically. Business - description, region and sector are not updated by third parties. -

-

- Think some details are wrong? ‘Edit’ and - ‘Submit’ new details for review. -

-
- )} - - - - - - - {canEditOneList(permissions) && ( - - )} - ({ - values, - companyId, - csrfToken, - })} - archiveReasons={[ - { - label: COMPANY_DISSOLVED_OPTION, - value: COMPANY_DISSOLVED_OPTION, - }, - ]} - /> -
-
- )} -
-) + {() => + isDnbPending && ( + <> +
+ + Changes to these business details are currently being + reviewed. + + + ) + } + + {isDnbCompany(company.dunsNumber) && ( +
+

+ Most business details have been verified by trusted + third-parties to keep them updated automatically. Business + description, region and sector are not updated by third + parties. +

+

+ Think some details are wrong? ‘Edit’ and + ‘Submit’ new details for review. +

+
+ )} + + + + + + + {() => + company.dunsNumber ? ( + + {(relatedCompanies) => ( + <> + + + )} + + ) : ( + <> + + + ) + } + + {canEditOneList(userPermissions) && ( + + )} + ({ + values, + companyId, + csrfToken, + })} + archiveReasons={[ + { + label: COMPANY_DISSOLVED_OPTION, + value: COMPANY_DISSOLVED_OPTION, + }, + ]} + /> + + + )} + + ) +} CompanyBusinessDetails.propTypes = { - subsidiariesCount: PropTypes.number, - dnbRelatedCompaniesCount: PropTypes.number, - globalUltimate: PropTypes.object, - companyId: PropTypes.string.isRequired, flashMessages: PropTypes.object, csrfToken: PropTypes.string, permissions: PropTypes.array, } -CompanyBusinessDetails.defaultProps = { - subsidiariesCount: 0, - dnbRelatedCompaniesCount: 0, -} - export default connect(state2props)(CompanyBusinessDetails) diff --git a/src/apps/companies/apps/business-details/client/SectionHierarchy.jsx b/src/apps/companies/apps/business-details/client/SectionHierarchy.jsx index 85af6764d2d..88989b10b6f 100644 --- a/src/apps/companies/apps/business-details/client/SectionHierarchy.jsx +++ b/src/apps/companies/apps/business-details/client/SectionHierarchy.jsx @@ -8,7 +8,7 @@ import { SPACING_POINTS } from '@govuk-react/constants' import { SummaryTable } from '../../../../../client/components/' import WideSummaryTableRow from './WideSummaryTableRow' import { hqLabels } from '../../../labels' -import { companies } from '../../../../../lib/urls' +import urls, { companies } from '../../../../../lib/urls' const StyledRowActionLink = styled(Link)` float: right; @@ -46,7 +46,9 @@ const SubsectionDnBHierarchy = ({ {!isGlobalUltimate && globalUltimate && ( - {globalUltimate.name} + + {globalUltimate.name} + )} diff --git a/src/apps/companies/apps/business-details/client/reducer.js b/src/apps/companies/apps/business-details/client/reducer.js index 8c3efb4425a..bb78ad9bf4b 100644 --- a/src/apps/companies/apps/business-details/client/reducer.js +++ b/src/apps/companies/apps/business-details/client/reducer.js @@ -1,11 +1,24 @@ -import { DNB__CHECK_PENDING_REQUEST } from '../../../../../client/actions' +import { + COMPANIES__GLOBAL_ULTIMATE_LOADED, + DNB__CHECK_PENDING_REQUEST, +} from '../../../../../client/actions' export default ( state = { isDnbPending: false, + globalUltimate: false, }, { type, result } -) => - type === DNB__CHECK_PENDING_REQUEST - ? { ...state, isDnbPending: result } - : state +) => { + switch (type) { + case DNB__CHECK_PENDING_REQUEST: + return { ...state, isDnbPending: result } + case COMPANIES__GLOBAL_ULTIMATE_LOADED: + return { + ...state, + globalUltimate: result ? result.data.results[0] : null, + } + default: + return state + } +} diff --git a/src/apps/companies/apps/business-details/client/state.js b/src/apps/companies/apps/business-details/client/state.js index c2de4499dac..891408d2775 100644 --- a/src/apps/companies/apps/business-details/client/state.js +++ b/src/apps/companies/apps/business-details/client/state.js @@ -2,8 +2,11 @@ export const ID = 'dnbCheckPendingRequest' export const DNB__CHECK_PENDING_REQUEST = 'DNB__CHECK_PENDING_REQUEST' export const TASK_ARCHIVE_COMPANY = 'TASK_ARCHIVE_COMPANY' +export const TASK_GET_GLOBAL_ULTIMATE = 'TASK_GET_GLOBAL_ULTIMATE' export const state2props = ({ values, ...state }) => ({ + csrfToken: state.csrfToken, + userPermissions: state.userPermissions, ...state[ID], values, }) diff --git a/src/apps/companies/apps/business-details/client/tasks.js b/src/apps/companies/apps/business-details/client/tasks.js index e8c5d68a3f2..ebf3b60d223 100644 --- a/src/apps/companies/apps/business-details/client/tasks.js +++ b/src/apps/companies/apps/business-details/client/tasks.js @@ -1,6 +1,7 @@ import axios from 'axios' import urls from '../../../../../lib/urls' +import { apiProxyAxios } from '../../../../../client/components/Task/utils' const { isDateAfter, @@ -44,3 +45,10 @@ export function archiveSubmitCallback({ companyId, csrfToken, values }) { data: values, }) } + +export const getGlobalUltimate = (globalUltimateDunsNumber) => + globalUltimateDunsNumber + ? apiProxyAxios.post('/v4/search/company', { + duns_number: globalUltimateDunsNumber, + }) + : '' diff --git a/src/apps/routers.js b/src/apps/routers.js index 335bf4caf52..6aba5446696 100644 --- a/src/apps/routers.js +++ b/src/apps/routers.js @@ -110,6 +110,7 @@ const reactRoutes = [ '/tasks/create', '/tasks/:taskId/edit', '/companies/:companyId/overview', + '/companies/:companyId/business-details', ] reactRoutes.forEach((path) => { diff --git a/src/client/actions.js b/src/client/actions.js index 9922e567bd9..49f7baa4696 100644 --- a/src/client/actions.js +++ b/src/client/actions.js @@ -320,3 +320,6 @@ export const PAGINATED_RESOURCE__ON_SUCCESS = 'PAGINATED_RESOURCE__ON_SUCCESS' export const MY_TASKS_CHECK_COMPLETE = 'MY_TASKS_CHECK_COMPLETE' export const MY_TASKS_LOADED = 'MY_TASKS_LOADED' + +export const COMPANIES__GLOBAL_ULTIMATE_LOADED = + 'COMPANIES__GLOBAL_ULTIMATE_LOADED' diff --git a/src/client/routes.js b/src/client/routes.js index 4f00c04146e..a97b2069a90 100644 --- a/src/client/routes.js +++ b/src/client/routes.js @@ -82,6 +82,7 @@ import CreateOrder from './modules/Omis/CreateOrder/CreateOrder' import PaymentReceipt from './modules/Omis/PaymentReceipt' import { TaskFormAdd, TaskFormEdit } from './modules/Tasks/TaskForm' import CompanyOverview from './modules/Companies/CompanyOverview/CompanyOverview' +import CompanyBusinessDetails from '../apps/companies/apps/business-details/client/CompanyBusinessDetails' const routes = { companies: [ @@ -170,6 +171,11 @@ const routes = { module: 'datahub:companies', component: CompanyOverview, }, + { + path: '/companies/:companyId/business-details', + module: 'datahub:companies', + component: CompanyBusinessDetails, + }, ], contacts: [ { diff --git a/src/client/tasks.js b/src/client/tasks.js index 9a4f1ef6aa2..02773226557 100644 --- a/src/client/tasks.js +++ b/src/client/tasks.js @@ -25,6 +25,7 @@ import * as manageAdviser from '../apps/companies/apps/advisers/client/tasks' import { DNB__CHECK_PENDING_REQUEST, TASK_ARCHIVE_COMPANY, + TASK_GET_GLOBAL_ULTIMATE, } from '../apps/companies/apps/business-details/client/state' import * as businessDetails from '../apps/companies/apps/business-details/client/tasks' @@ -652,4 +653,5 @@ export const tasks = { reminders.getNextTaskAmendedByOthersReminder, [TASK_SAVE_TASK_AMENDED_BY_OTHERS_REMINDER_SUBSCRIPTIONS]: reminderSettings.saveTaskAmendedByOthersSubscriptions, + [TASK_GET_GLOBAL_ULTIMATE]: businessDetails.getGlobalUltimate, } diff --git a/src/lib/urls.js b/src/lib/urls.js index 3ecf6e8ee30..0a0e275ee58 100644 --- a/src/lib/urls.js +++ b/src/lib/urls.js @@ -226,6 +226,7 @@ module.exports = { remove: url('/companies', '/:companyId/hierarchies/ghq/remove'), }, subsidiaries: { + index: url('/companies', '/:companyId/subsidiaries'), search: url( '/companies', '/:companyId/hierarchies/subsidiaries/search' diff --git a/test/component/cypress/specs/Companies/BusinessDetails/SectionAbout.cy.jsx b/test/component/cypress/specs/Companies/BusinessDetails/SectionAbout.cy.jsx index ac850c96b16..67854755385 100644 --- a/test/component/cypress/specs/Companies/BusinessDetails/SectionAbout.cy.jsx +++ b/test/component/cypress/specs/Companies/BusinessDetails/SectionAbout.cy.jsx @@ -5,7 +5,7 @@ import { assertSummaryTable } from '../../../../../functional/cypress/support/as const { default: SectionAbout, -} = require('../../../../../../src/apps/companies/apps/business-details/client/SectionAbout') +} = require('../../../../../../src/client/modules/Companies/CompanyBusinessDetails/SectionAbout') const { companyFaker, } = require('../../../../../functional/cypress/fakers/companies') diff --git a/test/component/cypress/specs/Companies/BusinessDetails/SectionAddresses.cy.jsx b/test/component/cypress/specs/Companies/BusinessDetails/SectionAddresses.cy.jsx index 611e8cbb7ce..38ea0a019b2 100644 --- a/test/component/cypress/specs/Companies/BusinessDetails/SectionAddresses.cy.jsx +++ b/test/component/cypress/specs/Companies/BusinessDetails/SectionAddresses.cy.jsx @@ -5,7 +5,7 @@ import { assertSummaryTable } from '../../../../../functional/cypress/support/as const { default: SectionAddresses, -} = require('../../../../../../src/apps/companies/apps/business-details/client/SectionAddresses') +} = require('../../../../../../src/client/modules/Companies/CompanyBusinessDetails/SectionAddresses') const { companyFaker, } = require('../../../../../functional/cypress/fakers/companies') diff --git a/test/component/cypress/specs/Companies/BusinessDetails/SectionHierarchy.cy.jsx b/test/component/cypress/specs/Companies/BusinessDetails/SectionHierarchy.cy.jsx index f41529f4603..a9de5bb6ef9 100644 --- a/test/component/cypress/specs/Companies/BusinessDetails/SectionHierarchy.cy.jsx +++ b/test/component/cypress/specs/Companies/BusinessDetails/SectionHierarchy.cy.jsx @@ -1,6 +1,6 @@ import React from 'react' -import SectionHierarchy from '../../../../../../src/apps/companies/apps/business-details/client/SectionHierarchy' +import SectionHierarchy from '../../../../../../src/client/modules/Companies/CompanyBusinessDetails/SectionHierarchy' import { companyFaker } from '../../../../../functional/cypress/fakers/companies' import urls from '../../../../../../src/lib/urls' import DataHubProvider from '../../provider' diff --git a/test/component/cypress/specs/Companies/BusinessDetails/SectionOneList.cy.jsx b/test/component/cypress/specs/Companies/BusinessDetails/SectionOneList.cy.jsx index 73116ef8afc..a2b66238273 100644 --- a/test/component/cypress/specs/Companies/BusinessDetails/SectionOneList.cy.jsx +++ b/test/component/cypress/specs/Companies/BusinessDetails/SectionOneList.cy.jsx @@ -5,7 +5,7 @@ import { assertSummaryTable } from '../../../../../functional/cypress/support/as const { default: SectionOneList, -} = require('../../../../../../src/apps/companies/apps/business-details/client/SectionOneList') +} = require('../../../../../../src/client/modules/Companies/CompanyBusinessDetails/SectionOneList') const { companyFaker, } = require('../../../../../functional/cypress/fakers/companies') diff --git a/test/component/cypress/specs/Companies/BusinessDetails/SectionRegion.cy.jsx b/test/component/cypress/specs/Companies/BusinessDetails/SectionRegion.cy.jsx index eec5952b6ae..51bf7dc09c0 100644 --- a/test/component/cypress/specs/Companies/BusinessDetails/SectionRegion.cy.jsx +++ b/test/component/cypress/specs/Companies/BusinessDetails/SectionRegion.cy.jsx @@ -5,7 +5,7 @@ import { assertSummaryTable } from '../../../../../functional/cypress/support/as const { default: SectionRegion, -} = require('../../../../../../src/apps/companies/apps/business-details/client/SectionRegion') +} = require('../../../../../../src/client/modules/Companies/CompanyBusinessDetails/SectionRegion') const { companyFaker, } = require('../../../../../functional/cypress/fakers/companies') diff --git a/test/component/cypress/specs/Companies/BusinessDetails/SectionSector.cy.jsx b/test/component/cypress/specs/Companies/BusinessDetails/SectionSector.cy.jsx index 6f2211ed4d4..60185e0bd4c 100644 --- a/test/component/cypress/specs/Companies/BusinessDetails/SectionSector.cy.jsx +++ b/test/component/cypress/specs/Companies/BusinessDetails/SectionSector.cy.jsx @@ -5,7 +5,7 @@ import { assertSummaryTable } from '../../../../../functional/cypress/support/as const { default: SectionSector, -} = require('../../../../../../src/apps/companies/apps/business-details/client/SectionSector') +} = require('../../../../../../src/client/modules/Companies/CompanyBusinessDetails/SectionSector') const { companyFaker, } = require('../../../../../functional/cypress/fakers/companies') diff --git a/test/end-to-end/cypress/specs/DIT/business-hierarchy-spec.js b/test/end-to-end/cypress/specs/DIT/business-hierarchy-spec.js index 3aadb99e437..a5911ed2c86 100644 --- a/test/end-to-end/cypress/specs/DIT/business-hierarchy-spec.js +++ b/test/end-to-end/cypress/specs/DIT/business-hierarchy-spec.js @@ -68,40 +68,14 @@ describe('Business hierarchy', () => { }) beforeEach(() => { - cy.visit(companies.businessDetails(company.pk)) + cy.visit(companies.hierarchies.subsidiaries.index(company.pk)) }) it('should hide subsidiaries links for archived companies', () => { - cy.get(selectors.companySubsidiaries().linkASubsidiaryToHierarchy).should( - 'not.exist' - ) - - cy.get(selectors.companySubsidiaries().oneLinkedSubsidiary).click() cy.get(selectors.companySubsidiariesLink().removeSubsidiary).should( 'not.exist' ) cy.get(selectors.companySubsidiaries().whyNoSubLink).should('be.visible') }) }) - - describe('DnB Company Subsidiary', () => { - const company = fixtures.company.create.corp() - const subsidiaryCompany = fixtures.company.create.subsidiaryCorp(company.pk) - - before(() => { - cy.loadFixture([company]) - cy.loadFixture([subsidiaryCompany]) - }) - - beforeEach(() => { - cy.visit(companies.businessDetails(company.pk)) - }) - - it('should display subsidiaries links for dnb companies', () => { - cy.get(selectors.companySubsidiaries().oneLinkedSubsidiary).click() - cy.get(selectors.companySubsidiariesLink().removeSubsidiary).should( - 'be.visible' - ) - }) - }) }) From 14837ae3bb7504a7032a5eb3c66bd7ff068107b6 Mon Sep 17 00:00:00 2001 From: Christopher Sunkel Date: Mon, 8 Jan 2024 13:09:55 +0000 Subject: [PATCH 2/5] Move Global HQ setting logic to redux --- src/apps/routers.js | 2 + .../LinkGlobalHQ/RemoveGlobalHQ.jsx | 48 +++++++++++++++++++ .../LinkGlobalHQ/SetGlobalHQ.jsx | 48 +++++++++++++++++++ .../LinkGlobalHQ/state.js | 6 +++ .../LinkGlobalHQ/tasks.js | 10 ++++ src/client/routes.js | 12 +++++ src/client/tasks.js | 14 +++++- .../specs/companies/link-global-hq-spec.js | 27 ++++++----- 8 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/RemoveGlobalHQ.jsx create mode 100644 src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/SetGlobalHQ.jsx diff --git a/src/apps/routers.js b/src/apps/routers.js index 6aba5446696..dfc8d334b6b 100644 --- a/src/apps/routers.js +++ b/src/apps/routers.js @@ -111,6 +111,8 @@ const reactRoutes = [ '/tasks/:taskId/edit', '/companies/:companyId/overview', '/companies/:companyId/business-details', + '/companies/:companyId/hierarchies/ghq/:globalHqId/add', + '/companies/:companyId/hierarchies/ghq/remove', ] reactRoutes.forEach((path) => { diff --git a/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/RemoveGlobalHQ.jsx b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/RemoveGlobalHQ.jsx new file mode 100644 index 00000000000..ab0a00d047b --- /dev/null +++ b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/RemoveGlobalHQ.jsx @@ -0,0 +1,48 @@ +import React from 'react' +import { useParams } from 'react-router-dom' + +import { DefaultLayout } from '../../../../components' +import Task from '../../../../components/Task' +import { TASK_REMOVE_GLOBAL_HQ, REMOVE_GLOBAL_HQ_ID } from './state' +import urls from '../../../../../lib/urls' +import { CompanyResource } from '../../../../components/Resource' +import { buildCompanyBreadcrumbs } from '../../utils' + +const RemoveGlobalHQ = () => { + const { companyId } = useParams() + return ( + + {(company) => ( + + + {() => { + window.location.assign(urls.companies.businessDetails(companyId)) + }} + + + )} + + ) +} + +export default RemoveGlobalHQ diff --git a/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/SetGlobalHQ.jsx b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/SetGlobalHQ.jsx new file mode 100644 index 00000000000..b74743d6602 --- /dev/null +++ b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/SetGlobalHQ.jsx @@ -0,0 +1,48 @@ +import React from 'react' +import { useParams } from 'react-router-dom' + +import { DefaultLayout } from '../../../../components' +import Task from '../../../../components/Task' +import { TASK_SET_GLOBAL_HQ, SET_GLOBAL_HQ_ID } from './state' +import urls from '../../../../../lib/urls' +import { CompanyResource } from '../../../../components/Resource' +import { buildCompanyBreadcrumbs } from '../../utils' + +const SetGlobalHQ = () => { + const { companyId, globalHqId } = useParams() + return ( + + {(company) => ( + + + {() => { + window.location.assign(urls.companies.businessDetails(companyId)) + }} + + + )} + + ) +} + +export default SetGlobalHQ diff --git a/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/state.js b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/state.js index 098d1d2d8f3..4440ad77e6f 100644 --- a/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/state.js +++ b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/state.js @@ -4,8 +4,12 @@ import { SORT_OPTIONS } from '../../CollectionList/constants' import { parseQueryString } from '../../../../utils' export const ID = 'linkGlobalHQ' +export const SET_GLOBAL_HQ_ID = 'setGlobalHQ' +export const REMOVE_GLOBAL_HQ_ID = 'removeGlobalHQ' export const TASK_GET_GLOBAL_HQ_LIST = 'TASK_GET_GLOBAL_HQ_LIST' +export const TASK_SET_GLOBAL_HQ = 'TASK_SET_GLOBAL_HQ' +export const TASK_REMOVE_GLOBAL_HQ = 'TASK_REMOVE_GLOBAL_HQ' export const state2props = ({ router, ...state }) => { const queryString = router.location.search.slice(1) @@ -29,3 +33,5 @@ export const state2props = ({ router, ...state }) => { selectedFilters, } } + +export const setState2Props = (state) => state[SET_GLOBAL_HQ_ID] diff --git a/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/tasks.js b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/tasks.js index cedd4d12eef..d40f3bef6e9 100644 --- a/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/tasks.js +++ b/src/client/modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/tasks.js @@ -37,3 +37,13 @@ export const getGlobalHeadquartersCollection = ({ transformResponseToGlobalHQCollection(childCompanyId, data) ) } + +export const setGlobalHq = (values) => + apiProxyAxios.patch(`/v4/company/${values.companyId}`, { + global_headquarters: values.globalHqId, + }) + +export const removeGlobalHq = (values) => + apiProxyAxios.patch(`/v4/company/${values.companyId}`, { + global_headquarters: null, + }) diff --git a/src/client/routes.js b/src/client/routes.js index a97b2069a90..88257ef029b 100644 --- a/src/client/routes.js +++ b/src/client/routes.js @@ -83,6 +83,8 @@ import PaymentReceipt from './modules/Omis/PaymentReceipt' import { TaskFormAdd, TaskFormEdit } from './modules/Tasks/TaskForm' import CompanyOverview from './modules/Companies/CompanyOverview/CompanyOverview' import CompanyBusinessDetails from '../apps/companies/apps/business-details/client/CompanyBusinessDetails' +import SetGlobalHQ from './modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/SetGlobalHQ' +import RemoveGlobalHQ from './modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/RemoveGlobalHQ' const routes = { companies: [ @@ -176,6 +178,16 @@ const routes = { module: 'datahub:companies', component: CompanyBusinessDetails, }, + { + path: '/companies/:companyId/hierarchies/ghq/:globalHqId/add', + module: 'datahub:companies', + component: SetGlobalHQ, + }, + { + path: '/companies/:companyId/hierarchies/ghq/remove', + module: 'datahub:companies', + component: RemoveGlobalHQ, + }, ], contacts: [ { diff --git a/src/client/tasks.js b/src/client/tasks.js index 02773226557..7a1dbe6324a 100644 --- a/src/client/tasks.js +++ b/src/client/tasks.js @@ -301,8 +301,16 @@ import { import { TASK_GET_DNB_FAMILY_TREE } from './modules/Companies/CompanyHierarchy/state' import { getDnbFamilyTree } from './modules/Companies/CompanyHierarchy/tasks' -import { TASK_GET_GLOBAL_HQ_LIST } from './modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/state' -import { getGlobalHeadquartersCollection } from './modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/tasks' +import { + TASK_GET_GLOBAL_HQ_LIST, + TASK_SET_GLOBAL_HQ, + TASK_REMOVE_GLOBAL_HQ, +} from './modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/state' +import { + getGlobalHeadquartersCollection, + setGlobalHq, + removeGlobalHq, +} from './modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/tasks' import { TASK_GET_SUBSIDIARY_LIST } from './modules/Companies/CompanyBusinessDetails/LinkSubsidiary/state' import { getSubsidiaryCollection } from './modules/Companies/CompanyBusinessDetails/LinkSubsidiary/tasks' @@ -654,4 +662,6 @@ export const tasks = { [TASK_SAVE_TASK_AMENDED_BY_OTHERS_REMINDER_SUBSCRIPTIONS]: reminderSettings.saveTaskAmendedByOthersSubscriptions, [TASK_GET_GLOBAL_ULTIMATE]: businessDetails.getGlobalUltimate, + [TASK_SET_GLOBAL_HQ]: setGlobalHq, + [TASK_REMOVE_GLOBAL_HQ]: removeGlobalHq, } diff --git a/test/functional/cypress/specs/companies/link-global-hq-spec.js b/test/functional/cypress/specs/companies/link-global-hq-spec.js index 1b3bf7b95b8..f407905d844 100644 --- a/test/functional/cypress/specs/companies/link-global-hq-spec.js +++ b/test/functional/cypress/specs/companies/link-global-hq-spec.js @@ -4,10 +4,7 @@ import { assertMetadataItem, assertListLength, } from '../../support/collection-list-assertions' -import { - assertCompanyBreadcrumbs, - assertFlashMessage, -} from '../../support/assertions' +import { assertCompanyBreadcrumbs } from '../../support/assertions' import { collectionListRequest } from '../../support/actions' import urls from '../../../../../src/lib/urls' @@ -119,21 +116,25 @@ describe('Link Global HQ', () => { assertMetadataItem('@secondListItem', 'Company Corp, Company Ltd') }) - it('should link the global HQ', () => { - cy.contains('Global HQ Test Company').click() - - assertFlashMessage('You’ve linked the Global Headquarters') + it('should render the correct URL', () => { + cy.contains('Global HQ Test Company').should( + 'have.attr', + 'href', + urls.companies.hierarchies.ghq.add(testCompany.id, company1.id) + ) }) }) - context('should remove global HQ', () => { + context('When a company has a Global HQ', () => { before(() => { cy.visit(urls.companies.businessDetails(companyWithGlobalHQ.id)) }) - it('should remove the global HQ', () => { - cy.contains('Remove link').click() - - assertFlashMessage('You’ve removed the link to Global Headquarters') + it('should render the removal link', () => { + cy.contains('Remove link').should( + 'have.attr', + 'href', + urls.companies.hierarchies.ghq.remove(companyWithGlobalHQ.id) + ) }) }) }) From 4ff3b4209fe98e4f46b3e35208c17d63bcf8b626 Mon Sep 17 00:00:00 2001 From: Christopher Sunkel Date: Fri, 5 Jan 2024 18:41:55 +0000 Subject: [PATCH 3/5] Remove legacy code --- src/apps/companies/__test__/router.test.js | 3 -- .../business-details/__test__/router.test.js | 8 ---- .../apps/business-details/controllers.js | 29 ------------- .../companies/apps/business-details/router.js | 8 ---- .../views/client-container.njk | 9 ---- src/apps/companies/middleware/hierarchies.js | 41 ------------------- src/apps/companies/router.js | 15 +------ src/client/index.jsx | 9 ---- 8 files changed, 1 insertion(+), 121 deletions(-) delete mode 100644 src/apps/companies/apps/business-details/__test__/router.test.js delete mode 100644 src/apps/companies/apps/business-details/controllers.js delete mode 100644 src/apps/companies/apps/business-details/router.js delete mode 100644 src/apps/companies/apps/business-details/views/client-container.njk diff --git a/src/apps/companies/__test__/router.test.js b/src/apps/companies/__test__/router.test.js index 463d9164683..6f83484c85d 100644 --- a/src/apps/companies/__test__/router.test.js +++ b/src/apps/companies/__test__/router.test.js @@ -9,9 +9,6 @@ describe('Company router', () => { '/:companyId/unarchive', '/:companyId', '/:companyId/details', - '/:companyId/business-details', - '/:companyId/hierarchies/ghq/:globalHqId/add', - '/:companyId/hierarchies/ghq/remove', '/:companyId/hierarchies/subsidiaries/:subsidiaryCompanyId/add', '/:companyId/contacts', '/:companyId/orders', diff --git a/src/apps/companies/apps/business-details/__test__/router.test.js b/src/apps/companies/apps/business-details/__test__/router.test.js deleted file mode 100644 index cf6ef98e32d..00000000000 --- a/src/apps/companies/apps/business-details/__test__/router.test.js +++ /dev/null @@ -1,8 +0,0 @@ -const router = require('../router') - -describe('Business details routes', () => { - it('should define all routes', () => { - const paths = router.stack.filter((r) => r.route).map((r) => r.route.path) - expect(paths).to.deep.equal(['/:companyId/business-details']) - }) -}) diff --git a/src/apps/companies/apps/business-details/controllers.js b/src/apps/companies/apps/business-details/controllers.js deleted file mode 100644 index 9238721e8ef..00000000000 --- a/src/apps/companies/apps/business-details/controllers.js +++ /dev/null @@ -1,29 +0,0 @@ -/* eslint-disable camelcase */ - -const { pick } = require('lodash') - -const { getCompanySubsidiaries } = require('../../repos') - -async function renderBusinessDetails(req, res) { - const { company, globalUltimate, dnbRelatedCompaniesCount } = res.locals - const permissions = res.locals.user.permissions - const subsidiaries = await getCompanySubsidiaries(req, company.id) - - res.render('companies/apps/business-details/views/client-container', { - props: { - subsidiariesCount: subsidiaries.count, - dnbRelatedCompaniesCount, - globalUltimate: globalUltimate - ? pick(globalUltimate, ['name', 'url']) - : undefined, - permissions, - localNavItems: res.locals.localNavItems, - flashMessages: res.locals.getMessages(), - companyId: company.id, - }, - }) -} - -module.exports = { - renderBusinessDetails, -} diff --git a/src/apps/companies/apps/business-details/router.js b/src/apps/companies/apps/business-details/router.js deleted file mode 100644 index b564c1cfad5..00000000000 --- a/src/apps/companies/apps/business-details/router.js +++ /dev/null @@ -1,8 +0,0 @@ -const router = require('express').Router() - -const urls = require('../../../../lib/urls') -const { renderBusinessDetails } = require('./controllers') - -router.get(urls.companies.businessDetails.route, renderBusinessDetails) - -module.exports = router diff --git a/src/apps/companies/apps/business-details/views/client-container.njk b/src/apps/companies/apps/business-details/views/client-container.njk deleted file mode 100644 index 3a373a42a5f..00000000000 --- a/src/apps/companies/apps/business-details/views/client-container.njk +++ /dev/null @@ -1,9 +0,0 @@ -{% extends "_layouts/template-no-local-header.njk" %} - -{% block body %} - {% component 'react-slot', { - id: 'company-business-details', - props: props - } %} - -{% endblock %} diff --git a/src/apps/companies/middleware/hierarchies.js b/src/apps/companies/middleware/hierarchies.js index 0de9e9e7e6d..564719f836e 100644 --- a/src/apps/companies/middleware/hierarchies.js +++ b/src/apps/companies/middleware/hierarchies.js @@ -6,45 +6,6 @@ function transformErrorMessage(error) { return get(error, 'global_headquarters', ['There has been an error'])[0] } -async function setGlobalHQ(req, res, next) { - const companyId = req.params.companyId - const globalHqId = req.params.globalHqId - const body = { global_headquarters: globalHqId } - const detailsUrl = `/companies/${companyId}/business-details` - - try { - await updateCompany(req, companyId, body) - - req.flash('success', 'You’ve linked the Global Headquarters') - return res.redirect(detailsUrl) - } catch (error) { - if (error.statusCode === 400) { - req.flash('error', transformErrorMessage(error.error)) - return res.redirect(detailsUrl) - } - next(error) - } -} - -async function removeGlobalHQ(req, res, next) { - const companyId = req.params.companyId - const body = { global_headquarters: null } - const detailsUrl = `/companies/${companyId}/business-details` - - try { - await updateCompany(req, companyId, body) - - req.flash('success', 'You’ve removed the link to Global Headquarters') - return res.redirect(detailsUrl) - } catch (error) { - if (error.statusCode === 400) { - req.flash('error', transformErrorMessage(error.error)) - return res.redirect(detailsUrl) - } - next(error) - } -} - async function addSubsidiary(req, res, next) { const { companyId, subsidiaryCompanyId } = req.params const body = { global_headquarters: companyId } @@ -64,7 +25,5 @@ async function addSubsidiary(req, res, next) { } module.exports = { - setGlobalHQ, - removeGlobalHQ, addSubsidiary, } diff --git a/src/apps/companies/router.js b/src/apps/companies/router.js index 65462afaf44..008218b0f59 100644 --- a/src/apps/companies/router.js +++ b/src/apps/companies/router.js @@ -12,8 +12,6 @@ const { const { renderDetails } = require('./controllers/details') -const { renderBusinessDetails } = require('./apps/business-details/controllers') - const { renderOrders } = require('./controllers/orders') const { archiveCompany, unarchiveCompany } = require('./controllers/archive') const { renderContacts } = require('./controllers/contacts') @@ -31,11 +29,7 @@ const { addCompanyOrRemoveFromList, } = require('./middleware/params') const { setInteractionsDetails } = require('./middleware/interactions') -const { - setGlobalHQ, - removeGlobalHQ, - addSubsidiary, -} = require('./middleware/hierarchies') +const { addSubsidiary } = require('./middleware/hierarchies') const lastInteractionDate = require('./middleware/last-interaction-date') const formatPostcodes = require('./middleware/format-postcodes') @@ -43,7 +37,6 @@ const addCompanyFormRouter = require('./apps/add-company/router') const editCompanyFormRouter = require('./apps/edit-company/router') const activityFeedRouter = require('./apps/activity-feed/router') const dnbHierarchyRouter = require('./apps/dnb-hierarchy/router') -const businessDetailsRouter = require('./apps/business-details/router') const editHistoryRouter = require('./apps/edit-history/router') const matchCompanyRouter = require('./apps/match-company/router') const exportsRouter = require('./apps/exports/router') @@ -88,11 +81,6 @@ router.use( router.get(urls.companies.detail.route, redirectToFirstNavItem) router.get(urls.companies.details.route, renderDetails) -router.get(urls.companies.businessDetails.route, renderBusinessDetails) - -router.get(urls.companies.hierarchies.ghq.add.route, setGlobalHQ) -router.get(urls.companies.hierarchies.ghq.remove.route, removeGlobalHQ) - router.get(urls.companies.hierarchies.subsidiaries.add.route, addSubsidiary) router.get(urls.companies.contacts.route, setReturnUrl, renderContacts) @@ -116,7 +104,6 @@ router.get(urls.companies.subsidiaries.index.route, renderSubsidiaries) router.use(activityFeedRouter) router.use(dnbHierarchyRouter) -router.use(businessDetailsRouter) router.use(matchCompanyRouter) router.use(exportsRouter) router.use(referralsRouter) diff --git a/src/client/index.jsx b/src/client/index.jsx index fdb56b06f76..59db06e91cb 100644 --- a/src/client/index.jsx +++ b/src/client/index.jsx @@ -21,7 +21,6 @@ import CannotFindMatch from '../apps/companies/apps/match-company/client/CannotF import EditCompanyList from '../apps/company-lists/client/EditCompanyList' import CreateListForm from '../apps/company-lists/client/CreateListForm' import ManageAdviser from '../apps/companies/apps/advisers/client/ManageAdviser' -import CompanyBusinessDetails from '../apps/companies/apps/business-details/client/CompanyBusinessDetails' import ExportsIndex from '../apps/companies/apps/exports/client/ExportsIndex' import ExportsHistory from '../apps/companies/apps/exports/client/ExportsHistory/' import ReferralDetails from '../apps/companies/apps/referrals/details/client/ReferralDetails' @@ -191,14 +190,6 @@ function App() { {(props) => } - - {(props) => ( - - )} - {(props) => ( From 3f477039a2355e9404eb23903d15aaa8cf58e840 Mon Sep 17 00:00:00 2001 From: Christopher Sunkel Date: Mon, 8 Jan 2024 10:12:16 +0000 Subject: [PATCH 4/5] Move business details code to modules --- src/apps/companies/constants.js | 2 -- src/apps/companies/labels.js | 21 -------------- .../Companies/CollectionList/labels.js | 21 -------------- .../CompanyBusinessDetails.jsx | 28 +++++++++---------- .../CompanyBusinessDetails}/SectionAbout.jsx | 8 +++--- .../SectionAddresses.jsx | 4 +-- .../SectionHierarchy.jsx | 8 +++--- .../SectionOneList.jsx | 4 +-- .../CompanyBusinessDetails}/SectionRegion.jsx | 4 +-- .../CompanyBusinessDetails}/SectionSector.jsx | 4 +-- .../WideSummaryTableRow.jsx | 0 .../CompanyBusinessDetails/labels.js | 19 +++++++++++++ .../CompanyBusinessDetails}/reducer.js | 2 +- .../CompanyBusinessDetails}/state.js | 0 .../CompanyBusinessDetails}/tasks.js | 10 ++----- .../Omis/WorkOrderTables/SubscribersTable.jsx | 2 +- src/client/reducers.js | 4 +-- src/client/routes.js | 2 +- src/client/tasks.js | 4 +-- 19 files changed, 59 insertions(+), 88 deletions(-) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/CompanyBusinessDetails.jsx (91%) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/SectionAbout.jsx (95%) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/SectionAddresses.jsx (94%) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/SectionHierarchy.jsx (96%) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/SectionOneList.jsx (94%) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/SectionRegion.jsx (86%) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/SectionSector.jsx (85%) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/WideSummaryTableRow.jsx (100%) create mode 100644 src/client/modules/Companies/CompanyBusinessDetails/labels.js rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/reducer.js (92%) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/state.js (100%) rename src/{apps/companies/apps/business-details/client => client/modules/Companies/CompanyBusinessDetails}/tasks.js (84%) diff --git a/src/apps/companies/constants.js b/src/apps/companies/constants.js index 0d555a249ea..ed1f0709a91 100644 --- a/src/apps/companies/constants.js +++ b/src/apps/companies/constants.js @@ -81,7 +81,6 @@ const QUERY_FIELDS = Object.values(QUERY_FIELDS_MAP) const NONE_TEXT = 'None' const NOT_SET_TEXT = 'Not set' const NOT_AVAILABLE_TEXT = 'Not available' -const COMPANY_DISSOLVED_OPTION = 'Company is dissolved' module.exports = { GLOBAL_NAV_ITEM, @@ -92,5 +91,4 @@ module.exports = { NONE_TEXT, NOT_SET_TEXT, NOT_AVAILABLE_TEXT, - COMPANY_DISSOLVED_OPTION, } diff --git a/src/apps/companies/labels.js b/src/apps/companies/labels.js index 7373ee32027..1ae0e12a5b9 100644 --- a/src/apps/companies/labels.js +++ b/src/apps/companies/labels.js @@ -103,25 +103,6 @@ const exportPotentialLabels = { }, } -const exportSegmentsLabels = { - hep: 'High export potential', - 'non-hep': 'Not high export potential', -} -const exportSubSegmentsLabels = { - sustain_nurture_and_grow: 'Sustain: nurture & grow', - sustain_develop_export_capability: 'Sustain: develop export capability', - sustain_communicate_benefits: 'Sustain: communicate benefits', - sustain_increase_competitiveness: 'Sustain: increase competitiveness', - reassure_nurture_and_grow: 'Reassure: nurture & grow', - reassure_develop_export_capability: 'Reassure: develop export capability', - reassure_leave_be: 'Reassure: leave be', - reassure_change_the_game: 'Reassure: change the game', - promote_develop_export_capability: 'Promote: develop export capability', - promote_communicate_benefits: 'Promote: communicate benefits', - promote_change_the_game: 'Promote: change the game', - challenge: 'Challenge', -} - module.exports = { companyDetailsLabels, companyTypeOptions, @@ -132,6 +113,4 @@ module.exports = { aboutLabels, businessHierarchyLabels, exportPotentialLabels, - exportSegmentsLabels, - exportSubSegmentsLabels, } diff --git a/src/client/modules/Companies/CollectionList/labels.js b/src/client/modules/Companies/CollectionList/labels.js index b35a359c9bf..fe6baf37bcd 100644 --- a/src/client/modules/Companies/CollectionList/labels.js +++ b/src/client/modules/Companies/CollectionList/labels.js @@ -112,25 +112,6 @@ const exportPotentialLabels = { }, } -const exportSegmentsLabels = { - hep: 'High export potential', - 'non-hep': 'Not high export potential', -} -const exportSubSegmentsLabels = { - sustain_nurture_and_grow: 'Sustain: nurture & grow', - sustain_develop_export_capability: 'Sustain: develop export capability', - sustain_communicate_benefits: 'Sustain: communicate benefits', - sustain_increase_competitiveness: 'Sustain: increase competitiveness', - reassure_nurture_and_grow: 'Reassure: nurture & grow', - reassure_develop_export_capability: 'Reassure: develop export capability', - reassure_leave_be: 'Reassure: leave be', - reassure_change_the_game: 'Reassure: change the game', - promote_develop_export_capability: 'Promote: develop export capability', - promote_communicate_benefits: 'Promote: communicate benefits', - promote_change_the_game: 'Promote: change the game', - challenge: 'Challenge', -} - export default { companyDetailsLabels, companyTypeOptions, @@ -142,6 +123,4 @@ export default { aboutLabels, businessHierarchyLabels, exportPotentialLabels, - exportSegmentsLabels, - exportSubSegmentsLabels, } diff --git a/src/apps/companies/apps/business-details/client/CompanyBusinessDetails.jsx b/src/client/modules/Companies/CompanyBusinessDetails/CompanyBusinessDetails.jsx similarity index 91% rename from src/apps/companies/apps/business-details/client/CompanyBusinessDetails.jsx rename to src/client/modules/Companies/CompanyBusinessDetails/CompanyBusinessDetails.jsx index db160a18371..a0db6f9027a 100644 --- a/src/apps/companies/apps/business-details/client/CompanyBusinessDetails.jsx +++ b/src/client/modules/Companies/CompanyBusinessDetails/CompanyBusinessDetails.jsx @@ -14,18 +14,19 @@ import SectionHierarchy from './SectionHierarchy' import SectionRegion from './SectionRegion' import SectionSector from './SectionSector' import SectionOneList from './SectionOneList' -import ArchiveForm from '../../../../../client/components/ArchiveForm' -import { StatusMessage } from '../../../../../client/components/' -import { COMPANY_DISSOLVED_OPTION } from '../../../constants' +import ArchiveForm from '../../../components/ArchiveForm' +import { StatusMessage } from '../../../components' import { CompanyResource, RelatedCompaniesCountResource, -} from '../../../../../client/components/Resource' -import CompanyLayoutNew from '../../../../../client/components/Layout/CompanyLayoutNew' -import urls from '../../../../../lib/urls' +} from '../../../components/Resource' +import CompanyLayoutNew from '../../../components/Layout/CompanyLayoutNew' +import Task from '../../../components/Task' +import urls from '../../../../lib/urls' +import { format } from '../../../utils/date' import { - ID as CHECK_PENDING_REQUEST_ID, + ID, TASK_ARCHIVE_COMPANY, TASK_GET_GLOBAL_ULTIMATE, state2props, @@ -33,10 +34,7 @@ import { import { COMPANIES__GLOBAL_ULTIMATE_LOADED, DNB__CHECK_PENDING_REQUEST, -} from '../../../../../client/actions' -import Task from '../../../../../client/components/Task' - -const { format } = require('../../../../../client/utils/date') +} from '../../../actions' const StyledRoot = styled('div')` & > table { @@ -59,6 +57,8 @@ const canEditOneList = (permissions) => 'company.change_one_list_tier_and_global_account_manager' ) +const COMPANY_DISSOLVED_OPTION = 'Company is dissolved' + const CompanyBusinessDetails = ({ globalUltimate, isDnbPending, @@ -94,7 +94,7 @@ const CompanyBusinessDetails = ({ )} - + {globalUltimate.name} diff --git a/src/apps/companies/apps/business-details/client/SectionOneList.jsx b/src/client/modules/Companies/CompanyBusinessDetails/SectionOneList.jsx similarity index 94% rename from src/apps/companies/apps/business-details/client/SectionOneList.jsx rename to src/client/modules/Companies/CompanyBusinessDetails/SectionOneList.jsx index ed4291e01a0..9a10ad8b1bf 100644 --- a/src/apps/companies/apps/business-details/client/SectionOneList.jsx +++ b/src/client/modules/Companies/CompanyBusinessDetails/SectionOneList.jsx @@ -4,8 +4,8 @@ import Link from '@govuk-react/link' import styled from 'styled-components' import { SPACING_POINTS } from '@govuk-react/constants' -import { SummaryTable } from '../../../../../client/components/' -import urls from '../../../../../lib/urls' +import { SummaryTable } from '../../../components' +import urls from '../../../../lib/urls' const StyledSummaryFooterLink = styled(Link)` margin-top: -${SPACING_POINTS[7]}px; diff --git a/src/apps/companies/apps/business-details/client/SectionRegion.jsx b/src/client/modules/Companies/CompanyBusinessDetails/SectionRegion.jsx similarity index 86% rename from src/apps/companies/apps/business-details/client/SectionRegion.jsx rename to src/client/modules/Companies/CompanyBusinessDetails/SectionRegion.jsx index 8fd9b0f6eab..26303505704 100644 --- a/src/apps/companies/apps/business-details/client/SectionRegion.jsx +++ b/src/client/modules/Companies/CompanyBusinessDetails/SectionRegion.jsx @@ -2,8 +2,8 @@ import React from 'react' import PropTypes from 'prop-types' import Link from '@govuk-react/link' -import { SummaryTable } from '../../../../../client/components/' -import urls from '../../../../../lib/urls' +import { SummaryTable } from '../../../components' +import urls from '../../../../lib/urls' const SectionRegion = ({ company, isArchived }) => !!company.ukBased ? ( diff --git a/src/apps/companies/apps/business-details/client/SectionSector.jsx b/src/client/modules/Companies/CompanyBusinessDetails/SectionSector.jsx similarity index 85% rename from src/apps/companies/apps/business-details/client/SectionSector.jsx rename to src/client/modules/Companies/CompanyBusinessDetails/SectionSector.jsx index bbcd054570e..4f7d3b68745 100644 --- a/src/apps/companies/apps/business-details/client/SectionSector.jsx +++ b/src/client/modules/Companies/CompanyBusinessDetails/SectionSector.jsx @@ -2,8 +2,8 @@ import React from 'react' import PropTypes from 'prop-types' import Link from '@govuk-react/link' -import { SummaryTable } from '../../../../../client/components/' -import urls from '../../../../../lib/urls' +import { SummaryTable } from '../../../components' +import urls from '../../../../lib/urls' const SectionSector = ({ company, isArchived }) => ( subscribers.map(({ name, ditTeam }) => ( diff --git a/src/client/reducers.js b/src/client/reducers.js index 0e06712df9d..257f68bdc4f 100644 --- a/src/client/reducers.js +++ b/src/client/reducers.js @@ -35,8 +35,8 @@ import investmentOpportunitiesListReducer from './modules/Investments/Opportunit import { ID as INVESTMENT_OPPORTUNITIES_DETAILS_ID } from './modules/Investments/Opportunities/state' import investmentOpportunitiesDetailsReducer from './modules/Investments/Opportunities/reducer' -import { ID as DNB_CHECK_ID } from '../apps/companies/apps/business-details/client/state' -import dnbCheckReducer from '../apps/companies/apps/business-details/client/reducer' +import { ID as DNB_CHECK_ID } from './modules/Companies/CompanyBusinessDetails/state.js' +import dnbCheckReducer from './modules/Companies/CompanyBusinessDetails/reducer.js' import { ID as INVESTMENT_PROFILES_ID } from './modules/Investments/Profiles/state' import investmentProfileReducer from './modules/Investments/Profiles/reducer' diff --git a/src/client/routes.js b/src/client/routes.js index 88257ef029b..1fb65ccc975 100644 --- a/src/client/routes.js +++ b/src/client/routes.js @@ -82,7 +82,7 @@ import CreateOrder from './modules/Omis/CreateOrder/CreateOrder' import PaymentReceipt from './modules/Omis/PaymentReceipt' import { TaskFormAdd, TaskFormEdit } from './modules/Tasks/TaskForm' import CompanyOverview from './modules/Companies/CompanyOverview/CompanyOverview' -import CompanyBusinessDetails from '../apps/companies/apps/business-details/client/CompanyBusinessDetails' +import CompanyBusinessDetails from './modules/Companies/CompanyBusinessDetails/CompanyBusinessDetails' import SetGlobalHQ from './modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/SetGlobalHQ' import RemoveGlobalHQ from './modules/Companies/CompanyBusinessDetails/LinkGlobalHQ/RemoveGlobalHQ' diff --git a/src/client/tasks.js b/src/client/tasks.js index 7a1dbe6324a..b958f5c5b7c 100644 --- a/src/client/tasks.js +++ b/src/client/tasks.js @@ -26,8 +26,8 @@ import { DNB__CHECK_PENDING_REQUEST, TASK_ARCHIVE_COMPANY, TASK_GET_GLOBAL_ULTIMATE, -} from '../apps/companies/apps/business-details/client/state' -import * as businessDetails from '../apps/companies/apps/business-details/client/tasks' +} from './modules/Companies/CompanyBusinessDetails/state.js' +import * as businessDetails from './modules/Companies/CompanyBusinessDetails/tasks.js' import { TASK_GET_COMPANIES_LIST, From d9b63c9c63324aabce6acae1ce625e46fc75122e Mon Sep 17 00:00:00 2001 From: Christopher Sunkel Date: Tue, 16 Jan 2024 15:51:50 +0000 Subject: [PATCH 5/5] Create stripped down layout so layout can appear as root --- .../CompanyLocalHeaderNew.jsx | 253 -------------- .../components/Layout/CompanyLayoutNew.jsx | 43 ++- .../components/Layout/DefaultLayoutBase.jsx | 51 +++ .../CompanyBusinessDetails.jsx | 315 +++++++++--------- .../CompanyOverview/CompanyOverview.jsx | 100 +++--- 5 files changed, 284 insertions(+), 478 deletions(-) delete mode 100644 src/client/components/CompanyLocalHeader/CompanyLocalHeaderNew.jsx create mode 100644 src/client/components/Layout/DefaultLayoutBase.jsx diff --git a/src/client/components/CompanyLocalHeader/CompanyLocalHeaderNew.jsx b/src/client/components/CompanyLocalHeader/CompanyLocalHeaderNew.jsx deleted file mode 100644 index 2103926cfdb..00000000000 --- a/src/client/components/CompanyLocalHeader/CompanyLocalHeaderNew.jsx +++ /dev/null @@ -1,253 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' -import styled from 'styled-components' -import Main from '@govuk-react/main' -import GridCol from '@govuk-react/grid-col' -import GridRow from '@govuk-react/grid-row' -import Button from '@govuk-react/button' -import Details from '@govuk-react/details' -import { SPACING, FONT_SIZE, BREAKPOINTS } from '@govuk-react/constants' -import { Link } from 'govuk-react' -import { H4 } from '@govuk-react/heading' - -import { GREY_3, TEXT_COLOUR } from '../../utils/colours' -import LocalHeaderCompanyLists from './LocalHeaderCompanyLists' -import LocalHeaderCompanyRefer from './LocalHeaderCompanyRefer' -import Badge from '../Badge' -import StatusMessage from '../StatusMessage' -import { addressToStringResource } from '../../utils/addresses' -import urls from '../../../lib/urls' -import ArchivePanel from '../ArchivePanel' -import { isItaTierDAccount } from '../../modules/Companies/utils' -import { RelatedCompaniesCountResource } from '../Resource' - -const LocalHeaderTradingNames = styled(H4)` - font-weight: normal; -` - -const StyledAddress = styled('p')` - margin-top: ${SPACING.SCALE_2}; - margin-bottom: ${SPACING.SCALE_2}; -` - -const BadgeText = styled('span')` - font-weight: 600; - font-size: ${FONT_SIZE.SIZE_16}; -` - -const TypeWrapper = styled('div')` - @media (min-width: ${BREAKPOINTS.TABLET}) { - display: table-row; - } -` -const StyledButtonContainer = styled('div')` - width: 100%; - display: inline-block; -` - -const StyledList = styled('div')` - padding-bottom: 10px; - display: inline-flex; -` - -const StyledButtonLink = styled.a({ - marginBottom: 10, - float: 'right', -}) - -const BadgeWrapper = styled('div')` - @media (min-width: ${BREAKPOINTS.TABLET}) { - display: table-cell; - } -` - -const StyledDetails = styled(Details)` - @media (min-width: ${BREAKPOINTS.TABLET}) { - margin: 0 0 0 ${SPACING.SCALE_3}; - } - span, - div { - font-size: ${FONT_SIZE.SIZE_16}; - } -` - -const StyledDescription = styled('div')` - padding: ${SPACING.SCALE_2}; - background-color: ${GREY_3}; - - * + & { - margin-top: ${SPACING.SCALE_3}; - } - - p { - margin-top: 0; - margin-bottom: 0; - - &:not(:last-child) { - margin-bottom: ${SPACING.SCALE_2}; - } - } - - & + * { - margin-top: ${SPACING.SCALE_3}; - } -` - -const StyledMain = styled(Main)` - padding-top: ${SPACING.SCALE_1}; - div { - font-size: ${FONT_SIZE.SIZE_20}; - } -` -const StyledRelatedCompaniesWrapper = styled('div')` - padding-bottom: 20px; -` - -const isUltimate = (company) => !!company.isGlobalUltimate -const isGlobalHQ = (company) => - company.headquarterType && company.headquarterType.name === 'ghq' - -const hasAllocatedLeadIta = (company) => - company.oneListGroupGlobalAccountManager != null - -const hasManagedAccountDetails = (company) => - company.oneListGroupTier && hasAllocatedLeadIta(company) - -const CompanyLocalHeaderNew = ({ company, returnUrl, csrfToken }) => - company && ( - <> - - - {company?.tradingNames?.length > 0 && ( - - Trading as: {company.tradingNames.join(', ')} - - )} - - - {addressToStringResource(company.address)} - - {company.dunsNumber && ( - - {({ relatedCompaniesCount }) => - relatedCompaniesCount > 0 && ( - - - {`View company tree: ${ - relatedCompaniesCount + 1 - } companies`} - - - ) - } - - )} - - - - - - - - - - - - - {(isUltimate(company) || isGlobalHQ(company)) && ( - - - - - {isUltimate(company) ? 'Ultimate HQ' : 'Global HQ'} - - - - {isUltimate(company) && ( - - This HQ is in control of all related company records for{' '} - {company.name}. - - )} - - )} - {hasManagedAccountDetails(company) && ( - - {hasManagedAccountDetails(company) && ( - <> -

- This is an account managed company (One List{' '} - {company.oneListGroupTier.name}) -

-

- {isItaTierDAccount(company.oneListGroupTier) - ? 'Lead ITA' - : 'Global Account Manager'} - : {company.oneListGroupGlobalAccountManager.name}{' '} - - {isItaTierDAccount(company.oneListGroupTier) - ? 'View Lead adviser' - : 'View core team'} - -

- - )} -
- )} - - {company.archived && ( - - )} - - {company.pendingDnbInvestigation && ( - - - This company record is based on information that has not yet been - validated. This information is currently being checked by the Data - Hub support team. - - - )} - - ) - -CompanyLocalHeaderNew.propTypes = { - company: PropTypes.object.isRequired, - returnUrl: PropTypes.string, -} - -CompanyLocalHeaderNew.defaultProps = { - returnUrl: null, -} - -export default CompanyLocalHeaderNew diff --git a/src/client/components/Layout/CompanyLayoutNew.jsx b/src/client/components/Layout/CompanyLayoutNew.jsx index b42ecf84b95..5cea77cd3ea 100644 --- a/src/client/components/Layout/CompanyLayoutNew.jsx +++ b/src/client/components/Layout/CompanyLayoutNew.jsx @@ -3,39 +3,36 @@ import PropTypes from 'prop-types' import GridCol from '@govuk-react/grid-col' import GridRow from '@govuk-react/grid-row' -import { CompanyTabbedLocalNavigation, DefaultLayout } from '..' +import { CompanyTabbedLocalNavigation, Main } from '..' import CompanyInvestmentSubNavigation from '../CompanyTabbedLocalNavigation/CompanyInvestmentTab' -import { buildCompanyBreadcrumbs } from '../../modules/Companies/utils' -import CompanyLocalHeaderNew from '../CompanyLocalHeader/CompanyLocalHeaderNew' +import CompanyLocalHeader from '../CompanyLocalHeader' const CompanyLayoutNew = ({ company, breadcrumbs, children, returnUrl, - pageTitle, + flashMessages, isInvestment = false, isLCP = false, }) => ( - - ) - } - > - - {isInvestment && ( - - )} - - {children} - - + <> + +
+ + {isInvestment && ( + + )} + + {children} + +
+ ) CompanyLayoutNew.propTypes = { diff --git a/src/client/components/Layout/DefaultLayoutBase.jsx b/src/client/components/Layout/DefaultLayoutBase.jsx new file mode 100644 index 00000000000..040a214015c --- /dev/null +++ b/src/client/components/Layout/DefaultLayoutBase.jsx @@ -0,0 +1,51 @@ +import React, { useEffect, useState } from 'react' +import { createGlobalStyle } from 'styled-components' +import PropTypes from 'prop-types' +import GridCol from '@govuk-react/grid-col' +import GridRow from '@govuk-react/grid-row' + +import Footer from '../Footer' +import DataHubHeader from '../DataHubHeader' + +const GlobalStyles = createGlobalStyle` + *, *:before, *:after { + box-sizing: initial; + } +` + +/** + * This is a reduced version of DefaultLayout, similar to the _layout + * template used by the old Nunjucks pages. + */ +const DefaultLayoutBase = ({ pageTitle, children }) => { + const [showVerticalNav, setShowVerticalNav] = useState(false) + useEffect(() => { + document.title = `${pageTitle} - DBT Data Hub` + }, [pageTitle]) + return ( + <> + + + + {children} + +