Skip to content

Commit

Permalink
new login modal, sidebar, profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill gai committed May 8, 2024
1 parent bc7a164 commit c06899d
Show file tree
Hide file tree
Showing 51 changed files with 350 additions and 127 deletions.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_widgets_SideBar_Common.png
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.
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.
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.
Binary file modified .loki/reference/chrome_laptop_widgets_SideBar_Common.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@
"password": "123"
}
],
"profile": { "name": "typicode" }
"profile": {
"first": "Кирилл",
"last": "Гай",
"age": 21,
"currency": "RUB",
"country": "Russia",
"city": "St. Petersburg",
"username": "gilead",
"avatar": "https://sun9-3.userapi.com/impg/fRt9rFPnIPsoR2qXjrNgmhYkYKOZJ9wc1K007w/PG5c7b_rDSI.jpg?size=2560x1707&quality=96&sign=e80fed43bd21fb613295d5b390954162&type=album"
}
}
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
},
"dependencies": {
"@reduxjs/toolkit": "^1.8.0",
"@tabler/icons-react": "^3.3.0",
"axios": "^1.6.8",
"i18next": "^21.6.11",
"i18next-browser-languagedetector": "^6.1.3",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"Вернуться на главную": "Вернуться на главную",
"Вернуться на глвную": "",
"Войти": "Login",
"Вы ввели неверный логин или пароль": "Вы ввели неверный логин или пароль",
"Выйти": "Logout",
"Главная": "Main",
"Главная страница": "",
Expand All @@ -16,6 +17,7 @@
"Перевести": "Translate",
"Перезагрузить": "Перезагрузить",
"Почта": "Почта",
"Профиль": "Профиль",
"Страница не найдена": "Страница не найдена",
"Тестовый перевод": "Test Translate",
"Тогл": "toggle",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/ru/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"Вернуться на главную": "Вернуться на главную",
"Вернуться на глвную": "",
"Войти": "Войти",
"Вы ввели неверный логин или пароль": "Вы ввели неверный логин или пароль",
"Выйти": "Выйти",
"Главная": "Главная",
"Главная страница": "",
Expand All @@ -16,6 +17,7 @@
"Перевести": "Перевести",
"Перезагрузить": "Перезагрузить",
"Почта": "Почта",
"Профиль": "Профиль",
"Страница не найдена": "Страница не найдена",
"Тестовый перевод": "Тестовый перевод",
"Тогл": "Тогл",
Expand Down
2 changes: 2 additions & 0 deletions src/app/providers/StoreProvider/config/StateSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import {
Reducer,
ReducersMapObject,
} from '@reduxjs/toolkit';
import { ProfileSchema } from 'entities/Profile';

export interface StateSchema {
counter: CounterSchema;
user: UserSchema;

// async
loginForm?: LoginSchema;
profile?: ProfileSchema;
}

export type StateSchemaKey = keyof StateSchema;
Expand Down
3 changes: 3 additions & 0 deletions src/entities/Profile/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type { ProfileT, ProfileSchema } from './model/type/profile';

export { profileReducer, profileActions } from './model/slice/profileSlice';
18 changes: 18 additions & 0 deletions src/entities/Profile/model/slice/profileSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createSlice } from '@reduxjs/toolkit';
import { ProfileSchema } from '../type/profile';

const initialState: ProfileSchema = {
readonly: true,
data: undefined,
error: undefined,
isLoading: false,
};

export const profileSlice = createSlice({
name: 'profile',
initialState,
reducers: {},
});

export const { actions: profileActions } = profileSlice;
export const { reducer: profileReducer } = profileSlice;
19 changes: 19 additions & 0 deletions src/entities/Profile/model/type/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { CountryT, CurrencyT } from 'shared/const/common';

export interface ProfileT {
first: string | null;
last: string | null;
age: number | null;
currency: CurrencyT | null;
country: CountryT | null;
city: string | null;
username: string | null;
avatar: string | null;
}

