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 { storiesOf } from '@storybook/react';
|
|
|
|
import { isBoolean } from 'lodash';
|
|
|
|
import { boolean } from '@storybook/addon-knobs';
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
|
|
|
|
import { GroupV1MigrationDialog, PropsType } from './GroupV1MigrationDialog';
|
|
|
|
import { setup as setupI18n } from '../../js/modules/i18n';
|
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const contact1 = {
|
|
|
|
title: 'Alice',
|
2020-12-03 16:03:21 +00:00
|
|
|
number: '+1 (300) 555-0000',
|
2020-11-20 17:30:45 +00:00
|
|
|
id: 'guid-1',
|
|
|
|
markedUnread: false,
|
|
|
|
type: 'direct' as const,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const contact2 = {
|
|
|
|
title: 'Bob',
|
2020-12-03 16:03:21 +00:00
|
|
|
number: '+1 (300) 555-0001',
|
|
|
|
id: 'guid-2',
|
|
|
|
markedUnread: false,
|
|
|
|
type: 'direct' as const,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const contact3 = {
|
|
|
|
title: 'Chet',
|
|
|
|
number: '+1 (300) 555-0002',
|
|
|
|
id: 'guid-3',
|
2020-11-20 17:30:45 +00:00
|
|
|
markedUnread: false,
|
|
|
|
type: 'direct' as const,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
};
|
|
|
|
|
|
|
|
function booleanOr(value: boolean | undefined, defaultValue: boolean): boolean {
|
|
|
|
return isBoolean(value) ? value : defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
|
2020-12-01 23:45:39 +00:00
|
|
|
areWeInvited: boolean(
|
|
|
|
'areWeInvited',
|
|
|
|
booleanOr(overrideProps.areWeInvited, false)
|
|
|
|
),
|
2020-12-03 16:03:21 +00:00
|
|
|
droppedMembers: overrideProps.droppedMembers || [contact3, contact1],
|
2020-11-20 17:30:45 +00:00
|
|
|
hasMigrated: boolean(
|
|
|
|
'hasMigrated',
|
|
|
|
booleanOr(overrideProps.hasMigrated, false)
|
|
|
|
),
|
|
|
|
i18n,
|
|
|
|
invitedMembers: overrideProps.invitedMembers || [contact2],
|
|
|
|
migrate: action('migrate'),
|
|
|
|
onClose: action('onClose'),
|
|
|
|
});
|
|
|
|
|
|
|
|
const stories = storiesOf('Components/GroupV1MigrationDialog', module);
|
|
|
|
|
|
|
|
stories.add('Not yet migrated, basic', () => {
|
|
|
|
return <GroupV1MigrationDialog {...createProps()} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
stories.add('Migrated, basic', () => {
|
|
|
|
return (
|
|
|
|
<GroupV1MigrationDialog
|
|
|
|
{...createProps({
|
|
|
|
hasMigrated: true,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-01 23:45:39 +00:00
|
|
|
stories.add('Migrated, you are invited', () => {
|
|
|
|
return (
|
|
|
|
<GroupV1MigrationDialog
|
|
|
|
{...createProps({
|
|
|
|
hasMigrated: true,
|
|
|
|
areWeInvited: true,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-11-20 17:30:45 +00:00
|
|
|
stories.add('Not yet migrated, multiple dropped and invited members', () => {
|
|
|
|
return (
|
|
|
|
<GroupV1MigrationDialog
|
|
|
|
{...createProps({
|
2020-12-03 16:03:21 +00:00
|
|
|
droppedMembers: [contact3, contact1, contact2],
|
|
|
|
invitedMembers: [contact2, contact3, contact1],
|
2020-11-20 17:30:45 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
stories.add('Not yet migrated, no members', () => {
|
|
|
|
return (
|
|
|
|
<GroupV1MigrationDialog
|
|
|
|
{...createProps({
|
|
|
|
droppedMembers: [],
|
|
|
|
invitedMembers: [],
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
stories.add('Not yet migrated, just dropped member', () => {
|
|
|
|
return (
|
|
|
|
<GroupV1MigrationDialog
|
|
|
|
{...createProps({
|
|
|
|
invitedMembers: [],
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|