signal-desktop/ts/components/GroupV1MigrationDialog.stories.tsx

187 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';
2020-11-20 17:30:45 +00:00
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
import type { PropsType } from './GroupV1MigrationDialog';
import { GroupV1MigrationDialog } from './GroupV1MigrationDialog';
import type { ConversationType } from '../state/ducks/conversations';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2020-11-20 17:30:45 +00:00
import enMessages from '../../_locales/en/messages.json';
2021-05-07 22:21:10 +00:00
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
2021-11-20 15:41:21 +00:00
import { ThemeType } from '../types/Util';
2020-11-20 17:30:45 +00:00
const i18n = setupI18n('en', enMessages);
2021-05-07 22:21:10 +00:00
const contact1: ConversationType = getDefaultConversation({
2020-11-20 17:30:45 +00:00
title: 'Alice',
2021-05-07 22:21:10 +00:00
phoneNumber: '+1 (300) 555-0000',
2020-11-20 17:30:45 +00:00
id: 'guid-1',
2021-05-07 22:21:10 +00:00
});
2020-11-20 17:30:45 +00:00
2021-05-07 22:21:10 +00:00
const contact2: ConversationType = getDefaultConversation({
2020-11-20 17:30:45 +00:00
title: 'Bob',
2021-05-07 22:21:10 +00:00
phoneNumber: '+1 (300) 555-0001',
id: 'guid-2',
2021-05-07 22:21:10 +00:00
});
2021-05-07 22:21:10 +00:00
const contact3: ConversationType = getDefaultConversation({
title: 'Chet',
2021-05-07 22:21:10 +00:00
phoneNumber: '+1 (300) 555-0002',
id: 'guid-3',
2021-05-07 22:21:10 +00:00
});
2020-11-20 17:30:45 +00:00
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
areWeInvited: Boolean(overrideProps.areWeInvited),
2024-04-30 13:24:21 +00:00
droppedMembers: overrideProps.droppedMembers,
droppedMemberCount: overrideProps.droppedMemberCount || 0,
2021-11-20 15:41:21 +00:00
getPreferredBadge: () => undefined,
hasMigrated: Boolean(overrideProps.hasMigrated),
2020-11-20 17:30:45 +00:00
i18n,
2024-04-30 13:24:21 +00:00
invitedMembers: overrideProps.invitedMembers,
invitedMemberCount: overrideProps.invitedMemberCount || 0,
onMigrate: action('onMigrate'),
2020-11-20 17:30:45 +00:00
onClose: action('onClose'),
2021-11-20 15:41:21 +00:00
theme: ThemeType.light,
2020-11-20 17:30:45 +00:00
});
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/GroupV1MigrationDialog',
} satisfies Meta<PropsType>;
2020-11-20 17:30:45 +00:00
2022-11-18 00:45:19 +00:00
export function NotYetMigratedBasic(): JSX.Element {
2020-11-20 17:30:45 +00:00
return <GroupV1MigrationDialog {...createProps()} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function MigratedBasic(): JSX.Element {
2020-11-20 17:30:45 +00:00
return (
<GroupV1MigrationDialog
{...createProps({
hasMigrated: true,
})}
/>
);
2022-11-18 00:45:19 +00:00
}
2020-11-20 17:30:45 +00:00
2022-11-18 00:45:19 +00:00
export function MigratedYouAreInvited(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
hasMigrated: true,
areWeInvited: true,
})}
/>
);
2022-11-18 00:45:19 +00:00
}
2024-04-30 13:24:21 +00:00
export function MigratedMultipleDroppedAndInvitedMember(): JSX.Element {
2022-11-18 00:45:19 +00:00
return (
<GroupV1MigrationDialog
{...createProps({
2024-04-30 13:24:21 +00:00
hasMigrated: true,
droppedMembers: [contact1],
droppedMemberCount: 1,
invitedMembers: [contact2],
invitedMemberCount: 1,
})}
/>
);
}
export function MigratedMultipleDroppedAndInvitedMembers(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
hasMigrated: true,
2022-11-18 00:45:19 +00:00
droppedMembers: [contact3, contact1, contact2],
2024-04-30 13:24:21 +00:00
droppedMemberCount: 3,
2022-11-18 00:45:19 +00:00
invitedMembers: [contact2, contact3, contact1],
2024-04-30 13:24:21 +00:00
invitedMemberCount: 3,
2022-11-18 00:45:19 +00:00
})}
/>
);
}
2022-06-07 00:48:02 +00:00
2024-04-30 13:24:21 +00:00
export function MigratedNoMembers(): JSX.Element {
2020-11-20 17:30:45 +00:00
return (
<GroupV1MigrationDialog
{...createProps({
2024-04-30 13:24:21 +00:00
hasMigrated: true,
droppedMemberCount: 0,
invitedMemberCount: 0,
2020-11-20 17:30:45 +00:00
})}
/>
);
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function NotYetMigratedJustDroppedMember(): JSX.Element {
2020-11-20 17:30:45 +00:00
return (
<GroupV1MigrationDialog
{...createProps({
2024-04-30 13:24:21 +00:00
droppedMembers: [contact1],
droppedMemberCount: 1,
})}
/>
);
}
export function NotYetMigratedJustDroppedMembers(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
droppedMembers: [contact1, contact2],
droppedMemberCount: 2,
})}
/>
);
}
export function NotYetMigratedDropped1(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
droppedMemberCount: 1,
invitedMemberCount: 0,
})}
/>
);
}
export function NotYetMigratedDropped2(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
droppedMemberCount: 2,
invitedMemberCount: 0,
})}
/>
);
}
export function MigratedJustCountIs1(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
hasMigrated: true,
droppedMemberCount: 1,
invitedMemberCount: 1,
})}
/>
);
}
export function MigratedJustCountIs2(): JSX.Element {
return (
<GroupV1MigrationDialog
{...createProps({
hasMigrated: true,
droppedMemberCount: 2,
invitedMemberCount: 2,
2020-11-20 17:30:45 +00:00
})}
/>
);
2022-11-18 00:45:19 +00:00
}