blob: a4c32d7b890fd18bccb195226facb03cbeebf46f [file] [log] [blame]
Adrien Béraud35e7d7c2021-04-13 03:28:39 -04001import React from 'react';
2import { useHistory } from "react-router-dom";
3
4import { Box, Container, Fab, Card, CardContent, Typography } 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}))
19
20export default function AddContactPage(props) {
21 const classes = useStyles()
22 const history = useHistory();
23 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) {
38 history.push(`/account/${accountId}/conversation/${response.conversationId}`)
39 }
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}