Skip to content

Commit 4edfe94

Browse files
committed
Create nicer layout for encryption page
1 parent 0a0453b commit 4edfe94

File tree

3 files changed

+105
-42
lines changed

3 files changed

+105
-42
lines changed

src/app/(authed)/encrypt/page.tsx

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,45 @@
1-
'use client'
1+
import { Box, Typography } from '@mui/material'
2+
import MessageLinkFooter from "@/common/ui/MessageLinkFooter"
3+
import { EncryptionForm } from "@/features/encrypt/view/EncryptionForm"
4+
import { env } from '@/common'
25

3-
import { useState } from 'react'
4-
import { encrypt } from './action'
5-
import { Box, Button, TextareaAutosize, Typography } from '@mui/material'
6-
7-
export default function EncryptPage() {
8-
const [inputText, setInputText] = useState('')
9-
const [encryptedText, setEncryptedText] = useState('')
10-
11-
const handleSubmit = async (event: React.FormEvent) => {
12-
event.preventDefault()
13-
const encrypted = await encrypt(inputText)
14-
setEncryptedText(encrypted)
15-
}
6+
const HELP_URL = env.getOrThrow("FRAMNA_DOCS_HELP_URL")
7+
const SITE_NAME = env.getOrThrow("FRAMNA_DOCS_TITLE")
168

9+
export default async function EncryptPage() {
1710
return (
1811
<Box
1912
display="flex"
20-
alignItems="center"
2113
justifyContent="center"
22-
flexDirection="column"
23-
height={1}
14+
alignItems="center"
2415
width={1}
25-
gap={6}
2616
>
27-
<Typography variant="h4">
28-
Encrypt text for remote config
29-
</Typography>
30-
<Typography variant="body1">
31-
Use this to encrypt values to be used in the configuration file.<br />
32-
The input text is encrypted using the public key of the server.
33-
</Typography>
34-
<form onSubmit={handleSubmit}>
35-
<TextareaAutosize
36-
value={inputText}
37-
onChange={(e) => setInputText(e.target.value)}
38-
cols={50}
39-
minRows={10}
40-
/>
41-
<br />
42-
<Button type="submit" variant="outlined"
43-
color="primary"
44-
size="large"
45-
sx={{ height: 56, width: 1 }}
46-
>Encrypt</Button>
47-
</form>
48-
{encryptedText && (
49-
<textarea readOnly value={encryptedText} rows={10} cols={50} />
50-
)}
17+
<Box
18+
display="flex"
19+
alignItems="center"
20+
flexDirection="column"
21+
gap={6}
22+
sx={{ width: '80%', maxWidth: '600px' }}
23+
>
24+
<Typography variant="h4">
25+
Encrypt secrets for remote config
26+
</Typography>
27+
<Typography sx={{ textAlign: "center" }}>
28+
When adding authentication information to remote specifications it
29+
is required to encrypt the authentication information with our public
30+
key before storing it in the repository.<br />
31+
<br />
32+
This page allows you to encrypt the secret using {SITE_NAME}{SITE_NAME.endsWith('s') ? "'" : "'s"}
33+
public key, which means only {SITE_NAME} can decrypt it.
34+
</Typography>
35+
<EncryptionForm />
36+
{HELP_URL &&
37+
<MessageLinkFooter
38+
url={HELP_URL}
39+
content="Need help? Explore our wiki for more info."
40+
/>
41+
}
42+
</Box>
5143
</Box>
5244
)
5345
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
'use client'
2+
3+
import { useState } from 'react'
4+
import { Box, Button, Snackbar, TextField, Tooltip } from '@mui/material'
5+
import { encrypt } from "./encryptAction"
6+
7+
export const EncryptionForm = () => {
8+
const [inputText, setInputText] = useState('')
9+
const [encryptedText, setEncryptedText] = useState('')
10+
const [openSnackbar, setOpenSnackbar] = useState(false)
11+
12+
const handleSubmit = async (event: React.FormEvent) => {
13+
event.preventDefault()
14+
const encrypted = await encrypt(inputText)
15+
setEncryptedText(encrypted)
16+
}
17+
18+
const handleCopy = () => {
19+
navigator.clipboard.writeText(encryptedText)
20+
setOpenSnackbar(true)
21+
}
22+
23+
const handleCloseSnackbar = () => {
24+
setOpenSnackbar(false)
25+
}
26+
27+
return <Box
28+
component="form"
29+
onSubmit={handleSubmit}
30+
display="flex"
31+
flexDirection="column"
32+
gap={2}
33+
alignItems="center"
34+
>
35+
<TextField
36+
value={inputText}
37+
onChange={(e) => setInputText(e.target.value)}
38+
multiline
39+
rows={8}
40+
variant="outlined"
41+
placeholder="Enter text to encrypt"
42+
sx={{ width: "300px" }}
43+
/>
44+
45+
<Button
46+
type="submit"
47+
variant="outlined"
48+
color="primary"
49+
size="large"
50+
sx={{ width: "300px" }}
51+
>Encrypt</Button>
52+
53+
<Tooltip title="Click to copy to clipboard">
54+
<TextField
55+
value={encryptedText}
56+
onClick={handleCopy}
57+
sx={{ input: { cursor: 'pointer' }, width: "300px" }}
58+
slotProps={{ input: { readOnly: true } }}
59+
placeholder="Encrypted text will appear here"
60+
/>
61+
</Tooltip>
62+
63+
<Snackbar
64+
open={openSnackbar}
65+
autoHideDuration={3000}
66+
onClose={handleCloseSnackbar}
67+
message="Copied to clipboard"
68+
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
69+
/>
70+
</Box>;
71+
}
File renamed without changes.

0 commit comments

Comments
 (0)