[5d6f37a] | 1 | import { useCallback } from 'react';
|
---|
| 2 | import { PDFDownloadLink, PDFViewer } from '@react-pdf/renderer';
|
---|
| 3 | // @mui
|
---|
| 4 | import Box from '@mui/material/Box';
|
---|
| 5 | import Stack from '@mui/material/Stack';
|
---|
| 6 | import Button from '@mui/material/Button';
|
---|
| 7 | import Dialog from '@mui/material/Dialog';
|
---|
| 8 | import Tooltip from '@mui/material/Tooltip';
|
---|
| 9 | import MenuItem from '@mui/material/MenuItem';
|
---|
| 10 | import TextField from '@mui/material/TextField';
|
---|
| 11 | import IconButton from '@mui/material/IconButton';
|
---|
| 12 | import DialogActions from '@mui/material/DialogActions';
|
---|
| 13 | import CircularProgress from '@mui/material/CircularProgress';
|
---|
| 14 | // routes
|
---|
| 15 | import { paths } from 'src/routes/paths';
|
---|
| 16 | import { useRouter } from 'src/routes/hooks';
|
---|
| 17 | // hooks
|
---|
| 18 | import { useBoolean } from 'src/hooks/use-boolean';
|
---|
| 19 | // types
|
---|
[057453c] | 20 | import { Invoice } from 'src/schemas';
|
---|
[5d6f37a] | 21 | // components
|
---|
| 22 | import Iconify from 'src/components/iconify';
|
---|
| 23 | import InvoicePDF from './invoice-pdf';
|
---|
| 24 |
|
---|
| 25 | // ----------------------------------------------------------------------
|
---|
| 26 |
|
---|
| 27 | type Props = {
|
---|
| 28 | invoice: Invoice;
|
---|
| 29 | currentStatus: string;
|
---|
| 30 | onChangeStatus: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
---|
| 31 | statusOptions: {
|
---|
| 32 | value: string;
|
---|
| 33 | label: string;
|
---|
| 34 | }[];
|
---|
| 35 | };
|
---|
| 36 |
|
---|
| 37 | export default function InvoiceToolbar({
|
---|
| 38 | invoice,
|
---|
| 39 | currentStatus,
|
---|
| 40 | statusOptions,
|
---|
| 41 | onChangeStatus,
|
---|
| 42 | }: Props) {
|
---|
| 43 | const router = useRouter();
|
---|
| 44 |
|
---|
| 45 | const view = useBoolean();
|
---|
| 46 |
|
---|
| 47 | const handleEdit = useCallback(() => {
|
---|
| 48 | router.push(paths.dashboard.invoice.edit(invoice.id));
|
---|
| 49 | }, [invoice.id, router]);
|
---|
| 50 |
|
---|
| 51 | return (
|
---|
| 52 | <>
|
---|
| 53 | <Stack
|
---|
| 54 | spacing={3}
|
---|
| 55 | direction={{ xs: 'column', sm: 'row' }}
|
---|
| 56 | alignItems={{ xs: 'flex-end', sm: 'center' }}
|
---|
| 57 | sx={{ mb: { xs: 3, md: 5 } }}
|
---|
| 58 | >
|
---|
| 59 | <Stack direction="row" spacing={1} flexGrow={1} sx={{ width: 1 }}>
|
---|
| 60 | <Tooltip title="Edit">
|
---|
| 61 | <IconButton disabled={currentStatus === 'processing'} onClick={handleEdit}>
|
---|
| 62 | <Iconify icon="solar:pen-bold" />
|
---|
| 63 | </IconButton>
|
---|
| 64 | </Tooltip>
|
---|
| 65 |
|
---|
| 66 | <Tooltip title="View">
|
---|
| 67 | <IconButton onClick={view.onTrue}>
|
---|
| 68 | <Iconify icon="solar:eye-bold" />
|
---|
| 69 | </IconButton>
|
---|
| 70 | </Tooltip>
|
---|
| 71 |
|
---|
| 72 | <PDFDownloadLink
|
---|
| 73 | document={<InvoicePDF invoice={invoice} currentStatus={currentStatus} />}
|
---|
| 74 | fileName={invoice.invoiceNumber}
|
---|
| 75 | style={{ textDecoration: 'none' }}
|
---|
| 76 | >
|
---|
| 77 | {({ loading }) => (
|
---|
| 78 | <Tooltip title="Download">
|
---|
| 79 | <IconButton>
|
---|
| 80 | {loading ? (
|
---|
| 81 | <CircularProgress size={24} color="inherit" />
|
---|
| 82 | ) : (
|
---|
| 83 | <Iconify icon="eva:cloud-download-fill" />
|
---|
| 84 | )}
|
---|
| 85 | </IconButton>
|
---|
| 86 | </Tooltip>
|
---|
| 87 | )}
|
---|
| 88 | </PDFDownloadLink>
|
---|
| 89 |
|
---|
| 90 | {/* <Tooltip title="Print">
|
---|
| 91 | <IconButton>
|
---|
| 92 | <Iconify icon="solar:printer-minimalistic-bold" />
|
---|
| 93 | </IconButton>
|
---|
| 94 | </Tooltip>
|
---|
| 95 |
|
---|
| 96 | <Tooltip title="Send">
|
---|
| 97 | <IconButton>
|
---|
| 98 | <Iconify icon="iconamoon:send-fill" />
|
---|
| 99 | </IconButton>
|
---|
| 100 | </Tooltip>
|
---|
| 101 |
|
---|
| 102 | <Tooltip title="Share">
|
---|
| 103 | <IconButton>
|
---|
| 104 | <Iconify icon="solar:share-bold" />
|
---|
| 105 | </IconButton>
|
---|
| 106 | </Tooltip> */}
|
---|
| 107 | </Stack>
|
---|
| 108 |
|
---|
| 109 | <TextField
|
---|
| 110 | fullWidth
|
---|
| 111 | select
|
---|
| 112 | label="Status"
|
---|
| 113 | value={currentStatus}
|
---|
| 114 | onChange={onChangeStatus}
|
---|
| 115 | sx={{
|
---|
| 116 | maxWidth: 160,
|
---|
| 117 | }}
|
---|
| 118 | disabled={currentStatus === 'processing'}
|
---|
| 119 | >
|
---|
| 120 | {statusOptions.map((option) => (
|
---|
| 121 | <MenuItem key={option.value} value={option.value}>
|
---|
| 122 | {option.label}
|
---|
| 123 | </MenuItem>
|
---|
| 124 | ))}
|
---|
| 125 | </TextField>
|
---|
| 126 | </Stack>
|
---|
| 127 |
|
---|
| 128 | <Dialog fullScreen open={view.value}>
|
---|
| 129 | <Box sx={{ height: 1, display: 'flex', flexDirection: 'column' }}>
|
---|
| 130 | <DialogActions
|
---|
| 131 | sx={{
|
---|
| 132 | p: 1.5,
|
---|
| 133 | }}
|
---|
| 134 | >
|
---|
| 135 | <Button color="inherit" variant="contained" onClick={view.onFalse}>
|
---|
| 136 | Close
|
---|
| 137 | </Button>
|
---|
| 138 | </DialogActions>
|
---|
| 139 |
|
---|
| 140 | <Box sx={{ flexGrow: 1, height: 1, overflow: 'hidden' }}>
|
---|
| 141 | <PDFViewer width="100%" height="100%" style={{ border: 'none' }}>
|
---|
| 142 | <InvoicePDF invoice={invoice} currentStatus={currentStatus} />
|
---|
| 143 | </PDFViewer>
|
---|
| 144 | </Box>
|
---|
| 145 | </Box>
|
---|
| 146 | </Dialog>
|
---|
| 147 | </>
|
---|
| 148 | );
|
---|
| 149 | }
|
---|