2020-11-20 17:30:45 +00:00
|
|
|
// Copyright 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 { Intl } from '../Intl';
|
|
|
|
import { ContactName } from './ContactName';
|
|
|
|
import { GroupV1MigrationDialog } from '../GroupV1MigrationDialog';
|
|
|
|
|
|
|
|
export type PropsDataType = {
|
2020-12-01 23:45:39 +00:00
|
|
|
areWeInvited: boolean;
|
2020-11-20 17:30:45 +00:00
|
|
|
droppedMembers: Array<ConversationType>;
|
|
|
|
invitedMembers: Array<ConversationType>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsHousekeepingType = {
|
|
|
|
i18n: LocalizerType;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsType = PropsDataType & PropsHousekeepingType;
|
|
|
|
|
|
|
|
export function GroupV1Migration(props: PropsType): React.ReactElement {
|
2020-12-01 23:45:39 +00:00
|
|
|
const { areWeInvited, droppedMembers, i18n, invitedMembers } = 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 (
|
|
|
|
<div className="module-group-v1-migration">
|
|
|
|
<div className="module-group-v1-migration--icon" />
|
|
|
|
<div className="module-group-v1-migration--text">
|
|
|
|
{i18n('GroupV1--Migration--was-upgraded')}
|
|
|
|
</div>
|
2020-12-01 23:45:39 +00:00
|
|
|
{areWeInvited ? (
|
|
|
|
<div className="module-group-v1-migration--text">
|
|
|
|
{i18n('GroupV1--Migration--invited--you')}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{renderUsers(invitedMembers, i18n, 'GroupV1--Migration--invited')}
|
|
|
|
{renderUsers(droppedMembers, i18n, 'GroupV1--Migration--removed')}
|
|
|
|
</>
|
|
|
|
)}
|
2020-11-20 17:30:45 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="module-group-v1-migration--button"
|
|
|
|
onClick={showDialog}
|
|
|
|
>
|
|
|
|
{i18n('GroupV1--Migration--learn-more')}
|
|
|
|
</button>
|
|
|
|
{showingDialog ? (
|
2021-03-03 20:09:58 +00:00
|
|
|
<GroupV1MigrationDialog
|
|
|
|
areWeInvited={areWeInvited}
|
|
|
|
droppedMembers={droppedMembers}
|
|
|
|
hasMigrated
|
|
|
|
i18n={i18n}
|
|
|
|
invitedMembers={invitedMembers}
|
|
|
|
migrate={() =>
|
|
|
|
window.log.warn('GroupV1Migration: Modal called migrate()')
|
|
|
|
}
|
|
|
|
onClose={dismissDialog}
|
|
|
|
/>
|
2020-11-20 17:30:45 +00:00
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderUsers(
|
|
|
|
members: Array<ConversationType>,
|
|
|
|
i18n: LocalizerType,
|
|
|
|
keyPrefix: string
|
|
|
|
): React.ReactElement | null {
|
|
|
|
if (!members || members.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const className = 'module-group-v1-migration--text';
|
|
|
|
|
|
|
|
if (members.length === 1) {
|
|
|
|
return (
|
|
|
|
<div className={className}>
|
|
|
|
<Intl
|
|
|
|
i18n={i18n}
|
|
|
|
id={`${keyPrefix}--one`}
|
|
|
|
components={[<ContactName title={members[0].title} i18n={i18n} />]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={className}>
|
|
|
|
{i18n(`${keyPrefix}--many`, [members.length.toString()])}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|