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

112 lines
2.8 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2018-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import classNames from 'classnames';
import { ContactName } from './ContactName';
import { Intl } from '../Intl';
2019-01-14 21:49:58 +00:00
import { LocalizerType } from '../../types/Util';
export type TimerNotificationType =
| 'fromOther'
| 'fromMe'
| 'fromSync'
| 'fromMember';
export type PropsData = {
type: TimerNotificationType;
2020-07-24 01:35:32 +00:00
phoneNumber?: string;
profileName?: string;
2020-07-24 01:35:32 +00:00
title: string;
name?: string;
disabled: boolean;
timespan: string;
};
type PropsHousekeeping = {
2019-01-14 21:49:58 +00:00
i18n: LocalizerType;
};
2020-08-26 00:41:43 +00:00
export type Props = PropsData & PropsHousekeeping;
export class TimerNotification extends React.Component<Props> {
2020-09-14 19:51:27 +00:00
public renderContents(): JSX.Element | string | null {
const {
i18n,
name,
phoneNumber,
profileName,
2020-07-24 01:35:32 +00:00
title,
timespan,
type,
disabled,
} = this.props;
2019-01-14 21:49:58 +00:00
const changeKey = disabled
? 'disabledDisappearingMessages'
: 'theyChangedTheTimer';
switch (type) {
case 'fromOther':
return (
<Intl
i18n={i18n}
2019-01-14 21:49:58 +00:00
id={changeKey}
components={{
name: (
<ContactName
key="external-1"
phoneNumber={phoneNumber}
profileName={profileName}
title={title}
name={name}
i18n={i18n}
/>
),
time: timespan,
}}
/>
);
case 'fromMe':
return disabled
? i18n('youDisabledDisappearingMessages')
: i18n('youChangedTheTimer', [timespan]);
case 'fromSync':
return disabled
? i18n('disappearingMessagesDisabled')
: i18n('timerSetOnSync', [timespan]);
2020-09-09 02:25:05 +00:00
case 'fromMember':
return disabled
? i18n('disappearingMessagesDisabledByMember')
: i18n('timerSetByMember', [timespan]);
default:
2020-09-14 19:51:27 +00:00
window.log.warn('TimerNotification: unsupported type provided:', type);
return null;
}
}
2020-09-14 19:51:27 +00:00
public render(): JSX.Element {
const { timespan, disabled } = this.props;
return (
<div className="module-timer-notification">
<div className="module-timer-notification__icon-container">
<div
className={classNames(
'module-timer-notification__icon',
disabled ? 'module-timer-notification__icon--disabled' : null
)}
/>
<div className="module-timer-notification__icon-label">
{timespan}
</div>
</div>
<div className="module-timer-notification__message">
{this.renderContents()}
</div>
</div>
);
}
}