simon | 575c940 | 2022-10-25 16:21:40 -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 | */ |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 18 | import { Box, Stack, Typography } from '@mui/material'; |
idillon | 9e542ca | 2022-12-15 17:54:07 -0500 | [diff] [blame] | 19 | import dayjs from 'dayjs'; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 20 | import { IConversationSummary } from 'jami-web-common'; |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 21 | import { QRCodeCanvas } from 'qrcode.react'; |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 22 | import { useCallback, useContext, useMemo, useState } from 'react'; |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 23 | import { useTranslation } from 'react-i18next'; |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 24 | import { useNavigate } from 'react-router-dom'; |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 25 | |
simon | 5da8ca6 | 2022-11-09 15:21:25 -0500 | [diff] [blame] | 26 | import { useAuthContext } from '../contexts/AuthProvider'; |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 27 | import { CallManagerContext } from '../contexts/CallManagerProvider'; |
Michelle Sepkap Sime | c050d9c | 2022-12-05 09:39:34 -0500 | [diff] [blame] | 28 | import { CallStatus, useCallContext } from '../contexts/CallProvider'; |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 29 | import { useConversationDisplayNameShort } from '../hooks/useConversationDisplayName'; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 30 | import { useUrlParams } from '../hooks/useUrlParams'; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 31 | import { ConversationRouteParams } from '../router'; |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 32 | import { useRemoveConversationMutation } from '../services/conversationQueries'; |
idillon | 9e542ca | 2022-12-15 17:54:07 -0500 | [diff] [blame] | 33 | import { getMessageCallText, getMessageMemberText } from '../utils/chatmessages'; |
| 34 | import { formatRelativeDate, formatTime } from '../utils/dates×'; |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 35 | import ContextMenu, { ContextMenuHandler, useContextMenuHandler } from './ContextMenu'; |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 36 | import ConversationAvatar from './ConversationAvatar'; |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 37 | import { CustomListItemButton } from './CustomListItemButton'; |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 38 | import { ConfirmationDialog, DialogContentList, InfosDialog, useDialogHandler } from './Dialog'; |
| 39 | import { PopoverListItemData } from './PopoverList'; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 40 | import { AudioCallIcon, CancelIcon, MessageIcon, PersonIcon, VideoCallIcon } from './SvgIcon'; |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 41 | |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 42 | type ConversationListItemProps = { |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 43 | conversationSummary: IConversationSummary; |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 44 | }; |
| 45 | |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 46 | export default function ConversationListItem({ conversationSummary }: ConversationListItemProps) { |
idillon | 9e542ca | 2022-12-15 17:54:07 -0500 | [diff] [blame] | 47 | const { account } = useAuthContext(); |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 48 | const { |
| 49 | urlParams: { conversationId: selectedConversationId }, |
| 50 | } = useUrlParams<ConversationRouteParams>(); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 51 | const contextMenuHandler = useContextMenuHandler(); |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 52 | const navigate = useNavigate(); |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 53 | |
| 54 | const conversationId = conversationSummary.id; |
| 55 | const isSelected = conversationId === selectedConversationId; |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 56 | |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 57 | const onClick = useCallback(() => { |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 58 | if (conversationId) { |
| 59 | navigate(`/conversation/${conversationId}`); |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 60 | } |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 61 | }, [navigate, conversationId]); |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 62 | |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 63 | const conversationName = useConversationDisplayNameShort( |
| 64 | account, |
| 65 | conversationSummary.title, |
| 66 | conversationSummary.membersNames |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 67 | ); |
| 68 | |
| 69 | return ( |
| 70 | <Box> |
| 71 | <ConversationMenu |
| 72 | conversationId={conversationId} |
| 73 | conversationName={conversationName} |
| 74 | onMessageClick={onClick} |
| 75 | isSelected={isSelected} |
| 76 | contextMenuProps={contextMenuHandler.props} |
| 77 | /> |
| 78 | <CustomListItemButton |
| 79 | selected={isSelected} |
| 80 | onClick={onClick} |
| 81 | onContextMenu={contextMenuHandler.handleAnchorPosition} |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 82 | icon={<ConversationAvatar displayName={conversationName} src={conversationSummary.avatar} />} |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 83 | primaryText={<Typography variant="body1">{conversationName}</Typography>} |
| 84 | secondaryText={<SecondaryText conversationSummary={conversationSummary} isSelected={isSelected} />} |
| 85 | /> |
| 86 | </Box> |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | type SecondaryTextProps = { |
| 91 | conversationSummary: IConversationSummary; |
| 92 | isSelected: boolean; |
| 93 | }; |
| 94 | |
| 95 | const SecondaryText = ({ conversationSummary, isSelected }: SecondaryTextProps) => { |
| 96 | const { account } = useAuthContext(); |
| 97 | const callContext = useCallContext(true); |
| 98 | const { callData } = useContext(CallManagerContext); |
| 99 | const { t, i18n } = useTranslation(); |
| 100 | |
idillon | 9e542ca | 2022-12-15 17:54:07 -0500 | [diff] [blame] | 101 | const timeIndicator = useMemo(() => { |
| 102 | const message = conversationSummary.lastMessage; |
| 103 | const time = dayjs.unix(Number(message.timestamp)); |
| 104 | if (time.isToday()) { |
| 105 | return formatTime(time, i18n); |
| 106 | } else { |
| 107 | return formatRelativeDate(time, i18n); |
| 108 | } |
| 109 | }, [conversationSummary, i18n]); |
| 110 | |
| 111 | const lastMessageText = useMemo(() => { |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 112 | if (!callContext || !callData || callData.conversationId !== conversationSummary.id) { |
idillon | 9e542ca | 2022-12-15 17:54:07 -0500 | [diff] [blame] | 113 | const message = conversationSummary.lastMessage; |
| 114 | switch (message.type) { |
| 115 | case 'initial': { |
| 116 | return t('message_swarm_created'); |
| 117 | } |
| 118 | case 'application/data-transfer+json': { |
| 119 | return message.fileId; |
| 120 | } |
| 121 | case 'application/call-history+json': { |
| 122 | const isAccountMessage = message.author === account.getUri(); |
| 123 | return getMessageCallText(isAccountMessage, message, i18n); |
| 124 | } |
| 125 | case 'member': { |
| 126 | return getMessageMemberText(message, i18n); |
| 127 | } |
| 128 | case 'text/plain': { |
| 129 | return message.body; |
| 130 | } |
| 131 | default: { |
| 132 | console.error(`${ConversationListItem.name} received an unexpected lastMessage type: ${message.type}`); |
| 133 | return ''; |
| 134 | } |
| 135 | } |
Michelle Sepkap Sime | c050d9c | 2022-12-05 09:39:34 -0500 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | if (callContext.callStatus === CallStatus.InCall) { |
| 139 | return callContext.isAudioOn ? t('ongoing_call_unmuted') : t('ongoing_call_muted'); |
| 140 | } |
| 141 | |
| 142 | if (callContext.callStatus === CallStatus.Connecting) { |
| 143 | return t('connecting_call'); |
| 144 | } |
| 145 | |
| 146 | return callContext.callRole === 'caller' ? t('outgoing_call') : t('incoming_call'); |
idillon | 9e542ca | 2022-12-15 17:54:07 -0500 | [diff] [blame] | 147 | }, [account, conversationSummary, callContext, callData, t, i18n]); |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 148 | |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 149 | return ( |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 150 | <Stack direction="row" spacing="5px"> |
| 151 | <Typography variant="body2" fontWeight={isSelected ? 'bold' : 'normal'}> |
| 152 | {timeIndicator} |
| 153 | </Typography> |
| 154 | <Typography variant="body2">{lastMessageText}</Typography> |
| 155 | </Stack> |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 156 | ); |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 157 | }; |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 158 | |
| 159 | interface ConversationMenuProps { |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 160 | conversationId: string; |
| 161 | conversationName: string; |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 162 | onMessageClick: () => void; |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 163 | isSelected: boolean; |
| 164 | contextMenuProps: ContextMenuHandler['props']; |
| 165 | } |
| 166 | |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 167 | const ConversationMenu = ({ |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 168 | conversationId, |
| 169 | conversationName, |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 170 | onMessageClick, |
| 171 | isSelected, |
| 172 | contextMenuProps, |
| 173 | }: ConversationMenuProps) => { |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 174 | const { t } = useTranslation(); |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 175 | const { startCall } = useContext(CallManagerContext); |
simon | 416d079 | 2022-11-03 02:46:18 -0400 | [diff] [blame] | 176 | const [isSwarm] = useState(true); |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 177 | |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 178 | const detailsDialogHandler = useDialogHandler(); |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 179 | const RemoveConversationDialogHandler = useDialogHandler(); |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 180 | |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 181 | const navigate = useNavigate(); |
| 182 | |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 183 | const menuOptions: PopoverListItemData[] = useMemo( |
| 184 | () => [ |
| 185 | { |
| 186 | label: t('conversation_message'), |
| 187 | Icon: MessageIcon, |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 188 | onClick: onMessageClick, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 189 | }, |
| 190 | { |
| 191 | label: t('conversation_start_audiocall'), |
| 192 | Icon: AudioCallIcon, |
| 193 | onClick: () => { |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 194 | if (conversationId) { |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 195 | startCall({ |
| 196 | conversationId, |
| 197 | role: 'caller', |
| 198 | }); |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 199 | } |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 200 | }, |
| 201 | }, |
| 202 | { |
| 203 | label: t('conversation_start_videocall'), |
| 204 | Icon: VideoCallIcon, |
| 205 | onClick: () => { |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 206 | if (conversationId) { |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 207 | startCall({ |
| 208 | conversationId, |
| 209 | role: 'caller', |
| 210 | withVideoOn: true, |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 211 | }); |
| 212 | } |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 213 | }, |
| 214 | }, |
| 215 | ...(isSelected |
| 216 | ? [ |
| 217 | { |
| 218 | label: t('conversation_close'), |
| 219 | Icon: CancelIcon, |
| 220 | onClick: () => { |
| 221 | navigate(`/`); |
| 222 | }, |
| 223 | }, |
| 224 | ] |
| 225 | : []), |
| 226 | { |
| 227 | label: t('conversation_details'), |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 228 | Icon: PersonIcon, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 229 | onClick: () => { |
| 230 | detailsDialogHandler.openDialog(); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 231 | }, |
| 232 | }, |
| 233 | { |
| 234 | label: t('conversation_delete'), |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 235 | Icon: CancelIcon, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 236 | onClick: () => { |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 237 | RemoveConversationDialogHandler.openDialog(); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 238 | }, |
| 239 | }, |
| 240 | ], |
| 241 | [ |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 242 | navigate, |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 243 | onMessageClick, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 244 | isSelected, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 245 | detailsDialogHandler, |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 246 | RemoveConversationDialogHandler, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 247 | t, |
simon | ff1cb35 | 2022-11-24 15:15:26 -0500 | [diff] [blame] | 248 | startCall, |
| 249 | conversationId, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 250 | ] |
| 251 | ); |
simon | 575c940 | 2022-10-25 16:21:40 -0400 | [diff] [blame] | 252 | |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 253 | return ( |
| 254 | <> |
| 255 | <ContextMenu {...contextMenuProps} items={menuOptions} /> |
| 256 | |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 257 | <DetailsDialog |
| 258 | {...detailsDialogHandler.props} |
| 259 | conversationId={conversationId} |
| 260 | conversationName={conversationName} |
| 261 | isSwarm={isSwarm} |
| 262 | /> |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 263 | |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 264 | <RemoveConversationDialog |
| 265 | {...RemoveConversationDialogHandler.props} |
| 266 | conversationId={conversationId} |
| 267 | isSelected={isSelected} |
| 268 | /> |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 269 | </> |
| 270 | ); |
| 271 | }; |
| 272 | |
| 273 | interface DetailsDialogProps { |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 274 | conversationId: string; |
| 275 | conversationName: string; |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 276 | open: boolean; |
| 277 | onClose: () => void; |
| 278 | isSwarm: boolean; |
| 279 | } |
| 280 | |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 281 | const DetailsDialog = ({ conversationId, conversationName, open, onClose, isSwarm }: DetailsDialogProps) => { |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 282 | const { t } = useTranslation(); |
| 283 | const items = useMemo( |
| 284 | () => [ |
| 285 | { |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 286 | label: t('conversation_details_name'), |
| 287 | value: conversationName, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 288 | }, |
| 289 | { |
| 290 | label: t('conversation_details_identifier'), |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 291 | value: conversationId, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 292 | }, |
| 293 | { |
| 294 | label: t('conversation_details_qr_code'), |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 295 | value: <QRCodeCanvas size={80} value={`${conversationId}`} />, |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 296 | }, |
| 297 | { |
| 298 | label: t('conversation_details_is_swarm'), |
| 299 | value: isSwarm ? t('conversation_details_is_swarm_true') : t('conversation_details_is_swarm_false'), |
| 300 | }, |
| 301 | ], |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 302 | [conversationId, conversationName, isSwarm, t] |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 303 | ); |
| 304 | return ( |
| 305 | <InfosDialog |
| 306 | open={open} |
| 307 | onClose={onClose} |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 308 | icon={<ConversationAvatar sx={{ width: 'inherit', height: 'inherit' }} displayName={conversationName} />} |
| 309 | title={conversationName} |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 310 | content={<DialogContentList title={t('conversation_details_informations')} items={items} />} |
| 311 | /> |
| 312 | ); |
| 313 | }; |
| 314 | |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 315 | interface RemoveConversationDialogProps { |
| 316 | conversationId: string; |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 317 | isSelected: boolean; |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 318 | open: boolean; |
| 319 | onClose: () => void; |
| 320 | } |
| 321 | |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 322 | const RemoveConversationDialog = ({ conversationId, isSelected, open, onClose }: RemoveConversationDialogProps) => { |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 323 | const { t } = useTranslation(); |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 324 | const navigate = useNavigate(); |
| 325 | const removeConversationMutation = useRemoveConversationMutation(); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 326 | |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame^] | 327 | const remove = useCallback(async () => { |
| 328 | removeConversationMutation.mutate( |
| 329 | { conversationId }, |
| 330 | { |
| 331 | onSuccess: () => { |
| 332 | if (isSelected) { |
| 333 | navigate('/conversation/'); |
| 334 | } |
| 335 | }, |
| 336 | onError: (e) => { |
| 337 | console.error(`Error removing conversation : `, e); |
| 338 | }, |
| 339 | onSettled: () => { |
| 340 | onClose(); |
| 341 | }, |
| 342 | } |
| 343 | ); |
| 344 | }, [conversationId, isSelected, navigate, onClose, removeConversationMutation]); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 345 | |
| 346 | return ( |
| 347 | <ConfirmationDialog |
| 348 | open={open} |
| 349 | onClose={onClose} |
| 350 | title={t('dialog_confirm_title_default')} |
| 351 | content={t('conversation_ask_confirm_remove')} |
| 352 | onConfirm={remove} |
| 353 | confirmButtonText={t('conversation_confirm_remove')} |
| 354 | /> |
| 355 | ); |
| 356 | }; |