blob: 703f842eeb8ad2deecf25ab1de37acc147b906bd [file] [log] [blame]
Adrien Béraude5cad982021-06-07 10:05:50 -04001import React, { useState } from 'react'
2import { useHistory } from "react-router-dom"
Adrien Béraude74741b2021-04-19 13:22:54 -04003
Adrien Béraude5cad982021-06-07 10:05:50 -04004import { Box, Container, Fab, Card, CardContent, Typography, Input } from '@material-ui/core'
5import GroupAddRounded from '@material-ui/icons/GroupAddRounded'
6import { makeStyles } from '@material-ui/core/styles'
Adrien Béraude74741b2021-04-19 13:22:54 -04007import authManager from '../AuthManager'
8
9const useStyles = makeStyles((theme) => ({
10 root: {
11 '& > *': {
12 margin: theme.spacing(1),
13 },
14 },
15 extendedIcon: {
16 marginRight: theme.spacing(1),
17 },
18 wizardCard: {
19 borderRadius: 8,
20 maxWidth: 360,
21 margin: "16px auto"
22 }, textField: {
23 margin: theme.spacing(1),
24 }
25}))
26
27export default function ServerSetup(props) {
28 const classes = useStyles()
Adrien Béraude5cad982021-06-07 10:05:50 -040029 const history = useHistory()
30 const [password, setPassword] = useState('')
31 const [passwordRepeat, setPasswordRepeat] = useState('')
32 const [loading, setLoading] = useState(false)
Adrien Béraude74741b2021-04-19 13:22:54 -040033
34 const isValid = () => password && password === passwordRepeat
35
Adrien Béraude5cad982021-06-07 10:05:50 -040036 const handleSubmit = e => {
Adrien Béraude74741b2021-04-19 13:22:54 -040037 e.preventDefault()
Adrien Béraud150b4782021-04-21 19:40:59 -040038 setLoading(true)
Adrien Béraude74741b2021-04-19 13:22:54 -040039 if (!isValid())
40 return
Adrien Béraude5cad982021-06-07 10:05:50 -040041 authManager.setup(password)
Adrien Béraude74741b2021-04-19 13:22:54 -040042 }
43
44 return (
45 <Container className='message-list'>
Adrien Béraud150b4782021-04-21 19:40:59 -040046 <Card className={classes.wizardCard} disabled={loading}>
Adrien Béraude74741b2021-04-19 13:22:54 -040047 <CardContent component="form" onSubmit={handleSubmit}>
48 <Typography gutterBottom variant="h5" component="h2">
49 Jami Web Node setup
50 </Typography>
51 <Typography variant="body2" color="textSecondary" component="p">
52 Welcome to the Jami web node setup.<br/>
53 Let's start by creating a new administrator account to control access to the server configuration.
54 </Typography>
55
Adrien Béraud150b4782021-04-21 19:40:59 -040056 <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}>
Adrien Béraude74741b2021-04-19 13:22:54 -040057 <div><Input className={classes.textField} value="admin" name="username" autoComplete="username" disabled /></div>
58 <div><Input
59 className={classes.textField}
60 value={password}
61 onChange={e => setPassword(e.target.value)}
62 name="password"
63 type='password'
64 placeholder="New password"
65 autoComplete="new-password" />
66 </div>
67 <div><Input
68 className={classes.textField}
69 value={passwordRepeat}
70 onChange={e => setPasswordRepeat(e.target.value)}
71 name="password"
72 error={!!passwordRepeat && !isValid()}
73 type='password'
74 placeholder="Repeat password"
75 autoComplete="new-password" /></div>
Adrien Béraud150b4782021-04-21 19:40:59 -040076 </Box>
77 <Box style={{ textAlign: 'center', marginTop: 24 }}>
Adrien Béraude74741b2021-04-19 13:22:54 -040078 <Fab variant='extended' color='primary' type='submit' disabled={!isValid()}>
79 <GroupAddRounded className={classes.extendedIcon} />
80 Create admin account
81 </Fab>
82 </Box>
83 </CardContent>
84 </Card>
85 </Container>)
86}