2024-05-24 19:53:37 +03:00
|
|
|
import { useEffect } from 'react';
|
2023-06-05 23:20:55 +03:00
|
|
|
import { ThemeProvider } from '@emotion/react';
|
2024-04-11 18:28:12 +03:00
|
|
|
import { Preview } from '@storybook/react';
|
2023-12-13 16:37:55 +03:00
|
|
|
import { initialize, mswDecorator } from 'msw-storybook-addon';
|
2024-04-11 18:28:12 +03:00
|
|
|
import { useDarkMode } from 'storybook-dark-mode';
|
2024-06-12 19:36:25 +03:00
|
|
|
import { THEME_DARK, THEME_LIGHT, ThemeContextProvider } from 'twenty-ui';
|
2024-02-25 15:52:48 +03:00
|
|
|
|
2023-07-24 10:57:56 +03:00
|
|
|
import { RootDecorator } from '../src/testing/decorators/RootDecorator';
|
2023-07-22 08:05:45 +03:00
|
|
|
import { mockedUserJWT } from '../src/testing/mock-data/jwt';
|
2023-07-25 21:00:15 +03:00
|
|
|
|
2023-12-10 18:22:43 +03:00
|
|
|
import 'react-loading-skeleton/dist/skeleton.css';
|
|
|
|
|
2023-12-13 16:37:55 +03:00
|
|
|
initialize({
|
|
|
|
onUnhandledRequest: async (request: Request) => {
|
2024-01-04 01:07:25 +03:00
|
|
|
const fileExtensionsToIgnore =
|
|
|
|
/\.(ts|tsx|js|jsx|svg|css|png)(\?v=[a-zA-Z0-9]+)?/;
|
2023-12-13 16:37:55 +03:00
|
|
|
|
|
|
|
if (fileExtensionsToIgnore.test(request.url)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const requestBody = await request.json();
|
2024-04-04 16:38:01 +03:00
|
|
|
// eslint-disable-next-line no-console
|
2023-12-13 16:37:55 +03:00
|
|
|
console.warn(`Unhandled ${request.method} request to ${request.url}
|
|
|
|
with payload ${JSON.stringify(requestBody)}\n
|
|
|
|
This request should be mocked with MSW`);
|
|
|
|
},
|
|
|
|
});
|
2023-05-29 12:02:38 +03:00
|
|
|
|
|
|
|
const preview: Preview = {
|
2023-06-05 23:20:55 +03:00
|
|
|
decorators: [
|
2024-04-11 18:28:12 +03:00
|
|
|
(Story) => {
|
2024-05-23 13:19:50 +03:00
|
|
|
const theme = useDarkMode() ? THEME_DARK : THEME_LIGHT;
|
2024-04-11 18:28:12 +03:00
|
|
|
|
2024-05-24 19:53:37 +03:00
|
|
|
useEffect(() => {
|
|
|
|
document.documentElement.className =
|
|
|
|
theme.name === 'dark' ? 'dark' : 'light';
|
|
|
|
}, [theme]);
|
|
|
|
|
2024-04-11 18:28:12 +03:00
|
|
|
return (
|
|
|
|
<ThemeProvider theme={theme}>
|
2024-06-12 19:36:25 +03:00
|
|
|
<ThemeContextProvider theme={theme}>
|
|
|
|
<Story />
|
|
|
|
</ThemeContextProvider>
|
2024-04-11 18:28:12 +03:00
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
},
|
2023-07-14 01:03:23 +03:00
|
|
|
RootDecorator,
|
2023-12-13 16:37:55 +03:00
|
|
|
mswDecorator,
|
2023-06-05 23:20:55 +03:00
|
|
|
],
|
2023-05-29 12:02:38 +03:00
|
|
|
parameters: {
|
|
|
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
|
|
|
controls: {
|
|
|
|
matchers: {
|
|
|
|
color: /(background|color)$/i,
|
|
|
|
date: /Date$/,
|
|
|
|
},
|
|
|
|
},
|
2023-07-18 03:14:53 +03:00
|
|
|
options: {
|
|
|
|
storySort: {
|
|
|
|
order: ['UI', 'Modules', 'Pages'],
|
|
|
|
},
|
|
|
|
},
|
2023-12-10 18:22:43 +03:00
|
|
|
cookie: {
|
|
|
|
tokenPair: `{%22accessToken%22:{%22token%22:%22${mockedUserJWT}%22%2C%22expiresAt%22:%222023-07-18T15:06:40.704Z%22%2C%22__typename%22:%22AuthToken%22}%2C%22refreshToken%22:{%22token%22:%22${mockedUserJWT}%22%2C%22expiresAt%22:%222023-10-15T15:06:41.558Z%22%2C%22__typename%22:%22AuthToken%22}%2C%22__typename%22:%22AuthTokenPair%22}`,
|
|
|
|
},
|
2023-05-29 12:02:38 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-07-14 01:03:23 +03:00
|
|
|
export default preview;
|