Skip to content

Commit f358605

Browse files
committed
Update users screens
1 parent d27bda1 commit f358605

File tree

15 files changed

+155
-121
lines changed

15 files changed

+155
-121
lines changed

resources/scripts/components/FlashMessageRender.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ const FlashMessageRender = ({ byKey, className }: Props) => {
1414
));
1515

1616
return (
17-
<div className={className}>
18-
{
19-
flashes.map((flash, index) => (
20-
<React.Fragment key={flash.id || flash.type + flash.message}>
21-
{index > 0 && <div css={tw`mt-2`}></div>}
22-
<MessageBox type={flash.type} title={flash.title}>
23-
{flash.message}
24-
</MessageBox>
25-
</React.Fragment>
26-
))
27-
}
28-
</div>
17+
flashes.length ?
18+
<div className={className}>
19+
{
20+
flashes.map((flash, index) => (
21+
<React.Fragment key={flash.id || flash.type + flash.message}>
22+
{index > 0 && <div css={tw`mt-2`}></div>}
23+
<MessageBox type={flash.type} title={flash.title}>
24+
{flash.message}
25+
</MessageBox>
26+
</React.Fragment>
27+
))
28+
}
29+
</div>
30+
:
31+
null
2932
);
3033
};
3134

resources/scripts/components/elements/Checkbox.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React from 'react';
22
import { Field, FieldProps } from 'formik';
3+
import Input from '@/components/elements/Input';
34

45
interface Props {
56
name: string;
67
value: string;
78
}
89

9-
type OmitFields = 'name' | 'value' | 'type' | 'checked' | 'onChange';
10+
type OmitFields = 'ref' | 'name' | 'value' | 'type' | 'checked' | 'onClick' | 'onChange';
1011

11-
type InputProps = Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, OmitFields>;
12+
type InputProps = Omit<JSX.IntrinsicElements['input'], OmitFields>;
1213

1314
const Checkbox = ({ name, value, ...props }: Props & InputProps) => (
1415
<Field name={name}>
@@ -20,7 +21,7 @@ const Checkbox = ({ name, value, ...props }: Props & InputProps) => (
2021
}
2122

2223
return (
23-
<input
24+
<Input
2425
{...field}
2526
{...props}
2627
type={'checkbox'}

resources/scripts/components/elements/DropdownMenu.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState } from 'react';
22
import { CSSTransition } from 'react-transition-group';
33
import styled from 'styled-components/macro';
44
import tw from 'twin.macro';
5+
import Fade from '@/components/elements/Fade';
56

67
interface Props {
78
children: React.ReactNode;
@@ -55,29 +56,25 @@ const DropdownMenu = ({ renderToggle, children }: Props) => {
5556

5657
return () => {
5758
document.removeEventListener('click', windowListener);
58-
}
59+
};
5960
}, [ visible ]);
6061

6162
return (
6263
<div>
6364
{renderToggle(onClickHandler)}
64-
<CSSTransition
65-
timeout={250}
66-
in={visible}
67-
unmountOnExit={true}
68-
classNames={'fade'}
69-
>
65+
<Fade timeout={250} in={visible} unmountOnExit>
7066
<div
7167
ref={menu}
7268
onClick={e => {
7369
e.stopPropagation();
7470
setVisible(false);
7571
}}
76-
className={'absolute bg-white p-2 rounded border border-neutral-700 shadow-lg text-neutral-500 min-w-48'}
72+
css={tw`absolute bg-white p-2 rounded border border-neutral-700 shadow-lg text-neutral-500`}
73+
style={{ minWidth: '12rem' }}
7774
>
7875
{children}
7976
</div>
80-
</CSSTransition>
77+
</Fade>
8178
</div>
8279
);
8380
};

resources/scripts/components/elements/Input.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ const light = css<Props>`
1616
}
1717
`;
1818

