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

126 lines
3.3 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 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;
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,
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={
<>
<p>{i18n('GroupV1--Migration--was-upgraded')}</p>
<p>
{areWeInvited ? (
i18n('GroupV1--Migration--invited--you')
) : (
<>
{renderUsers(
invitedMembers,
i18n,
'GroupV1--Migration--invited'
)}
{renderUsers(
droppedMembers,
i18n,
'GroupV1--Migration--removed'
)}
</>
)}
</p>
</>
}
button={
<Button
onClick={showDialog}
size={ButtonSize.Small}
variant={ButtonVariant.SystemMessage}
>
{i18n('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}
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,
keyPrefix: string
): React.ReactElement | null {
if (!members || members.length === 0) {
return null;
}
if (members.length === 1) {
return (
<p>
2020-11-20 17:30:45 +00:00
<Intl
i18n={i18n}
id={`${keyPrefix}--one`}
components={[<ContactName title={members[0].title} />]}
2020-11-20 17:30:45 +00:00
/>
</p>
2020-11-20 17:30:45 +00:00
);
}
return <p>{i18n(`${keyPrefix}--many`, [members.length.toString()])}</p>;
2020-11-20 17:30:45 +00:00
}