simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 18 | import GroupAddRounded from '@mui/icons-material/GroupAddRounded'; |
| 19 | import { Box, Card, CardContent, Container, Fab, Typography } from '@mui/material'; |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 20 | import { ContactDetails } from 'jami-web-common'; |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 21 | import { useTranslation } from 'react-i18next'; |
simon | 5da8ca6 | 2022-11-09 15:21:25 -0500 | [diff] [blame] | 22 | import { useNavigate } from 'react-router-dom'; |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 23 | |
simon | 5da8ca6 | 2022-11-09 15:21:25 -0500 | [diff] [blame] | 24 | import { useAuthContext } from '../contexts/AuthProvider'; |
simon | d8ca2f2 | 2022-10-11 23:30:55 -0400 | [diff] [blame] | 25 | import { setRefreshFromSlice } from '../redux/appSlice'; |
| 26 | import { useAppDispatch } from '../redux/hooks'; |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 27 | |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 28 | type AddContactPageProps = { |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 29 | contactId: string; |
| 30 | }; |
| 31 | |
simon | 5da8ca6 | 2022-11-09 15:21:25 -0500 | [diff] [blame] | 32 | export default function AddContactPage({ contactId }: AddContactPageProps) { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 33 | const { t } = useTranslation(); |
simon | 94fe53e | 2022-11-10 12:51:58 -0500 | [diff] [blame] | 34 | const { axiosInstance } = useAuthContext(); |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 35 | const navigate = useNavigate(); |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 36 | |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 37 | const dispatch = useAppDispatch(); |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 38 | |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 39 | const handleClick = async () => { |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 40 | const { data } = await axiosInstance.put<ContactDetails>(`/contacts/${contactId}`); |
simon | 94fe53e | 2022-11-10 12:51:58 -0500 | [diff] [blame] | 41 | dispatch(setRefreshFromSlice()); |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 42 | |
simon | 94fe53e | 2022-11-10 12:51:58 -0500 | [diff] [blame] | 43 | if (data.conversationId) { |
| 44 | navigate(`/conversation/${data.conversationId}`); |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 45 | } |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 46 | }; |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 47 | |
| 48 | return ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 49 | <Container className="messenger"> |
| 50 | <Card variant="outlined" style={{ borderRadius: 16, maxWidth: 560, margin: '16px auto' }}> |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 51 | <CardContent> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 52 | <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 /> |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 57 | {t('conversation_add_contact')} |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 58 | </Fab> |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 59 | </Box> |
| 60 | </CardContent> |
| 61 | </Card> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 62 | </Container> |
| 63 | ); |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 64 | } |