-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnowYourCommissionWidget.jsx
More file actions
144 lines (133 loc) · 3.31 KB
/
KnowYourCommissionWidget.jsx
File metadata and controls
144 lines (133 loc) · 3.31 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React from "react";
import { Avatar, Divider, Flex, Text } from "@chakra-ui/react";
import { Icon } from "components";
import { useCommissionSummary, useUser } from "contexts";
import useHslColor from "hooks/useHslColor";
import { useRouter } from "next/router";
import { WidgetBase } from "..";
/**
* A <KnowYourCommission> component
* TODO: Write more description here
* @param {object} prop Properties passed to the component
* @param {string} prop.prop1 TODO: Property description.
* @param {...*} rest Rest of the props passed to this component.
* @example `<KnowYourCommission></KnowYourCommission>` TODO: Fix example
*/
const KnowYourCommission = () => {
const router = useRouter();
const commissionData = useCommissionSummary();
const { isLoggedIn, isAdminAgentMode, isAdmin } = useUser();
const commissionProductIds = Object.keys(commissionData?.data || {});
if (!commissionProductIds.length) return null;
// const uniqueCommissionData = commissionData?.data.filter(
// (value, index, self) =>
// index === self.findIndex((item) => item.product === value.product)
// );
const handleShowDetail = (id) => {
if (id) {
const prefix = isAdmin && isAdminAgentMode ? "/admin" : "";
router.push(`${prefix}/commissions/${id}`);
}
};
if (!isLoggedIn) return null;
return (
<WidgetBase title="Know Your Commissions" noPadding>
<Flex
direction="column"
className="customScrollbars"
overflowY={{ base: "none", md: "scroll" }}
>
{commissionProductIds?.map((id, index) => {
const prod = commissionData?.data?.[id];
return (
<React.Fragment key={id}>
<Tr
id={id}
prod={prod}
handleShowDetail={handleShowDetail}
/>
{commissionProductIds?.length - 1 !== index ? (
<Divider />
) : null}
</React.Fragment>
);
})}
</Flex>
</WidgetBase>
);
};
/**
* Internal table-row component
* @param root0
* @param root0.id
* @param root0.prod
* @param root0.handleShowDetail
*/
const Tr = ({ id, prod, handleShowDetail }) => {
const { h } = useHslColor(prod.label);
return (
<Flex
p="8px 4px 8px 16px"
pr={{ base: "8px", md: "4px" }}
align="center"
justify="center"
// borderBottom="1px solid #F5F6F8"
>
<Avatar
size={{ base: "sm", md: "md" }}
name={prod.icon ? null : prod.label}
border={`2px solid hsl(${h},80%,85%)`}
bg={`hsl(${h},80%,95%)`}
color={`hsl(${h},80%,30%)`}
icon={
<Icon
size={{ base: "sm", md: "md" }}
name={prod.icon}
color={`hsl(${h},80%,30%)`}
/>
}
/>
<Flex
alignItems="center"
justifyContent="space-between"
w="100%"
ml="10px"
>
<Flex direction="column">
<Text
fontSize={{
base: "xs",
md: "sm",
}}
fontWeight="medium"
noOfLines={1}
>
{prod.label}
</Text>
</Flex>
<Flex
justifyContent="space-between"
alignItems="center"
ml={2}
onClick={() => handleShowDetail(id)}
cursor="pointer"
>
<Text
color="accent.DEFAULT"
pr="6px"
display={{ base: "none", md: "block" }}
fontSize="sm"
>
Details
</Text>
<Icon
size="12px"
name="arrow-forward"
color="accent.DEFAULT"
/>
</Flex>
</Flex>
</Flex>
);
};
export default KnowYourCommission;