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

182 lines
4.6 KiB
TypeScript
Raw Normal View History

2021-07-19 19:26:06 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useState } from 'react';
import { text, boolean, select } from '@storybook/addon-knobs';
2021-07-19 19:26:06 +00:00
import { action } from '@storybook/addon-actions';
import type { PropsType } from './ProfileEditor';
import { ProfileEditor } from './ProfileEditor';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2021-07-19 19:26:06 +00:00
import enMessages from '../../_locales/en/messages.json';
import {
getFirstName,
getLastName,
} from '../test-both/helpers/getDefaultConversation';
2021-08-06 00:17:05 +00:00
import { getRandomColor } from '../test-both/helpers/getRandomColor';
import { UsernameSaveState } from '../state/ducks/conversationsEnums';
2021-07-19 19:26:06 +00:00
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/ProfileEditor',
};
2021-07-19 19:26:06 +00:00
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
aboutEmoji: overrideProps.aboutEmoji,
aboutText: text('about', overrideProps.aboutText || ''),
profileAvatarPath: overrideProps.profileAvatarPath,
clearUsernameSave: action('clearUsernameSave'),
2021-08-06 00:17:05 +00:00
conversationId: '123',
color: overrideProps.color || getRandomColor(),
deleteAvatarFromDisk: action('deleteAvatarFromDisk'),
2021-07-19 19:26:06 +00:00
familyName: overrideProps.familyName,
firstName: text('firstName', overrideProps.firstName || getFirstName()),
i18n,
isUsernameFlagEnabled: boolean(
'isUsernameFlagEnabled',
overrideProps.isUsernameFlagEnabled !== undefined
? overrideProps.isUsernameFlagEnabled
: false
),
2021-07-19 19:26:06 +00:00
onEditStateChanged: action('onEditStateChanged'),
onProfileChanged: action('onProfileChanged'),
onSetSkinTone: overrideProps.onSetSkinTone || action('onSetSkinTone'),
recentEmojis: [],
2021-08-06 00:17:05 +00:00
replaceAvatar: action('replaceAvatar'),
saveAvatarToDisk: action('saveAvatarToDisk'),
saveUsername: action('saveUsername'),
2021-07-19 19:26:06 +00:00
skinTone: overrideProps.skinTone || 0,
2021-08-06 00:17:05 +00:00
userAvatarData: [],
username: overrideProps.username,
usernameSaveState: select(
'usernameSaveState',
Object.values(UsernameSaveState),
overrideProps.usernameSaveState || UsernameSaveState.None
),
2021-07-19 19:26:06 +00:00
});
2022-06-07 00:48:02 +00:00
export const FullSet = (): JSX.Element => {
2021-07-19 19:26:06 +00:00
const [skinTone, setSkinTone] = useState(0);
return (
<ProfileEditor
{...createProps({
aboutEmoji: '🙏',
aboutText: 'Live. Laugh. Love',
profileAvatarPath: '/fixtures/kitten-3-64-64.jpg',
2021-07-19 19:26:06 +00:00
onSetSkinTone: setSkinTone,
familyName: getLastName(),
skinTone,
})}
/>
);
2022-06-07 00:48:02 +00:00
};
2021-07-19 19:26:06 +00:00
2022-06-07 00:48:02 +00:00
export const WithFullName = (): JSX.Element => (
2021-07-19 19:26:06 +00:00
<ProfileEditor
{...createProps({
familyName: getLastName(),
})}
/>
2022-06-07 00:48:02 +00:00
);
WithFullName.story = {
name: 'with Full Name',
};
2021-07-19 19:26:06 +00:00
2022-06-07 00:48:02 +00:00
export const WithCustomAbout = (): JSX.Element => (
2021-07-19 19:26:06 +00:00
<ProfileEditor
{...createProps({
aboutEmoji: '🙏',
aboutText: 'Live. Laugh. Love',
})}
/>
2022-06-07 00:48:02 +00:00
);
WithCustomAbout.story = {
name: 'with Custom About',
};
2022-06-07 00:48:02 +00:00
export const WithUsernameFlagEnabled = (): JSX.Element => (
<ProfileEditor
{...createProps({
isUsernameFlagEnabled: true,
})}
/>
2022-06-07 00:48:02 +00:00
);
2022-06-07 00:48:02 +00:00
WithUsernameFlagEnabled.story = {
name: 'with Username flag enabled',
};
export const WithUsernameFlagEnabledAndUsername = (): JSX.Element => (
<ProfileEditor
{...createProps({
isUsernameFlagEnabled: true,
username: 'unicorn55',
})}
/>
2022-06-07 00:48:02 +00:00
);
WithUsernameFlagEnabledAndUsername.story = {
name: 'with Username flag enabled and username',
};
2022-06-07 00:48:02 +00:00
export const UsernameEditingSaving = (): JSX.Element => (
<ProfileEditor
{...createProps({
isUsernameFlagEnabled: true,
usernameSaveState: UsernameSaveState.Saving,
username: 'unicorn55',
})}
/>
2022-06-07 00:48:02 +00:00
);
2022-06-07 00:48:02 +00:00
UsernameEditingSaving.story = {
name: 'Username editing, saving',
};
export const UsernameEditingUsernameTaken = (): JSX.Element => (
<ProfileEditor
{...createProps({
isUsernameFlagEnabled: true,
usernameSaveState: UsernameSaveState.UsernameTakenError,
username: 'unicorn55',
})}
/>
2022-06-07 00:48:02 +00:00
);
UsernameEditingUsernameTaken.story = {
name: 'Username editing, username taken',
};
2022-06-07 00:48:02 +00:00
export const UsernameEditingUsernameMalformed = (): JSX.Element => (
<ProfileEditor
{...createProps({
isUsernameFlagEnabled: true,
usernameSaveState: UsernameSaveState.UsernameMalformedError,
username: 'unicorn55',
})}
/>
2022-06-07 00:48:02 +00:00
);
2022-06-07 00:48:02 +00:00
UsernameEditingUsernameMalformed.story = {
name: 'Username editing, username malformed',
};
export const UsernameEditingGeneralError = (): JSX.Element => (
<ProfileEditor
{...createProps({
isUsernameFlagEnabled: true,
usernameSaveState: UsernameSaveState.GeneralError,
username: 'unicorn55',
})}
/>
2022-06-07 00:48:02 +00:00
);
UsernameEditingGeneralError.story = {
name: 'Username editing, general error',
};