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

167 lines
4.9 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 type { Meta, StoryFn } 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';
import { v4 as generateUuid } from 'uuid';
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,
2023-07-20 03:14:08 +00:00
UsernameLinkState,
2022-10-18 17:12:02 +00:00
UsernameReservationState,
} from '../state/ducks/usernameEnums';
2022-07-20 21:29:09 +00:00
import { getRandomColor } from '../test-both/helpers/getRandomColor';
import { setupI18n } from '../util/setupI18n';
import { SignalService as Proto } from '../protobuf';
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: {
isUsernameFlagEnabled: {
control: { type: 'checkbox' },
},
2022-10-18 17:12:02 +00:00
usernameEditState: {
control: { type: 'radio' },
options: {
Editing: UsernameEditState.Editing,
ConfirmingDelete: UsernameEditState.ConfirmingDelete,
Deleting: UsernameEditState.Deleting,
},
},
usernameCorrupted: {
control: 'boolean',
},
2023-07-20 03:14:08 +00:00
usernameLinkState: {
control: { type: 'select' },
options: [UsernameLinkState.Ready, UsernameLinkState.Updating],
},
usernameLinkCorrupted: {
control: 'boolean',
},
2022-07-20 21:29:09 +00:00
},
args: {
aboutEmoji: '',
aboutText: casual.sentence,
profileAvatarPath: undefined,
conversationId: generateUuid(),
color: getRandomColor(),
deleteAvatarFromDisk: action('deleteAvatarFromDisk'),
familyName: casual.last_name,
firstName: casual.first_name,
i18n,
usernameLink: 'https://signal.me/#eu/testtest',
usernameLinkColor: Proto.AccountRecord.UsernameLink.Color.PURPLE,
isUsernameFlagEnabled: false,
usernameEditState: UsernameEditState.Editing,
usernameLinkState: UsernameLinkState.Ready,
recentEmojis: [],
skinTone: 0,
userAvatarData: [],
username: undefined,
onEditStateChanged: action('onEditStateChanged'),
onProfileChanged: action('onProfileChanged'),
onSetSkinTone: action('onSetSkinTone'),
saveAttachment: action('saveAttachment'),
setUsernameLinkColor: action('setUsernameLinkColor'),
showToast: action('showToast'),
replaceAvatar: action('replaceAvatar'),
resetUsernameLink: action('resetUsernameLink'),
saveAvatarToDisk: action('saveAvatarToDisk'),
markCompletedUsernameOnboarding: action('markCompletedUsernameOnboarding'),
markCompletedUsernameLinkOnboarding: action(
'markCompletedUsernameLinkOnboarding'
),
openUsernameReservationModal: action('openUsernameReservationModal'),
setUsernameEditState: action('setUsernameEditState'),
deleteUsername: action('deleteUsername'),
},
} satisfies Meta<PropsType>;
2022-07-20 21:29:09 +00:00
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-11-18 00:45:19 +00:00
// eslint-disable-next-line react/function-component-definition
const Template: StoryFn<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,
};
export const WithCustomAbout = Template.bind({});
WithCustomAbout.args = {
aboutEmoji: '🙏',
aboutText: 'Live. Laugh. Love',
};
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
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-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
};