| 
									
										
										
										
											2021-02-18 08:40:26 -08:00
										 |  |  | // Copyright 2021 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import React, { useCallback, useState, ReactElement } from 'react'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { LocalizerType } from '../../types/Util'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-26 16:51:55 -04:00
										 |  |  | import { Button, ButtonSize, ButtonVariant } from '../Button'; | 
					
						
							| 
									
										
										
										
											2021-09-07 14:55:03 -05:00
										 |  |  | import { SystemMessage } from './SystemMessage'; | 
					
						
							| 
									
										
										
										
											2021-02-18 08:40:26 -08:00
										 |  |  | import { ChatSessionRefreshedDialog } from './ChatSessionRefreshedDialog'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type PropsHousekeepingType = { | 
					
						
							|  |  |  |   i18n: LocalizerType; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export type PropsActionsType = { | 
					
						
							|  |  |  |   contactSupport: () => unknown; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export type PropsType = PropsHousekeepingType & PropsActionsType; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function ChatSessionRefreshedNotification( | 
					
						
							|  |  |  |   props: PropsType | 
					
						
							|  |  |  | ): ReactElement { | 
					
						
							|  |  |  |   const { contactSupport, i18n } = props; | 
					
						
							|  |  |  |   const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const openDialog = useCallback(() => { | 
					
						
							|  |  |  |     setIsDialogOpen(true); | 
					
						
							|  |  |  |   }, [setIsDialogOpen]); | 
					
						
							|  |  |  |   const closeDialog = useCallback(() => { | 
					
						
							|  |  |  |     setIsDialogOpen(false); | 
					
						
							|  |  |  |   }, [setIsDialogOpen]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const wrappedContactSupport = useCallback(() => { | 
					
						
							|  |  |  |     setIsDialogOpen(false); | 
					
						
							|  |  |  |     contactSupport(); | 
					
						
							|  |  |  |   }, [contactSupport, setIsDialogOpen]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2021-09-07 14:55:03 -05:00
										 |  |  |     <> | 
					
						
							|  |  |  |       <SystemMessage | 
					
						
							|  |  |  |         contents={i18n('ChatRefresh--notification')} | 
					
						
							|  |  |  |         button={ | 
					
						
							|  |  |  |           <Button | 
					
						
							|  |  |  |             onClick={openDialog} | 
					
						
							|  |  |  |             size={ButtonSize.Small} | 
					
						
							|  |  |  |             variant={ButtonVariant.SystemMessage} | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             {i18n('ChatRefresh--learnMore')} | 
					
						
							|  |  |  |           </Button> | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         icon="session-refresh" | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2021-02-18 08:40:26 -08:00
										 |  |  |       {isDialogOpen ? ( | 
					
						
							| 
									
										
										
										
											2021-05-28 12:11:19 -07:00
										 |  |  |         <ChatSessionRefreshedDialog | 
					
						
							|  |  |  |           onClose={closeDialog} | 
					
						
							|  |  |  |           contactSupport={wrappedContactSupport} | 
					
						
							|  |  |  |           i18n={i18n} | 
					
						
							|  |  |  |         /> | 
					
						
							| 
									
										
										
										
											2021-02-18 08:40:26 -08:00
										 |  |  |       ) : null} | 
					
						
							| 
									
										
										
										
											2021-09-07 14:55:03 -05:00
										 |  |  |     </> | 
					
						
							| 
									
										
										
										
											2021-02-18 08:40:26 -08:00
										 |  |  |   ); | 
					
						
							|  |  |  | } |