source: src/sections/invoice/invoice-table-row.tsx@ 5d6f37a

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

add customer

  • 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 'mvpmasters-shared';
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 createDate,
54 dueDate,
55 status,
56 invoiceTo,
57 currency,
58 totalAmount,
59 month,
60 } = row;
61
62 const confirmSend = useBoolean();
63 const confirmDelete = useBoolean();
64
65 const popover = usePopover();
66
67 return (
68 <>
69 <TableRow hover selected={selected}>
70 {/* <TableCell padding="checkbox">
71 <Checkbox checked={selected} onClick={onSelectRow} />
72 </TableCell> */}
73
74 <TableCell sx={{ display: 'flex', alignItems: 'center' }}>
75 <Avatar alt={invoiceTo.name} src={invoiceTo.logoUrl} sx={{ mr: 2 }}>
76 {invoiceTo.name.charAt(0).toUpperCase()}
77 </Avatar>
78
79 <ListItemText
80 disableTypography
81 primary={
82 <Typography variant="body2" noWrap>
83 {invoiceTo.name}
84 </Typography>
85 }
86 secondary={
87 <Link
88 noWrap
89 variant="body2"
90 onClick={onViewRow}
91 sx={{ color: 'text.disabled', cursor: 'pointer' }}
92 >
93 {invoiceNumber}
94 </Link>
95 }
96 />
97 </TableCell>
98
99 <TableCell>{fNumber(totalAmount)}</TableCell>
100
101 <TableCell>{currency}</TableCell>
102
103 <TableCell>{month}</TableCell>
104
105 <TableCell>
106 <ListItemText
107 primary={format(createDate.toDate(), 'dd MMM yyyy')}
108 secondary={format(createDate.toDate(), 'p')}
109 primaryTypographyProps={{ typography: 'body2', noWrap: true }}
110 secondaryTypographyProps={{
111 mt: 0.5,
112 component: 'span',
113 typography: 'caption',
114 }}
115 />
116 </TableCell>
117
118 <TableCell>
119 <ListItemText
120 primary={format(dueDate.toDate(), 'dd MMM yyyy')}
121 secondary={format(dueDate.toDate(), 'p')}
122 primaryTypographyProps={{ typography: 'body2', noWrap: true }}
123 secondaryTypographyProps={{
124 mt: 0.5,
125 component: 'span',
126 typography: 'caption',
127 }}
128 />
129 </TableCell>
130
131 <TableCell align="center">{sent}</TableCell>
132
133 <TableCell>
134 <Label
135 variant="soft"
136 color={
137 (status === 'paid' && 'success') ||
138 (status === 'processing' && 'info') ||
139 (status === 'pending' && 'warning') ||
140 (status === 'overdue' && 'error') ||
141 'default'
142 }
143 >
144 {status}
145 </Label>
146 </TableCell>
147
148 <TableCell align="right" sx={{ px: 1 }}>
149 <IconButton color={popover.open ? 'inherit' : 'default'} onClick={popover.onOpen}>
150 <Iconify icon="eva:more-vertical-fill" />
151 </IconButton>
152 </TableCell>
153 </TableRow>
154
155 <CustomPopover
156 open={popover.open}
157 onClose={popover.onClose}
158 arrow="right-top"
159 sx={{ width: 160 }}
160 >
161 <MenuItem
162 onClick={() => {
163 onCopyRow();
164 popover.onClose();
165 }}
166 >
167 <Iconify icon="solar:copy-bold" />
168 Copy
169 </MenuItem>
170
171 <MenuItem
172 onClick={() => {
173 onViewRow();
174 popover.onClose();
175 }}
176 >
177 <Iconify icon="solar:eye-bold" />
178 View
179 </MenuItem>
180
181 <MenuItem
182 onClick={() => {
183 onEditRow();
184 popover.onClose();
185 }}
186 disabled={status === 'processing'}
187 >
188 <Iconify icon="solar:pen-bold" />
189 Edit
190 </MenuItem>
191
192 <MenuItem
193 onClick={() => {
194 popover.onClose();
195 onToggleCompose();
196 }}
197 sx={{ color: 'info.main' }}
198 disabled={status === 'processing' || status === 'paid'}
199 >
200 <Iconify icon="iconamoon:send-fill" />
201 Send
202 </MenuItem>
203
204 <Divider sx={{ borderStyle: 'dashed' }} />
205
206 <MenuItem
207 onClick={() => {
208 confirmDelete.onTrue();
209 popover.onClose();
210 }}
211 disabled={status === 'processing'}
212 sx={{ color: 'error.main' }}
213 >
214 <Iconify icon="solar:trash-bin-trash-bold" />
215 Delete
216 </MenuItem>
217 </CustomPopover>
218
219 <ConfirmDialog
220 open={confirmSend.value}
221 onClose={confirmSend.onFalse}
222 title="Confirm"
223 content="Are you sure you want to send?"
224 action={
225 <Button
226 variant="contained"
227 color="info"
228 onClick={() => {
229 onSendRow();
230 confirmSend.onFalse();
231 }}
232 >
233 Send
234 </Button>
235 }
236 />
237
238 <ConfirmDialog
239 open={confirmDelete.value}
240 onClose={confirmDelete.onFalse}
241 title="Delete"
242 content="Are you sure you want to delete?"
243 action={
244 <Button
245 variant="contained"
246 color="error"
247 onClick={async () => {
248 await onDeleteRow();
249 confirmDelete.onToggle();
250 }}
251 >
252 Delete
253 </Button>
254 }
255 />
256 </>
257 );
258}
Note: See TracBrowser for help on using the repository browser.