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

87 lines
2.1 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';
import { missingCaseError } from '../../util/missingCaseError';
type Contact = {
2020-07-24 01:35:32 +00:00
phoneNumber?: string;
profileName?: string;
name?: string;
2020-07-24 01:35:32 +00:00
title: string;
};
export type PropsData = {
type: 'markVerified' | 'markNotVerified';
isLocal: boolean;
contact: Contact;
};
type PropsHousekeeping = {
2019-01-14 21:49:58 +00:00
i18n: LocalizerType;
};
export type Props = PropsData & PropsHousekeeping;
export class VerificationNotification extends React.Component<Props> {
2020-09-14 19:51:27 +00:00
public getStringId(): string {
const { isLocal, type } = this.props;
switch (type) {
case 'markVerified':
return isLocal
? 'youMarkedAsVerified'
: 'youMarkedAsVerifiedOtherDevice';
case 'markNotVerified':
return isLocal
? 'youMarkedAsNotVerified'
: 'youMarkedAsNotVerifiedOtherDevice';
default:
throw missingCaseError(type);
}
}
2020-09-14 19:51:27 +00:00
public renderContents(): JSX.Element {
const { contact, i18n } = this.props;
const id = this.getStringId();
return (
2021-08-26 20:51:55 +00:00
<div className="SystemMessage__text">
<Intl
id={id}
components={[
<ContactName
key="external-1"
name={contact.name}
profileName={contact.profileName}
phoneNumber={contact.phoneNumber}
title={contact.title}
module="module-verification-notification__contact"
i18n={i18n}
/>,
]}
i18n={i18n}
/>
</div>
);
}
2020-09-14 19:51:27 +00:00
public render(): JSX.Element {
const { type } = this.props;
2021-08-26 20:51:55 +00:00
const suffix = type === 'markVerified' ? 'verified' : 'verified-not';
return (
2021-08-26 20:51:55 +00:00
<div className="SystemMessage">
<div className={`SystemMessage__icon SystemMessage__icon--${suffix}`} />
{this.renderContents()}
</div>
);
}
}