| 1 | import type { Metadata } from 'next' |
| 2 | import { headers } |
| 3 | import { redirect } |
| 4 | import { resolveProjectContext } |
| 5 | import { projectsService } |
| 6 | import { requirementsService } |
| 7 | import { signaturesService } |
| 8 | import { teamService } |
| 9 | import { createMetadata } |
| 10 | import type { Role |
| 11 | import RequirementEditor from '../_components/requirement-editor |
| 12 | |
| 13 | export const metadata: |
| 14 | title: 'Requirement', |
| 15 | description: 'Review and edit a project requirement.', |
| 16 | openGraph: { |
| 17 | images: ['/api/og?page=Requirements'], |
| 18 | }, |
| 19 | twitter: { |
| 20 | images: ['/api/og?page=Requirements'], |
| 21 | }, |
| 22 | }) |
| 23 | |
| 24 | export default async function |
| 25 | params, |
| 26 | }: PageProps< |
| 27 | const { org, |
| 28 | const { |
| 29 | project: currentProject, |
| 30 | orgMember, |
| 31 | role, |
| 32 | organization, |
| 33 | } = await resolveProjectContext |
| 34 | |
| 35 | if (!role.authorize |
| 36 | redirect( |
| 37 | `/error/403?message=${encodeURIComponent('You do not have permission to view requirements |
| 38 | ) |
| 39 | } |
| 40 | |
| 41 | const requirement = |
| 42 | currentProject.id, |
| 43 | slug, |
| 44 | await headers() |
| 45 | ) |
| 46 | |
| 47 | if (!requirement) |
| 48 | redirect( |
| 49 | `/error/404?message=${encodeURIComponent('Requirement not found |
| 50 | ) |
| 51 | } |
| 52 | |
| 53 | const canEdit = |
| 54 | role.authorize({ |
| 55 | requirement.status !== |
| 56 | const canSendForSign = |
| 57 | requirement: ['send_for_sign'], |
| 58 | }).success |
| 59 | |
| 60 | const [ |
| 61 | threads, |
| 62 | projectClients, |
| 63 | recipients, |
| 64 | signatures, |
| 65 | changeRequests, |
| 66 | signatureMedia, |
| 67 | settings, |
| 68 | ] = await Promise |
| 69 | requirementsService.getThreads(currentProject |
| 70 | canSendForSign ? teamService. |
| 71 | requirementsService.getRecipients(requirement |
| 72 | requirementsService.getSignatures(requirement |
| 73 | requirementsService.getChangeRequests(requirement |
| 74 | signaturesService.getSignatureMediaForMember(orgMember |
| 75 | projectsService.getSettings(organization |
| 76 | ]) |
| 77 | |
| 78 | const isRecipient = |
| 79 | const hasSigned = |
| 80 | |
| 81 | return ( |
| 82 | <RequirementEditor |
| 83 | canEdit={canEdit} |
| 84 | canSendForSign={canSendForSign} |
| 85 | canSign={isRecipient} |
| 86 | changeRequests={changeRequests} |
| 87 | hasSignedAlready={hasSigned} |
| 88 | isClientInvolved={settings.clientInvolvement |
| 89 | mode='edit' |
| 90 | orgSlug={org} |
| 91 | projectClients={projectClients} |
| 92 | projectId={currentProject.id |
| 93 | projectName={currentProject.name |
| 94 | projectSlug={projectSlug} |
| 95 | requirement={requirement} |
| 96 | role={orgMember.role |
| 97 | signatureMedia={signatureMedia} |
| 98 | signatures={signatures} |
| 99 | threads={threads} |
| 100 | /> |
| 101 | ) |
| 102 | } |