signal-desktop/ts/components/CallNeedPermissionScreen.tsx

85 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-10-01 19:09:15 +00:00
import React, { useRef, useEffect } from 'react';
import type { LocalizerType } from '../types/Util';
2021-08-06 00:17:05 +00:00
import { AvatarColors } from '../types/Colors';
2022-12-09 20:37:45 +00:00
import { Avatar, AvatarSize } from './Avatar';
2020-10-01 19:09:15 +00:00
import { Intl } from './Intl';
import { ContactName } from './conversation/ContactName';
import type { ConversationType } from '../state/ducks/conversations';
2020-10-01 19:09:15 +00:00
type Props = {
conversation: Pick<
ConversationType,
| 'acceptedMessageRequest'
| 'avatarPath'
| 'color'
2021-05-07 22:21:10 +00:00
| 'isMe'
| 'name'
| 'phoneNumber'
| 'profileName'
| 'sharedGroupNames'
| 'title'
| 'unblurredAvatarPath'
>;
2020-10-01 19:09:15 +00:00
i18n: LocalizerType;
close: () => void;
};
2020-10-01 19:09:15 +00:00
const AUTO_CLOSE_MS = 10000;
2022-11-18 00:45:19 +00:00
export function CallNeedPermissionScreen({
conversation,
2020-10-01 19:09:15 +00:00
i18n,
close,
2022-11-18 00:45:19 +00:00
}: Props): JSX.Element {
2023-03-30 00:03:25 +00:00
const title = conversation.title || i18n('icu:unknownContact');
2020-10-01 19:09:15 +00:00
const autoCloseAtRef = useRef<number>(Date.now() + AUTO_CLOSE_MS);
useEffect(() => {
const timeout = setTimeout(close, autoCloseAtRef.current - Date.now());
return clearTimeout.bind(null, timeout);
}, [autoCloseAtRef, close]);
return (
<div className="module-call-need-permission-screen">
<Avatar
acceptedMessageRequest={conversation.acceptedMessageRequest}
avatarPath={conversation.avatarPath}
badge={undefined}
2021-08-06 00:17:05 +00:00
color={conversation.color || AvatarColors[0]}
2020-10-01 19:09:15 +00:00
noteToSelf={false}
conversationType="direct"
i18n={i18n}
2021-05-07 22:21:10 +00:00
isMe={conversation.isMe}
phoneNumber={conversation.phoneNumber}
profileName={conversation.profileName}
title={conversation.title}
2021-05-07 22:21:10 +00:00
sharedGroupNames={conversation.sharedGroupNames}
2022-12-09 20:37:45 +00:00
size={AvatarSize.EIGHTY}
2020-10-01 19:09:15 +00:00
/>
<p className="module-call-need-permission-screen__text">
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:callNeedPermission"
2023-03-27 23:37:39 +00:00
components={{
title: <ContactName title={title} />,
}}
2020-10-01 19:09:15 +00:00
/>
</p>
<button
type="button"
className="module-call-need-permission-screen__button"
onClick={() => {
close();
}}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:close')}
2020-10-01 19:09:15 +00:00
</button>
</div>
);
2022-11-18 00:45:19 +00:00
}