2022-07-12 16:41:41 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { Meta, Story } from '@storybook/react';
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
|
|
|
import { ToastManager } from './ToastManager';
|
2023-04-10 21:38:34 +00:00
|
|
|
import type { AnyToast } from '../types/Toast';
|
2022-12-15 00:48:36 +00:00
|
|
|
import { ToastType } from '../types/Toast';
|
2022-07-12 16:41:41 +00:00
|
|
|
import { setupI18n } from '../util/setupI18n';
|
2023-04-10 21:38:34 +00:00
|
|
|
import { missingCaseError } from '../util/missingCaseError';
|
|
|
|
import type { PropsType } from './ToastManager';
|
2022-07-12 16:41:41 +00:00
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2023-04-10 21:38:34 +00:00
|
|
|
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 };
|
2023-04-20 16:31:59 +00:00
|
|
|
case ToastType.CannotEditMessage:
|
|
|
|
return { toastType: ToastType.CannotEditMessage };
|
2023-04-10 21:38:34 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2022-07-12 16:41:41 +00:00
|
|
|
export default {
|
|
|
|
title: 'Components/ToastManager',
|
|
|
|
component: ToastManager,
|
|
|
|
argTypes: {
|
|
|
|
hideToast: { action: true },
|
2022-12-21 03:25:10 +00:00
|
|
|
openFileInFolder: { action: true },
|
|
|
|
onUndoArchive: { action: true },
|
2022-07-12 16:41:41 +00:00
|
|
|
i18n: {
|
|
|
|
defaultValue: i18n,
|
|
|
|
},
|
2023-04-10 21:38:34 +00:00
|
|
|
toastType: {
|
|
|
|
defaultValue: ToastType.AddingUserToGroup,
|
|
|
|
options: ToastType,
|
|
|
|
control: { type: 'select' },
|
2022-07-12 16:41:41 +00:00
|
|
|
},
|
2023-01-18 23:31:10 +00:00
|
|
|
OS: {
|
|
|
|
defaultValue: 'macOS',
|
|
|
|
},
|
2022-07-12 16:41:41 +00:00
|
|
|
},
|
2023-04-10 21:38:34 +00:00
|
|
|
} as Meta<Args>;
|
2022-07-12 16:41:41 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
// eslint-disable-next-line react/function-component-definition
|
2023-04-10 21:38:34 +00:00
|
|
|
const Template: Story<Args> = args => {
|
|
|
|
const { toastType, ...rest } = args;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<p>Select a toast type in controls</p>
|
|
|
|
<ToastManager toast={getToast(toastType)} {...rest} />
|
|
|
|
</>
|
|
|
|
);
|
2022-12-07 01:00:02 +00:00
|
|
|
};
|
|
|
|
|
2023-04-10 21:38:34 +00:00
|
|
|
export const BasicUsage = Template.bind({});
|