Ziwei Wang | e8d7703 | 2023-01-11 15:57:38 -0500 | [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 | */ |
| 18 | import { ContactDetails as ContactDetailType } from 'jami-web-common'; |
| 19 | import { QRCodeCanvas } from 'qrcode.react'; |
| 20 | import { useTranslation } from 'react-i18next'; |
| 21 | |
| 22 | import ConversationAvatar from './ConversationAvatar'; |
| 23 | import { InfosDialog } from './Dialog'; |
| 24 | import { DialogContentList } from './Dialog'; |
| 25 | |
| 26 | interface ContactDetailDialogProps { |
Ziwei Wang | 046fb20 | 2023-01-17 18:27:17 -0500 | [diff] [blame] | 27 | contactDetail: ContactDetailType | undefined; |
Ziwei Wang | e8d7703 | 2023-01-11 15:57:38 -0500 | [diff] [blame] | 28 | open: boolean; |
| 29 | onClose: () => void; |
| 30 | } |
| 31 | |
| 32 | const ContactDetailDialog = ({ contactDetail, open, onClose }: ContactDetailDialogProps) => { |
| 33 | const { t } = useTranslation(); |
| 34 | const items = [ |
| 35 | { |
| 36 | label: t('contact_details_name'), |
Ziwei Wang | 046fb20 | 2023-01-17 18:27:17 -0500 | [diff] [blame] | 37 | value: contactDetail?.id, |
Ziwei Wang | e8d7703 | 2023-01-11 15:57:38 -0500 | [diff] [blame] | 38 | }, |
| 39 | { |
| 40 | label: t('contact_details_identifier'), |
Ziwei Wang | 046fb20 | 2023-01-17 18:27:17 -0500 | [diff] [blame] | 41 | value: contactDetail?.id, |
Ziwei Wang | e8d7703 | 2023-01-11 15:57:38 -0500 | [diff] [blame] | 42 | }, |
| 43 | { |
| 44 | label: t('contact_details_qr_code'), |
Ziwei Wang | 046fb20 | 2023-01-17 18:27:17 -0500 | [diff] [blame] | 45 | value: <QRCodeCanvas size={80} value={`${contactDetail?.id}`} />, |
Ziwei Wang | e8d7703 | 2023-01-11 15:57:38 -0500 | [diff] [blame] | 46 | }, |
| 47 | ]; |
| 48 | |
| 49 | return ( |
| 50 | <InfosDialog |
| 51 | open={open} |
| 52 | onClose={onClose} |
| 53 | icon={ |
| 54 | <ConversationAvatar |
| 55 | sx={{ width: 'inherit', height: 'inherit' }} |
Ziwei Wang | 046fb20 | 2023-01-17 18:27:17 -0500 | [diff] [blame] | 56 | displayName={contactDetail?.id || contactDetail?.id} |
Ziwei Wang | e8d7703 | 2023-01-11 15:57:38 -0500 | [diff] [blame] | 57 | /> |
| 58 | } |
Ziwei Wang | 046fb20 | 2023-01-17 18:27:17 -0500 | [diff] [blame] | 59 | title={contactDetail?.id || 'No contact selected'} |
Ziwei Wang | e8d7703 | 2023-01-11 15:57:38 -0500 | [diff] [blame] | 60 | content={<DialogContentList title={t('contact_details_dialog_title')} items={items} />} |
| 61 | /> |
| 62 | ); |
| 63 | }; |
| 64 | |
| 65 | export default ContactDetailDialog; |