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

150 lines
3.9 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-11-20 17:30:45 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react';
2021-08-26 20:51:55 +00:00
import { Button, ButtonSize, ButtonVariant } from '../Button';
import { SystemMessage } from './SystemMessage';
2021-11-20 15:41:21 +00:00
import type { LocalizerType, ThemeType } from '../../types/Util';
import type { ConversationType } from '../../state/ducks/conversations';
2021-11-20 15:41:21 +00:00
import type { PreferredBadgeSelectorType } from '../../state/selectors/badges';
2020-11-20 17:30:45 +00:00
import { Intl } from '../Intl';
import { ContactName } from './ContactName';
import { GroupV1MigrationDialog } from '../GroupV1MigrationDialog';
import * as log from '../../logging/log';
2020-11-20 17:30:45 +00:00
export type PropsDataType = {
areWeInvited: boolean;
2022-12-08 06:41:37 +00:00
conversationId: string;
2020-11-20 17:30:45 +00:00
droppedMembers: Array<ConversationType>;
invitedMembers: Array<ConversationType>;
};
export type PropsHousekeepingType = {
2021-11-20 15:41:21 +00:00
getPreferredBadge: PreferredBadgeSelectorType;
2020-11-20 17:30:45 +00:00
i18n: LocalizerType;
2021-11-20 15:41:21 +00:00
theme: ThemeType;
2020-11-20 17:30:45 +00:00
};
export type PropsType = PropsDataType & PropsHousekeepingType;
export function GroupV1Migration(props: PropsType): React.ReactElement {
2021-11-20 15:41:21 +00:00
const {
areWeInvited,
2022-12-08 06:41:37 +00:00
conversationId,
2021-11-20 15:41:21 +00:00
droppedMembers,
getPreferredBadge,
i18n,
invitedMembers,
theme,
} = props;
2020-11-20 17:30:45 +00:00
const [showingDialog, setShowingDialog] = React.useState(false);
const showDialog = React.useCallback(() => {
setShowingDialog(true);
}, [setShowingDialog]);
const dismissDialog = React.useCallback(() => {
setShowingDialog(false);
}, [setShowingDialog]);
return (
<>
<SystemMessage
icon="group"
contents={
<>
2023-03-30 00:03:25 +00:00
<p>{i18n('icu:GroupV1--Migration--was-upgraded')}</p>
<p>
{areWeInvited ? (
2023-03-30 00:03:25 +00:00
i18n('icu:GroupV1--Migration--invited--you')
) : (
<>
{renderUsers(invitedMembers, i18n, 'invited')}
{renderUsers(droppedMembers, i18n, 'removed')}
</>
)}
</p>
</>
}
button={
<Button
onClick={showDialog}
size={ButtonSize.Small}
variant={ButtonVariant.SystemMessage}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:GroupV1--Migration--learn-more')}
</Button>
}
/>
2020-11-20 17:30:45 +00:00
{showingDialog ? (
2021-03-03 20:09:58 +00:00
<GroupV1MigrationDialog
areWeInvited={areWeInvited}
2022-12-08 06:41:37 +00:00
conversationId={conversationId}
2021-03-03 20:09:58 +00:00
droppedMembers={droppedMembers}
2021-11-20 15:41:21 +00:00
getPreferredBadge={getPreferredBadge}
2021-03-03 20:09:58 +00:00
hasMigrated
i18n={i18n}
invitedMembers={invitedMembers}
migrate={() => log.warn('GroupV1Migration: Modal called migrate()')}
2021-03-03 20:09:58 +00:00
onClose={dismissDialog}
2021-11-20 15:41:21 +00:00
theme={theme}
2021-03-03 20:09:58 +00:00
/>
2020-11-20 17:30:45 +00:00
) : null}
</>
2020-11-20 17:30:45 +00:00
);
}
function renderUsers(
members: Array<ConversationType>,
i18n: LocalizerType,
kind: 'invited' | 'removed'
2020-11-20 17:30:45 +00:00
): React.ReactElement | null {
if (!members || members.length === 0) {
return null;
}
if (members.length === 1) {
const contact = <ContactName title={members[0].title} />;
2020-11-20 17:30:45 +00:00
return (
<p>
{kind === 'invited' && (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:GroupV1--Migration--invited--one"
components={{ contact }}
/>
)}
{kind === 'removed' && (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:GroupV1--Migration--removed--one"
components={{ contact }}
/>
)}
</p>
2020-11-20 17:30:45 +00:00
);
}
const count = members.length.toString();
2023-03-27 23:37:39 +00:00
return (
<p>
{kind === 'invited' && members.length > 1 && (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:GroupV1--Migration--invited--many"
components={{ count }}
/>
)}
{kind === 'removed' && members.length > 1 && (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:GroupV1--Migration--removed--many"
components={{ count }}
/>
)}
2023-03-27 23:37:39 +00:00
</p>
);
2020-11-20 17:30:45 +00:00
}