blob: 29e4ea57bcf2e0856362aa45fe3625ffe6d8d531 [file] [log] [blame]
Adrien Béraude74741b2021-04-19 13:22:54 -04001import React, { useState } from 'react';
2import { useHistory } from "react-router-dom";
3
4import { 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';
7import 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()
29 const history = useHistory();
30 const [password, setPassword] = useState('');
31 const [passwordRepeat, setPasswordRepeat] = useState('');
Adrien Béraud150b4782021-04-21 19:40:59 -040032 const [loading, setLoading] = useState(false);
Adrien Béraude74741b2021-04-19 13:22:54 -040033
34 const isValid = () => password && password === passwordRepeat
35
36 const handleSubmit = async e => {
37 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
41 if (await authManager.setup(password)) {
42 history.replace('/')
43 }
44 }
45
46 return (
47 <Container className='message-list'>
Adrien Béraud150b4782021-04-21 19:40:59 -040048 <Card className={classes.wizardCard} disabled={loading}>
Adrien Béraude74741b2021-04-19 13:22:54 -040049 <CardContent component="form" onSubmit={handleSubmit}>
50 <Typography gutterBottom variant="h5" component="h2">
51 Jami Web Node setup
52 </Typography>
53 <Typography variant="body2" color="textSecondary" component="p">
54 Welcome to the Jami web node setup.<br/>
55 Let's start by creating a new administrator account to control access to the server configuration.
56 </Typography>
57
Adrien Béraud150b4782021-04-21 19:40:59 -040058 <Box style={{ textAlign: 'center', marginTop: 8, marginBottom: 16 }}>
Adrien Béraude74741b2021-04-19 13:22:54 -040059 <div><Input className={classes.textField} value="admin" name="username" autoComplete="username" disabled /></div>
60 <div><Input
61 className={classes.textField}
62 value={password}
63 onChange={e => setPassword(e.target.value)}
64 name="password"
65 type='password'
66 placeholder="New password"
67 autoComplete="new-password" />
68 </div>
69 <div><Input
70 className={classes.textField}
71 value={passwordRepeat}
72 onChange={e => setPasswordRepeat(e.target.value)}
73 name="password"
74 error={!!passwordRepeat && !isValid()}
75 type='password'
76 placeholder="Repeat password"
77 autoComplete="new-password" /></div>
Adrien Béraud150b4782021-04-21 19:40:59 -040078 </Box>
79 <Box style={{ textAlign: 'center', marginTop: 24 }}>
Adrien Béraude74741b2021-04-19 13:22:54 -040080 <Fab variant='extended' color='primary' type='submit' disabled={!isValid()}>
81 <GroupAddRounded className={classes.extendedIcon} />
82 Create admin account
83 </Fab>
84 </Box>
85 </CardContent>
86 </Card>
87 </Container>)
88}