source: src/sections/invoice/invoice-table-row.tsx@ 87c9f1e

main
Last change on this file since 87c9f1e was 87c9f1e, checked in by Naum Shapkarovski <naumshapkarovski@…>, 5 weeks ago

update the seed script. update the prisma schema, use mapping

  • Property mode set to 100644
File size: 6.6 KB
Line 
1import { format } from 'date-fns';
2// @mui
3import Link from '@mui/material/Link';
4import Button from '@mui/material/Button';
5import Avatar from '@mui/material/Avatar';
6import Divider from '@mui/material/Divider';
7import MenuItem from '@mui/material/MenuItem';
8import TableRow from '@mui/material/TableRow';
9import TableCell from '@mui/material/TableCell';
10import IconButton from '@mui/material/IconButton';
11import Typography from '@mui/material/Typography';
12import ListItemText from '@mui/material/ListItemText';
13// hooks
14import { useBoolean } from 'src/hooks/use-boolean';
15// utils
16import { fNumber } from 'src/utils/format-number';
17// types
18import { Invoice } from 'src/schemas';
19// components
20import Label from 'src/components/label';
21import Iconify from 'src/components/iconify';
22import { ConfirmDialog } from 'src/components/custom-dialog';
23import CustomPopover, { usePopover } from 'src/components/custom-popover';
24
25// ----------------------------------------------------------------------
26
27type Props = {
28 row: Invoice;
29 selected: boolean;
30 onSelectRow: VoidFunction;
31 onViewRow: VoidFunction;
32 onEditRow: VoidFunction;
33 onCopyRow: VoidFunction;
34 onDeleteRow: () => Promise<void>;
35 onSendRow: VoidFunction;
36 onToggleCompose: VoidFunction;
37};
38
39export default function InvoiceTableRow({
40 row,
41 selected,
42 onSelectRow,
43 onViewRow,
44 onEditRow,
45 onCopyRow,
46 onDeleteRow,
47 onSendRow,
48 onToggleCompose,
49}: Props) {
50 const {
51 sent,
52 invoiceNumber,
53 issueDate,
54 dueDate,
55 status,
56 invoiceTo,
57 currency,
58 totalAmount,
59 month,
60 } = row;
61
62 console.log(issueDate);
63
64 const confirmSend = useBoolean();
65 const confirmDelete = useBoolean();
66
67 const popover = usePopover();
68
69 return (
70 <>
71 <TableRow hover selected={selected}>
72 {/* <TableCell padding="checkbox">
73 <Checkbox checked={selected} onClick={onSelectRow} />
74 </TableCell> */}
75
76 <TableCell sx={{ display: 'flex', alignItems: 'center' }}>
77 <Avatar alt={invoiceTo.name} src={invoiceTo.logoUrl} sx={{ mr: 2 }}>
78 {invoiceTo.name.charAt(0).toUpperCase()}
79 </Avatar>
80
81 <ListItemText
82 disableTypography
83 primary={
84 <Typography variant="body2" noWrap>
85 {invoiceTo.name}
86 </Typography>
87 }
88 secondary={
89 <Link
90 noWrap
91 variant="body2"
92 onClick={onViewRow}
93 sx={{ color: 'text.disabled', cursor: 'pointer' }}
94 >
95 {invoiceNumber}
96 </Link>
97 }
98 />
99 </TableCell>
100
101 <TableCell>{fNumber(totalAmount)}</TableCell>
102
103 <TableCell>{currency}</TableCell>
104
105 <TableCell>{month}</TableCell>
106
107 <TableCell>
108 <ListItemText
109 primary={format(new Date(issueDate), 'dd MMM yyyy')}
110 secondary={format(new Date(issueDate), 'p')}
111 primaryTypographyProps={{ typography: 'body2', noWrap: true }}
112 secondaryTypographyProps={{
113 mt: 0.5,
114 component: 'span',
115 typography: 'caption',
116 }}
117 />
118 </TableCell>
119
120 <TableCell>
121 <ListItemText
122 primary={format(new Date(dueDate), 'dd MMM yyyy')}
123 secondary={format(new Date(dueDate), 'p')}
124 primaryTypographyProps={{ typography: 'body2', noWrap: true }}
125 secondaryTypographyProps={{
126 mt: 0.5,
127 component: 'span',
128 typography: 'caption',
129 }}
130 />
131 </TableCell>
132
133 <TableCell align="center">{sent}</TableCell>
134
135 <TableCell>
136 <Label
137 variant="soft"
138 color={
139 (status === 'paid' && 'success') ||
140 (status === 'processing' && 'info') ||
141 (status === 'pending' && 'warning') ||
142 (status === 'overdue' && 'error') ||
143 'default'
144 }
145 >
146 {status}
147 </Label>
148 </TableCell>
149
150 <TableCell align="right" sx={{ px: 1 }}>
151 <IconButton color={popover.open ? 'inherit' : 'default'} onClick={popover.onOpen}>
152 <Iconify icon="eva:more-vertical-fill" />
153 </IconButton>
154 </TableCell>
155 </TableRow>
156
157 <CustomPopover
158 open={popover.open}
159 onClose={popover.onClose}
160 arrow="right-top"
161 sx={{ width: 160 }}
162 >
163 <MenuItem
164 onClick={() => {
165 onCopyRow();
166 popover.onClose();
167 }}
168 >
169 <Iconify icon="solar:copy-bold" />
170 Copy
171 </MenuItem>
172
173 <MenuItem
174 onClick={() => {
175 onViewRow();
176 popover.onClose();
177 }}
178 >
179 <Iconify icon="solar:eye-bold" />
180 View
181 </MenuItem>
182
183 <MenuItem
184 onClick={() => {
185 onEditRow();
186 popover.onClose();
187 }}
188 disabled={status === 'processing'}
189 >
190 <Iconify icon="solar:pen-bold" />
191 Edit
192 </MenuItem>
193
194 <MenuItem
195 onClick={() => {
196 popover.onClose();
197 onToggleCompose();
198 }}
199 sx={{ color: 'info.main' }}
200 disabled={status === 'processing' || status === 'paid'}
201 >
202 <Iconify icon="iconamoon:send-fill" />
203 Send
204 </MenuItem>
205
206 <Divider sx={{ borderStyle: 'dashed' }} />
207
208 <MenuItem
209 onClick={() => {
210 confirmDelete.onTrue();
211 popover.onClose();
212 }}
213 disabled={status === 'processing'}
214 sx={{ color: 'error.main' }}
215 >
216 <Iconify icon="solar:trash-bin-trash-bold" />
217 Delete
218 </MenuItem>
219 </CustomPopover>
220
221 <ConfirmDialog
222 open={confirmSend.value}
223 onClose={confirmSend.onFalse}
224 title="Confirm"
225 content="Are you sure you want to send?"
226 action={
227 <Button
228 variant="contained"
229 color="info"
230 onClick={() => {
231 onSendRow();
232 confirmSend.onFalse();
233 }}
234 >
235 Send
236 </Button>
237 }
238 />
239
240 <ConfirmDialog
241 open={confirmDelete.value}
242 onClose={confirmDelete.onFalse}
243 title="Delete"
244 content="Are you sure you want to delete?"
245 action={
246 <Button
247 variant="contained"
248 color="error"
249 onClick={async () => {
250 await onDeleteRow();
251 confirmDelete.onToggle();
252 }}
253 >
254 Delete
255 </Button>
256 }
257 />
258 </>
259 );
260}
Note: See TracBrowser for help on using the repository browser.