Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 1 | import React from 'react'; |
| 2 | import { useHistory } from "react-router-dom"; |
| 3 | |
| 4 | import { Box, Container, Fab, Card, CardContent, Typography } from '@material-ui/core'; |
| 5 | import GroupAddRounded from '@material-ui/icons/GroupAddRounded'; |
| 6 | import { makeStyles } from '@material-ui/core/styles'; |
| 7 | import authManager from '../AuthManager' |
| 8 | |
| 9 | const useStyles = makeStyles((theme) => ({ |
| 10 | root: { |
| 11 | '& > *': { |
| 12 | margin: theme.spacing(1), |
| 13 | }, |
| 14 | }, |
| 15 | extendedIcon: { |
| 16 | marginRight: theme.spacing(1), |
| 17 | }, |
| 18 | })) |
| 19 | |
| 20 | export 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éraud | abba2e5 | 2021-04-24 21:39:56 -0400 | [diff] [blame] | 43 | <Container className='messenger'> |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 44 | <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 | } |