Skip to content

Commit 1c01173

Browse files
itsrachelfishellemouton
authored andcommitted
ui+common: SubServerRequired component
1 parent a54fe4d commit 1c01173

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

app/src/assets/icons/plug.svg

Lines changed: 3 additions & 0 deletions
Loading

app/src/components/base/icons.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ import { ReactComponent as CancelIcon } from 'assets/icons/slash.svg';
3232
import { ReactComponent as UserPlusIcon } from 'assets/icons/user-plus.svg';
3333
import { ReactComponent as QRCodeIcon } from 'assets/icons/qr.svg';
3434
import { ReactComponent as BoltOutlinedIcon } from 'assets/icons/bolt-outlined.svg';
35+
import { ReactComponent as PlugIcon } from 'assets/icons/plug.svg';
3536

3637
interface IconProps {
37-
size?: 'x-small' | 'small' | 'medium' | 'large';
38+
size?: 'x-small' | 'small' | 'medium' | 'large' | 'x-large';
3839
onClick?: () => void;
3940
disabled?: boolean;
4041
}
@@ -51,7 +52,7 @@ const Icon = styled.span<IconProps>`
5152
cursor: pointer;
5253
&:hover {
5354
color: ${props.theme.colors.blue};
54-
background-color: ${props.theme.colors.offWhite};
55+
background-color: ${props.theme.colors.offWhite};
5556
}
5657
`}
5758
@@ -88,6 +89,13 @@ const Icon = styled.span<IconProps>`
8889
width: 36px;
8990
height: 36px;
9091
`}
92+
93+
${props =>
94+
props.size === 'x-large' &&
95+
`
96+
width: 48px;
97+
height: 48px;
98+
`}
9199
`;
92100

93101
export const AlertTriangle = Icon.withComponent(AlertTriangleIcon);
@@ -123,3 +131,4 @@ export const BarChart = Icon.withComponent(BarChartIcon);
123131
export const List = Icon.withComponent(ListIcon);
124132
export const QRCode = Icon.withComponent(QRCodeIcon);
125133
export const BoltOutlined = Icon.withComponent(BoltOutlinedIcon);
134+
export const Plug = Icon.withComponent(PlugIcon);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import React from 'react';
2+
import styled from '@emotion/styled';
3+
import { usePrefixedTranslation } from 'hooks';
4+
import { Plug } from '../base';
5+
import { SubServerStatus } from 'types/state';
6+
7+
const Styled = {
8+
Wrapper: styled.div`
9+
min-height: 100vh;
10+
display: flex;
11+
align-items: center;
12+
justify-content: center;
13+
`,
14+
StatusMessage: styled.div`
15+
display: inline-block;
16+
border-radius: 24px;
17+
padding: 3px 16px 3px 6px;
18+
font-size: ${props => props.theme.sizes.s};
19+
color: ${props => props.theme.colors.lightningGray};
20+
font-weight: 600;
21+
white-space: nowrap;
22+
text-align: center;
23+
24+
svg {
25+
margin-bottom: 16px;
26+
color: ${props => props.theme.colors.gold};
27+
}
28+
`,
29+
Error: styled.div`
30+
font-weight: bold;
31+
`,
32+
};
33+
34+
interface StatusProps {
35+
isDisabled: boolean;
36+
errorMessage?: string;
37+
}
38+
39+
export const SubServerStatusMessage: React.FC<StatusProps> = ({
40+
isDisabled,
41+
errorMessage,
42+
}) => {
43+
const { l } = usePrefixedTranslation('cmps.common.SubServerStatus');
44+
const { Wrapper, StatusMessage, Error } = Styled;
45+
return (
46+
<Wrapper>
47+
<StatusMessage>
48+
<Plug size="x-large" />
49+
50+
{isDisabled ? (
51+
<p>{l('isDisabled')}</p>
52+
) : (
53+
<>
54+
<p>{l('isError')}</p>
55+
<Error>{errorMessage}</Error>
56+
</>
57+
)}
58+
</StatusMessage>
59+
</Wrapper>
60+
);
61+
};
62+
63+
interface Props {
64+
status: SubServerStatus;
65+
}
66+
67+
const SubServerRequired: React.FC<Props> = ({ status, children }) => {
68+
if (status.disabled) {
69+
return <SubServerStatusMessage isDisabled />;
70+
} else if (status.error) {
71+
return <SubServerStatusMessage isDisabled={false} errorMessage={status.error} />;
72+
}
73+
74+
return <>{children}</>;
75+
};
76+
77+
export default SubServerRequired;

app/src/i18n/locales/en-US.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
"cmps.common.PageHeader.exportTip": "Download CSV",
3232
"cmps.common.PageHeader.helpTip": "Take a Tour",
3333
"cmps.common.Wizard.backTip": "Back to Previous",
34+
"cmps.common.SubServerStatus.isDisabled": "This subserver is turned off so this interface is not accessible.",
35+
"cmps.common.SubServerStatus.isError": "This subserver encountered an error and failed to start up.",
36+
"cmps.common.SubServerStatus.isNotRunning": "The {{name}} subserver is not running so this interface is not accessible.",
3437
"cmps.connect.AddSession.create": "Create a new session",
3538
"cmps.connect.AddSession.label": "Label",
3639
"cmps.connect.AddSession.permissions": "Permissions",

0 commit comments

Comments
 (0)