blob: db5b1552e46ac355c9c2bf449b5b98129fb78513 [file] [log] [blame]
Adrien Béraude5cad982021-06-07 10:05:50 -04001import React, { useState } from 'react'
Adrien Béraudab519ff2022-05-03 15:34:48 -04002import { useNavigate } from "react-router-dom"
Adrien Béraude74741b2021-04-19 13:22:54 -04003
Adrien Béraudab519ff2022-05-03 15:34:48 -04004import { Box, Container, Fab, Card, CardContent, Typography, Input } from '@mui/material'
5import GroupAddRounded from '@mui/icons-material/GroupAddRounded'
6import { makeStyles } from '@mui/styles';
Adrien Béraude74741b2021-04-19 13:22:54 -04007import authManager from '../AuthManager'
8
9const useStyles = makeStyles((theme) => ({
10 root: {
11 '& > *': {
Adrien Béraudab519ff2022-05-03 15:34:48 -040012 //margin: theme.spacing(1),
Adrien Béraude74741b2021-04-19 13:22:54 -040013 },
14 },
15 extendedIcon: {
Adrien Béraudab519ff2022-05-03 15:34:48 -040016 //marginRight: theme.spacing(1),
Adrien Béraude74741b2021-04-19 13:22:54 -040017 },
18 wizardCard: {
19 borderRadius: 8,
20 maxWidth: 360,
21 margin: "16px auto"
Adrien Béraudab519ff2022-05-03 15:34:48 -040022 },
23 textField: {
24 //margin: theme.spacing(1),
Adrien Béraude74741b2021-04-19 13:22:54 -040025 }
26}))
27
28export default function ServerSetup(props) {
29 const classes = useStyles()
Adrien Béraudab519ff2022-05-03 15:34:48 -040030 const navigate = useNavigate()
Adrien Béraude5cad982021-06-07 10:05:50 -040031 const [password, setPassword] = useState('')
32 const [passwordRepeat, setPasswordRepeat] = useState('')
33 const [loading, setLoading] = useState(false)
Adrien Béraude74741b2021-04-19 13:22:54 -040034
35 const isValid = () => password && password === passwordRepeat
36
Adrien Béraude5cad982021-06-07 10:05:50 -040037 const handleSubmit = e => {
Adrien Béraude74741b2021-04-19 13:22:54 -040038 e.preventDefault()
Adrien Béraud150b4782021-04-21 19:40:59 -040039 setLoading(true)
Adrien Béraude74741b2021-04-19 13:22:54 -040040 if (!isValid())
41 return
Adrien Béraude5cad982021-06-07 10:05:50 -040042 authManager.setup(password)
Adrien Béraude74741b2021-04-19 13:22:54 -040043 }
44
45 return (
46 <Container className='message-list'>
Adrien Béraud150b4782021-04-21 19:40:59 -040047 <Card className={classes.wizardCard} disabled={loading}>
Adrien Béraude74741b2021-04-19 13:22:54 -040048 <CardContent component="form" onSubmit={handleSubmit}>
49 <Typography gutterBottom variant="h5" component="h2">
50 Jami Web Node setup
51 </Typography>
52 <Typography variant="body2" color="textSecondary" component="p">
53 Welcome to the Jami web node setup.<br/>
54 Let's start by creating a new administrator account to control access to the server configuration.
55 </Typography>
56
Adrien Béraud150b4782021-04-21 19:40:59 -040057 <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}>
Adrien Béraude74741b2021-04-19 13:22:54 -040058 <div><Input className={classes.textField} value="admin" name="username" autoComplete="username" disabled /></div>
59 <div><Input
60 className={classes.textField}
61 value={password}
62 onChange={e => setPassword(e.target.value)}
63 name="password"
64 type='password'
65 placeholder="New password"
66 autoComplete="new-password" />
67 </div>
68 <div><Input
69 className={classes.textField}
70 value={passwordRepeat}
71 onChange={e => setPasswordRepeat(e.target.value)}
72 name="password"
73 error={!!passwordRepeat && !isValid()}
74 type='password'
75 placeholder="Repeat password"
76 autoComplete="new-password" /></div>
Adrien Béraud150b4782021-04-21 19:40:59 -040077 </Box>
78 <Box style={{ textAlign: 'center', marginTop: 24 }}>
Adrien Béraude74741b2021-04-19 13:22:54 -040079 <Fab variant='extended' color='primary' type='submit' disabled={!isValid()}>
80 <GroupAddRounded className={classes.extendedIcon} />
81 Create admin account
82 </Fab>
83 </Box>
84 </CardContent>
85 </Card>
86 </Container>)
87}