blob: fb7e4bb165282b8741a5c7ebdba4ce0ef2c501e1 [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
simon07b4eb02022-09-29 17:50:26 -040018import GroupAddRounded from '@mui/icons-material/GroupAddRounded';
19import { Box, Card, CardContent, Container, Fab, Typography } from '@mui/material';
Misha Krieger-Raynauldcfa44302022-11-30 18:36:36 -050020import { ContactDetails } from 'jami-web-common';
simon4e7445c2022-11-16 21:18:46 -050021import { useTranslation } from 'react-i18next';
simon5da8ca62022-11-09 15:21:25 -050022import { useNavigate } from 'react-router-dom';
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040023
simon5da8ca62022-11-09 15:21:25 -050024import { useAuthContext } from '../contexts/AuthProvider';
simond8ca2f22022-10-11 23:30:55 -040025import { setRefreshFromSlice } from '../redux/appSlice';
26import { useAppDispatch } from '../redux/hooks';
ervinanoh34eb9472022-09-13 04:20:28 -040027
simonfe1de722022-10-02 00:21:43 -040028type AddContactPageProps = {
simonfe1de722022-10-02 00:21:43 -040029 contactId: string;
30};
31
simon5da8ca62022-11-09 15:21:25 -050032export default function AddContactPage({ contactId }: AddContactPageProps) {
simon4e7445c2022-11-16 21:18:46 -050033 const { t } = useTranslation();
simon94fe53e2022-11-10 12:51:58 -050034 const { axiosInstance } = useAuthContext();
Adrien Béraudab519ff2022-05-03 15:34:48 -040035 const navigate = useNavigate();
simonfe1de722022-10-02 00:21:43 -040036
ervinanoh34eb9472022-09-13 04:20:28 -040037 const dispatch = useAppDispatch();
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040038
simonfe1de722022-10-02 00:21:43 -040039 const handleClick = async () => {
Misha Krieger-Raynauldcfa44302022-11-30 18:36:36 -050040 const { data } = await axiosInstance.put<ContactDetails>(`/contacts/${contactId}`);
simon94fe53e2022-11-10 12:51:58 -050041 dispatch(setRefreshFromSlice());
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040042
simon94fe53e2022-11-10 12:51:58 -050043 if (data.conversationId) {
44 navigate(`/conversation/${data.conversationId}`);
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040045 }
simond47ef9e2022-09-28 22:24:28 -040046 };
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040047
48 return (
simond47ef9e2022-09-28 22:24:28 -040049 <Container className="messenger">
50 <Card variant="outlined" style={{ borderRadius: 16, maxWidth: 560, margin: '16px auto' }}>
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040051 <CardContent>
simond47ef9e2022-09-28 22:24:28 -040052 <Typography variant="h6">Jami key ID</Typography>
53 <Typography variant="body1">{contactId}</Typography>
54 <Box style={{ textAlign: 'center', marginTop: 16 }}>
55 <Fab variant="extended" color="primary" onClick={handleClick}>
56 <GroupAddRounded />
simon4e7445c2022-11-16 21:18:46 -050057 {t('conversation_add_contact')}
simond47ef9e2022-09-28 22:24:28 -040058 </Fab>
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040059 </Box>
60 </CardContent>
61 </Card>
simond47ef9e2022-09-28 22:24:28 -040062 </Container>
63 );
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040064}