signal-desktop/ts/components/CallNeedPermissionScreen.tsx

79 lines
2 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 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 { LocalizerType } from '../types/Util';
import { Avatar } from './Avatar';
import { Intl } from './Intl';
import { ContactName } from './conversation/ContactName';
import { ConversationType } from '../state/ducks/conversations';
2020-10-01 19:09:15 +00:00
type Props = {
conversation: Pick<
ConversationType,
| 'acceptedMessageRequest'
| 'avatarPath'
| 'color'
| '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;
export const CallNeedPermissionScreen: React.FC<Props> = ({
conversation,
2020-10-01 19:09:15 +00:00
i18n,
close,
}) => {
const title = conversation.title || i18n('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}
color={conversation.color || 'ultramarine'}
2020-10-01 19:09:15 +00:00
noteToSelf={false}
conversationType="direct"
i18n={i18n}
name={conversation.name}
phoneNumber={conversation.phoneNumber}
profileName={conversation.profileName}
title={conversation.title}
2020-10-01 19:09:15 +00:00
size={112}
/>
<p className="module-call-need-permission-screen__text">
<Intl
i18n={i18n}
id="callNeedPermission"
components={[<ContactName i18n={i18n} title={title} />]}
/>
</p>
<button
type="button"
className="module-call-need-permission-screen__button"
onClick={() => {
close();
}}
>
{i18n('close')}
</button>
</div>
);
};