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

176 lines
4.5 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
2022-07-20 21:29:09 +00:00
import type { Meta, Story } from '@storybook/react';
2022-10-18 17:12:02 +00:00
import { action } from '@storybook/addon-actions';
2021-07-19 19:26:06 +00:00
import React, { useState } from 'react';
2022-07-20 21:29:09 +00:00
import casual from 'casual';
2021-07-19 19:26:06 +00:00
import type { PropsType } from './ProfileEditor';
2021-07-19 19:26:06 +00:00
import enMessages from '../../_locales/en/messages.json';
2022-07-20 21:29:09 +00:00
import { ProfileEditor } from './ProfileEditor';
2022-10-18 17:12:02 +00:00
import { EditUsernameModalBody } from './EditUsernameModalBody';
import {
UsernameEditState,
UsernameReservationState,
} from '../state/ducks/usernameEnums';
2022-07-20 21:29:09 +00:00
import { UUID } from '../types/UUID';
import { getRandomColor } from '../test-both/helpers/getRandomColor';
import { setupI18n } from '../util/setupI18n';
2021-07-19 19:26:06 +00:00
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
2022-07-20 21:29:09 +00:00
component: ProfileEditor,
2022-06-07 00:48:02 +00:00
title: 'Components/ProfileEditor',
2022-07-20 21:29:09 +00:00
argTypes: {
aboutEmoji: {
defaultValue: '',
},
aboutText: {
defaultValue: casual.sentence,
},
profileAvatarPath: {
defaultValue: undefined,
},
conversationId: {
defaultValue: UUID.generate().toString(),
},
color: {
defaultValue: getRandomColor(),
},
deleteAvatarFromDisk: { action: true },
familyName: {
defaultValue: casual.last_name,
},
firstName: {
defaultValue: casual.first_name,
},
i18n: {
defaultValue: i18n,
},
isUsernameFlagEnabled: {
control: { type: 'checkbox' },
defaultValue: false,
},
2022-10-18 17:12:02 +00:00
usernameEditState: {
control: { type: 'radio' },
defaultValue: UsernameEditState.Editing,
options: {
Editing: UsernameEditState.Editing,
ConfirmingDelete: UsernameEditState.ConfirmingDelete,
Deleting: UsernameEditState.Deleting,
},
},
2022-07-20 21:29:09 +00:00
onEditStateChanged: { action: true },
onProfileChanged: { action: true },
onSetSkinTone: { action: true },
2022-10-18 17:12:02 +00:00
showToast: { action: true },
2022-07-20 21:29:09 +00:00
recentEmojis: {
defaultValue: [],
},
replaceAvatar: { action: true },
saveAvatarToDisk: { action: true },
2022-10-18 17:12:02 +00:00
openUsernameReservationModal: { action: true },
setUsernameEditState: { action: true },
deleteUsername: { action: true },
2022-07-20 21:29:09 +00:00
skinTone: {
defaultValue: 0,
},
userAvatarData: {
defaultValue: [],
},
username: {
2022-10-18 17:12:02 +00:00
defaultValue: undefined,
2022-07-20 21:29:09 +00:00
},
},
} as Meta;
2022-10-18 17:12:02 +00:00
function renderEditUsernameModalBody(props: {
onClose: () => void;
}): JSX.Element {
return (
<EditUsernameModalBody
i18n={i18n}
minNickname={3}
maxNickname={20}
2022-10-18 17:12:02 +00:00
state={UsernameReservationState.Open}
error={undefined}
setUsernameReservationError={action('setUsernameReservationError')}
reserveUsername={action('reserveUsername')}
confirmUsername={action('confirmUsername')}
{...props}
/>
);
}
2022-07-20 21:29:09 +00:00
const Template: Story<PropsType> = args => {
2021-07-19 19:26:06 +00:00
const [skinTone, setSkinTone] = useState(0);
return (
2022-10-18 17:12:02 +00:00
<ProfileEditor
{...args}
skinTone={skinTone}
onSetSkinTone={setSkinTone}
renderEditUsernameModalBody={renderEditUsernameModalBody}
/>
2021-07-19 19:26:06 +00:00
);
2022-06-07 00:48:02 +00:00
};
2021-07-19 19:26:06 +00:00
2022-07-20 21:29:09 +00:00
export const FullSet = Template.bind({});
FullSet.args = {
aboutEmoji: '🙏',
aboutText: 'Live. Laugh. Love',
familyName: casual.last_name,
firstName: casual.first_name,
profileAvatarPath: '/fixtures/kitten-3-64-64.jpg',
};
2022-06-07 00:48:02 +00:00
2022-07-20 21:29:09 +00:00
export const WithFullName = Template.bind({});
WithFullName.args = {
familyName: casual.last_name,
};
2022-06-07 00:48:02 +00:00
WithFullName.story = {
name: 'with Full Name',
};
2021-07-19 19:26:06 +00:00
2022-07-20 21:29:09 +00:00
export const WithCustomAbout = Template.bind({});
WithCustomAbout.args = {
aboutEmoji: '🙏',
aboutText: 'Live. Laugh. Love',
};
2022-06-07 00:48:02 +00:00
WithCustomAbout.story = {
name: 'with Custom About',
};
2022-07-20 21:29:09 +00:00
export const WithUsernameFlagEnabled = Template.bind({});
WithUsernameFlagEnabled.args = {
isUsernameFlagEnabled: true,
};
2022-06-07 00:48:02 +00:00
WithUsernameFlagEnabled.story = {
name: 'with Username flag enabled',
};
2022-07-20 21:29:09 +00:00
export const WithUsernameFlagEnabledAndUsername = Template.bind({});
WithUsernameFlagEnabledAndUsername.args = {
isUsernameFlagEnabled: true,
2022-10-18 17:12:02 +00:00
username: 'signaluser.123',
2022-07-20 21:29:09 +00:00
};
2022-06-07 00:48:02 +00:00
WithUsernameFlagEnabledAndUsername.story = {
name: 'with Username flag enabled and username',
};
2022-10-18 17:12:02 +00:00
export const DeletingUsername = Template.bind({});
DeletingUsername.args = {
2022-07-20 21:29:09 +00:00
isUsernameFlagEnabled: true,
2022-10-18 17:12:02 +00:00
username: 'signaluser.123',
usernameEditState: UsernameEditState.Deleting,
2022-06-07 00:48:02 +00:00
};
2022-10-18 17:12:02 +00:00
export const ConfirmingDelete = Template.bind({});
ConfirmingDelete.args = {
2022-07-20 21:29:09 +00:00
isUsernameFlagEnabled: true,
2022-10-18 17:12:02 +00:00
username: 'signaluser.123',
usernameEditState: UsernameEditState.ConfirmingDelete,
2022-06-07 00:48:02 +00:00
};