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

102 lines
2.9 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
import { AccessControlClass, MemberClass } from '../../textsecure.d';
export type PropsDataType = {
groupName?: string;
2020-09-09 02:25:05 +00:00
ourConversationId: string;
change: GroupV2ChangeType;
AccessControlEnum: typeof AccessControlClass.AccessRequired;
RoleEnum: typeof MemberClass.Role;
};
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 {
2020-09-09 02:25:05 +00:00
const {
AccessControlEnum,
change,
groupName,
2020-09-09 02:25:05 +00:00
i18n,
ourConversationId,
renderContact,
RoleEnum,
} = props;
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, {
AccessControlEnum,
i18n,
ourConversationId,
renderContact,
renderString: renderStringToIntl,
RoleEnum,
}).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>
);
}