Support for creating New Groups
This commit is contained in:
parent
1934120e46
commit
5de4babc0d
56 changed files with 6222 additions and 526 deletions
|
@ -2,10 +2,9 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { LocalizerType } from '../types/Util';
|
||||
import { ConversationType } from '../state/ducks/conversations';
|
||||
import { Avatar } from './Avatar';
|
||||
import { GroupDialog } from './GroupDialog';
|
||||
import { sortByTitle } from '../util/sortByTitle';
|
||||
|
||||
type CallbackType = () => unknown;
|
||||
|
@ -25,61 +24,64 @@ export type HousekeepingPropsType = {
|
|||
|
||||
export type PropsType = DataPropsType & HousekeepingPropsType;
|
||||
|
||||
function focusRef(el: HTMLElement | null) {
|
||||
if (el) {
|
||||
el.focus();
|
||||
}
|
||||
}
|
||||
export const GroupV1MigrationDialog: React.FunctionComponent<PropsType> = React.memo(
|
||||
(props: PropsType) => {
|
||||
const {
|
||||
areWeInvited,
|
||||
droppedMembers,
|
||||
hasMigrated,
|
||||
i18n,
|
||||
invitedMembers,
|
||||
migrate,
|
||||
onClose,
|
||||
} = props;
|
||||
|
||||
export const GroupV1MigrationDialog = 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}`;
|
||||
|
||||
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 (
|
||||
<div className="module-group-v2-migration-dialog">
|
||||
<button
|
||||
aria-label={i18n('close')}
|
||||
type="button"
|
||||
className="module-group-v2-migration-dialog__close-button"
|
||||
onClick={onClose}
|
||||
/>
|
||||
<div className="module-group-v2-migration-dialog__title">{title}</div>
|
||||
<div className="module-group-v2-migration-dialog__scrollable">
|
||||
<div className="module-group-v2-migration-dialog__item">
|
||||
<div className="module-group-v2-migration-dialog__item__bullet" />
|
||||
<div className="module-group-v2-migration-dialog__item__content">
|
||||
{i18n('GroupV1--Migration--info--summary')}
|
||||
</div>
|
||||
</div>
|
||||
<div className="module-group-v2-migration-dialog__item">
|
||||
<div className="module-group-v2-migration-dialog__item__bullet" />
|
||||
<div className="module-group-v2-migration-dialog__item__content">
|
||||
{keepHistory}
|
||||
</div>
|
||||
</div>
|
||||
return (
|
||||
<GroupDialog
|
||||
i18n={i18n}
|
||||
onClickPrimaryButton={onClickPrimaryButton}
|
||||
onClose={onClose}
|
||||
primaryButtonText={primaryButtonText}
|
||||
title={title}
|
||||
{...secondaryButtonProps}
|
||||
>
|
||||
<GroupDialog.Paragraph>
|
||||
{i18n('GroupV1--Migration--info--summary')}
|
||||
</GroupDialog.Paragraph>
|
||||
<GroupDialog.Paragraph>{keepHistory}</GroupDialog.Paragraph>
|
||||
{areWeInvited ? (
|
||||
<div className="module-group-v2-migration-dialog__item">
|
||||
<div className="module-group-v2-migration-dialog__item__bullet" />
|
||||
<div className="module-group-v2-migration-dialog__item__content">
|
||||
{i18n('GroupV1--Migration--info--invited--you')}
|
||||
</div>
|
||||
</div>
|
||||
<GroupDialog.Paragraph>
|
||||
{i18n('GroupV1--Migration--info--invited--you')}
|
||||
</GroupDialog.Paragraph>
|
||||
) : (
|
||||
<>
|
||||
{renderMembers(
|
||||
|
@ -90,67 +92,16 @@ export const GroupV1MigrationDialog = React.memo((props: PropsType) => {
|
|||
{renderMembers(droppedMembers, droppedMembersKey, i18n)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{renderButtons(hasMigrated, onClose, migrate, i18n)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
function renderButtons(
|
||||
hasMigrated: boolean,
|
||||
onClose: CallbackType,
|
||||
migrate: CallbackType,
|
||||
i18n: LocalizerType
|
||||
) {
|
||||
if (hasMigrated) {
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
'module-group-v2-migration-dialog__buttons',
|
||||
'module-group-v2-migration-dialog__buttons--narrow'
|
||||
)}
|
||||
>
|
||||
<button
|
||||
className="module-group-v2-migration-dialog__button"
|
||||
ref={focusRef}
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
>
|
||||
{i18n('Confirmation--confirm')}
|
||||
</button>
|
||||
</div>
|
||||
</GroupDialog>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="module-group-v2-migration-dialog__buttons">
|
||||
<button
|
||||
className={classNames(
|
||||
'module-group-v2-migration-dialog__button',
|
||||
'module-group-v2-migration-dialog__button--secondary'
|
||||
)}
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
>
|
||||
{i18n('cancel')}
|
||||
</button>
|
||||
<button
|
||||
className="module-group-v2-migration-dialog__button"
|
||||
ref={focusRef}
|
||||
type="button"
|
||||
onClick={migrate}
|
||||
>
|
||||
{i18n('GroupV1--Migration--migrate')}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
function renderMembers(
|
||||
members: Array<ConversationType>,
|
||||
prefix: string,
|
||||
i18n: LocalizerType
|
||||
): React.ReactElement | null {
|
||||
): React.ReactNode {
|
||||
if (!members.length) {
|
||||
return null;
|
||||
}
|
||||
|
@ -159,27 +110,9 @@ function renderMembers(
|
|||
const key = `${prefix}${postfix}`;
|
||||
|
||||
return (
|
||||
<div className="module-group-v2-migration-dialog__item">
|
||||
<div className="module-group-v2-migration-dialog__item__bullet" />
|
||||
<div className="module-group-v2-migration-dialog__item__content">
|
||||
<div>{i18n(key)}</div>
|
||||
{sortByTitle(members).map(member => (
|
||||
<div
|
||||
key={member.id}
|
||||
className="module-group-v2-migration-dialog__member"
|
||||
>
|
||||
<Avatar
|
||||
{...member}
|
||||
conversationType={member.type}
|
||||
size={28}
|
||||
i18n={i18n}
|
||||
/>{' '}
|
||||
<span className="module-group-v2-migration-dialog__member__name">
|
||||
{member.title}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<>
|
||||
<GroupDialog.Paragraph>{i18n(key)}</GroupDialog.Paragraph>
|
||||
<GroupDialog.Contacts contacts={sortByTitle(members)} i18n={i18n} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue