-
Notifications
You must be signed in to change notification settings - Fork 3
/
LoadErrorMessage.tsx
182 lines (175 loc) · 5.07 KB
/
LoadErrorMessage.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
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
import { Alert, Button, Link, Paper, Typography, lighten } from "@mui/material";
import React, { useState } from "react";
import { LoadErrorMessageProps } from "./LoadErrorMessage.types";
import { VirtoHeadScratching } from "../SvgIcons/VirtoMascots/VirtoHeadScratching";
import { VirtoShrugging } from "../SvgIcons";
import { VirtoThinking } from "../SvgIcons/VirtoMascots/VirtoThinking";
// LoadErrorMessage component
const LoadErrorMessage = ({
actionButtonText,
contactTeam = "Support",
errorDetails,
message,
title,
image = "virto-thinking",
contactUrl,
onButtonClick
}: LoadErrorMessageProps) => {
// State to track whether the error details are visible or not
const [detailsVisible, setDetailsVisible] = useState(false);
// Function to toggle the visibility of the error details
const handleDetailsClick = () => {
setDetailsVisible(!detailsVisible);
};
// Render the LoadErrorMessage component
return (
<Paper
variant="outlined"
sx={{
alignItems: "center",
borderRadius: "3px",
display: "flex",
flexDirection: "column",
gap: 2,
padding: 3,
width: "320px"
}}
>
{/* Render image */}
{image === "virto-thinking" && (
<VirtoThinking
sx={{
height: "150px",
width: "100%"
}}
/>
)}
{image === "virto-shrugging" && (
<VirtoShrugging
sx={{
height: "150px",
width: "100%"
}}
/>
)}
{image === "virto-head-scratching" && (
<VirtoHeadScratching
sx={{
height: "150px",
width: "100%"
}}
/>
)}
{/* Render the error title */}
<Typography
variant="h6"
sx={[
{
fontWeight: "600",
textAlign: "center"
},
theme => ({
color: theme.palette.error.main
})
]}
>
{title}
</Typography>
{/* Render the error message */}
<Typography
variant="body2"
sx={[
{
textAlign: "center"
},
theme => ({
color: theme.palette.text.primary,
...theme.applyStyles("dark", {
color: lighten(theme.palette.text.secondary, 0.7)
})
})
]}
>
{message}
</Typography>
{/* Render the action button if actionButtonText prop is provided */}
{actionButtonText && (
<Button variant="contained" size="small" onClick={onButtonClick}>
{actionButtonText}
</Button>
)}
{/* Render the error details if detailsVisible state is true */}
{detailsVisible && (
<>
{/* Render the "Hide More Details" text */}
<Typography
variant="body2"
sx={theme => ({
color: theme.palette.primary.main,
cursor: "pointer"
})}
onClick={handleDetailsClick}
>
Hide More Details
</Typography>
{/* Render the error details */}
<Alert severity="error" sx={{ alignItems: "center" }}>
{errorDetails}
</Alert>
</>
)}
{/* Render the "View More Details" text if errorDetails isn't empty and detailsVisible state is false */}
{errorDetails && !detailsVisible && (
<Typography
variant="body2"
sx={theme => ({
color: theme.palette.primary.main,
cursor: "pointer"
})}
onClick={handleDetailsClick}
>
View More Details
</Typography>
)}
{/* Render the contact team text */}
{contactTeam !== "none" ? (
<Typography
variant="caption"
sx={theme => ({
color: theme.palette.text.primary,
...theme.applyStyles("dark", {
color: lighten(theme.palette.text.secondary, 0.7)
})
})}
>
If this persists, contact {/* Render the contact team link */}
{contactUrl ? (
<Link href={contactUrl} target="_blank" rel="noopener noreferrer">
{contactTeam}
</Link>
) : (
<Typography variant="caption">{contactTeam}</Typography>
)}
</Typography>
) : null}
</Paper>
);
};
LoadErrorMessage.default404Props = {
contactTeam: "none",
image: "virto-shrugging",
message:
"We couldn't find the page you requested. It either does not exist or you may not have access to it.",
title: "Page not found!"
} as const;
LoadErrorMessage.defaultErrorProps = {
actionButtonText: "Refresh",
contactTeam: "Support",
contactUrl: "https://www.ipg-automotive.com/en/support/support-request/",
errorDetails: "Invalid token - length is 0",
image: "virto-head-scratching",
message:
"Oops! Something went wrong on our end 😓 Our team is actively addressing it and working to resolve the issue. Please try again later.",
title: "Something is not right!"
} as const;
export default LoadErrorMessage;