2021-03-12 23:31:47 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-01-29 21:19:24 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
import { storiesOf } from '@storybook/react';
|
|
|
|
import { action } from '@storybook/addon-actions';
|
2021-03-11 21:29:31 +00:00
|
|
|
import { times } from 'lodash';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../../../util/setupI18n';
|
2021-09-22 00:58:03 +00:00
|
|
|
import { CapabilityError } from '../../../types/errors';
|
2021-01-29 21:19:24 +00:00
|
|
|
import enMessages from '../../../../_locales/en/messages.json';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { Props } from './ConversationDetails';
|
|
|
|
import { ConversationDetails } from './ConversationDetails';
|
|
|
|
import type { ConversationType } from '../../../state/ducks/conversations';
|
2021-01-29 21:19:24 +00:00
|
|
|
import { getDefaultConversation } from '../../../test-both/helpers/getDefaultConversation';
|
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const story = storiesOf(
|
|
|
|
'Components/Conversation/ConversationDetails/ConversationDetails',
|
|
|
|
module
|
|
|
|
);
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const conversation: ConversationType = getDefaultConversation({
|
2021-01-29 21:19:24 +00:00
|
|
|
id: '',
|
|
|
|
lastUpdated: 0,
|
|
|
|
title: 'Some Conversation',
|
2021-06-02 00:24:28 +00:00
|
|
|
groupDescription: 'Hello World!',
|
2021-01-29 21:19:24 +00:00
|
|
|
type: 'group',
|
2021-05-07 22:21:10 +00:00
|
|
|
sharedGroupNames: [],
|
2021-05-28 16:15:17 +00:00
|
|
|
conversationColor: 'ultramarine' as const,
|
2021-05-07 22:21:10 +00:00
|
|
|
});
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2021-06-01 20:45:43 +00:00
|
|
|
const createProps = (hasGroupLink = false, expireTimer?: number): Props => ({
|
2021-03-11 21:29:31 +00:00
|
|
|
addMembers: async () => {
|
|
|
|
action('addMembers');
|
|
|
|
},
|
2021-01-29 21:19:24 +00:00
|
|
|
canEditGroupInfo: false,
|
2021-03-11 21:29:31 +00:00
|
|
|
candidateContactsToAdd: times(10, () => getDefaultConversation()),
|
2021-06-01 20:45:43 +00:00
|
|
|
conversation: expireTimer
|
|
|
|
? {
|
|
|
|
...conversation,
|
|
|
|
expireTimer,
|
|
|
|
}
|
|
|
|
: conversation,
|
2021-01-29 21:19:24 +00:00
|
|
|
hasGroupLink,
|
|
|
|
i18n,
|
|
|
|
isAdmin: false,
|
2021-10-20 23:46:41 +00:00
|
|
|
isGroup: true,
|
2021-01-29 21:19:24 +00:00
|
|
|
loadRecentMediaItems: action('loadRecentMediaItems'),
|
2021-04-29 18:32:38 +00:00
|
|
|
memberships: times(32, i => ({
|
|
|
|
isAdmin: i === 1,
|
|
|
|
member: getDefaultConversation({
|
|
|
|
isMe: i === 2,
|
|
|
|
}),
|
|
|
|
})),
|
2021-05-13 14:47:30 +00:00
|
|
|
pendingApprovalMemberships: times(8, () => ({
|
|
|
|
member: getDefaultConversation(),
|
|
|
|
})),
|
|
|
|
pendingMemberships: times(5, () => ({
|
|
|
|
metadata: {},
|
|
|
|
member: getDefaultConversation(),
|
|
|
|
})),
|
2021-01-29 21:19:24 +00:00
|
|
|
setDisappearingMessages: action('setDisappearingMessages'),
|
|
|
|
showAllMedia: action('showAllMedia'),
|
|
|
|
showContactModal: action('showContactModal'),
|
2021-10-20 23:46:41 +00:00
|
|
|
showChatColorEditor: action('showChatColorEditor'),
|
2021-01-29 21:19:24 +00:00
|
|
|
showGroupLinkManagement: action('showGroupLinkManagement'),
|
|
|
|
showGroupV2Permissions: action('showGroupV2Permissions'),
|
2021-08-05 12:35:33 +00:00
|
|
|
showConversationNotificationsSettings: action(
|
|
|
|
'showConversationNotificationsSettings'
|
|
|
|
),
|
2021-01-29 21:19:24 +00:00
|
|
|
showPendingInvites: action('showPendingInvites'),
|
|
|
|
showLightboxForMedia: action('showLightboxForMedia'),
|
2021-03-12 23:31:47 +00:00
|
|
|
updateGroupAttributes: async () => {
|
|
|
|
action('updateGroupAttributes')();
|
|
|
|
},
|
2021-04-28 20:27:16 +00:00
|
|
|
onBlock: action('onBlock'),
|
|
|
|
onLeave: action('onLeave'),
|
2021-10-20 23:46:41 +00:00
|
|
|
onUnblock: action('onUnblock'),
|
2021-08-06 00:17:05 +00:00
|
|
|
deleteAvatarFromDisk: action('deleteAvatarFromDisk'),
|
|
|
|
replaceAvatar: action('replaceAvatar'),
|
|
|
|
saveAvatarToDisk: action('saveAvatarToDisk'),
|
2021-10-20 23:46:41 +00:00
|
|
|
setMuteExpiration: action('setMuteExpiration'),
|
2021-08-06 00:17:05 +00:00
|
|
|
userAvatarData: [],
|
2021-10-20 23:46:41 +00:00
|
|
|
toggleSafetyNumberModal: action('toggleSafetyNumberModal'),
|
|
|
|
onOutgoingAudioCallInConversation: action(
|
|
|
|
'onOutgoingAudioCallInConversation'
|
|
|
|
),
|
|
|
|
onOutgoingVideoCallInConversation: action(
|
|
|
|
'onOutgoingVideoCallInConversation'
|
|
|
|
),
|
|
|
|
searchInConversation: action('searchInConversation'),
|
2021-01-29 21:19:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Basic', () => {
|
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return <ConversationDetails {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('as Admin', () => {
|
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return <ConversationDetails {...props} isAdmin />;
|
|
|
|
});
|
|
|
|
|
2021-04-05 17:44:13 +00:00
|
|
|
story.add('as last admin', () => {
|
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConversationDetails
|
|
|
|
{...props}
|
|
|
|
isAdmin
|
2021-04-29 18:32:38 +00:00
|
|
|
memberships={times(32, i => ({
|
|
|
|
isAdmin: i === 2,
|
|
|
|
member: getDefaultConversation({
|
|
|
|
isMe: i === 2,
|
|
|
|
}),
|
|
|
|
}))}
|
2021-04-05 17:44:13 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('as only admin', () => {
|
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConversationDetails
|
|
|
|
{...props}
|
|
|
|
isAdmin
|
2021-04-29 18:32:38 +00:00
|
|
|
memberships={[
|
|
|
|
{
|
|
|
|
isAdmin: true,
|
|
|
|
member: getDefaultConversation({
|
|
|
|
isMe: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
]}
|
2021-04-05 17:44:13 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
story.add('Group Editable', () => {
|
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return <ConversationDetails {...props} canEditGroupInfo />;
|
|
|
|
});
|
|
|
|
|
2021-06-01 20:45:43 +00:00
|
|
|
story.add('Group Editable with custom disappearing timeout', () => {
|
|
|
|
const props = createProps(false, 3 * 24 * 60 * 60);
|
|
|
|
|
|
|
|
return <ConversationDetails {...props} canEditGroupInfo />;
|
|
|
|
});
|
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
story.add('Group Links On', () => {
|
|
|
|
const props = createProps(true);
|
|
|
|
|
|
|
|
return <ConversationDetails {...props} isAdmin />;
|
|
|
|
});
|
2021-07-20 20:18:35 +00:00
|
|
|
|
|
|
|
story.add('Group add with missing capabilities', () => (
|
|
|
|
<ConversationDetails
|
|
|
|
{...createProps()}
|
|
|
|
canEditGroupInfo
|
|
|
|
addMembers={async () => {
|
2021-09-22 00:58:03 +00:00
|
|
|
throw new CapabilityError('stories');
|
2021-07-20 20:18:35 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
));
|
2021-10-20 23:46:41 +00:00
|
|
|
|
|
|
|
story.add('1:1', () => (
|
|
|
|
<ConversationDetails {...createProps()} isGroup={false} />
|
|
|
|
));
|