blob: d0451dfad3535584147291ade60b388935a4d565 [file] [log] [blame]
Adrien Béraud35e7d7c2021-04-13 03:28:39 -04001import React from 'react';
Adrien Béraudab519ff2022-05-03 15:34:48 -04002import { useNavigate } from "react-router-dom";
Adrien Béraud35e7d7c2021-04-13 03:28:39 -04003
Adrien Béraudab519ff2022-05-03 15:34:48 -04004import { Box, Container, Fab, Card, CardContent, Typography } from '@mui/material';
5import GroupAddRounded from '@mui/icons-material/GroupAddRounded';
6import makeStyles from '@mui/styles/makeStyles';
Adrien Béraud35e7d7c2021-04-13 03:28:39 -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}))
19
20export default function AddContactPage(props) {
21 const classes = useStyles()
Adrien Béraudab519ff2022-05-03 15:34:48 -040022 const navigate = useNavigate();
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040023 const accountId = props.accountId || props.match.params.accountId
24 const contactId = props.contactId || props.match.params.contactId
25
26 const handleClick = async e => {
27 const response = await authManager.fetch(`/api/accounts/${accountId}/conversations`, {
28 method: 'POST',
29 headers: {
30 'Accept': 'application/json',
31 'Content-Type': 'application/json'
32 },
33 body: JSON.stringify({members:[contactId]})
34 }).then(res => res.json())
35
36 console.log(response)
37 if (response.conversationId) {
Adrien Béraudab519ff2022-05-03 15:34:48 -040038 navigate(`/account/${accountId}/conversation/${response.conversationId}`)
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040039 }
40 }
41
42 return (
Adrien Béraudabba2e52021-04-24 21:39:56 -040043 <Container className='messenger'>
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040044 <Card variant='outlined' style={{ borderRadius: 16, maxWidth: 560, margin: "16px auto" }}>
45 <CardContent>
46 <Typography variant='h6'>Jami key ID</Typography>
47 <Typography variant='body1'>{contactId}</Typography>
48 <Box style={{textAlign: 'center', marginTop: 16}}>
49 <Fab variant='extended' color='primary' onClick={handleClick}>
50 <GroupAddRounded className={classes.extendedIcon} />
51 Add contact
52 </Fab>
53 </Box>
54 </CardContent>
55 </Card>
56 </Container>)
57}