Merge delete for me/everyone into one modal

This commit is contained in:
Jamie Kyle 2023-04-10 14:38:34 -07:00 committed by GitHub
parent c956c0e025
commit 822b162136
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 658 additions and 672 deletions

View file

@ -4,14 +4,136 @@
import type { Meta, Story } from '@storybook/react';
import React from 'react';
import type { PropsType } from './ToastManager';
import enMessages from '../../_locales/en/messages.json';
import { ToastManager } from './ToastManager';
import type { AnyToast } from '../types/Toast';
import { ToastType } from '../types/Toast';
import { setupI18n } from '../util/setupI18n';
import { missingCaseError } from '../util/missingCaseError';
import type { PropsType } from './ToastManager';
const i18n = setupI18n('en', enMessages);
function getToast(toastType: ToastType): AnyToast {
switch (toastType) {
case ToastType.AddingUserToGroup:
return { toastType, parameters: { contact: 'Sam Mirete' } };
case ToastType.AlreadyGroupMember:
return { toastType: ToastType.AlreadyGroupMember };
case ToastType.AlreadyRequestedToJoin:
return { toastType: ToastType.AlreadyRequestedToJoin };
case ToastType.Blocked:
return { toastType: ToastType.Blocked };
case ToastType.BlockedGroup:
return { toastType: ToastType.BlockedGroup };
case ToastType.CannotForwardEmptyMessage:
return { toastType: ToastType.CannotForwardEmptyMessage };
case ToastType.CannotMixMultiAndNonMultiAttachments:
return { toastType: ToastType.CannotMixMultiAndNonMultiAttachments };
case ToastType.CannotOpenGiftBadgeIncoming:
return { toastType: ToastType.CannotOpenGiftBadgeIncoming };
case ToastType.CannotOpenGiftBadgeOutgoing:
return { toastType: ToastType.CannotOpenGiftBadgeOutgoing };
case ToastType.CannotStartGroupCall:
return { toastType: ToastType.CannotStartGroupCall };
case ToastType.ConversationArchived:
return {
toastType: ToastType.ConversationArchived,
parameters: { conversationId: 'some-conversation-id' },
};
case ToastType.ConversationMarkedUnread:
return { toastType: ToastType.ConversationMarkedUnread };
case ToastType.ConversationRemoved:
return {
toastType: ToastType.ConversationRemoved,
parameters: { title: 'Alice' },
};
case ToastType.ConversationUnarchived:
return { toastType: ToastType.ConversationUnarchived };
case ToastType.CopiedUsername:
return { toastType: ToastType.CopiedUsername };
case ToastType.CopiedUsernameLink:
return { toastType: ToastType.CopiedUsernameLink };
case ToastType.DangerousFileType:
return { toastType: ToastType.DangerousFileType };
case ToastType.DeleteForEveryoneFailed:
return { toastType: ToastType.DeleteForEveryoneFailed };
case ToastType.Error:
return { toastType: ToastType.Error };
case ToastType.Expired:
return { toastType: ToastType.Expired };
case ToastType.FailedToDeleteUsername:
return { toastType: ToastType.FailedToDeleteUsername };
case ToastType.FileSaved:
return {
toastType: ToastType.FileSaved,
parameters: { fullPath: '/image.png' },
};
case ToastType.FileSize:
return {
toastType: ToastType.FileSize,
parameters: { limit: 100, units: 'MB' },
};
case ToastType.InvalidConversation:
return { toastType: ToastType.InvalidConversation };
case ToastType.LeftGroup:
return { toastType: ToastType.LeftGroup };
case ToastType.MaxAttachments:
return { toastType: ToastType.MaxAttachments };
case ToastType.MessageBodyTooLong:
return { toastType: ToastType.MessageBodyTooLong };
case ToastType.OriginalMessageNotFound:
return { toastType: ToastType.OriginalMessageNotFound };
case ToastType.PinnedConversationsFull:
return { toastType: ToastType.PinnedConversationsFull };
case ToastType.ReactionFailed:
return { toastType: ToastType.ReactionFailed };
case ToastType.ReportedSpamAndBlocked:
return { toastType: ToastType.ReportedSpamAndBlocked };
case ToastType.StoryMuted:
return { toastType: ToastType.StoryMuted };
case ToastType.StoryReact:
return { toastType: ToastType.StoryReact };
case ToastType.StoryReply:
return { toastType: ToastType.StoryReply };
case ToastType.StoryVideoError:
return { toastType: ToastType.StoryVideoError };
case ToastType.StoryVideoUnsupported:
return { toastType: ToastType.StoryVideoUnsupported };
case ToastType.TapToViewExpiredIncoming:
return { toastType: ToastType.TapToViewExpiredIncoming };
case ToastType.TapToViewExpiredOutgoing:
return { toastType: ToastType.TapToViewExpiredOutgoing };
case ToastType.TooManyMessagesToDeleteForEveryone:
return {
toastType: ToastType.TooManyMessagesToDeleteForEveryone,
parameters: { count: 30 },
};
case ToastType.TooManyMessagesToForward:
return { toastType: ToastType.TooManyMessagesToForward };
case ToastType.UnableToLoadAttachment:
return { toastType: ToastType.UnableToLoadAttachment };
case ToastType.UnsupportedMultiAttachment:
return { toastType: ToastType.UnsupportedMultiAttachment };
case ToastType.UnsupportedOS:
return { toastType: ToastType.UnsupportedOS };
case ToastType.UserAddedToGroup:
return {
toastType: ToastType.UserAddedToGroup,
parameters: {
contact: 'Sam Mirete',
group: 'Hike Group 🏔',
},
};
default:
throw missingCaseError(toastType);
}
}
type Args = Omit<PropsType, 'toast'> & {
toastType: ToastType;
};
export default {
title: 'Components/ToastManager',
component: ToastManager,
@ -22,331 +144,26 @@ export default {
i18n: {
defaultValue: i18n,
},
toast: {
defaultValue: undefined,
toastType: {
defaultValue: ToastType.AddingUserToGroup,
options: ToastType,
control: { type: 'select' },
},
OS: {
defaultValue: 'macOS',
},
},
} as Meta;
} as Meta<Args>;
// eslint-disable-next-line react/function-component-definition
const Template: Story<PropsType> = args => <ToastManager {...args} />;
export const UndefinedToast = Template.bind({});
UndefinedToast.args = {};
export const InvalidToast = Template.bind({});
InvalidToast.args = {
toast: {
toastType: 'this is a toast that does not exist' as ToastType,
},
const Template: Story<Args> = args => {
const { toastType, ...rest } = args;
return (
<>
<p>Select a toast type in controls</p>
<ToastManager toast={getToast(toastType)} {...rest} />
</>
);
};
export const AddingUserToGroup = Template.bind({});
AddingUserToGroup.args = {
toast: {
toastType: ToastType.AddingUserToGroup,
parameters: {
contact: 'Sam Mirete',
},
},
};
export const AlreadyGroupMember = Template.bind({});
AlreadyGroupMember.args = {
toast: {
toastType: ToastType.AlreadyGroupMember,
},
};
export const AlreadyRequestedToJoin = Template.bind({});
AlreadyRequestedToJoin.args = {
toast: {
toastType: ToastType.AlreadyRequestedToJoin,
},
};
export const Blocked = Template.bind({});
Blocked.args = {
toast: {
toastType: ToastType.Blocked,
},
};
export const BlockedGroup = Template.bind({});
BlockedGroup.args = {
toast: {
toastType: ToastType.BlockedGroup,
},
};
export const CannotMixMultiAndNonMultiAttachments = Template.bind({});
CannotMixMultiAndNonMultiAttachments.args = {
toast: {
toastType: ToastType.CannotMixMultiAndNonMultiAttachments,
},
};
export const CannotOpenGiftBadgeIncoming = Template.bind({});
CannotOpenGiftBadgeIncoming.args = {
toast: {
toastType: ToastType.CannotOpenGiftBadgeIncoming,
},
};
export const CannotOpenGiftBadgeOutgoing = Template.bind({});
CannotOpenGiftBadgeOutgoing.args = {
toast: {
toastType: ToastType.CannotOpenGiftBadgeOutgoing,
},
};
export const CannotStartGroupCall = Template.bind({});
CannotStartGroupCall.args = {
toast: {
toastType: ToastType.CannotStartGroupCall,
},
};
export const ConversationArchived = Template.bind({});
ConversationArchived.args = {
toast: {
toastType: ToastType.ConversationArchived,
parameters: {
conversationId: 'some-conversation-id',
},
},
};
export const ConversationMarkedUnread = Template.bind({});
ConversationMarkedUnread.args = {
toast: {
toastType: ToastType.ConversationMarkedUnread,
},
};
export const ConversationRemoved = Template.bind({});
ConversationRemoved.args = {
toast: {
toastType: ToastType.ConversationRemoved,
parameters: {
title: 'Alice',
},
},
};
export const ConversationUnarchived = Template.bind({});
ConversationUnarchived.args = {
toast: {
toastType: ToastType.ConversationUnarchived,
},
};
export const CopiedUsername = Template.bind({});
CopiedUsername.args = {
toast: {
toastType: ToastType.CopiedUsername,
},
};
export const CopiedUsernameLink = Template.bind({});
CopiedUsernameLink.args = {
toast: {
toastType: ToastType.CopiedUsernameLink,
},
};
export const DangerousFileType = Template.bind({});
DangerousFileType.args = {
toast: {
toastType: ToastType.DangerousFileType,
},
};
export const DeleteForEveryoneFailed = Template.bind({});
DeleteForEveryoneFailed.args = {
toast: {
toastType: ToastType.DeleteForEveryoneFailed,
},
};
export const Error = Template.bind({});
Error.args = {
toast: {
toastType: ToastType.Error,
},
};
export const Expired = Template.bind({});
Expired.args = {
toast: {
toastType: ToastType.Expired,
},
};
export const FailedToDeleteUsername = Template.bind({});
FailedToDeleteUsername.args = {
toast: {
toastType: ToastType.FailedToDeleteUsername,
},
};
export const FileSaved = Template.bind({});
FileSaved.args = {
toast: {
toastType: ToastType.FileSaved,
parameters: {
fullPath: '/image.png',
},
},
};
export const FileSize = Template.bind({});
FileSize.args = {
toast: {
toastType: ToastType.FileSize,
parameters: {
limit: '100',
units: 'MB',
},
},
};
export const InvalidConversation = Template.bind({});
InvalidConversation.args = {
toast: {
toastType: ToastType.InvalidConversation,
},
};
export const LeftGroup = Template.bind({});
LeftGroup.args = {
toast: {
toastType: ToastType.LeftGroup,
},
};
export const MaxAttachments = Template.bind({});
MaxAttachments.args = {
toast: {
toastType: ToastType.MaxAttachments,
},
};
export const OriginalMessageNotFound = Template.bind({});
OriginalMessageNotFound.args = {
toast: {
toastType: ToastType.OriginalMessageNotFound,
},
};
export const MessageBodyTooLong = Template.bind({});
MessageBodyTooLong.args = {
toast: {
toastType: ToastType.MessageBodyTooLong,
},
};
export const PinnedConversationsFull = Template.bind({});
PinnedConversationsFull.args = {
toast: {
toastType: ToastType.PinnedConversationsFull,
},
};
export const ReactionFailed = Template.bind({});
ReactionFailed.args = {
toast: {
toastType: ToastType.ReactionFailed,
},
};
export const ReportedSpamAndBlocked = Template.bind({});
ReportedSpamAndBlocked.args = {
toast: {
toastType: ToastType.ReportedSpamAndBlocked,
},
};
export const StoryMuted = Template.bind({});
StoryMuted.args = {
toast: {
toastType: ToastType.StoryMuted,
},
};
export const StoryReact = Template.bind({});
StoryReact.args = {
toast: {
toastType: ToastType.StoryReact,
},
};
export const StoryReply = Template.bind({});
StoryReply.args = {
toast: {
toastType: ToastType.StoryReply,
},
};
export const StoryVideoError = Template.bind({});
StoryVideoError.args = {
toast: {
toastType: ToastType.StoryVideoError,
},
};
export const StoryVideoUnsupported = Template.bind({});
StoryVideoUnsupported.args = {
toast: {
toastType: ToastType.StoryVideoUnsupported,
},
};
export const TapToViewExpiredIncoming = Template.bind({});
TapToViewExpiredIncoming.args = {
toast: {
toastType: ToastType.TapToViewExpiredIncoming,
},
};
export const TapToViewExpiredOutgoing = Template.bind({});
TapToViewExpiredOutgoing.args = {
toast: {
toastType: ToastType.TapToViewExpiredOutgoing,
},
};
export const UnableToLoadAttachment = Template.bind({});
UnableToLoadAttachment.args = {
toast: {
toastType: ToastType.UnableToLoadAttachment,
},
};
export const UnsupportedMultiAttachment = Template.bind({});
UnsupportedMultiAttachment.args = {
toast: {
toastType: ToastType.UnsupportedMultiAttachment,
},
};
export const UnsupportedOS = Template.bind({});
UnsupportedOS.args = {
toast: {
toastType: ToastType.UnsupportedOS,
},
};
export const UserAddedToGroup = Template.bind({});
UserAddedToGroup.args = {
toast: {
toastType: ToastType.UserAddedToGroup,
parameters: {
contact: 'Sam Mirete',
group: 'Hike Group 🏔',
},
},
};
export const BasicUsage = Template.bind({});