signal-desktop/ts/components/conversation/conversation-details/PendingInvites.stories.tsx

97 lines
2.6 KiB
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react';
import { times } from 'lodash';
import { action } from '@storybook/addon-actions';
2021-10-26 22:59:08 +00:00
import { UUID } from '../../../types/UUID';
import { StorySendMode } from '../../../types/Stories';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../../util/setupI18n';
import enMessages from '../../../../_locales/en/messages.json';
import type { PropsType } from './PendingInvites';
import { PendingInvites } from './PendingInvites';
import type { ConversationType } from '../../../state/ducks/conversations';
import { getDefaultConversation } from '../../../test-both/helpers/getDefaultConversation';
2021-11-18 22:27:48 +00:00
import { getFakeBadge } from '../../../test-both/helpers/getFakeBadge';
import { StorybookThemeContext } from '../../../../.storybook/StorybookThemeContext';
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Conversation/ConversationDetails/PendingInvites',
};
const sortedGroupMembers = Array.from(Array(32)).map((_, i) =>
i === 0
? getDefaultConversation({ id: 'def456' })
: getDefaultConversation({})
);
const conversation: ConversationType = {
2021-05-07 22:21:10 +00:00
acceptedMessageRequest: true,
areWeAdmin: true,
2021-11-02 23:01:13 +00:00
badges: [],
id: '',
lastUpdated: 0,
markedUnread: false,
2021-05-07 22:21:10 +00:00
isMe: false,
sortedGroupMembers,
title: 'Some Conversation',
type: 'group',
2021-05-07 22:21:10 +00:00
sharedGroupNames: [],
acknowledgedGroupNameCollisions: {},
storySendMode: StorySendMode.IfActive,
};
2021-10-26 22:59:08 +00:00
const OUR_UUID = UUID.generate().toString();
2021-11-18 22:27:48 +00:00
const useProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
approvePendingMembershipFromGroupV2: action(
'approvePendingMembershipFromGroupV2'
),
conversation,
2021-11-18 22:27:48 +00:00
getPreferredBadge: () => undefined,
i18n,
2021-10-26 22:59:08 +00:00
ourUuid: OUR_UUID,
pendingApprovalMemberships: times(5, () => ({
member: getDefaultConversation(),
})),
pendingMemberships: [
...times(4, () => ({
member: getDefaultConversation(),
metadata: {
2021-10-26 22:59:08 +00:00
addedByUserId: OUR_UUID,
},
})),
...times(8, () => ({
member: getDefaultConversation(),
metadata: {
2021-10-26 22:59:08 +00:00
addedByUserId: UUID.generate().toString(),
},
})),
],
revokePendingMembershipsFromGroupV2: action(
'revokePendingMembershipsFromGroupV2'
),
2021-11-18 22:27:48 +00:00
theme: React.useContext(StorybookThemeContext),
...overrideProps,
});
2022-11-18 00:45:19 +00:00
export function Basic(): JSX.Element {
2021-11-18 22:27:48 +00:00
const props = useProps();
return <PendingInvites {...props} />;
2022-11-18 00:45:19 +00:00
}
2021-11-18 22:27:48 +00:00
2022-11-18 00:45:19 +00:00
export function WithBadges(): JSX.Element {
2021-11-18 22:27:48 +00:00
const props = useProps({ getPreferredBadge: () => getFakeBadge() });
return <PendingInvites {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
WithBadges.story = {
name: 'With badges',
};