mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-07-07 02:46:58 +00:00
feat(design-system): pre-port of roleypoly/ui
This commit is contained in:
parent
c41fcabfd0
commit
ea2683da00
98 changed files with 2339 additions and 0 deletions
10
src/design-system/templates/errors/Errors.story.tsx
Normal file
10
src/design-system/templates/errors/Errors.story.tsx
Normal file
|
@ -0,0 +1,10 @@
|
|||
import * as React from 'react';
|
||||
import { templateStories } from 'templates/templates.story';
|
||||
import { Error } from './Errors';
|
||||
import { errorMessages } from './errorStrings';
|
||||
|
||||
const messages = templateStories('Errors/Messages', module);
|
||||
|
||||
for (let message in errorMessages) {
|
||||
messages.add(`${message}`, () => <Error code={message} />);
|
||||
}
|
26
src/design-system/templates/errors/Errors.tsx
Normal file
26
src/design-system/templates/errors/Errors.tsx
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { DotOverlay } from 'atoms/dot-overlay';
|
||||
import { Hero } from 'atoms/hero';
|
||||
import { AppShell } from 'organisms/app-shell';
|
||||
import * as React from 'react';
|
||||
import { ErrorMessage, getMessageFromCode } from './errorStrings';
|
||||
import { ErrorBanner } from 'organisms/error-banner';
|
||||
import { RoleypolyUser } from '@roleypoly/rpc/shared';
|
||||
|
||||
export type ErrorProps = {
|
||||
code: string | number;
|
||||
messageOverride?: ErrorMessage;
|
||||
user?: RoleypolyUser.AsObject | null;
|
||||
};
|
||||
|
||||
export const Error = (props: ErrorProps) => {
|
||||
const messageFromCode = getMessageFromCode(props.code);
|
||||
|
||||
return (
|
||||
<AppShell user={props.user || null}>
|
||||
<DotOverlay />
|
||||
<Hero topSpacing={100} bottomSpacing={25}>
|
||||
<ErrorBanner message={messageFromCode} />
|
||||
</Hero>
|
||||
</AppShell>
|
||||
);
|
||||
};
|
66
src/design-system/templates/errors/errorStrings.ts
Normal file
66
src/design-system/templates/errors/errorStrings.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
export type ErrorMessage = {
|
||||
english: string;
|
||||
japanese?: string;
|
||||
friendlyCode?: string;
|
||||
};
|
||||
|
||||
const defaultMessage: Required<ErrorMessage> = {
|
||||
english: `Something went bad. How could this happen?`,
|
||||
japanese: `わかりません...`,
|
||||
friendlyCode: 'Oops.',
|
||||
};
|
||||
|
||||
export const errorMessages: { [code: string]: ErrorMessage } = {
|
||||
default: defaultMessage,
|
||||
'400': {
|
||||
english: 'Your client sent me something weird...',
|
||||
japanese: '((((;゜Д゜)))',
|
||||
},
|
||||
'403': {
|
||||
english: `You weren't allowed to access this.`,
|
||||
japanese: 'あなたはこの点に合格しないかもしれません',
|
||||
},
|
||||
'404': {
|
||||
english: `This page is in another castle.`,
|
||||
japanese: 'お探しのページは見つかりませんでした',
|
||||
},
|
||||
'419': {
|
||||
english: 'Something went too slowly...',
|
||||
japanese: 'おやすみなさい〜',
|
||||
},
|
||||
'500': {
|
||||
english: `The server doesn't like you right now. Feed it a cookie.`,
|
||||
japanese: 'クッキーを送ってください〜 クッキーを送ってください〜',
|
||||
},
|
||||
serverFailure: {
|
||||
english: `Server is super unhappy with you today...`,
|
||||
japanese: 'クッキーを送ってください〜',
|
||||
friendlyCode: `Oh no!`,
|
||||
},
|
||||
magicExpired: {
|
||||
english: 'That magic login link was expired.',
|
||||
friendlyCode: 'Woah.',
|
||||
},
|
||||
authFailure: {
|
||||
english: `I tried to tell the server who you were...`,
|
||||
japanese: `...but it didn't believe me. :( ごめんなさい`,
|
||||
friendlyCode: 'Yo.',
|
||||
},
|
||||
};
|
||||
|
||||
export const getMessageFromCode = (
|
||||
code: keyof typeof errorMessages
|
||||
): Required<ErrorMessage> => {
|
||||
const codeStr = String(code);
|
||||
const baseMessage = errorMessages[codeStr];
|
||||
|
||||
const message: Required<ErrorMessage> = {
|
||||
english: baseMessage?.english || defaultMessage.english,
|
||||
japanese: baseMessage?.japanese || defaultMessage.japanese,
|
||||
friendlyCode: baseMessage
|
||||
? baseMessage?.friendlyCode || codeStr
|
||||
: defaultMessage.friendlyCode,
|
||||
};
|
||||
|
||||
return message;
|
||||
};
|
1
src/design-system/templates/errors/index.ts
Normal file
1
src/design-system/templates/errors/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './Errors';
|
Loading…
Add table
Add a link
Reference in a new issue