-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: payment received mail receipt preview
- Loading branch information
Showing
18 changed files
with
622 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...c/containers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailBoot.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { createContext, useContext } from 'react'; | ||
import { Spinner } from '@blueprintjs/core'; | ||
import { | ||
PaymentReceivedStateResponse, | ||
usePaymentReceivedState, | ||
} from '@/hooks/query'; | ||
import { useDrawerContext } from '@/components/Drawer/DrawerProvider'; | ||
|
||
interface PaymentReceivedSendMailBootValues { | ||
paymentReceivedId: number; | ||
|
||
paymentReceivedMailState: PaymentReceivedStateResponse | undefined; | ||
isPaymentReceivedStateLoading: boolean; | ||
} | ||
interface InvoiceSendMailBootProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
const PaymentReceivedSendMailBootContext = | ||
createContext<PaymentReceivedSendMailBootValues>( | ||
{} as PaymentReceivedSendMailBootValues, | ||
); | ||
|
||
export const PaymentReceivedSendMailBoot = ({ | ||
children, | ||
}: InvoiceSendMailBootProps) => { | ||
const { | ||
payload: { paymentReceivedId }, | ||
} = useDrawerContext(); | ||
|
||
const { | ||
data: paymentReceivedMailState, | ||
isLoading: isPaymentReceivedStateLoading, | ||
} = usePaymentReceivedState(paymentReceivedId); | ||
|
||
const isLoading = isPaymentReceivedStateLoading; | ||
|
||
if (isLoading) { | ||
return <Spinner size={20} />; | ||
} | ||
const value = { | ||
paymentReceivedId, | ||
|
||
// # mail options | ||
isPaymentReceivedStateLoading, | ||
paymentReceivedMailState, | ||
}; | ||
|
||
return ( | ||
<PaymentReceivedSendMailBootContext.Provider value={value}> | ||
{children} | ||
</PaymentReceivedSendMailBootContext.Provider> | ||
); | ||
}; | ||
PaymentReceivedSendMailBoot.displayName = 'PaymentReceivedSendMailBoot'; | ||
|
||
export const usePaymentReceivedSendMailBoot = () => { | ||
return useContext<PaymentReceivedSendMailBootValues>( | ||
PaymentReceivedSendMailBootContext, | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
...ontainers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailContent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Stack } from '@/components'; | ||
import { Classes } from '@blueprintjs/core'; | ||
import { PaymentReceivedSendMailBoot } from './PaymentReceivedMailBoot'; | ||
import { PaymentReceivedSendMailForm } from './PaymentReceivedMailForm'; | ||
import { PaymentReceivedSendMailPreview } from './PaymentReceivedMailPreviewTabs'; | ||
// import { InvoiceSendMailFields } from './InvoiceSendMailFields'; | ||
import { SendMailViewHeader } from '../../Estimates/SendMailViewDrawer/SendMailViewHeader'; | ||
import { SendMailViewLayout } from '../../Estimates/SendMailViewDrawer/SendMailViewLayout'; | ||
import { PaymentReceivedSendMailFields } from './PaymentReceivedMailFields'; | ||
|
||
export function PaymentReceivedSendMailContent() { | ||
return ( | ||
<Stack className={Classes.DRAWER_BODY}> | ||
<PaymentReceivedSendMailBoot> | ||
<PaymentReceivedSendMailForm> | ||
<SendMailViewLayout | ||
header={<SendMailViewHeader label={'Send Payment Mail'} />} | ||
fields={<PaymentReceivedSendMailFields />} | ||
preview={<PaymentReceivedSendMailPreview />} | ||
/> | ||
</PaymentReceivedSendMailForm> | ||
</PaymentReceivedSendMailBoot> | ||
</Stack> | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
...containers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailDrawer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// @ts-nocheck | ||
import React from 'react'; | ||
import * as R from 'ramda'; | ||
import { Drawer, DrawerSuspense } from '@/components'; | ||
import withDrawers from '@/containers/Drawer/withDrawers'; | ||
|
||
const PaymentReceivedMailContent = React.lazy(() => | ||
import('./PaymentReceivedMailContent').then((module) => ({ | ||
default: module.PaymentReceivedSendMailContent, | ||
})), | ||
); | ||
|
||
interface PaymentReceivedSendMailDrawerProps { | ||
name: string; | ||
isOpen?: boolean; | ||
payload?: any; | ||
} | ||
|
||
function PaymentReceivedSendMailDrawerRoot({ | ||
name, | ||
|
||
// #withDrawer | ||
isOpen, | ||
payload, | ||
}: PaymentReceivedSendMailDrawerProps) { | ||
return ( | ||
<Drawer | ||
isOpen={isOpen} | ||
name={name} | ||
payload={payload} | ||
size={'calc(100% - 10px)'} | ||
> | ||
<DrawerSuspense> | ||
<PaymentReceivedMailContent /> | ||
</DrawerSuspense> | ||
</Drawer> | ||
); | ||
} | ||
|
||
export const PaymentReceivedSendMailDrawer = R.compose(withDrawers())( | ||
PaymentReceivedSendMailDrawerRoot, | ||
); |
77 changes: 77 additions & 0 deletions
77
...containers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailFields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// @ts-nocheck | ||
import { Button, Intent } from '@blueprintjs/core'; | ||
import { useFormikContext } from 'formik'; | ||
import { FCheckbox, FFormGroup, FInputGroup, Group, Stack } from '@/components'; | ||
import { useDrawerContext } from '@/components/Drawer/DrawerProvider'; | ||
import { useDrawerActions } from '@/hooks/state'; | ||
import { SendMailViewToAddressField } from '../../Estimates/SendMailViewDrawer/SendMailViewToAddressField'; | ||
import { SendMailViewMessageField } from '../../Estimates/SendMailViewDrawer/SendMailViewMessageField'; | ||
|
||
const items = []; | ||
const argsOptions = []; | ||
|
||
export function PaymentReceivedSendMailFields() { | ||
// const items = useInvoiceMailItems(); | ||
// const argsOptions = useSendInvoiceFormatArgsOptions(); | ||
|
||
return ( | ||
<Stack> | ||
<Stack spacing={0} overflow="auto" flex="1" p={'30px'}> | ||
<SendMailViewToAddressField | ||
toMultiSelectProps={{ items }} | ||
ccMultiSelectProps={{ items }} | ||
bccMultiSelectProps={{ items }} | ||
/> | ||
<FFormGroup label={'Submit'} name={'subject'}> | ||
<FInputGroup name={'subject'} large fastField /> | ||
</FFormGroup> | ||
|
||
<SendMailViewMessageField argsOptions={argsOptions} /> | ||
|
||
<Group> | ||
<FCheckbox name={'attachPdf'} label={'Attach PDF'} /> | ||
</Group> | ||
</Stack> | ||
|
||
<PaymentReceivedSendMailFooter /> | ||
</Stack> | ||
); | ||
} | ||
|
||
function PaymentReceivedSendMailFooter() { | ||
const { isSubmitting } = useFormikContext(); | ||
const { name } = useDrawerContext(); | ||
const { closeDrawer } = useDrawerActions(); | ||
|
||
const handleClose = () => { | ||
closeDrawer(name); | ||
}; | ||
|
||
return ( | ||
<Group | ||
py={'12px'} | ||
px={'16px'} | ||
borderTop="1px solid #d8d8d9" | ||
position={'apart'} | ||
> | ||
<Group spacing={10} ml={'auto'}> | ||
<Button | ||
disabled={isSubmitting} | ||
onClick={handleClose} | ||
style={{ minWidth: '65px' }} | ||
> | ||
Close | ||
</Button> | ||
|
||
<Button | ||
intent={Intent.PRIMARY} | ||
loading={isSubmitting} | ||
style={{ minWidth: '85px' }} | ||
type="submit" | ||
> | ||
Send Mail | ||
</Button> | ||
</Group> | ||
</Group> | ||
); | ||
} |
81 changes: 81 additions & 0 deletions
81
...c/containers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Form, Formik, FormikHelpers } from 'formik'; | ||
import { css } from '@emotion/css'; | ||
import { Intent } from '@blueprintjs/core'; | ||
import { PaymentReceivedSendMailFormSchema } from './_types'; | ||
import { AppToaster } from '@/components'; | ||
import { useSendSaleInvoiceMail } from '@/hooks/query'; | ||
import { usePaymentReceivedSendMailBoot } from './PaymentReceivedMailBoot'; | ||
import { useDrawerActions } from '@/hooks/state'; | ||
import { useDrawerContext } from '@/components/Drawer/DrawerProvider'; | ||
import { transformToForm } from '@/utils'; | ||
import { PaymentReceivedSendMailFormValues } from './_types'; | ||
|
||
const initialValues: PaymentReceivedSendMailFormValues = { | ||
subject: '', | ||
message: '', | ||
to: [], | ||
cc: [], | ||
bcc: [], | ||
attachPdf: true, | ||
}; | ||
|
||
interface PaymentReceivedSendMailFormProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export function PaymentReceivedSendMailForm({ | ||
children, | ||
}: PaymentReceivedSendMailFormProps) { | ||
const { mutateAsync: sendInvoiceMail } = useSendSaleInvoiceMail(); | ||
const { paymentReceivedId, paymentReceivedMailState } = | ||
usePaymentReceivedSendMailBoot(); | ||
|
||
const { name } = useDrawerContext(); | ||
const { closeDrawer } = useDrawerActions(); | ||
|
||
const _initialValues: PaymentReceivedSendMailFormValues = { | ||
...initialValues, | ||
...transformToForm(paymentReceivedMailState, initialValues), | ||
}; | ||
const handleSubmit = ( | ||
values: PaymentReceivedSendMailFormValues, | ||
{ setSubmitting }: FormikHelpers<PaymentReceivedSendMailFormValues>, | ||
) => { | ||
setSubmitting(true); | ||
sendInvoiceMail({ id: paymentReceivedId, values: { ...values } }) | ||
.then(() => { | ||
AppToaster.show({ | ||
message: 'The invoice mail has been sent to the customer.', | ||
intent: Intent.SUCCESS, | ||
}); | ||
setSubmitting(false); | ||
closeDrawer(name); | ||
}) | ||
.catch(() => { | ||
setSubmitting(false); | ||
AppToaster.show({ | ||
message: 'Something went wrong!', | ||
intent: Intent.SUCCESS, | ||
}); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Formik | ||
initialValues={_initialValues} | ||
validationSchema={PaymentReceivedSendMailFormSchema} | ||
onSubmit={handleSubmit} | ||
> | ||
<Form | ||
className={css` | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
overflow: hidden; | ||
`} | ||
> | ||
{children} | ||
</Form> | ||
</Formik> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
...ers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailPreviewHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { SendViewPreviewHeader } from "../../Estimates/SendMailViewDrawer/SendMailViewPreviewHeader"; | ||
|
||
export function PaymentReceivedMailPreviewHeader() { | ||
return ( | ||
<SendViewPreviewHeader | ||
companyName="A" | ||
customerName="A" | ||
subject={'adsfsdf'} | ||
from={['[email protected]']} | ||
to={['[email protected]']} | ||
/> | ||
); | ||
} |
Oops, something went wrong.