19+
const checkboxStyle = css<Props>`
20+
${tw`cursor-pointer appearance-none inline-block align-middle select-none flex-shrink-0 w-4 h-4 text-primary-400 border border-neutral-300 rounded-sm`};
21+
color-adjust: exact;
22+
background-origin: border-box;
23+
transition: all 75ms linear, box-shadow 25ms linear;
24+
25+
&:checked {
26+
${tw`border-transparent bg-no-repeat bg-center`};
27+
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M5.707 7.293a1 1 0 0 0-1.414 1.414l2 2a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0-1.414-1.414L7 8.586 5.707 7.293z'/%3e%3c/svg%3e");
28+
background-color: currentColor;
29+
background-size: 100% 100%;
30+
}
31+
32+
&:focus {
33+
${tw`outline-none border-primary-300`};
34+
box-shadow: 0 0 0 1px rgba(9, 103, 210, 0.25);
35+
}
36+
`;
37+
1938
const inputStyle = css<Props>`
2039
// Reset to normal styling.
2140
${tw`appearance-none w-full min-w-0`};
@@ -43,7 +62,19 @@ const inputStyle = css<Props>`
4362
${props => props.hasError && tw`text-red-600 border-red-500 hover:border-red-600`};
4463
`;
4564

46-
const Input = styled.input<Props>`${inputStyle}`;
65+
const Input = styled.input<Props>`
66+
&:not([type="checkbox"]):not([type="radio"]) {
67+
${inputStyle};
68+
}
69+
70+
&[type="checkbox"], &[type="radio"] {
71+
${checkboxStyle};
72+
73+
&[type="radio"] {
74+
${tw`rounded-full`};
75+
}
76+
}
77+
`;
4778
const Textarea = styled.textarea<Props>`${inputStyle}`;
4879

4980
export { Textarea };

resources/scripts/components/elements/Modal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const ModalMask = styled.div`
2727

