mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 15:50:32 +00:00
feat(CreditNotePdf): credit note pdf preview.
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { AnchorButton } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
import { DialogContent, PdfDocumentPreview, T } from 'components';
|
||||||
|
import { usePdfCreditNote } from 'hooks/query';
|
||||||
|
|
||||||
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function CreditNotePdfPreviewDialogContent({
|
||||||
|
subscriptionForm: { creditNoteId },
|
||||||
|
}) {
|
||||||
|
const { isLoading, pdfUrl } = usePdfCreditNote(creditNoteId);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogContent>
|
||||||
|
<div class="dialog__header-actions">
|
||||||
|
<AnchorButton
|
||||||
|
href={pdfUrl}
|
||||||
|
target={'__blank'}
|
||||||
|
minimal={true}
|
||||||
|
outlined={true}
|
||||||
|
>
|
||||||
|
<T id={'pdf_preview.preview.button'} />
|
||||||
|
</AnchorButton>
|
||||||
|
|
||||||
|
<AnchorButton
|
||||||
|
href={pdfUrl}
|
||||||
|
download={'creditNote.pdf'}
|
||||||
|
minimal={true}
|
||||||
|
outlined={true}
|
||||||
|
>
|
||||||
|
<T id={'pdf_preview.download.button'} />
|
||||||
|
</AnchorButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<PdfDocumentPreview
|
||||||
|
height={760}
|
||||||
|
width={1000}
|
||||||
|
isLoading={isLoading}
|
||||||
|
url={pdfUrl}
|
||||||
|
/>
|
||||||
|
</DialogContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(withDialogActions)(CreditNotePdfPreviewDialogContent);
|
||||||
42
src/containers/Dialogs/CreditNotePdfPreviewDialog/index.js
Normal file
42
src/containers/Dialogs/CreditNotePdfPreviewDialog/index.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
import { T, Dialog, DialogSuspense } from 'components';
|
||||||
|
|
||||||
|
import withDialogRedux from 'components/DialogReduxConnect';
|
||||||
|
|
||||||
|
import { CLASSES } from 'common/classes';
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
const PdfPreviewDialogContent = React.lazy(() =>
|
||||||
|
import('./CreditNotePdfPreviewDialogContent'),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Credit note PDF previwe dialog.
|
||||||
|
*/
|
||||||
|
function CreditNotePdfPreviewDialog({
|
||||||
|
dialogName,
|
||||||
|
payload = { creditNoteId: null },
|
||||||
|
isOpen,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
name={dialogName}
|
||||||
|
title={<T id={'credit_note_preview.dialog.title'} />}
|
||||||
|
className={classNames(CLASSES.DIALOG_PDF_PREVIEW)}
|
||||||
|
autoFocus={true}
|
||||||
|
canEscapeKeyClose={true}
|
||||||
|
isOpen={isOpen}
|
||||||
|
style={{ width: '1000px' }}
|
||||||
|
>
|
||||||
|
<DialogSuspense>
|
||||||
|
<PdfPreviewDialogContent
|
||||||
|
dialogName={dialogName}
|
||||||
|
subscriptionForm={payload}
|
||||||
|
/>
|
||||||
|
</DialogSuspense>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
export default compose(withDialogRedux())(CreditNotePdfPreviewDialog);
|
||||||
@@ -65,6 +65,11 @@ function CreditNoteDetailActionsBar({
|
|||||||
openDialog('reconcile-credit-note', { creditNoteId });
|
openDialog('reconcile-credit-note', { creditNoteId });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle print credit note.
|
||||||
|
const handlePrintCreditNote = () => {
|
||||||
|
openDialog('credit-note-pdf-preview', { creditNoteId });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DrawerActionsBar>
|
<DrawerActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
@@ -88,6 +93,14 @@ function CreditNoteDetailActionsBar({
|
|||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
</If>
|
</If>
|
||||||
</Can>
|
</Can>
|
||||||
|
<Can I={CreditNoteAction.View} a={AbilitySubject.CreditNote}>
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon="print-16" />}
|
||||||
|
text={<T id={'print'} />}
|
||||||
|
onClick={handlePrintCreditNote}
|
||||||
|
/>
|
||||||
|
</Can>
|
||||||
<Can I={CreditNoteAction.Delete} a={AbilitySubject.CreditNote}>
|
<Can I={CreditNoteAction.Delete} a={AbilitySubject.CreditNote}>
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useQueryClient, useMutation } from 'react-query';
|
|||||||
import { useRequestQuery } from '../useQueryRequest';
|
import { useRequestQuery } from '../useQueryRequest';
|
||||||
import { transformPagination } from 'utils';
|
import { transformPagination } from 'utils';
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
|
import { useRequestPdf } from '../utils';
|
||||||
import t from './types';
|
import t from './types';
|
||||||
|
|
||||||
const commonInvalidateQueries = (queryClient) => {
|
const commonInvalidateQueries = (queryClient) => {
|
||||||
@@ -341,3 +342,10 @@ export function useRefundCreditTransaction(id, props, requestProps) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the credit note pdf document data,
|
||||||
|
*/
|
||||||
|
export function usePdfCreditNote(creditNoteId) {
|
||||||
|
return useRequestPdf(`sales/credit_notes/${creditNoteId}`);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user