fix: Invoice pdf customize

This commit is contained in:
Ahmed Bouhuolia
2024-09-25 11:04:17 +02:00
parent 1c8e19378f
commit 2f9adfd908
21 changed files with 74 additions and 45 deletions

View File

@@ -1,17 +1,16 @@
import { NextFunction, Request, Response } from 'express';
import multer from 'multer';
import type { Multer } from 'multer';
import multerS3 from 'multer-s3';
import { s3 } from '@/lib/S3/S3';
import { Service } from 'typedi';
import config from '@/config';
import { NextFunction, Request, Response } from 'express';
@Service()
export class AttachmentUploadPipeline {
/**
* Middleware to ensure that S3 configuration is properly set before proceeding.
* This function checks if the necessary S3 configuration keys are present and throws an error if any are missing.
*
* @param req The HTTP request object.
* @param res The HTTP response object.
* @param next The callback to pass control to the next middleware function.
@@ -49,6 +48,11 @@ export class AttachmentUploadPipeline {
key: function (req, file, cb) {
cb(null, Date.now().toString());
},
acl: function(req, file, cb) {
// Conditionally set file to public or private based on isPublic flag
const aclValue = true ? 'public-read' : 'private';
cb(null, aclValue); // Set ACL based on the isPublic flag
}
}),
});
}

View File

@@ -134,8 +134,3 @@ export function BrandingTemplateForm<T extends BrandingTemplateValues>({
export const validationSchema = Yup.object().shape({
templateName: Yup.string().required('Template Name is required'),
});
// Initial values - companyLogoKey, companyLogoUri
// Form - _companyLogoFile, companyLogoKey, companyLogoUri
// Request - companyLogoKey

View File

@@ -3,6 +3,7 @@
export interface BrandingTemplateValues {
templateName: string;
// Company logo
companyLogoKey?: string;
companyLogoUri?: string;
}

View File

@@ -53,10 +53,14 @@ export interface CreditNotePaperTemplateProps extends PaperTemplateProps {
}
export function CreditNotePaperTemplate({
// # Colors
primaryColor,
secondaryColor,
// # Company Logo
showCompanyLogo = true,
companyLogo,
companyLogoUri = '',
companyName = 'Bigcapital Technology, Inc.',
// Address
@@ -123,7 +127,7 @@ export function CreditNotePaperTemplate({
primaryColor={primaryColor}
secondaryColor={secondaryColor}
showCompanyLogo={showCompanyLogo}
companyLogo={companyLogo}
companyLogoUri={companyLogoUri}
bigtitle={'Credit Note'}
>
<Stack spacing={24}>

View File

@@ -7,8 +7,8 @@ export const initialValues = {
// Company logo.
showCompanyLogo: true,
companyLogo:
'https://cdn-development.mercury.com/demo-assets/avatars/mercury-demo-dark.png',
companyLogoKey: '',
companyLogoUri: '',
// Address
showBilledToAddress: true,

View File

@@ -7,7 +7,6 @@ export interface CreditNoteCustomizeValues extends BrandingTemplateValues {
// Company Logo
showCompanyLogo?: boolean;
companyLogo?: string;
// Entries
itemNameLabel?: string;

View File

@@ -76,7 +76,6 @@ export function EstimateCustomizeGeneralField() {
name={'showCompanyLogo'}
label={'Display company logo in the paper'}
style={{ fontSize: 14 }}
large
fastField
/>
</FFormGroup>

View File

@@ -1,4 +1,4 @@
import { Group, Stack } from '@/components';
import { Stack } from '@/components';
import {
PaperTemplate,
PaperTemplateProps,
@@ -57,8 +57,10 @@ export interface EstimatePaperTemplateProps extends PaperTemplateProps {
export function EstimatePaperTemplate({
primaryColor,
secondaryColor,
showCompanyLogo = true,
companyLogo,
companyLogoUri = '',
companyName,
billedToAddress = [
@@ -122,7 +124,7 @@ export function EstimatePaperTemplate({
primaryColor={primaryColor}
secondaryColor={secondaryColor}
showCompanyLogo={showCompanyLogo}
companyLogo={companyLogo}
companyLogoUri={companyLogoUri}
bigtitle={'Estimate'}
>
<Stack spacing={24}>

View File

@@ -1,14 +1,14 @@
export const initialValues = {
templateName: '',
// Colors
primaryColor: '#2c3dd8',
secondaryColor: '#2c3dd8',
// Company logo.
showCompanyLogo: true,
companyLogo:
'https://cdn-development.mercury.com/demo-assets/avatars/mercury-demo-dark.png',
companyLogoKey: '',
companyLogoUri: '',
// Top details.
showEstimateNumber: true,

View File

@@ -1,4 +1,4 @@
import { BrandingTemplateValues } from "@/containers/BrandingTemplates/types";
import { BrandingTemplateValues } from '@/containers/BrandingTemplates/types';
export interface EstimateCustomizeValues extends BrandingTemplateValues {
// Colors
@@ -7,7 +7,8 @@ export interface EstimateCustomizeValues extends BrandingTemplateValues {
// Company Logo
showCompanyLogo?: boolean;
companyLogo?: string;
companyLogoKey?: string;
companyLogoUri?: string;
// Top details.
estimateNumberLabel?: string;

View File

@@ -13,6 +13,10 @@ import { CreditCardIcon } from '@/icons/CreditCardIcon';
import { Overlay } from './Overlay';
import { useIsTemplateNamedFilled } from '@/containers/BrandingTemplates/utils';
import { BrandingCompanyLogoUploadField } from '@/containers/ElementCustomize/components/BrandingCompanyLogoUploadField';
import { Link } from 'react-router-dom';
import { MANAGE_LINK_URL } from './constants';
import { useDrawerContext } from '@/components/Drawer/DrawerProvider';
import { useDrawerActions } from '@/hooks/state';
export function InvoiceCustomizeGeneralField() {
const isTemplateNameFilled = useIsTemplateNamedFilled();
@@ -93,6 +97,13 @@ export function InvoiceCustomizeGeneralField() {
}
function InvoiceCustomizePaymentManage() {
const { name } = useDrawerContext();
const { closeDrawer } = useDrawerActions();
const handleLinkClick = () => {
closeDrawer(name);
};
return (
<Group
style={{
@@ -108,9 +119,13 @@ function InvoiceCustomizePaymentManage() {
<Text>Accept payment methods</Text>
</Group>
<a style={{ fontSize: 13 }} href={'#'}>
<Link
style={{ fontSize: 13 }}
to={MANAGE_LINK_URL}
onClick={handleLinkClick}
>
Manage
</a>
</Link>
</Group>
);
}

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { PaperTemplate, PaperTemplateTotalBorder } from './PaperTemplate';
import { Group, Stack } from '@/components';
import { Stack } from '@/components';
interface PapaerLine {
item?: string;
@@ -95,7 +95,7 @@ export function InvoicePaperTemplate({
companyName = 'Bigcapital Technology, Inc.',
showCompanyLogo = true,
companyLogoUri,
companyLogoUri = '',
dueDate = 'September 3, 2024',
dueDateLabel = 'Date due',
@@ -185,7 +185,7 @@ export function InvoicePaperTemplate({
primaryColor={primaryColor}
secondaryColor={secondaryColor}
showCompanyLogo={showCompanyLogo}
companyLogo={companyLogoUri}
companyLogoUri={companyLogoUri}
bigtitle={'Invoice'}
>
<Stack spacing={24}>

View File

@@ -9,7 +9,7 @@ export interface PaperTemplateProps {
secondaryColor?: string;
showCompanyLogo?: boolean;
companyLogo?: string;
companyLogoUri?: string;
companyName?: string;
bigtitle?: string;
@@ -21,7 +21,7 @@ export function PaperTemplate({
primaryColor,
secondaryColor,
showCompanyLogo,
companyLogo,
companyLogoUri,
bigtitle = 'Invoice',
children,
}: PaperTemplateProps) {
@@ -32,9 +32,9 @@ export function PaperTemplate({
<div>
<h1 className={styles.bigTitle}>{bigtitle}</h1>
{showCompanyLogo && (
{showCompanyLogo && companyLogoUri && (
<div className={styles.logoWrap}>
<img alt="" src={companyLogo} />
<img alt="" src={companyLogoUri} />
</div>
)}
</div>
@@ -120,8 +120,8 @@ PaperTemplate.MutedText = () => {};
PaperTemplate.Text = () => {};
PaperTemplate.AddressesGroup = (props: GroupProps) => {
return <Group spacing={10} {...props} className={styles.addressRoot} />
}
return <Group spacing={10} {...props} className={styles.addressRoot} />;
};
PaperTemplate.Address = ({
items,
}: {

View File

@@ -1,3 +1,5 @@
export const MANAGE_LINK_URL = '/preferences/payment-methods';
export const initialValues = {
templateName: '',

View File

@@ -76,7 +76,6 @@ export function PaymentReceivedCustomizeGeneralField() {
name={'showCompanyLogo'}
label={'Display company logo in the paper'}
style={{ fontSize: 14 }}
large
fastField
/>
</FFormGroup>

View File

@@ -41,10 +41,15 @@ export interface PaymentReceivedPaperTemplateProps extends PaperTemplateProps {
}
export function PaymentReceivedPaperTemplate({
// # Colors
primaryColor,
secondaryColor,
// # Company logo
showCompanyLogo = true,
companyLogo,
companyLogoUri,
// # Company name
companyName = 'Bigcapital Technology, Inc.',
billedToAddress = [
@@ -94,7 +99,7 @@ export function PaymentReceivedPaperTemplate({
primaryColor={primaryColor}
secondaryColor={secondaryColor}
showCompanyLogo={showCompanyLogo}
companyLogo={companyLogo}
companyLogoUri={companyLogoUri}
bigtitle={'Payment'}
>
<Stack spacing={24}>

View File

@@ -1,14 +1,14 @@
export const initialValues = {
templateName: '',
// Colors
primaryColor: '#2c3dd8',
secondaryColor: '#2c3dd8',
// Company logo.
showCompanyLogo: true,
companyLogo:
'https://cdn-development.mercury.com/demo-assets/avatars/mercury-demo-dark.png',
companyLogoUri: '',
companyLogokey: '',
// Top details.
showPaymentReceivedNumber: true,

View File

@@ -7,7 +7,6 @@ export interface PaymentReceivedCustomizeValues extends BrandingTemplateValues {
// Company Logo
showCompanyLogo?: boolean;
companyLogo?: string;
// Top details.
showInvoiceNumber?: boolean;

View File

@@ -1,4 +1,4 @@
import { Group, Stack } from '@/components';
import { Stack } from '@/components';
import {
PaperTemplate,
PaperTemplateProps,
@@ -53,10 +53,15 @@ export interface ReceiptPaperTemplateProps extends PaperTemplateProps {
}
export function ReceiptPaperTemplate({
// # Colors
primaryColor,
secondaryColor,
// # Company logo
showCompanyLogo = true,
companyLogo,
companyLogoUri,
// # Company name
companyName = 'Bigcapital Technology, Inc.',
// # Address
@@ -117,7 +122,7 @@ export function ReceiptPaperTemplate({
primaryColor={primaryColor}
secondaryColor={secondaryColor}
showCompanyLogo={showCompanyLogo}
companyLogo={companyLogo}
companyLogoUri={companyLogoUri}
bigtitle={'Receipt'}
>
<Stack spacing={24}>

View File

@@ -7,8 +7,8 @@ export const initialValues = {
// Company logo.
showCompanyLogo: true,
companyLogo:
'https://cdn-development.mercury.com/demo-assets/avatars/mercury-demo-dark.png',
companyLogoKey: '',
companyLogoUri: '',
// Receipt Number
showReceiptNumber: true,

View File

@@ -7,7 +7,6 @@ export interface ReceiptCustomizeValues extends BrandingTemplateValues {
// Company Logo
showCompanyLogo?: boolean;
companyLogo?: string;
// Receipt Number
showReceiptNumber?: boolean;