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

88 lines
2.7 KiB
TypeScript
Raw Normal View History

2021-06-17 17:15:51 +00:00
// Copyright 2020-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { ReactElement, useState } from 'react';
2020-09-09 02:25:05 +00:00
import { ReplacementValuesType } from '../../types/I18N';
import { FullJSXType, Intl } from '../Intl';
import { LocalizerType } from '../../types/Util';
2021-06-17 17:15:51 +00:00
import { GroupDescriptionText } from '../GroupDescriptionText';
import { Button, ButtonSize, ButtonVariant } from '../Button';
2020-09-09 02:25:05 +00:00
import { GroupV2ChangeType, GroupV2DescriptionChangeType } from '../../groups';
2020-09-09 02:25:05 +00:00
import { renderChange, SmartContactRendererType } from '../../groupChange';
import { Modal } from '../Modal';
2020-09-09 02:25:05 +00:00
export type PropsDataType = {
groupName?: string;
2020-09-09 02:25:05 +00:00
ourConversationId: string;
change: GroupV2ChangeType;
};
export type PropsHousekeepingType = {
i18n: LocalizerType;
renderContact: SmartContactRendererType;
};
export type PropsType = PropsDataType & PropsHousekeepingType;
function renderStringToIntl(
id: string,
i18n: LocalizerType,
components?: Array<FullJSXType> | ReplacementValuesType<FullJSXType>
): FullJSXType {
return <Intl id={id} i18n={i18n} components={components} />;
}
export function GroupV2Change(props: PropsType): ReactElement {
2021-07-09 19:36:10 +00:00
const { change, groupName, i18n, ourConversationId, renderContact } = props;
2020-09-09 02:25:05 +00:00
const [
isGroupDescriptionDialogOpen,
setIsGroupDescriptionDialogOpen,
] = useState<boolean>(false);
2021-06-17 17:15:51 +00:00
const newGroupDescription = change.details.find(
(item): item is GroupV2DescriptionChangeType =>
Boolean(item.type === 'description' && item.description)
2021-06-17 17:15:51 +00:00
)?.description;
2020-09-09 02:25:05 +00:00
return (
<div className="module-group-v2-change">
<div className="module-group-v2-change--icon" />
{renderChange(change, {
i18n,
ourConversationId,
renderContact,
renderString: renderStringToIntl,
}).map((item: FullJSXType, index: number) => (
2020-09-14 19:51:27 +00:00
// Difficult to find a unique key for this type
// eslint-disable-next-line react/no-array-index-key
2020-09-09 02:25:05 +00:00
<div key={index}>{item}</div>
))}
2021-06-17 17:15:51 +00:00
{newGroupDescription ? (
<div className="module-group-v2-change--button-container">
<Button
size={ButtonSize.Small}
variant={ButtonVariant.SecondaryAffirmative}
onClick={() => setIsGroupDescriptionDialogOpen(true)}
>
{i18n('view')}
</Button>
</div>
) : null}
2021-06-17 17:15:51 +00:00
{newGroupDescription && isGroupDescriptionDialogOpen ? (
<Modal
hasXButton
i18n={i18n}
title={groupName}
onClose={() => setIsGroupDescriptionDialogOpen(false)}
>
2021-06-17 17:15:51 +00:00
<GroupDescriptionText text={newGroupDescription} />
</Modal>
) : null}
2020-09-09 02:25:05 +00:00
</div>
);
}