-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathroutes.tsx
More file actions
215 lines (209 loc) · 4.87 KB
/
routes.tsx
File metadata and controls
215 lines (209 loc) · 4.87 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import {
DiscordLogo,
GithubLogo,
MediumLogo,
TwitterLogo,
YoutubeLogo
} from "phosphor-react";
import { ReactElement } from "react";
import { generatePath } from "react-router-dom";
import { DrCenterRoutes } from "../../lib/routing/drCenterRoutes";
import { UrlParameters } from "../../lib/routing/parameters";
import {
BosonProtocolRoutes,
BosonRoutes,
SellerCenterRoutes,
SocialRoutes
} from "../../lib/routing/routes";
import { isTruthy } from "../../lib/types/helpers";
import { getViewModeUrl, ViewMode } from "../../lib/viewMode";
import { UserRoles } from "../../router/routes";
import { checkIfUserHaveRole } from "../../router/useUserRoles";
import { getSellerCenterPath } from "../seller/paths";
import ViewTxButton from "../transactions/ViewTxButton";
export const SOCIAL_ROUTES = [
{
name: "twitter",
logo: TwitterLogo,
url: SocialRoutes.Twitter
},
{
name: "discord",
logo: DiscordLogo,
url: SocialRoutes.Discord
},
{
name: "medium",
logo: MediumLogo,
url: SocialRoutes.Medium
},
{
name: "youtube",
logo: YoutubeLogo,
url: SocialRoutes.Youtube
},
{
name: "github",
logo: GithubLogo,
url: SocialRoutes.Github
}
];
export const ADDITIONAL_LINKS: Array<{ label: string; value: string }> = [
{
label: "Privacy Policy",
value: BosonRoutes.PrivacyPolicy
},
{
label: "Terms & Conditions",
value: BosonRoutes.TermsAndConditions
},
{
label: "Community Guidelines",
value: BosonRoutes.CommunityRules
}
];
export const ADDITIONAL_LINKS_DR_CENTER: Array<{
label: string;
value: string;
}> = [
{
label: "Privacy Policy",
value: DrCenterRoutes.PrivacyPolicy
},
{
label: "Terms & Conditions",
value: DrCenterRoutes.TermsAndConditions
}
];
export const getShopRoutes = ({
roles,
isSupportFunctionalityDefined,
hasExchangesAsABuyer,
onlySeller
}: {
roles: (keyof typeof UserRoles)[];
isSupportFunctionalityDefined: boolean;
hasExchangesAsABuyer: boolean;
onlySeller: boolean;
}) => {
const isAccountBuyer = roles.some((role) => role === UserRoles.Buyer);
const productRoutes: (
| {
name: string;
url: string;
}
| { component: (props?: Record<string, unknown>) => ReactElement }
)[] = [];
if (
!isSupportFunctionalityDefined ||
(isSupportFunctionalityDefined && !onlySeller)
) {
productRoutes.push({
name: "Explore",
url: BosonRoutes.Explore
});
}
if (
(!isSupportFunctionalityDefined ||
(isSupportFunctionalityDefined && !onlySeller)) &&
isAccountBuyer &&
hasExchangesAsABuyer
) {
productRoutes.push({
name: "View Exchanges",
url: BosonRoutes.YourAccount
});
}
if (
!isSupportFunctionalityDefined ||
(isSupportFunctionalityDefined && !onlySeller)
) {
productRoutes.push({
component: (props) => (
<ViewTxButton {...props}>View Transactions</ViewTxButton>
)
});
}
return productRoutes;
};
export const getSellRoutes = ({
roles,
isSupportFunctionalityDefined,
sellerId,
onlyBuyer,
onlySeller
}: {
roles: (keyof typeof UserRoles)[];
sellerId: string;
isSupportFunctionalityDefined: boolean;
onlyBuyer: boolean;
onlySeller: boolean;
}) => {
const isAccountSeller = roles.some((role) => role === UserRoles.Seller);
const productRoutes: { name: string; url: string }[] = [];
productRoutes.push({
name: "Templates",
url: BosonRoutes.Sell
});
productRoutes.push({
name: "Create Products",
url: SellerCenterRoutes.CreateProduct
});
if (
(!isSupportFunctionalityDefined ||
(isSupportFunctionalityDefined && (!onlyBuyer || onlySeller))) &&
isAccountSeller
) {
productRoutes.push({
name: "Seller Hub",
url: getSellerCenterPath("Dashboard")
});
}
if (
(!isSupportFunctionalityDefined ||
(isSupportFunctionalityDefined && (!onlyBuyer || onlySeller))) &&
isAccountSeller &&
sellerId
) {
productRoutes.push({
name: "Seller Profile",
url: generatePath(BosonRoutes.SellerPage, {
[UrlParameters.sellerId]: sellerId
})
});
}
return productRoutes;
};
export const getHelpLinks = ({
roles,
hasExchangesAsBuyerOrSeller
}: {
roles: string[];
hasExchangesAsBuyerOrSeller: boolean;
}) => {
return [
checkIfUserHaveRole(roles, [UserRoles.Buyer, UserRoles.Seller], false) &&
hasExchangesAsBuyerOrSeller && {
name: "Chat",
url: BosonRoutes.Chat
},
checkIfUserHaveRole(
roles,
[UserRoles.Buyer, UserRoles.Seller, UserRoles.DisputeResolver],
false
) && {
name: "Resolution Center",
url: getViewModeUrl(ViewMode.DR_CENTER, DrCenterRoutes.Root),
absolute: true
},
{
name: "Email",
email: "info@bosonapp.io"
},
{
name: "Guides",
url: BosonProtocolRoutes.Guides,
absolute: true
}
].filter(isTruthy);
};