blob: 702b01d35cac82f26c2c77a1620b5bf2f721b131 [file] [log] [blame]
Adrien Béraudab519ff2022-05-03 15:34:48 -04001import { useNavigate } from "react-router-dom";
Adrien Béraud35e7d7c2021-04-13 03:28:39 -04002
Adrien Béraudab519ff2022-05-03 15:34:48 -04003import { Box, Container, Fab, Card, CardContent, Typography } from '@mui/material';
4import GroupAddRounded from '@mui/icons-material/GroupAddRounded';
Adrien Béraud35e7d7c2021-04-13 03:28:39 -04005import authManager from '../AuthManager'
ervinanoh34eb9472022-09-13 04:20:28 -04006import { useAppDispatch } from '../../redux/hooks';
7import { setRefreshFromSlice } from '../../redux/appSlice';
8
Adrien Béraud35e7d7c2021-04-13 03:28:39 -04009
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040010export default function AddContactPage(props) {
Adrien Béraudab519ff2022-05-03 15:34:48 -040011 const navigate = useNavigate();
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040012 const accountId = props.accountId || props.match.params.accountId
13 const contactId = props.contactId || props.match.params.contactId
ervinanoh34eb9472022-09-13 04:20:28 -040014 const dispatch = useAppDispatch();
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040015
16 const handleClick = async e => {
17 const response = await authManager.fetch(`/api/accounts/${accountId}/conversations`, {
18 method: 'POST',
19 headers: {
20 'Accept': 'application/json',
21 'Content-Type': 'application/json'
22 },
23 body: JSON.stringify({members:[contactId]})
ervinanoh34eb9472022-09-13 04:20:28 -040024 }).then(res => {
25 dispatch(setRefreshFromSlice())
26 return res.json()
27 })
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040028
29 console.log(response)
30 if (response.conversationId) {
Adrien Béraudab519ff2022-05-03 15:34:48 -040031 navigate(`/account/${accountId}/conversation/${response.conversationId}`)
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040032 }
33 }
34
35 return (
Adrien Béraudabba2e52021-04-24 21:39:56 -040036 <Container className='messenger'>
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040037 <Card variant='outlined' style={{ borderRadius: 16, maxWidth: 560, margin: "16px auto" }}>
38 <CardContent>
39 <Typography variant='h6'>Jami key ID</Typography>
40 <Typography variant='body1'>{contactId}</Typography>
41 <Box style={{textAlign: 'center', marginTop: 16}}>
42 <Fab variant='extended' color='primary' onClick={handleClick}>
idillonfb2af5b2022-09-16 13:40:08 -040043 <GroupAddRounded/>
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040044 Add contact
45 </Fab>
46 </Box>
47 </CardContent>
48 </Card>
49 </Container>)
50}