Skip to content

Commit

Permalink
O3-3016 Fix breaking print receipt function on the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Apr 2, 2024
1 parent 38a3eb4 commit 5f2534c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/invoice/printable-invoice/print-receipt.component.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import React, { useState } from 'react';
import { Button } from '@carbon/react';
import { Printer } from '@carbon/react/icons';
import { useTranslation } from 'react-i18next';
import { ConfigurableLink } from '@openmrs/esm-framework';
import styles from './print-receipt.scss';
import { apiBasePath } from '../../constants';

Expand All @@ -11,17 +10,25 @@ interface PrintReceiptProps {
}
const PrintReceipt: React.FC<PrintReceiptProps> = ({ billId }) => {
const { t } = useTranslation();
const [isRedirecting, setIsRedirecting] = useState(false);

const handlePrintReceiptClick = () => {
setIsRedirecting(true);
setTimeout(() => {
window.location.href = `/openmrs${apiBasePath}receipt?billId=${billId}`;
setIsRedirecting(false);
}, 1000);
};

return (
<Button
kind="secondary"
className={styles.button}
size="md"
renderIcon={(props) => <Printer size={24} {...props} />}>
<ConfigurableLink
className={styles.configurableLink}
to={`\${openmrsBase}${apiBasePath}receipt?billId=${billId}`}>
{t('printReceipt', 'Print receipt')}
</ConfigurableLink>{' '}
renderIcon={(props) => <Printer size={24} {...props} />}
onClick={handlePrintReceiptClick}
disabled={isRedirecting}>
{isRedirecting ? t('loading', 'Loading') : t('printReceipt', 'Print receipt')}
</Button>
);
};
Expand Down

0 comments on commit 5f2534c

Please sign in to comment.