signal-desktop/ts/components/conversation/ContactModal.stories.tsx

148 lines
3.6 KiB
TypeScript
Raw Normal View History

2021-05-07 22:21:10 +00:00
// Copyright 2020-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react';
import { action } from '@storybook/addon-actions';
import { boolean } from '@storybook/addon-knobs';
2021-05-07 22:21:10 +00:00
import { getDefaultConversation } from '../../test-both/helpers/getDefaultConversation';
import type { PropsType } from './ContactModal';
import { ContactModal } from './ContactModal';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../util/setupI18n';
import enMessages from '../../../_locales/en/messages.json';
import type { ConversationType } from '../../state/ducks/conversations';
2021-11-02 23:01:13 +00:00
import { getFakeBadges } from '../../test-both/helpers/getFakeBadge';
2021-11-11 16:23:00 +00:00
import { ThemeType } from '../../types/Util';
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/Conversation/ContactModal',
};
2021-05-07 22:21:10 +00:00
const defaultContact: ConversationType = getDefaultConversation({
id: 'abcdef',
title: 'Pauline Oliveros',
phoneNumber: '(333) 444-5515',
2021-01-26 01:01:19 +00:00
about: '👍 Free to chat',
2021-05-07 22:21:10 +00:00
});
const defaultGroup: ConversationType = getDefaultConversation({
id: 'abcdef',
areWeAdmin: true,
title: "It's a group",
groupLink: 'something',
});
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
areWeASubscriber: false,
areWeAdmin: boolean('areWeAdmin', overrideProps.areWeAdmin || false),
2021-11-02 23:01:13 +00:00
badges: overrideProps.badges || [],
contact: overrideProps.contact || defaultContact,
conversation: overrideProps.conversation || defaultGroup,
2021-09-21 22:37:10 +00:00
hideContactModal: action('hideContactModal'),
i18n,
isAdmin: boolean('isAdmin', overrideProps.isAdmin || false),
isMember: boolean('isMember', overrideProps.isMember || true),
2021-09-21 22:37:10 +00:00
removeMemberFromGroup: action('removeMemberFromGroup'),
2022-06-16 19:12:50 +00:00
showConversation: action('showConversation'),
2021-11-11 16:23:00 +00:00
theme: ThemeType.light,
toggleSafetyNumberModal: action('toggleSafetyNumberModal'),
toggleAdmin: action('toggleAdmin'),
2021-09-21 22:37:10 +00:00
updateConversationModelSharedGroups: action(
'updateConversationModelSharedGroups'
),
});
2022-06-07 00:48:02 +00:00
export const AsNonAdmin = (): JSX.Element => {
const props = createProps({
areWeAdmin: false,
});
return <ContactModal {...props} />;
2022-06-07 00:48:02 +00:00
};
AsNonAdmin.story = {
name: 'As non-admin',
};
2022-06-07 00:48:02 +00:00
export const AsAdmin = (): JSX.Element => {
const props = createProps({
areWeAdmin: true,
});
return <ContactModal {...props} />;
2022-06-07 00:48:02 +00:00
};
AsAdmin.story = {
name: 'As admin',
};
2022-06-07 00:48:02 +00:00
export const AsAdminWithNoGroupLink = (): JSX.Element => {
const props = createProps({
areWeAdmin: true,
conversation: {
...defaultGroup,
groupLink: undefined,
},
});
return <ContactModal {...props} />;
2022-06-07 00:48:02 +00:00
};
AsAdminWithNoGroupLink.story = {
name: 'As admin with no group link',
};
2022-06-07 00:48:02 +00:00
export const AsAdminViewingNonMemberOfGroup = (): JSX.Element => {
const props = createProps({
isMember: false,
});
return <ContactModal {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
AsAdminViewingNonMemberOfGroup.story = {
name: 'As admin, viewing non-member of group',
};
export const WithoutPhoneNumber = (): JSX.Element => {
const props = createProps({
contact: {
...defaultContact,
phoneNumber: undefined,
},
});
return <ContactModal {...props} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
WithoutPhoneNumber.story = {
name: 'Without phone number',
};
export const ViewingSelf = (): JSX.Element => {
const props = createProps({
contact: {
...defaultContact,
isMe: true,
},
});
return <ContactModal {...props} />;
2022-06-07 00:48:02 +00:00
};
2021-11-02 23:01:13 +00:00
2022-06-07 00:48:02 +00:00
ViewingSelf.story = {
name: 'Viewing self',
};
export const WithBadges = (): JSX.Element => {
2021-11-02 23:01:13 +00:00
const props = createProps({
badges: getFakeBadges(2),
});
return <ContactModal {...props} />;
2022-06-07 00:48:02 +00:00
};
WithBadges.story = {
name: 'With badges',
};