-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathNewCustomers.tsx
71 lines (66 loc) · 2.19 KB
/
NewCustomers.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as React from 'react';
import { Avatar, Box, Button } from '@mui/material';
import CustomerIcon from '@mui/icons-material/PersonAdd';
import { Link } from 'react-router-dom';
import {
ListBase,
WithListContext,
SimpleList,
useTranslate,
} from 'react-admin';
import { subDays } from 'date-fns';
import CardWithIcon from './CardWithIcon';
import { Customer } from '../types';
const NewCustomers = () => {
const translate = useTranslate();
const aMonthAgo = subDays(new Date(), 30);
aMonthAgo.setDate(aMonthAgo.getDate() - 30);
aMonthAgo.setHours(0);
aMonthAgo.setMinutes(0);
aMonthAgo.setSeconds(0);
aMonthAgo.setMilliseconds(0);
return (
<ListBase
resource="customers"
filter={{
has_ordered: true,
first_seen_gte: aMonthAgo.toISOString(),
}}
sort={{ field: 'first_seen', order: 'DESC' }}
perPage={100}
disableSyncWithLocation
>
<CardWithIcon
to="/customers"
icon={CustomerIcon}
title={translate('pos.dashboard.new_customers')}
subtitle={
<WithListContext render={({ total }) => <>{total}</>} />
}
>
<SimpleList<Customer>
primaryText="%{first_name} %{last_name}"
leftAvatar={customer => (
<Avatar
src={`${customer.avatar}?size=32x32`}
alt={`${customer.first_name} ${customer.last_name}`}
/>
)}
/>
<Box flexGrow={1}> </Box>
<Button
sx={{ borderRadius: 0 }}
component={Link}
to="/customers"
size="small"
color="primary"
>
<Box p={1} sx={{ color: 'primary.main' }}>
{translate('pos.dashboard.all_customers')}
</Box>
</Button>
</CardWithIcon>
</ListBase>
);
};
export default NewCustomers;