From a6a4f34782f33d21bbd0554fc8e4d6f5b20e46c3 Mon Sep 17 00:00:00 2001 From: Bau Nguyen Date: Mon, 29 Jan 2024 15:06:56 +0000 Subject: [PATCH] Add delete option to proposition document Add delete call for proposition documents --- src/apps/routers.js | 1 + .../DeletePropositionDocument.jsx | 60 +++++++++++++++++++ .../Propositions/PropositionDetails.jsx | 2 +- .../Projects/Propositions/state.js | 5 ++ .../Projects/Propositions/tasks.js | 8 +++ .../Projects/Propositions/transformers.js | 47 +++++++++++---- src/client/routes.js | 6 ++ src/client/tasks.js | 3 + src/lib/urls.js | 14 +++-- 9 files changed, 128 insertions(+), 18 deletions(-) create mode 100644 src/client/modules/Investments/Projects/Propositions/DeletePropositionDocument.jsx diff --git a/src/apps/routers.js b/src/apps/routers.js index a4ebe81faa2..f4bf2a422a7 100644 --- a/src/apps/routers.js +++ b/src/apps/routers.js @@ -96,6 +96,7 @@ const reactRoutes = [ '/companies/:companyId/referrals/:referralId/help', '/investments/projects/:projectId/propositions/:propositionId/abandon', '/investments/projects/:projectId/propositions/create/proposition', + '/investments/projects/:projectId/propositions/:propositionId/document/:documentId/delete', '/events/:eventId/attendees/find-new', '/interactions/ess/:essInteractionId/details', '/investments/opportunities/create', diff --git a/src/client/modules/Investments/Projects/Propositions/DeletePropositionDocument.jsx b/src/client/modules/Investments/Projects/Propositions/DeletePropositionDocument.jsx new file mode 100644 index 00000000000..ceb70d98887 --- /dev/null +++ b/src/client/modules/Investments/Projects/Propositions/DeletePropositionDocument.jsx @@ -0,0 +1,60 @@ +import React from 'react' +import { useParams } from 'react-router-dom' + +import { DefaultLayout } from '../../../../components' +import Task from '../../../../components/Task' +import { + DELETE_PROPOSITION_DOCUMENT_ID, + TASK_DELETE_PROPOSITION_DOCUMENT, +} from './state' +import urls from '../../../../../lib/urls' +import { InvestmentResource } from '../../../../components/Resource' +import { buildProjectBreadcrumbs } from '../../utils' + +const DeletePropositionDocument = () => { + const { projectId, propositionId, documentId } = useParams() + return ( + + {(project) => ( + + + {() => + window.location.assign( + urls.investments.projects.proposition.details( + projectId, + propositionId + ) + ) + } + + + )} + + ) +} + +export default DeletePropositionDocument diff --git a/src/client/modules/Investments/Projects/Propositions/PropositionDetails.jsx b/src/client/modules/Investments/Projects/Propositions/PropositionDetails.jsx index faea0d3197c..ea8d2720bae 100644 --- a/src/client/modules/Investments/Projects/Propositions/PropositionDetails.jsx +++ b/src/client/modules/Investments/Projects/Propositions/PropositionDetails.jsx @@ -125,7 +125,7 @@ const PropositionDetails = ({ {checkStatus(proposition.status) && ( <> `v3/investment/${values.projectId}/proposition/${values.propositionId}/abandon`, values ) + +export const deletePropositionDocument = (values) => { + const options = { + url: `v3/investment/${values.projectId}/proposition/${values.propositionId}/document/${values.documentId}`, + method: 'DELETE', + } + return apiProxyAxios(options) +} diff --git a/src/client/modules/Investments/Projects/Propositions/transformers.js b/src/client/modules/Investments/Projects/Propositions/transformers.js index 512fd0ac388..cd8cb47d76c 100644 --- a/src/client/modules/Investments/Projects/Propositions/transformers.js +++ b/src/client/modules/Investments/Projects/Propositions/transformers.js @@ -1,9 +1,12 @@ import React from 'react' import { Link } from 'govuk-react' +import styled from 'styled-components' import { transformValueForAPI } from '../../../../utils/date' import { VIRUS_SCAN_STATUSES } from '../constants' +import urls from '../../../../../lib/urls' + export const buildPropositionUrl = (propositionId, projectId) => `v3/investment/${projectId}/proposition/${propositionId}` @@ -45,25 +48,43 @@ export const transformAbandonedPropositionForAPI = ({ } } +const StyledSpan = styled('span')` + padding-left: 10px; +` const buildDocumentLink = ( avClean, documentId, propositionId, projectId, originalFilename -) => - avClean ? ( - - Download - - ) : ( - - The file didn't pass virus scanning, contact your administrator - - ) +) => ( + <> + {avClean ? ( + + Download + + ) : ( + + The file didn't pass virus scanning, contact your administrator + + )} + + + Delete + + + +) export const transformDocumentStatus = ( originalFilename, diff --git a/src/client/routes.js b/src/client/routes.js index dfa9a5a0adf..4824949fcd2 100644 --- a/src/client/routes.js +++ b/src/client/routes.js @@ -73,6 +73,7 @@ import ExportsEdit from './modules/Companies/CompanyExports/ExportsEdit' import ReferralHelp from './modules/Companies/Referrals/Help/ReferralHelp' import AbandonProposition from './modules/Investments/Projects/Propositions/AbandonProposition' import CreateProposition from './modules/Investments/Projects/Propositions/CreateProposition' +import DeletePropositionDocument from './modules/Investments/Projects/Propositions/DeletePropositionDocument' import AttendeeSearch from './modules/Events/AttendeeSearch/AttendeeSearch' import CreateUKInvestmentOpportunity from './modules/Investments/Opportunities/CreateUKInvestmentOpportunity' import OpportunityChangeStatusForm from './modules/Investments/Opportunities/OpportunityChangeStatusForm' @@ -557,6 +558,11 @@ const routes = { module: 'datahub:investments', component: CreateProposition, }, + { + path: '/investments/projects/:projectId/propositions/:propositionId/document/:documentId/delete', + module: 'datahub:investments', + component: DeletePropositionDocument, + }, ], tasks: [ { diff --git a/src/client/tasks.js b/src/client/tasks.js index 18cd25b1976..11e3b6e4a28 100644 --- a/src/client/tasks.js +++ b/src/client/tasks.js @@ -300,10 +300,12 @@ import { TASK_GET_LISTS_COMPANY_IS_IN } from './components/CompanyLocalHeader/st import { TASK_CREATE_INVESTMENT_PROPOSITION, TASK_ABANDON_INVESTMENT_PROPOSITION, + TASK_DELETE_PROPOSITION_DOCUMENT, } from './modules/Investments/Projects/Propositions/state' import { createInvestmentProposition, abandonInvestmentProposition, + deletePropositionDocument, } from './modules/Investments/Projects/Propositions/tasks' import { TASK_GET_DNB_FAMILY_TREE } from './modules/Companies/CompanyHierarchy/state' @@ -626,6 +628,7 @@ export const tasks = { [TASK_GET_ONE_LIST_DETAILS]: getOneListDetails, [TASK_ARCHIVE_OBJECTIVE]: archiveObjective, [TASK_DELETE_PROJECT_DOCUMENT]: deleteProjectDocument, + [TASK_DELETE_PROPOSITION_DOCUMENT]: deletePropositionDocument, [TASK_EDIT_OMIS_QUOTE_INFORMATION]: updateOrder, [TASK_EDIT_OMIS_INTERNAL_INFORMATION]: updateOrder, [TASK_GET_TASK_DETAILS]: getTaskDetail, diff --git a/src/lib/urls.js b/src/lib/urls.js index 3bc37caec8a..02b13ce3e31 100644 --- a/src/lib/urls.js +++ b/src/lib/urls.js @@ -393,10 +393,16 @@ module.exports = { '/investments', '/projects/:investmentId/propositions/:propositionId/abandon' ), - document: url( - '/investments', - '/projects/:investmentId/propositions/:propositionId/document' - ), + document: { + index: url( + '/investments', + '/projects/:investmentId/propositions/:propositionId/document' + ), + delete: url( + '/investments', + '/projects/:investmentId/propositions/:propositionId/document/:documentId/delete' + ), + }, complete: url( '/investments', '/projects/:investmentId/propositions/:propositionId/complete'