export interface ProfileSchema {
data?: ProfileT;
isLoading: boolean;
error?: string;
readonly?: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import axios from 'axios';
import { loginByUsername } from 'features/AuthByUsername/model/services/loginByUsername/loginByUsername';
import i18n from 'shared/configs/i18n/i18n';
import { TestAsyncThunk } from 'shared/lib/test/TestAsyncThunk/TestAsyncThunk';
import { userActions } from 'entities/User';

jest.mock('axios');
jest.mock('shared/configs/i18n/i18n', () => ({
t: jest.fn().mockImplementation((key) => key),
}));

const mockedAxios = jest.mocked(axios, true);

Expand Down Expand Up @@ -63,11 +59,9 @@ describe('longByUsername.test', () => {
});

test('error login', async () => {
const rejectValue = 'Неверный логин или пароль';
mockedAxios.post.mockReturnValue(Promise.resolve({ status: 403 }));
const thunk = new TestAsyncThunk(loginByUsername);
const result = await thunk.callThunk({ username: '123', password: '123' });
expect(i18n.t).toHaveBeenCalledWith(rejectValue);

expect(mockedAxios.post).toHaveBeenCalled();
expect(thunk.dispatch).toHaveBeenCalledTimes(2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';
import { User, userActions } from 'entities/User';
import i18n from 'shared/configs/i18n/i18n';
import { USER_LOCAL_TOKEN } from 'shared/const/localStorage';

interface LoginByUsernameProps {
Expand All @@ -26,6 +25,6 @@ export const loginByUsername = createAsyncThunk<

return response.data;
} catch (e) {
return thunkAPI.rejectWithValue(i18n.t('Неверный логин или пароль'));
return thunkAPI.rejectWithValue('error');
}
});
7 changes: 5 additions & 2 deletions src/features/AuthByUsername/ui/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const LoginForm: FC<LoginFormProps> = ({ className, onSuccess }) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const loginForm = useSelector(getLoginState);
useDynamicModuleLoader({ reducers: { loginForm: loginReducer } });
useDynamicModuleLoader({ reducers: initialReducers });

const onChangeUsername = useCallback(
(value: string) => {
Expand Down Expand Up @@ -60,7 +60,10 @@ const LoginForm: FC<LoginFormProps> = ({ className, onSuccess }) => {
<div className={classNames(cls.loginForm, {}, [className])}>
<Text className={cls.loginForm__title} title={t('Войти')} />
{loginForm?.error && (
<Text text={loginForm.error} theme={TextTheme.ERROR} />
<Text
text={t('Вы ввели неверный логин или пароль')}
theme={TextTheme.ERROR}
/>
)}
<Input
className={cls.loginForm__input}
Expand Down
Empty file.
3 changes: 1 addition & 2 deletions src/features/AuthByUsername/ui/LoginModal/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { classNames } from 'shared/lib/classNames/classNames';
import { Loader } from 'shared/ui/Loader/Loader';
import { Modal } from 'shared/ui/Modal/Modal';
import { LoginFormAsync } from '../LoginForm/LonginForm.async';
import cls from './LoginModal.module.scss';

interface LoginModalProps {
className?: string;
Expand All @@ -18,7 +17,7 @@ export const LoginModal: FC<LoginModalProps> = ({
}) => {
return (
<Modal
className={classNames(cls.loginModal, {}, [className])}
className={classNames('', {}, [className])}
onClose={onClose}
isOpen={isOpen}
lazy
Expand Down
1 change: 1 addition & 0 deletions src/pages/ProfilePage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ProfilePageAsync as ProfilePage } from './ui/ProfilePage.async';
3 changes: 3 additions & 0 deletions src/pages/ProfilePage/ui/ProfilePage.async.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { lazy } from 'react';

export const ProfilePageAsync = lazy(() => import('./ProfilePage'));
30 changes: 30 additions & 0 deletions src/pages/ProfilePage/ui/ProfilePage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Meta, StoryObj } from '@storybook/react';
import ProfilePage from './ProfilePage';
import { StoreDecorator } from '../../../shared/configs/storybook/StoreDecorator/StoreDecorator';
import { profileReducer } from '../../../entities/Profile';

const meta: Meta<typeof ProfilePage> = {
title: 'pages/ProfilePage',
component: ProfilePage,
tags: ['autodocs'],
};

export default meta;

type Story = StoryObj<typeof ProfilePage>;

export const Common: Story = {
decorators: [
StoreDecorator(
{
profile: {
data: undefined,
isLoading: false,
error: undefined,
readonly: true,
},
},
{ profile: profileReducer },
),
],
};
25 changes: 25 additions & 0 deletions src/pages/ProfilePage/ui/ProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { FC } from 'react';
import { useTranslation } from 'react-i18next';
import { classNames } from 'shared/lib/classNames/classNames';
import {
ReducersList,
useDynamicModuleLoader,
} from 'shared/hooks/useDynamicModuleLoader/useDynamicModuleLoader';
import { profileReducer } from '../../../entities/Profile';

const reducers: ReducersList = {
profile: profileReducer,
};

interface ProfilePageProps {
className?: string;
}

const ProfilePage: FC<ProfilePageProps> = ({ className }) => {
const { t } = useTranslation();
useDynamicModuleLoader({ reducers, removeAfterUnmount: true });

return <div className={classNames('', {}, [className])}>{t('Профиль')}</div>;
};

export default ProfilePage;
7 changes: 7 additions & 0 deletions src/shared/configs/routerConfig/routerConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { MainPage } from 'pages/MainPage';
import { AboutPage } from 'pages/AboutPage';
import { RouteProps } from 'react-router-dom';
import { NotFoundPage } from 'pages/NotFoundPage';
import { ProfilePage } from 'pages/ProfilePage';

export enum AppRouter {
MAIN = 'main',
ABOUT = 'about',
PROFILE = 'profile',
NOT_FOUND = 'not_found',
}

export const RouterPath: Record<AppRouter, string> = {
[AppRouter.MAIN]: '/',
[AppRouter.ABOUT]: '/about',
[AppRouter.PROFILE]: '/profile',
[AppRouter.NOT_FOUND]: '*',
};

Expand All @@ -24,6 +27,10 @@ export const routerConfig: Record<AppRouter, RouteProps> = {
path: RouterPath.about,
element: <AboutPage />,
},
[AppRouter.PROFILE]: {
path: RouterPath.profile,
element: <ProfilePage />,
},
[AppRouter.NOT_FOUND]: {
path: RouterPath.not_found,
element: <NotFoundPage />,
Expand Down
13 changes: 13 additions & 0 deletions src/shared/const/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export enum CurrencyT {
RUB = 'RUB',
EUR = 'EUR',
USD = 'USD',
}

export enum CountryT {
Russia = 'Russia',
Belarus = 'Belarus',
Ukraine = 'Ukraine',
Kazakhstan = 'Kazakhstan',
Armenia = 'Armenia',
}
5 changes: 5 additions & 0 deletions src/shared/ui/Button/Button.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
display: flex;
column-gap: 8px;
align-items: center;
justify-content: center;
}

.unstyled {
Expand All @@ -37,3 +38,7 @@
background-color: var(--gray-light-color);
color: var(--gray-color);
}

.square {
padding: 5px;
}
Loading

0 comments on commit c06899d

Please sign in to comment.