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

169 lines
4.3 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';
2024-05-15 21:48:02 +00:00
import { I18n } from '../I18n';
2020-11-20 17:30:45 +00:00
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;
2024-04-30 13:24:21 +00:00
droppedMembers?: Array<ConversationType>;
invitedMembers?: Array<ConversationType>;
droppedMemberCount: number;
invitedMemberCount: number;
2020-11-20 17:30:45 +00:00
};
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,
droppedMembers,
2024-04-30 13:24:21 +00:00
droppedMemberCount,
2021-11-20 15:41:21 +00:00
getPreferredBadge,
i18n,
invitedMembers,
2024-04-30 13:24:21 +00:00
invitedMemberCount,
2021-11-20 15:41:21 +00:00
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>
2024-04-30 13:24:21 +00:00
{' '}
{areWeInvited ? (
2023-03-30 00:03:25 +00:00
i18n('icu:GroupV1--Migration--invited--you')
) : (
<>
2024-04-30 13:24:21 +00:00
{renderUsers({
members: invitedMembers,
count: invitedMemberCount,
i18n,
kind: 'invited',
})}
{renderUsers({
members: droppedMembers,
count: droppedMemberCount,
i18n,
kind: '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}
droppedMembers={droppedMembers}
2024-04-30 13:24:21 +00:00
droppedMemberCount={droppedMemberCount}
2021-11-20 15:41:21 +00:00
getPreferredBadge={getPreferredBadge}
2021-03-03 20:09:58 +00:00
hasMigrated
i18n={i18n}
invitedMembers={invitedMembers}
2024-04-30 13:24:21 +00:00
invitedMemberCount={invitedMemberCount}
onMigrate={() => 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
);
}
2024-04-30 13:24:21 +00:00
function renderUsers({
members,
count,
i18n,
kind,
}: {
members?: Array<ConversationType>;
count: number;
i18n: LocalizerType;
kind: 'invited' | 'removed';
}): React.ReactElement | null {
if (count === 0) {
2020-11-20 17:30:45 +00:00
return null;
}
2024-04-30 13:24:21 +00:00
if (members && count === 1) {
const contact = <ContactName title={members[0].title} />;
2020-11-20 17:30:45 +00:00
return (
<p>
{kind === 'invited' && (
2024-05-15 21:48:02 +00:00
<I18n
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:GroupV1--Migration--invited--one"
components={{ contact }}
/>
)}
{kind === 'removed' && (
2024-05-15 21:48:02 +00:00
<I18n
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
);
}
2023-03-27 23:37:39 +00:00
return (
<p>
2024-04-30 13:24:21 +00:00
{kind === 'invited' && (
2024-05-15 21:48:02 +00:00
<I18n
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:GroupV1--Migration--invited--many"
components={{ count }}
/>
)}
2024-04-30 13:24:21 +00:00
{kind === 'removed' && (
2024-05-15 21:48:02 +00:00
<I18n
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
}