From 728b4cacd96632b8be1306ba5ab1a57de101da9f Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 24 Oct 2024 20:48:16 +0200 Subject: [PATCH] feat: wip send invoice mail preview --- .../ElementCustomizeFields.tsx | 6 +- .../InvoiceMailReceiptPreviewConnected..tsx | 33 ++++++ .../InvoiceSendMailContentBoot.tsx | 22 +++- .../InvoiceSendMailFields.tsx | 106 +++++++++++++++++- .../InvoiceSendMailForm.tsx | 5 +- .../InvoiceSendMailPreview.tsx | 32 ++---- .../InvoiceSendPdfPreviewConnected.tsx | 27 +++++ 7 files changed, 194 insertions(+), 37 deletions(-) create mode 100644 packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected..tsx create mode 100644 packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendPdfPreviewConnected.tsx diff --git a/packages/webapp/src/containers/ElementCustomize/ElementCustomizeFields.tsx b/packages/webapp/src/containers/ElementCustomize/ElementCustomizeFields.tsx index 2e0ec0c94..76abd88c1 100644 --- a/packages/webapp/src/containers/ElementCustomize/ElementCustomizeFields.tsx +++ b/packages/webapp/src/containers/ElementCustomize/ElementCustomizeFields.tsx @@ -37,8 +37,10 @@ export function ElementCustomizeFieldsMain() { - - {CustomizeTabPanel} + + + {CustomizeTabPanel} + diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected..tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected..tsx new file mode 100644 index 000000000..f07a341a0 --- /dev/null +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected..tsx @@ -0,0 +1,33 @@ +import { Box } from '@/components'; +import { InvoiceMailReceiptPreview } from '../InvoiceCustomize/InvoiceMailReceiptPreview'; +import { css } from '@emotion/css'; +import { useInvoiceSendMailBoot } from './InvoiceSendMailContentBoot'; +import { useMemo } from 'react'; + +export function InvoiceMailReceiptPreviewConneceted() { + const { invoice } = useInvoiceSendMailBoot(); + + const items = useMemo( + () => + invoice.entries.map((entry: any) => ({ + quantity: entry.quantity, + total: entry.rate_formatted, + label: entry.item.name, + })), + [invoice.entries], + ); + + return ( + + + + ); +} diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailContentBoot.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailContentBoot.tsx index cb129282f..fde83ff94 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailContentBoot.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailContentBoot.tsx @@ -1,7 +1,13 @@ +// @ts-nocheck import React, { createContext, useContext } from 'react'; import { Spinner } from '@blueprintjs/core'; +import { useInvoice } from '@/hooks/query'; +import { useDrawerContext } from '@/components/Drawer/DrawerProvider'; -interface InvoiceSendMailBootValues {} +interface InvoiceSendMailBootValues { + invoice: any; + isInvoiceLoading: boolean; +} interface InvoiceSendMailBootProps { children: React.ReactNode; } @@ -10,12 +16,22 @@ const InvoiceSendMailContentBootContext = createContext({} as InvoiceSendMailBootValues); export const InvoiceSendMailBoot = ({ children }: InvoiceSendMailBootProps) => { - const isLoading = false; + const { + payload: { invoiceId }, + } = useDrawerContext(); + + const { data: invoice, isLoading: isInvoiceLoading } = useInvoice(invoiceId, { + enabled: !!invoiceId, + }); + const isLoading = isInvoiceLoading; if (isLoading) { return ; } - const value = {}; + const value = { + invoice, + isInvoiceLoading, + }; return ( diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailFields.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailFields.tsx index 460b948aa..908890730 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailFields.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailFields.tsx @@ -1,13 +1,107 @@ -import { Button, Intent } from "@blueprintjs/core"; -import { useFormikContext } from "formik"; -import { FFormGroup, FInputGroup, Group, Stack } from "@/components"; -import { useDrawerContext } from "@/components/Drawer/DrawerProvider"; -import { useDrawerActions } from "@/hooks/state"; +// @ts-nocheck +import { Button, Intent, MenuItem } from '@blueprintjs/core'; +import { useFormikContext } from 'formik'; +import { + FFormGroup, + FInputGroup, + FMultiSelect, + Group, + Stack, +} from '@/components'; +import { useDrawerContext } from '@/components/Drawer/DrawerProvider'; +import { useDrawerActions } from '@/hooks/state'; + +const commonAddressSelect = { + placeholder: '', + labelAccessor: '', + valueAccessor: 'mail', + + tagAccessor: (item) => `<${item.label}> (${item.mail})`, + textAccessor: (item) => `<${item.label}> (${item.mail})`, +}; + +// Create new account renderer. +const createNewItemRenderer = (query, active, handleClick) => { + return ( + + ); +}; + +// Create new item from the given query string. +const createNewItemFromQuery = (name) => ({ name }); export function InvoiceSendMailFields() { + const allowCreate = true; + // Maybe inject new item props to select component. + const maybeCreateNewItemRenderer = allowCreate ? createNewItemRenderer : null; + const maybeCreateNewItemFromQuery = allowCreate + ? createNewItemFromQuery + : null; + return ( - + + + + + CC + BCC + + ), + }} + fill={true} + createNewItemRenderer={maybeCreateNewItemRenderer} + createNewItemFromQuery={maybeCreateNewItemFromQuery} + {...commonAddressSelect} + /> + + + + + diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailForm.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailForm.tsx index 196807aaf..ca4cf35e6 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailForm.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailForm.tsx @@ -5,8 +5,9 @@ import { css } from '@emotion/css'; const initialValues = { subject: '', message: '', - to: '', - cc: '', + to: [], + cc: [], + bcc: [] }; interface InvoiceSendMailFormValues { subject: string; diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailPreview.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailPreview.tsx index 83e7d8ae5..41034569d 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailPreview.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendMailPreview.tsx @@ -1,12 +1,12 @@ -import { Tab, Tabs } from "@blueprintjs/core"; -import { css } from "@emotion/css"; -import { Box, Stack } from "@/components"; -import { InvoiceMailReceiptPreview } from "../InvoiceCustomize/InvoiceMailReceiptPreview"; -import { InvoicePaperTemplate } from "../InvoiceCustomize/InvoicePaperTemplate"; +import { Tab, Tabs } from '@blueprintjs/core'; +import { css } from '@emotion/css'; +import { Stack } from '@/components'; +import { InvoiceMailReceiptPreviewConneceted } from './InvoiceMailReceiptPreviewConnected.'; +import { InvoiceSendPdfPreviewConnected } from './InvoiceSendPdfPreviewConnected'; export function InvoiceSendMailPreview() { return ( - + - - - } + panel={} /> - - - } + panel={} /> diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendPdfPreviewConnected.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendPdfPreviewConnected.tsx new file mode 100644 index 000000000..7a6eaf96c --- /dev/null +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceSendPdfPreviewConnected.tsx @@ -0,0 +1,27 @@ +import { Box } from "@/components"; +import { InvoicePaperTemplate } from "../InvoiceCustomize/InvoicePaperTemplate"; +import { css } from "@emotion/css"; +import { useInvoiceSendMailBoot } from "./InvoiceSendMailContentBoot"; + +export function InvoiceSendPdfPreviewConnected() { + const { invoice } = useInvoiceSendMailBoot(); + + return ( + + + + ); +}