// Copyright 2019-2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import * as React from 'react'; import { LocalizerType } from '../types/Util'; import { ConversationType } from '../state/ducks/conversations'; import { GroupDialog } from './GroupDialog'; import { sortByTitle } from '../util/sortByTitle'; type CallbackType = () => unknown; export type DataPropsType = { readonly areWeInvited: boolean; readonly droppedMembers: Array; readonly hasMigrated: boolean; readonly invitedMembers: Array; readonly migrate: CallbackType; readonly onClose: CallbackType; }; export type HousekeepingPropsType = { readonly i18n: LocalizerType; }; export type PropsType = DataPropsType & HousekeepingPropsType; export const GroupV1MigrationDialog: React.FunctionComponent = React.memo( (props: PropsType) => { const { areWeInvited, droppedMembers, hasMigrated, i18n, invitedMembers, migrate, onClose, } = props; const title = hasMigrated ? i18n('GroupV1--Migration--info--title') : i18n('GroupV1--Migration--migrate--title'); const keepHistory = hasMigrated ? i18n('GroupV1--Migration--info--keep-history') : i18n('GroupV1--Migration--migrate--keep-history'); const migrationKey = hasMigrated ? 'after' : 'before'; const droppedMembersKey = `GroupV1--Migration--info--removed--${migrationKey}`; let primaryButtonText: string; let onClickPrimaryButton: () => void; let secondaryButtonProps: | undefined | { secondaryButtonText: string; onClickSecondaryButton: () => void; }; if (hasMigrated) { primaryButtonText = i18n('Confirmation--confirm'); onClickPrimaryButton = onClose; } else { primaryButtonText = i18n('GroupV1--Migration--migrate'); onClickPrimaryButton = migrate; secondaryButtonProps = { secondaryButtonText: i18n('cancel'), onClickSecondaryButton: onClose, }; } return ( {i18n('GroupV1--Migration--info--summary')} {keepHistory} {areWeInvited ? ( {i18n('GroupV1--Migration--info--invited--you')} ) : ( <> {renderMembers( invitedMembers, 'GroupV1--Migration--info--invited', i18n )} {renderMembers(droppedMembers, droppedMembersKey, i18n)} )} ); } ); function renderMembers( members: Array, prefix: string, i18n: LocalizerType ): React.ReactNode { if (!members.length) { return null; } const postfix = members.length === 1 ? '--one' : '--many'; const key = `${prefix}${postfix}`; return ( <> {i18n(key)} ); }