Skip to content

Commit

Permalink
refactor!: use i18next with local provider as lib
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Dec 11, 2023
1 parent 9f78d95 commit d7a192c
Show file tree
Hide file tree
Showing 41 changed files with 341 additions and 166 deletions.
13 changes: 13 additions & 0 deletions src/I18nWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { I18nextProvider } from 'react-i18next';
import i18n from './i18n';

export interface Props {
children: React.ReactNode;
}

const I18nWrapper = ({ children }: Props) => (
<I18nextProvider i18n={i18n}>{children}</I18nextProvider>
);

export default I18nWrapper;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Meta, Story } from '@storybook/react';
import I18nWrapper from '../../I18nWrapper';
import AgeVerificationModal, { Props } from './AgeVerificationModal';

import './AgeVerificationModal.css';
Expand All @@ -15,7 +16,11 @@ const meta: Meta = {

export default meta;

const Template: Story<Props> = args => <AgeVerificationModal {...args} />;
const Template: Story<Props> = args => (
<I18nWrapper>
<AgeVerificationModal {...args} />
</I18nWrapper>
);

// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/react/workflows/unit-testing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Meta, Story } from '@storybook/react';
import I18nWrapper from '../../I18nWrapper';
import AttachmentLinkModal, { Props } from './AttachmentLinkModal';

import './AttachmentLinkModal.css';
Expand All @@ -15,7 +16,11 @@ const meta: Meta = {

export default meta;

const Template: Story<Props> = args => <AttachmentLinkModal {...args} />;
const Template: Story<Props> = args => (
<I18nWrapper>
<AttachmentLinkModal {...args} />
</I18nWrapper>
);

// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/react/workflows/unit-testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Meta, Story } from '@storybook/react';
import AttachmentMediaModal, { Props } from './AttachmentMediaModal';
import memoriAPIClient from '@memori.ai/memori-api-client';
import I18nWrapper from '../../I18nWrapper';
import { Asset } from '@memori.ai/memori-api-client/dist/types';

const client = memoriAPIClient();
Expand All @@ -17,7 +18,11 @@ const meta: Meta = {

export default meta;

const Template: Story<Props> = args => <AttachmentMediaModal {...args} />;
const Template: Story<Props> = args => (
<I18nWrapper>
<AttachmentMediaModal {...args} />
</I18nWrapper>
);

// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/react/workflows/unit-testing
Expand Down
27 changes: 16 additions & 11 deletions src/components/Auth/Auth.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import { Meta, Story } from '@storybook/react';
import I18nWrapper from '../../I18nWrapper';
import AuthWidget, { Props } from './Auth';

import './Auth.css';
Expand Down Expand Up @@ -33,11 +34,13 @@ const Template: Story<Props> = args => {
);

return (
<AuthWidget
{...args}
pwdOrTokens={pwdOrTokens}
setPwdOrTokens={setPwdOrTokens}
/>
<I18nWrapper>
<AuthWidget
{...args}
pwdOrTokens={pwdOrTokens}
setPwdOrTokens={setPwdOrTokens}
/>
</I18nWrapper>
);
};

Expand All @@ -47,12 +50,14 @@ const TemplateWithModal: Story<Props> = args => {
);

return (
<AuthWidget
{...args}
withModal
pwdOrTokens={pwdOrTokens}
setPwdOrTokens={setPwdOrTokens}
/>
<I18nWrapper>
<AuthWidget
{...args}
withModal
pwdOrTokens={pwdOrTokens}
setPwdOrTokens={setPwdOrTokens}
/>
</I18nWrapper>
);
};

Expand Down
53 changes: 28 additions & 25 deletions src/components/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Meta, Story } from '@storybook/react';
import { memori, tenant, integration } from '../../mocks/data';
import I18nWrapper from '../../I18nWrapper';
import Avatar, { Props } from './Avatar';

import './Avatar.css';
Expand Down Expand Up @@ -30,32 +31,34 @@ const Template: Story<Props> = args => {
);

