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

149 lines
3.4 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react';
2020-09-12 00:46:52 +00:00
import { action } from '@storybook/addon-actions';
import { boolean, text } from '@storybook/addon-knobs';
import type { PropsType } from './SafetyNumberViewer';
import { SafetyNumberViewer } from './SafetyNumberViewer';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
import enMessages from '../../_locales/en/messages.json';
2021-08-06 00:17:05 +00:00
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
const i18n = setupI18n('en', enMessages);
2021-08-06 00:17:05 +00:00
const contactWithAllData = getDefaultConversation({
title: 'Summer Smith',
2020-07-24 01:35:32 +00:00
name: 'Summer Smith',
phoneNumber: '(305) 123-4567',
isVerified: true,
2021-08-06 00:17:05 +00:00
});
2020-07-24 01:35:32 +00:00
2021-08-06 00:17:05 +00:00
const contactWithJustProfile = getDefaultConversation({
2020-07-24 01:35:32 +00:00
avatarPath: undefined,
title: '-*Smartest Dude*-',
2020-07-24 01:35:32 +00:00
profileName: '-*Smartest Dude*-',
name: undefined,
phoneNumber: '(305) 123-4567',
2021-08-06 00:17:05 +00:00
});
2020-07-24 01:35:32 +00:00
2021-08-06 00:17:05 +00:00
const contactWithJustNumber = getDefaultConversation({
2020-07-24 01:35:32 +00:00
avatarPath: undefined,
profileName: undefined,
name: undefined,
title: '(305) 123-4567',
2020-07-24 01:35:32 +00:00
phoneNumber: '(305) 123-4567',
2021-08-06 00:17:05 +00:00
});
2020-07-24 01:35:32 +00:00
2021-08-06 00:17:05 +00:00
const contactWithNothing = getDefaultConversation({
2020-07-24 01:35:32 +00:00
id: 'some-guid',
avatarPath: undefined,
profileName: undefined,
title: 'Unknown contact',
2020-07-24 01:35:32 +00:00
name: undefined,
phoneNumber: undefined,
2021-08-06 00:17:05 +00:00
});
2020-07-24 01:35:32 +00:00
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
contact: overrideProps.contact || contactWithAllData,
generateSafetyNumber: action('generate-safety-number'),
i18n,
safetyNumber: text('safetyNumber', overrideProps.safetyNumber || 'XXX'),
toggleVerified: action('toggle-verified'),
verificationDisabled: boolean(
'verificationDisabled',
overrideProps.verificationDisabled !== undefined
? overrideProps.verificationDisabled
: false
),
2022-03-02 18:24:28 +00:00
onClose: action('onClose'),
});
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/SafetyNumberViewer',
};
2022-06-07 00:48:02 +00:00
export const SafetyNumber = (): JSX.Element => {
return <SafetyNumberViewer {...createProps({})} />;
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
export const SafetyNumberNotVerified = (): JSX.Element => {
return (
<SafetyNumberViewer
{...createProps({
contact: {
...contactWithAllData,
isVerified: false,
},
})}
/>
);
2022-06-07 00:48:02 +00:00
};
SafetyNumberNotVerified.story = {
name: 'Safety Number (not verified)',
};
2022-06-07 00:48:02 +00:00
export const VerificationDisabled = (): JSX.Element => {
return (
<SafetyNumberViewer
{...createProps({
verificationDisabled: true,
})}
/>
);
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
export const SafetyNumberDialogClose = (): JSX.Element => {
return (
<SafetyNumberViewer
{...createProps({
onClose: action('close'),
})}
/>
);
2022-06-07 00:48:02 +00:00
};
SafetyNumberDialogClose.story = {
name: 'Safety Number (dialog close)',
};
2022-06-07 00:48:02 +00:00
export const JustProfileAndNumber = (): JSX.Element => {
return (
<SafetyNumberViewer
{...createProps({
contact: contactWithJustProfile,
})}
/>
);
2022-06-07 00:48:02 +00:00
};
JustProfileAndNumber.story = {
name: 'Just Profile and Number',
};
2022-06-07 00:48:02 +00:00
export const JustNumber = (): JSX.Element => {
return (
<SafetyNumberViewer
{...createProps({
contact: contactWithJustNumber,
})}
/>
);
2022-06-07 00:48:02 +00:00
};
2022-06-07 00:48:02 +00:00
export const NoPhoneNumberCannotVerify = (): JSX.Element => {
return (
<SafetyNumberViewer
{...createProps({
contact: contactWithNothing,
})}
/>
);
2022-06-07 00:48:02 +00:00
};
NoPhoneNumberCannotVerify.story = {
name: 'No Phone Number (cannot verify)',
};