-
Notifications
You must be signed in to change notification settings - Fork 0
/
InvoicesModal.tsx
100 lines (89 loc) · 2.98 KB
/
InvoicesModal.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { Modal, Tabs, TabsProps } from "antd"
import moment from "moment";
import { useEffect, useState } from "react";
import ElectricInvoices from "./ElectricInvoices";
import GasInvoices from "./GasInvoices";
import WaterInvoices from "./WaterInvoices";
import { Building, TimeStamp } from "../../types";
import { useAppSelector } from "../../hooks";
import { dataInRange } from "../../globalUtils";
interface InvoicesModal {
data: any,
visible: boolean,
setVisible: (arg: boolean) => void,
timeSpan: TimeStamp
building: Building
}
const InvoicesModal = ({ data, visible, setVisible, timeSpan, building }: InvoicesModal) => {
let elec: Array<any> = []
let gas: Array<any> = []
let water: Array<any> = []
const allOrganization = useAppSelector((state) => state.allOrganization.organization)
const [gasDetail, setGas] = useState({})
const [waterDetail, setWater] = useState({})
const [electricDetail, setElectric] = useState({})
useEffect(() => {
if (!allOrganization)
return
const organizationDetail = Object.values(allOrganization)
.find(el => el._id === building.organizationId)
if (organizationDetail !== undefined) {
setGas(organizationDetail.details.gas)
setWater(organizationDetail.details.water)
setElectric(organizationDetail.details.electric)
elec = []
gas = []
water = []
}
}, [allOrganization, building])
data.bills?.forEach((el: any) => {
const week = moment().subtract(7, 'days');
const month = moment().subtract(1, 'months');
const year = moment().subtract(1, 'years');
switch (timeSpan) {
case "Weekly":
dataInRange(el, elec, gas, water, week);
break;
case "Monthly":
dataInRange(el, elec, gas, water, month);
break;
case "Yearly":
dataInRange(el, elec, gas, water, year);
break;
default:
break;
}
});
const items: TabsProps['items'] = [
{
key: '1',
label: `Electric`,
children: <ElectricInvoices bills={data} cost={electricDetail} filtered={elec} />,
},
{
key: '2',
label: `Gas`,
children: <GasInvoices bills={data} cost={gasDetail} filtered={gas} />
},
{
key: '3',
label: `Water`,
children: <WaterInvoices bills={data} cost={waterDetail} filtered={water} />
},
];
return (
<Modal destroyOnClose open={visible}
width={1200}
onOk={() => setVisible(!visible)}
onCancel={() => setVisible(!visible)}
>
<Tabs
defaultActiveKey="1"
centered
destroyInactiveTabPane
items={items}
/>
</Modal>
)
}
export default InvoicesModal