-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
247 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"Настройки пользователя": "User settings", | ||
"Новый": "New", | ||
"Старый": "Old", | ||
"Вариант интерфейса": "Interface option" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"Настройки пользователя": "Настройки пользователя", | ||
"Новый": "Новый", | ||
"Старый": "Старый", | ||
"Вариант интерфейса": "Вариант интерфейса" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## Feature for switching old and new designs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { UiDesignSwitcher } from './ui/UiDesignSwitcher'; |
16 changes: 16 additions & 0 deletions
16
src/features/uiDesignSwitcher/ui/UiDesignSwitcher.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { UiDesignSwitcher } from './UiDesignSwitcher'; | ||
|
||
export default { | ||
title: 'shared/UiDesignSwitcher', | ||
component: UiDesignSwitcher, | ||
argTypes: { | ||
backgroundColor: { control: 'color' }, | ||
}, | ||
} as ComponentMeta<typeof UiDesignSwitcher>; | ||
|
||
const Template: ComponentStory<typeof UiDesignSwitcher> = (args) => <UiDesignSwitcher {...args} />; | ||
|
||
export const Normal = Template.bind({}); | ||
Normal.args = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { memo, useCallback, useMemo, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { ListBox } from '@/shared/ui/redesigned/Popups'; | ||
import { getFeatureFlag, updateFeatureFlags } from '@/shared/lib/features'; | ||
import { useAppDispatch } from '@/shared/lib/hooks/useAppDispatch/useAppDispatch'; | ||
import { getUserAuthData } from '@/entities/User'; | ||
import { HStack } from '@/shared/ui/redesigned/Stack'; | ||
import { Text } from '@/shared/ui/redesigned/Text'; | ||
import { Skeleton } from '@/shared/ui/redesigned/Skeleton'; | ||
|
||
interface UiDesignSwitcherProps { | ||
className?: string; | ||
} | ||
|
||
export const UiDesignSwitcher = memo((props: UiDesignSwitcherProps) => { | ||
const { className } = props; | ||
const { t } = useTranslation('settings'); | ||
const dispatch = useAppDispatch(); | ||
const authData = useSelector(getUserAuthData); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const isAppRedesigned = getFeatureFlag('isAppRedesigned'); | ||
const items = useMemo( | ||
() => [ | ||
{ | ||
content: t('Новый'), | ||
value: 'new', | ||
}, | ||
{ | ||
content: t('Старый'), | ||
value: 'old', | ||
}, | ||
], | ||
[t], | ||
); | ||
|
||
const onDesignChange = useCallback( | ||
async (value: string) => { | ||
if (authData?.id) { | ||
setIsLoading(true); | ||
|
||
await dispatch( | ||
updateFeatureFlags({ | ||
userId: authData.id, | ||
newFeatures: { | ||
isAppRedesigned: value === 'new', | ||
}, | ||
}), | ||
).unwrap(); | ||
|
||
setIsLoading(false); | ||
} | ||
}, | ||
[authData?.id, dispatch], | ||
); | ||
|
||
return ( | ||
<HStack gap="8" max> | ||
<Text text={t('Вариант интерфейса')} /> | ||
|
||
{isLoading ? ( | ||
<Skeleton width={100} height={40} /> | ||
) : ( | ||
<ListBox | ||
onChange={onDesignChange} | ||
value={isAppRedesigned ? 'new' : 'old'} | ||
items={items} | ||
className={className} | ||
/> | ||
)} | ||
</HStack> | ||
); | ||
}); | ||
|
||
UiDesignSwitcher.displayName = 'UiDesignSwitcher'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SettingsPageAsync as SettingsPage } from './ui/SettingsPage.async'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { lazy } from 'react'; | ||
|
||
export const SettingsPageAsync = lazy(() => | ||
import('./SettingsPage').then((module) => ({ default: module.SettingsPage })), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { SettingsPage } from './SettingsPage'; | ||
|
||
export default { | ||
title: 'pages/SettingsPage', | ||
component: SettingsPage, | ||
argTypes: { | ||
backgroundColor: { control: 'color' }, | ||
}, | ||
} as ComponentMeta<typeof SettingsPage>; | ||
|
||
const Template: ComponentStory<typeof SettingsPage> = (args) => <SettingsPage {...args} />; | ||
|
||
export const Normal = Template.bind({}); | ||
Normal.args = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { memo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Text } from '@/shared/ui/redesigned/Text'; | ||
import { Page } from '@/widgets/Page'; | ||
import { VStack } from '@/shared/ui/redesigned/Stack'; | ||
import { UiDesignSwitcher } from '@/features/uiDesignSwitcher'; | ||
|
||
interface SettingsPageProps { | ||
className?: string; | ||
} | ||
|
||
export const SettingsPage = memo((props: SettingsPageProps) => { | ||
const { className } = props; | ||
|
||
const { t } = useTranslation('settings'); | ||
|
||
return ( | ||
<Page className={className}> | ||
<VStack gap="16" max> | ||
<Text title={t('Настройки пользователя')} /> | ||
|
||
<UiDesignSwitcher /> | ||
</VStack> | ||
</Page> | ||
); | ||
}); | ||
|
||
SettingsPage.displayName = 'SettingsPage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { rtkApi } from '@/shared/api/rtkApi'; | ||
import { FeatureFlags } from '@/shared/types/featureFlags'; | ||
|
||
interface UpdateFeatureFlagsArg { | ||
userId: string; | ||
features: Partial<FeatureFlags>; | ||
} | ||
|
||
const featureFlagsApi = rtkApi.injectEndpoints({ | ||
endpoints: (build) => ({ | ||
updateFeatureFlags: build.mutation<void, UpdateFeatureFlagsArg>({ | ||
query: ({ userId, features }) => ({ | ||
url: `/users/${userId}`, | ||
method: 'PATCH', | ||
body: { | ||
features, | ||
}, | ||
}), | ||
}), | ||
}), | ||
}); | ||
|
||
export const updateFeatureFlagsMutation = featureFlagsApi.endpoints.updateFeatureFlags.initiate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { getFeatureFlag, setFeatureFlags } from './setGetFeatures'; | ||
export { toggleFeatures } from './toggleFeatures'; | ||
export { ToggleFeatures } from './ToggleFeatures/ToggleFeatures'; | ||
export { getFeatureFlag, setFeatureFlags } from './lib/setGetFeatures'; | ||
export { toggleFeatures } from './lib/toggleFeatures'; | ||
export { ToggleFeatures } from './components/ToggleFeatures/ToggleFeatures'; | ||
export { updateFeatureFlags } from './services/updateFeatureFlags'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
|
||
import { ThunkConfig } from '@/app/providers/StoreProvider'; | ||
import { updateFeatureFlagsMutation } from '@/shared/lib/features/api/featureFlagsApi'; | ||
import { FeatureFlags } from '@/shared/types/featureFlags'; | ||
import { getAllFeatureFlags } from '@/shared/lib/features/lib/setGetFeatures'; | ||
|
||
interface UpdateFeatureFlagsArg { | ||
userId: string; | ||
newFeatures: Partial<FeatureFlags>; | ||
} | ||
|
||
export const updateFeatureFlags = createAsyncThunk< | ||
void, | ||
UpdateFeatureFlagsArg, | ||
ThunkConfig<string> | ||
>('features/updateFeatureFlags', async ({ userId, newFeatures }, thunkAPI) => { | ||
const { rejectWithValue, dispatch } = thunkAPI; | ||
|
||
try { | ||
await dispatch( | ||
updateFeatureFlagsMutation({ | ||
userId, | ||
features: { | ||
...getAllFeatureFlags(), | ||
...newFeatures, | ||
}, | ||
}), | ||
); | ||
|
||
window.location.reload(); | ||
|
||
return undefined; | ||
} catch (e) { | ||
console.log(e); | ||
return rejectWithValue(''); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
.pageRedesigned { | ||
overflow-y: auto; | ||
height: 100%; | ||
} | ||
|
||
.trigger { | ||
|