-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWarningInfo.tsx
More file actions
executable file
·87 lines (78 loc) · 2.32 KB
/
WarningInfo.tsx
File metadata and controls
executable file
·87 lines (78 loc) · 2.32 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
import React from "react";
import { useLocation } from "react-router-dom";
import { WarningInfoProps } from "./WarningInfo.types";
import { Main } from "../Main";
import { LinkWithRef } from "../LinkWithRef";
const WarningInfo: React.FC<WarningInfoProps> = ({
messageHeading = "Warning or Info Heading",
message = "Warning or Info Heading message",
advice = "Try again later.",
applicationName = "Document and plan retrieval system",
applicationRoute = "/",
basePageName = "dashboard",
}) => {
let determineMessage: string;
const { state } = useLocation();
if (state && state.message) {
determineMessage = state.message;
} else {
determineMessage = message;
}
let determineMessageHeading: string;
if (state && state.messageHeading) {
determineMessageHeading = state.messageHeading;
} else {
determineMessageHeading = messageHeading;
}
let determineAdvice: string;
if (state && state.advice) {
determineAdvice = state.advice;
} else {
determineAdvice = advice;
}
let determineApplicationName: string;
if (state && state.applicationName) {
determineApplicationName = state.applicationName;
} else {
determineApplicationName = applicationName;
}
const refreshPage = (): void => {
if (window.location.pathname === "/") {
window.location.reload();
}
};
const hasMessage = (): boolean => {
return determineMessage?.length > 0;
};
return (
<Main>
<>
<h1 className="govuk-heading-xl">{determineMessageHeading}</h1>
{hasMessage() && (
<div className="govuk-warning-text">
<span className="govuk-warning-text__icon" aria-hidden="true">
!
</span>
<strong className="govuk-warning-text__text">
<span className="govuk-visually-hidden">Warning</span>
{determineMessage}
</strong>
</div>
)}
<p className="govuk-body">{determineAdvice}</p>
<p className="govuk-body">
You can go back to{" "}
<LinkWithRef
className="govuk-link"
to={applicationRoute}
onClick={() => refreshPage()}
>
{determineApplicationName}
</LinkWithRef>{" "}
{basePageName}.
</p>
</>
</Main>
);
};
export default WarningInfo;