Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(3501): add eMOU PDF download link #3559

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ import { theme } from './mantine-theme';
const bcsans = localFont({
src: [
{
path: '../fonts/bcsans-regular.woff',
path: '../public/fonts/bcsans-regular.woff',
weight: '400',
style: 'normal',
},
{
path: '../fonts/bcsans-regular.woff',
path: '../public/fonts/bcsans-italic.woff',
weight: '400',
style: 'italic',
},
{
path: '../fonts/bcsans-bold.woff',
path: '../public/fonts/bcsans-bold.woff',
weight: '700',
style: 'normal',
},
{
path: '../fonts/bcsans-bold.woff',
path: '../public/fonts/bcsans-bold-italic.woff',
weight: '700',
style: 'italic',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useEffect, useState } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { useSnapshot } from 'valtio';
import { z } from 'zod';
import PublicCloudBillingInfo from '@/components/billing/PublicCloudBillingInfo';
import PreviousButton from '@/components/buttons/Previous';
import SubmitButton from '@/components/buttons/SubmitButton';
import AccountCoding from '@/components/form/AccountCoding';
Expand Down Expand Up @@ -117,13 +118,18 @@ export default publicCloudProductEdit(({ pathParams, queryParams, session }) =>

return (
<div>
<PublicCloudBillingInfo product={snap.currentProduct} className="mb-2" />
<FormProvider {...methods}>
<FormErrorNotification />
<form autoComplete="off" onSubmit={methods.handleSubmit(() => setOpenComment(true))}>
<div className="space-y-12">
<ProjectDescriptionPublic mode="edit" />
<ProjectDescriptionPublic mode="edit" disabled={isDisabled} />
<hr className="my-7" />
<AccountEnvironmentsPublic selected={snap.currentProduct.environmentsEnabled} mode="edit" />
<AccountEnvironmentsPublic
selected={snap.currentProduct.environmentsEnabled}
mode="edit"
disabled={isDisabled}
/>
<hr className="my-7" />
<TeamContacts
disabled={isDisabled}
Expand All @@ -134,7 +140,7 @@ export default publicCloudProductEdit(({ pathParams, queryParams, session }) =>
<hr className="my-7" />
<ExpenseAuthority disabled={isDisabled} />
<hr className="my-7" />
<Budget disabled={false} />
<Budget disabled={isDisabled} />
<hr className="my-7" />
<AccountCoding accountCodingInitial={snap.currentProduct?.billing.accountCoding} disabled />
</div>
Expand Down
75 changes: 2 additions & 73 deletions app/app/public-cloud/requests/(request)/[id]/request/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { Alert } from '@mantine/core';
import { notifications } from '@mantine/notifications';
import { Prisma, $Enums } from '@prisma/client';
import { IconInfoCircle, IconInfoSquareRounded, IconSquareCheck, IconSquare } from '@tabler/icons-react';
import { useQuery, useMutation } from '@tanstack/react-query';
import classNames from 'classnames';
import { useEffect, useState } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { z } from 'zod';
import PublicCloudBillingInfo from '@/components/billing/PublicCloudBillingInfo';
import PreviousButton from '@/components/buttons/Previous';
import SubmitButton from '@/components/buttons/SubmitButton';
import AccountCoding from '@/components/form/AccountCoding';
Expand All @@ -24,75 +23,9 @@ import ReturnModal from '@/components/modal/ReturnDecision';
import { openReviewPublicCloudProductModal } from '@/components/modal/reviewPublicCloudProductModal';
import { openSignPublicCloudProductModal } from '@/components/modal/signPublicCloudProductModal';
import createClientPage from '@/core/client-page';
import { formatFullName } from '@/helpers/user';
import { PublicCloudRequestDecisionBodySchema } from '@/schema';
import { makePublicCloudRequestDecision } from '@/services/backend/public-cloud/requests';
import { usePublicProductState } from '@/states/global';
import { formatDate } from '@/utils/date';

function BillingInfo({
billing,
licencePlate,
className,
}: {
billing: Prisma.BillingGetPayload<{
include: {
signedBy: true;
approvedBy: true;
expenseAuthority: true;
};
}>;
licencePlate: string;
className?: string;
}) {
return (
<Alert
variant="light"
color="blue"
title="Billing eMOU status"
icon={<IconInfoCircle />}
className={classNames(className)}
>
<ul className="list-disc text-sm">
<li>
{billing.signed ? (
<>
<IconSquareCheck className="inline-block text-sm" />
Signed by <span className="font-bold">{formatFullName(billing.signedBy)}</span> at{' '}
<span className="font-bold">{formatDate(billing.signedAt)}</span>.
</>
) : (
<>
<IconSquare className="inline-block text-sm" />
Pending signature from <span className="font-bold">{formatFullName(billing.expenseAuthority)}</span>.
</>
)}
</li>
<li>
{billing.approved ? (
<>
<IconSquareCheck className="inline-block text-sm" />
Approved by <span className="font-bold">{formatFullName(billing.approvedBy)}</span> at{' '}
<span className="font-bold">{formatDate(billing.signedAt)}</span>.
</>
) : (
<>
<IconSquare className="inline-block text-sm" />
Pending approval from admin.
</>
)}
</li>
{licencePlate !== billing.licencePlate && (
<li>
<IconInfoSquareRounded className="inline-block text-sm" />
Exempted from the eMOU approval process for the product with licence plate{' '}
<span className="font-bold">{billing.licencePlate}</span>.
</li>
)}
</ul>
</Alert>
);
}

const pathParamSchema = z.object({
id: z.string(),
Expand Down Expand Up @@ -181,11 +114,7 @@ export default publicCloudProductRequest(({ pathParams, queryParams, session, ro

return (
<div>
<BillingInfo
licencePlate={publicSnap.currentRequest.licencePlate}
billing={publicSnap.currentRequest.decisionData.billing}
className="mb-2"
/>
<PublicCloudBillingInfo product={publicSnap.currentRequest.decisionData} className="mb-2" />
<FormProvider {...methods}>
<FormErrorNotification />
<form
Expand Down
165 changes: 165 additions & 0 deletions app/components/billing/PublicCloudBillingDownloadButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
'use client';

import { Alert, Button } from '@mantine/core';
import { PDFDownloadLink, Document, Font, Page, Text, View, StyleSheet, Svg, Circle } from '@react-pdf/renderer';
import { ministryKeyToName } from '@/helpers/product';
import { formatFullName } from '@/helpers/user';
import { formatDate } from '@/utils/date';
import { Product } from './types';

Font.register({
family: 'BCSans',
fonts: [
{
src: '/fonts/bcsans-regular.woff',
fontStyle: 'normal',
fontWeight: 'normal',
},
{
src: '/fonts/bcsans-italic.woff',
fontStyle: 'italic',
fontWeight: 'normal',
},
{
src: '/fonts/bcsans-bold.woff',
fontStyle: 'normal',
fontWeight: 'bold',
},
{
src: '/fonts/bcsans-bold-italic.woff',
fontStyle: 'italic',
fontWeight: 'bold',
},
],
});

const styles = StyleSheet.create({
page: {
fontSize: '10pt',
paddingVertical: '10pt',
paddingHorizontal: '20pt',
fontFamily: 'BCSans',
},
section: {
paddingLeft: '5pt',
},
title: {
fontWeight: 'bold',
fontSize: '20pt',
marginHorizontal: 'auto',
marginTop: '10pt',
marginBottom: '10pt',
},
h1: {
fontWeight: 'semibold',
fontSize: '15pt',
marginBottom: '2pt',
},
label: {
fontWeight: 'normal',
fontSize: '13pt',
},
value: {
fontWeight: 'normal',
fontSize: '13pt',
color: 'gray',
},
br: {
marginVertical: '5pt',
},
table: {
width: 'auto',
borderStyle: 'solid',
borderWidth: 1,
borderRightWidth: 0,
borderBottomWidth: 0,
},
tableRow: {
display: 'flex',
flexDirection: 'row',
},
tableCol: {
flex: 1,
borderStyle: 'solid',
borderWidth: 1,
borderLeftWidth: 0,
borderTopWidth: 0,
},
tableCell: {
margin: '5pt',
fontSize: '13pt',
},
tableHeader: {
fontWeight: 'bold',
textTransform: 'uppercase',
fontSize: '14pt',
},
});

function BillingDocument({ product }: { product: Product }) {
return (
<Document title="Electronic Memorandum of Understanding (eMOU)">
<Page size="LETTER" orientation="portrait" wrap style={styles.page}>
<View>
<Text style={styles.title}>Electronic Memorandum of Understanding (eMOU)</Text>
</View>
<Text style={styles.h1}>Product Description</Text>
<View style={styles.section}>
<Text style={styles.label}>Product Name</Text>
<Text style={styles.value}>{product.name}</Text>
<View style={styles.br} />
<Text style={styles.label}>Description</Text>
<Text style={styles.value}>{product.description}</Text>
<View style={styles.br} />
<Text style={styles.label}>Ministry</Text>
<Text style={styles.value}>{ministryKeyToName(product.ministry)}</Text>
<View style={styles.br} />
<Text style={styles.label}>Cloud Service Provider</Text>
<Text style={styles.value}>{product.provider}</Text>
</View>

<View style={styles.br} />

<Text style={styles.h1}>Agreement</Text>
<View style={styles.table}>
<View style={styles.tableRow}>
<View style={[styles.tableCol]}>
<Text style={styles.tableCell}>Account Coding</Text>
</View>
<View style={[styles.tableCol]}>
<Text style={styles.tableCell}>{product.billing.accountCoding}</Text>
</View>
</View>
<View style={styles.tableRow}>
<View style={[styles.tableCol]}>
<Text style={styles.tableCell}>Signed By</Text>
</View>
<View style={[styles.tableCol]}>
<Text style={styles.tableCell}>{formatFullName(product.billing.signedBy)}</Text>
</View>
</View>
<View style={styles.tableRow}>
<View style={[styles.tableCol]}>
<Text style={styles.tableCell}>Signed At</Text>
</View>
<View style={[styles.tableCol]}>
<Text style={styles.tableCell}>{formatDate(product.billing.signedAt)}</Text>
</View>
</View>
</View>
</Page>
</Document>
);
}

export default function BillingDownloadButton({ product }: { product: Product }) {
return (
<PDFDownloadLink document={<BillingDocument product={product} />}>
{({ blob, url, loading, error }) => (
<Button loading={loading} color="primary" size="xs" className="mt-2">
Download
</Button>
)}
</PDFDownloadLink>
);
}
Loading