Skip to content

Commit

Permalink
Add delete option to proposition document
Browse files Browse the repository at this point in the history
Add delete call for proposition documents
  • Loading branch information
bau123 committed Jan 30, 2024
1 parent aa645bd commit 1c8a435
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/apps/routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<InvestmentResource id={projectId}>
{(project) => (
<DefaultLayout
heading={'Deleting proposition document'}
pageTitle={`Delete proposition document - ${project.name} - Projects - Investments`}
breadcrumbs={buildProjectBreadcrumbs([
{
link: urls.investments.projects.details(project.id),
text: project.name,
},
{
link: urls.investments.projects.proposition.details(project.id),
text: 'Proposition',
},
{
text: 'Delete proposition document',
},
])}
useReactRouter={false}
>
<Task.Status
name={TASK_DELETE_PROPOSITION_DOCUMENT}
id={DELETE_PROPOSITION_DOCUMENT_ID}
progressMessage={'Deleting proposition document'}
startOnRender={{
payload: { projectId, propositionId, documentId },
}}
>
{() =>
window.location.assign(
urls.investments.projects.proposition.details(
projectId,
propositionId
)
)
}
</Task.Status>
</DefaultLayout>
)}
</InvestmentResource>
)
}

export default DeletePropositionDocument
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const PropositionDetails = ({
{checkStatus(proposition.status) && (
<>
<Link
href={urls.investments.projects.proposition.document(
href={urls.investments.projects.proposition.document.index(
investmentProjectId,
propositionId
)}
Expand Down
5 changes: 5 additions & 0 deletions src/client/modules/Investments/Projects/Propositions/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ export const TASK_CREATE_INVESTMENT_PROPOSITION =
'TASK_CREATE_INVESTMENT_PROPOSITION'
export const TASK_ABANDON_INVESTMENT_PROPOSITION =
'TASK_ABANDON_INVESTMENT_PROPOSITION'

export const DELETE_PROPOSITION_DOCUMENT_ID =
'deleteInvestmentPropositionDocument'
export const TASK_DELETE_PROPOSITION_DOCUMENT =
'TASK_DELETE_PROPOSITION_DOCUMENT'
8 changes: 8 additions & 0 deletions src/client/modules/Investments/Projects/Propositions/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ export const abandonInvestmentProposition = (values) =>
`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)
}
Original file line number Diff line number Diff line change
@@ -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}`

Expand Down Expand Up @@ -45,25 +48,43 @@ export const transformAbandonedPropositionForAPI = ({
}
}

const StyledSpan = styled('span')`
padding-left: 10px;
`
const buildDocumentLink = (
avClean,
documentId,
propositionId,
projectId,
originalFilename
) =>
avClean ? (
<Link
href={`/investments/projects/${projectId}/propositions/${propositionId}/download/${documentId}`}
aria-label={`Download the document ${originalFilename}`}
>
Download
</Link>
) : (
<strong>
The file didn't pass virus scanning, contact your administrator
</strong>
)
) => (
<>
{avClean ? (
<Link
href={`/investments/projects/${projectId}/propositions/${propositionId}/download/${documentId}`}
aria-label={`Download the document ${originalFilename}`}
>
Download
</Link>
) : (
<strong>
The file didn't pass virus scanning, contact your administrator
</strong>
)}
<StyledSpan>
<Link
href={urls.investments.projects.proposition.document.delete(
projectId,
propositionId,
documentId
)}
data-test="delete-link"
>
Delete
</Link>
</StyledSpan>
</>
)

export const transformDocumentStatus = (
originalFilename,
Expand Down
6 changes: 6 additions & 0 deletions src/client/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -639,6 +640,11 @@ const routes = {
module: 'datahub:investments',
component: CreateProposition,
},
{
path: '/investments/projects/:projectId/propositions/:propositionId/document/:documentId/delete',
module: 'datahub:investments',
component: DeletePropositionDocument,
},
],
tasks: [
{
Expand Down
3 changes: 3 additions & 0 deletions src/client/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,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'
Expand Down Expand Up @@ -635,6 +637,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,
Expand Down
14 changes: 10 additions & 4 deletions src/lib/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,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'
Expand Down

0 comments on commit 1c8a435

Please sign in to comment.