return (
<div
style={
args.integrationConfig?.avatar === 'customglb' ||
args.integrationConfig?.avatar === 'readyplayerme' ||
args.integrationConfig?.avatar === 'readyplayerme-full'
? {}
: { marginTop: '20vw' }
}
>
<Avatar
{...args}
integrationConfig={
args.integrationConfig
? {
...args.integrationConfig,
avatarURL:
args.integrationConfig.avatarURL?.split('#')?.[0] +
`#${new Date(Date.now()).toISOString()}`,
}
: undefined
<I18nWrapper>
<div
style={
args.integrationConfig?.avatar === 'customglb' ||
args.integrationConfig?.avatar === 'readyplayerme' ||
args.integrationConfig?.avatar === 'readyplayerme-full'
? {}
: { marginTop: '20vw' }
}
avatar3dVisible={avatar3dVisible}
setAvatar3dVisible={setAvatar3dVisible}
key={Date.now()}
/>
</div>
>
<Avatar
{...args}
integrationConfig={
args.integrationConfig
? {
...args.integrationConfig,
avatarURL:
args.integrationConfig.avatarURL?.split('#')?.[0] +
`#${new Date(Date.now()).toISOString()}`,
}
: undefined
}
avatar3dVisible={avatar3dVisible}
setAvatar3dVisible={setAvatar3dVisible}
key={Date.now()}
/>
</div>
</I18nWrapper>
);
};

Expand Down
13 changes: 8 additions & 5 deletions src/components/AvatarView/AvatarView.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Meta, Story } from '@storybook/react';
import I18nWrapper from '../../I18nWrapper';
import AvatarView, { Props } from './index';

const meta: Meta = {
Expand Down Expand Up @@ -67,11 +68,13 @@ const Template: Story<Props> = args => {
}, []);

return hydrated ? (
<AvatarView
{...args}
url={args.url + `#${new Date(Date.now()).toISOString()}`}
key={Date.now()}
/>
<I18nWrapper>
<AvatarView
{...args}
url={args.url + `#${new Date(Date.now()).toISOString()}`}
key={Date.now()}
/>
</I18nWrapper>
) : (
<></>
);
Expand Down
9 changes: 6 additions & 3 deletions src/components/Blob/Blob.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Meta, Story } from '@storybook/react';
import I18nWrapper from '../../I18nWrapper';
import Blob, { Props } from './Blob';
import './Blob.css';

Expand All @@ -26,9 +27,11 @@ const meta: Meta = {
export default meta;

const Template: Story<Props> = args => (
<div style={{ marginTop: '20vw' }}>
<Blob {...args} />
</div>
<I18nWrapper>
<div style={{ marginTop: '20vw' }}>
<Blob {...args} />
</div>
</I18nWrapper>
);

// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Meta, Story } from '@storybook/react';
import I18nWrapper from '../../I18nWrapper';
import BlockedMemoriBadge, { Props } from './BlockedMemoriBadge';

import './BlockedMemoriBadge.css';
Expand All @@ -15,7 +16,11 @@ const meta: Meta = {

export default meta;

const Template: Story<Props> = args => <BlockedMemoriBadge {...args} />;
const Template: Story<Props> = args => (
<I18nWrapper>
<BlockedMemoriBadge {...args} />
</I18nWrapper>
);

// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/react/workflows/unit-testing
Expand Down
15 changes: 9 additions & 6 deletions src/components/ChangeMode/ChangeMode.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Meta, Story } from '@storybook/react';
import I18nWrapper from '../../I18nWrapper';
import ChangeMode, { Props } from './ChangeMode';

import './ChangeMode.css';
Expand All @@ -25,12 +26,14 @@ const Template: Story<Props> = args => {
const [instruct, setInstruct] = React.useState(args.instruct);

return (
<ChangeMode
{...args}
canInstruct
instruct={instruct}
onChangeMode={mode => setInstruct(mode === 'instruct')}
/>
<I18nWrapper>
<ChangeMode
{...args}
canInstruct
instruct={instruct}
onChangeMode={mode => setInstruct(mode === 'instruct')}
/>
</I18nWrapper>
);
};

Expand Down
13 changes: 8 additions & 5 deletions src/components/Chat/Chat.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
sessionID,
dialogState as dialogStateWithHints,
} from '../../mocks/data';
import I18nWrapper from '../../I18nWrapper';
import Chat, { Props } from './Chat';

import './Chat.css';
Expand All @@ -33,11 +34,13 @@ const Template: Story<Props> = args => {
const [userMessage, setUserMessage] = useState(args.userMessage);

return (
<Chat
{...args}
userMessage={userMessage}
onChangeUserMessage={setUserMessage}
/>
<I18nWrapper>
<Chat
{...args}
userMessage={userMessage}
onChangeUserMessage={setUserMessage}
/>
</I18nWrapper>
);
};

Expand Down
Loading

0 comments on commit d7a192c

Please sign in to comment.