2828
const ModalContainer = styled.div<{ alignTop?: boolean }>`
2929
${tw`relative flex flex-col w-full m-auto`};
30+
max-height: calc(100vh - 8rem);
3031
max-width: 50%;
3132
// @todo max-w-screen-lg perhaps?
3233
${props => props.alignTop && 'margin-top: 10%'};

resources/scripts/components/server/backups/BackupContainer.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import FlashMessageRender from '@/components/FlashMessageRender';
1010
import BackupRow from '@/components/server/backups/BackupRow';
1111
import { ServerContext } from '@/state/server';
1212
import PageContentBlock from '@/components/elements/PageContentBlock';
13+
import tw from 'twin.macro';
1314

1415
export default () => {
1516
const { uuid, featureLimits } = useServer();
@@ -31,22 +32,22 @@ export default () => {
3132
}, []);
3233

3334
if (backups.length === 0 && loading) {
34-
return <Spinner size={'large'} centered={true}/>;
35+
return <Spinner size={'large'} centered/>;
3536
}
3637

3738
return (
3839
<PageContentBlock>
39-
<FlashMessageRender byKey={'backups'} className={'mb-4'}/>
40+
<FlashMessageRender byKey={'backups'} css={tw`mb-4`}/>
4041
{!backups.length ?
41-
<p className="text-center text-sm text-neutral-400">
42+
<p css={tw`text-center text-sm text-neutral-400`}>
4243
There are no backups stored for this server.
4344
</p>
4445
:
4546
<div>
4647
{backups.map((backup, index) => <BackupRow
4748
key={backup.uuid}
4849
backup={backup}
49-
className={index !== (backups.length - 1) ? 'mb-2' : undefined}
50+
css={index > 0 ? tw`mt-2` : undefined}
5051
/>)}
5152
</div>
5253
}
@@ -57,12 +58,12 @@ export default () => {
5758
}
5859
<Can action={'backup.create'}>
5960
{(featureLimits.backups > 0 && backups.length > 0) &&
60-
<p className="text-center text-xs text-neutral-400 mt-2">
61+
<p css={tw`text-center text-xs text-neutral-400 mt-2`}>
6162
{backups.length} of {featureLimits.backups} backups have been created for this server.
6263
</p>
6364
}
6465
{featureLimits.backups > 0 && featureLimits.backups !== backups.length &&
65-
<div className={'mt-6 flex justify-end'}>
66+
<div css={tw`mt-6 flex justify-end`}>
6667
<CreateBackupButton/>
6768
</div>
6869
}

resources/scripts/components/server/backups/BackupContextMenu.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import deleteBackup from '@/api/server/backups/deleteBackup';
1616
import { ServerContext } from '@/state/server';
1717
import ConfirmationModal from '@/components/elements/ConfirmationModal';
1818
import Can from '@/components/elements/Can';
19+
import tw from 'twin.macro';
1920

2021
interface Props {
2122
backup: ServerBackup;
@@ -61,8 +62,8 @@ export default ({ backup }: Props) => {
6162
<>
6263
{visible &&
6364
<ChecksumModal
65+
appear
6466
visible={visible}
65-
appear={true}
6667
onDismissed={() => setVisible(false)}
6768
checksum={backup.sha256Hash}
6869
/>
@@ -84,27 +85,27 @@ export default ({ backup }: Props) => {
8485
renderToggle={onClick => (
8586
<button
8687
onClick={onClick}
87-
className={'text-neutral-200 transition-color duration-150 hover:text-neutral-100 p-2'}
88+
css={tw`text-neutral-200 transition-colors duration-150 hover:text-neutral-100 p-2`}
8889
>
8990
<FontAwesomeIcon icon={faEllipsisH}/>
9091
</button>
9192
)}
9293
>
93-
<div className={'text-sm'}>
94+
<div css={tw`text-sm`}>
9495
<Can action={'backup.download'}>
9596
<DropdownButtonRow onClick={() => doDownload()}>
96-
<FontAwesomeIcon fixedWidth={true} icon={faCloudDownloadAlt} className={'text-xs'}/>
97-
<span className={'ml-2'}>Download</span>
97+
<FontAwesomeIcon fixedWidth icon={faCloudDownloadAlt} css={tw`text-xs`}/>
98+
<span css={tw`ml-2`}>Download</span>
9899
</DropdownButtonRow>
99100
</Can>
100101
<DropdownButtonRow onClick={() => setVisible(true)}>
101-
<FontAwesomeIcon fixedWidth={true} icon={faLock} className={'text-xs'}/>
102-
<span className={'ml-2'}>Checksum</span>
102+
<FontAwesomeIcon fixedWidth icon={faLock} css={tw`text-xs`}/>
103+
<span css={tw`ml-2`}>Checksum</span>
103104
</DropdownButtonRow>
104105
<Can action={'backup.delete'}>
105-
<DropdownButtonRow danger={true} onClick={() => setDeleteVisible(true)}>
106-
<FontAwesomeIcon fixedWidth={true} icon={faTrashAlt} className={'text-xs'}/>
107-
<span className={'ml-2'}>Delete</span>
106+
<DropdownButtonRow danger onClick={() => setDeleteVisible(true)}>
107+
<FontAwesomeIcon fixedWidth icon={faTrashAlt} css={tw`text-xs`}/>
108+
<span css={tw`ml-2`}>Delete</span>
108109
</DropdownButtonRow>
109110
</Can>
110111
</div>

resources/scripts/components/server/backups/BackupRow.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import useWebsocketEvent from '@/plugins/useWebsocketEvent';
1010
import { ServerContext } from '@/state/server';
1111
import BackupContextMenu from '@/components/server/backups/BackupContextMenu';
1212
import { faEllipsisH } from '@fortawesome/free-solid-svg-icons/faEllipsisH';
13+
import tw from 'twin.macro';
14+
import GreyRowBox from '@/components/elements/GreyRowBox';
1315

1416
interface Props {
1517
backup: ServerBackup;
@@ -34,45 +36,45 @@ export default ({ backup, className }: Props) => {
3436
});
3537

3638
return (
37-
<div className={`grey-row-box flex items-center ${className}`}>
38-
<div className={'mr-4'}>
39+
<GreyRowBox css={tw`flex items-center`} className={className}>
40+
<div css={tw`mr-4`}>
3941
{backup.completedAt ?
40-
<FontAwesomeIcon icon={faArchive} className={'text-neutral-300'}/>
42+
<FontAwesomeIcon icon={faArchive} css={tw`text-neutral-300`}/>
4143
:
4244
<Spinner size={'small'}/>
4345
}
4446
</div>
45-
<div className={'flex-1'}>
46-
<p className={'text-sm mb-1'}>
47+
<div css={tw`flex-1`}>
48+
<p css={tw`text-sm mb-1`}>
4749
{backup.name}
4850
{backup.completedAt &&
49-
<span className={'ml-3 text-neutral-300 text-xs font-thin'}>{bytesToHuman(backup.bytes)}</span>
51+
<span css={tw`ml-3 text-neutral-300 text-xs font-thin`}>{bytesToHuman(backup.bytes)}</span>
5052
}
5153
</p>
52-
<p className={'text-xs text-neutral-400 font-mono'}>
54+
<p css={tw`text-xs text-neutral-400 font-mono`}>
5355
{backup.uuid}
5456
</p>
5557
</div>
56-
<div className={'ml-8 text-center'}>
58+
<div css={tw`ml-8 text-center`}>
5759
<p
58-
title={format(backup.createdAt, 'ddd, MMMM Do, YYYY HH:mm:ss Z')}
59-
className={'text-sm'}
60+
title={format(backup.createdAt, 'ddd, MMMM do, yyyy HH:mm:ss')}
61+
css={tw`text-sm`}
6062
>
6163
{formatDistanceToNow(backup.createdAt, { includeSeconds: true, addSuffix: true })}
6264
</p>
63-
<p className={'text-2xs text-neutral-500 uppercase mt-1'}>Created</p>
65+
<p css={tw`text-2xs text-neutral-500 uppercase mt-1`}>Created</p>
6466
</div>
6567
<Can action={'backup.download'}>
66-
<div className={'ml-6'} style={{ marginRight: '-0.5rem' }}>
68+
<div css={tw`ml-6`} style={{ marginRight: '-0.5rem' }}>
6769
{!backup.completedAt ?
68-
<div className={'p-2 invisible'}>
70+
<div css={tw`p-2 invisible`}>
6971
<FontAwesomeIcon icon={faEllipsisH}/>
7072
</div>
7173
:
7274
<BackupContextMenu backup={backup}/>
7375
}
7476
</div>
7577
</Can>
76-
</div>
78+
</GreyRowBox>
7779
);
7880
};

resources/scripts/components/server/backups/ChecksumModal.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React from 'react';
22
import Modal, { RequiredModalProps } from '@/components/elements/Modal';
3+
import tw from 'twin.macro';
34

45
const ChecksumModal = ({ checksum, ...props }: RequiredModalProps & { checksum: string }) => (
56
<Modal {...props}>
6-
<h3 className={'mb-6'}>Verify file checksum</h3>
7-
<p className={'text-sm'}>
7+
<h3 css={tw`mb-6`}>Verify file checksum</h3>
8+
<p css={tw`text-sm`}>
89
The SHA256 checksum of this file is:
910
</p>
10-
<pre className={'mt-2 text-sm p-2 bg-neutral-900 rounded'}>
11-
<code className={'block font-mono'}>{checksum}</code>
11+
<pre css={tw`mt-2 text-sm p-2 bg-neutral-900 rounded`}>
12+
<code css={tw`block font-mono`}>{checksum}</code>
1213
</pre>
1314
</Modal>
1415
);

0 commit comments

Comments
 (0)