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

136 lines
3.9 KiB
TypeScript
Raw Normal View History

2020-05-27 21:37:06 +00:00
import * as React from 'react';
import classNames from 'classnames';
import { ContactName, Props as ContactNameProps } from './ContactName';
import {
MessageRequestActionsConfirmation,
MessageRequestState,
Props as MessageRequestActionsConfirmationProps,
} from './MessageRequestActionsConfirmation';
import { Intl } from '../Intl';
import { LocalizerType } from '../../types/Util';
export type Props = {
i18n: LocalizerType;
onAccept(): unknown;
2020-07-24 01:35:32 +00:00
} & Omit<ContactNameProps, 'module' | 'i18n'> &
2020-05-27 21:37:06 +00:00
Omit<
MessageRequestActionsConfirmationProps,
'i18n' | 'state' | 'onChangeState'
>;
2020-07-24 01:35:32 +00:00
// tslint:disable-next-line max-func-body-length
2020-05-27 21:37:06 +00:00
export const MessageRequestActions = ({
i18n,
name,
profileName,
phoneNumber,
2020-07-24 01:35:32 +00:00
title,
2020-05-27 21:37:06 +00:00
conversationType,
isBlocked,
onBlock,
onBlockAndDelete,
onUnblock,
onDelete,
onAccept,
}: Props) => {
const [mrState, setMrState] = React.useState(MessageRequestState.default);
return (
<>
{mrState !== MessageRequestState.default ? (
<MessageRequestActionsConfirmation
i18n={i18n}
onBlock={onBlock}
onBlockAndDelete={onBlockAndDelete}
onUnblock={onUnblock}
onDelete={onDelete}
name={name}
profileName={profileName}
phoneNumber={phoneNumber}
2020-07-24 01:35:32 +00:00
title={title}
2020-05-27 21:37:06 +00:00
conversationType={conversationType}
state={mrState}
onChangeState={setMrState}
/>
) : null}
<div className="module-message-request-actions">
<p className="module-message-request-actions__message">
<Intl
i18n={i18n}
id={`MessageRequests--message-${conversationType}${
isBlocked ? '-blocked' : ''
}`}
components={[
<strong
key="name"
className="module-message-request-actions__message__name"
>
<ContactName
name={name}
profileName={profileName}
phoneNumber={phoneNumber}
2020-07-24 01:35:32 +00:00
title={title}
i18n={i18n}
2020-05-27 21:37:06 +00:00
/>
</strong>,
]}
/>
</p>
<div className="module-message-request-actions__buttons">
{isBlocked ? (
<button
onClick={() => {
setMrState(MessageRequestState.unblocking);
}}
tabIndex={0}
className={classNames(
'module-message-request-actions__buttons__button',
'module-message-request-actions__buttons__button--accept'
)}
>
{i18n('MessageRequests--unblock')}
</button>
) : (
<button
onClick={() => {
setMrState(MessageRequestState.blocking);
}}
tabIndex={0}
className={classNames(
'module-message-request-actions__buttons__button',
'module-message-request-actions__buttons__button--deny'
)}
>
{i18n('MessageRequests--block')}
</button>
)}
<button
onClick={() => {
setMrState(MessageRequestState.deleting);
}}
tabIndex={0}
className={classNames(
'module-message-request-actions__buttons__button',
'module-message-request-actions__buttons__button--deny'
)}
>
{i18n('MessageRequests--delete')}
</button>
{!isBlocked ? (
<button
onClick={onAccept}
tabIndex={0}
className={classNames(
'module-message-request-actions__buttons__button',
'module-message-request-actions__buttons__button--accept'
)}
>
{i18n('MessageRequests--accept')}
</button>
) : null}
</div>
</div>
</>
);
};