signal-desktop/ts/components/conversation/ChatSessionRefreshedNotification.tsx

71 lines
2 KiB
TypeScript
Raw Normal View History

2021-02-18 16:40:26 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ReactElement } from 'react';
import React, { useCallback, useState } from 'react';
2021-02-18 16:40:26 +00:00
import type { LocalizerType } from '../../types/Util';
2021-02-18 16:40:26 +00:00
2021-08-26 20:51:55 +00:00
import { Button, ButtonSize, ButtonVariant } from '../Button';
import { SystemMessage } from './SystemMessage';
2021-02-18 16:40:26 +00:00
import { ChatSessionRefreshedDialog } from './ChatSessionRefreshedDialog';
import { openLinkInWebBrowser } from '../../util/openLinkInWebBrowser';
import { mapToSupportLocale } from '../../util/mapToSupportLocale';
2021-02-18 16:40:26 +00:00
type PropsHousekeepingType = {
i18n: LocalizerType;
};
export type PropsType = PropsHousekeepingType;
2021-02-18 16:40:26 +00:00
export function ChatSessionRefreshedNotification(
props: PropsType
): ReactElement {
const { i18n } = props;
2021-02-18 16:40:26 +00:00
const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false);
const openDialog = useCallback(() => {
setIsDialogOpen(true);
}, [setIsDialogOpen]);
const closeDialog = useCallback(() => {
setIsDialogOpen(false);
}, [setIsDialogOpen]);
const wrappedContactSupport = useCallback(() => {
setIsDialogOpen(false);
const baseUrl =
'https://support.signal.org/hc/LOCALE/requests/new?desktop&chat_refreshed';
const locale = window.SignalContext.getResolvedMessagesLocale();
const supportLocale = mapToSupportLocale(locale);
const url = baseUrl.replace('LOCALE', supportLocale);
openLinkInWebBrowser(url);
}, [setIsDialogOpen]);
2021-02-18 16:40:26 +00:00
return (
<>
<SystemMessage
2023-03-30 00:03:25 +00:00
contents={i18n('icu:ChatRefresh--notification')}
button={
<Button
onClick={openDialog}
size={ButtonSize.Small}
variant={ButtonVariant.SystemMessage}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:ChatRefresh--learnMore')}
</Button>
}
icon="session-refresh"
/>
2021-02-18 16:40:26 +00:00
{isDialogOpen ? (
2021-05-28 19:11:19 +00:00
<ChatSessionRefreshedDialog
onClose={closeDialog}
contactSupport={wrappedContactSupport}
i18n={i18n}
/>
2021-02-18 16:40:26 +00:00
) : null}
</>
2021-02-18 16:40:26 +00:00
);
}