blob: d431568e34f5e5119ea4d29d9e9a31100f085e32 [file] [log] [blame]
Adrien Béraude5cad982021-06-07 10:05:50 -04001import React, { useState } from 'react'
Adrien Béraude74741b2021-04-19 13:22:54 -04002
Adrien Béraudab519ff2022-05-03 15:34:48 -04003import { Box, Container, Fab, Card, CardContent, Typography, Input } from '@mui/material'
4import GroupAddRounded from '@mui/icons-material/GroupAddRounded'
5import { makeStyles } from '@mui/styles';
Adrien Béraude74741b2021-04-19 13:22:54 -04006import authManager from '../AuthManager'
7
8const useStyles = makeStyles((theme) => ({
9 root: {
10 '& > *': {
Adrien Béraudab519ff2022-05-03 15:34:48 -040011 //margin: theme.spacing(1),
Adrien Béraude74741b2021-04-19 13:22:54 -040012 },
13 },
Adrien Béraude74741b2021-04-19 13:22:54 -040014 wizardCard: {
15 borderRadius: 8,
16 maxWidth: 360,
17 margin: "16px auto"
Adrien Béraudab519ff2022-05-03 15:34:48 -040018 },
Adrien Béraude74741b2021-04-19 13:22:54 -040019}))
20
21export default function ServerSetup(props) {
22 const classes = useStyles()
Adrien Béraude5cad982021-06-07 10:05:50 -040023 const [password, setPassword] = useState('')
24 const [passwordRepeat, setPasswordRepeat] = useState('')
25 const [loading, setLoading] = useState(false)
Adrien Béraude74741b2021-04-19 13:22:54 -040026
27 const isValid = () => password && password === passwordRepeat
28
Adrien Béraude5cad982021-06-07 10:05:50 -040029 const handleSubmit = e => {
Adrien Béraude74741b2021-04-19 13:22:54 -040030 e.preventDefault()
Adrien Béraud150b4782021-04-21 19:40:59 -040031 setLoading(true)
Adrien Béraude74741b2021-04-19 13:22:54 -040032 if (!isValid())
33 return
Adrien Béraude5cad982021-06-07 10:05:50 -040034 authManager.setup(password)
Adrien Béraude74741b2021-04-19 13:22:54 -040035 }
36
37 return (
38 <Container className='message-list'>
Adrien Béraud150b4782021-04-21 19:40:59 -040039 <Card className={classes.wizardCard} disabled={loading}>
Adrien Béraude74741b2021-04-19 13:22:54 -040040 <CardContent component="form" onSubmit={handleSubmit}>
41 <Typography gutterBottom variant="h5" component="h2">
42 Jami Web Node setup
43 </Typography>
44 <Typography variant="body2" color="textSecondary" component="p">
45 Welcome to the Jami web node setup.<br/>
46 Let's start by creating a new administrator account to control access to the server configuration.
47 </Typography>
48
Adrien Béraud150b4782021-04-21 19:40:59 -040049 <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}>
Adrien Béraude74741b2021-04-19 13:22:54 -040050 <div><Input className={classes.textField} value="admin" name="username" autoComplete="username" disabled /></div>
51 <div><Input
52 className={classes.textField}
53 value={password}
54 onChange={e => setPassword(e.target.value)}
55 name="password"
56 type='password'
57 placeholder="New password"
58 autoComplete="new-password" />
59 </div>
60 <div><Input
61 className={classes.textField}
62 value={passwordRepeat}
63 onChange={e => setPasswordRepeat(e.target.value)}
64 name="password"
65 error={!!passwordRepeat && !isValid()}
66 type='password'
67 placeholder="Repeat password"
68 autoComplete="new-password" /></div>
Adrien Béraud150b4782021-04-21 19:40:59 -040069 </Box>
70 <Box style={{ textAlign: 'center', marginTop: 24 }}>
Adrien Béraude74741b2021-04-19 13:22:54 -040071 <Fab variant='extended' color='primary' type='submit' disabled={!isValid()}>
72 <GroupAddRounded className={classes.extendedIcon} />
73 Create admin account
74 </Fab>
75 </Box>
76 </CardContent>
77 </Card>
78 </Container>)
79}