mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 18:29:15 +03:00
refactor: folder structure
This commit is contained in:
parent
514448748d
commit
add3b1bb24
@ -1,11 +1,13 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Router, Switch } from 'react-router-dom';
|
import { Router, Switch } from 'react-router-dom';
|
||||||
|
import { UserRoleEnum } from 'enums';
|
||||||
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Components
|
* Components
|
||||||
*/
|
*/
|
||||||
import PrivateRoute from 'components/PrivateRoute/PrivateRoute';
|
import PrivateRoute from 'components/PrivateRoute';
|
||||||
import PublicRoute from 'components/PublicRoute/PublicRoute';
|
import PublicRoute from 'components/PublicRoute';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pages
|
* Pages
|
||||||
@ -17,13 +19,12 @@ import ProfilePage from 'pages/profile';
|
|||||||
import ControlPage from 'pages/control';
|
import ControlPage from 'pages/control';
|
||||||
import AuthPage from 'pages/auth';
|
import AuthPage from 'pages/auth';
|
||||||
import NotFoundPage from 'pages/404';
|
import NotFoundPage from 'pages/404';
|
||||||
import { UserRoleEnum } from 'enums';
|
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const {
|
const {
|
||||||
uiStore: { history },
|
uiStore: { history },
|
||||||
} = useRootStore();
|
} = useRootStore();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router history={history}>
|
<Router history={history}>
|
||||||
<Switch>
|
<Switch>
|
||||||
|
|||||||
10
src/api.config.ts
Normal file
10
src/api.config.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { AxiosRequestConfig } from 'axios';
|
||||||
|
import { API_BASE_URL } from './constants';
|
||||||
|
|
||||||
|
const apiConfig: AxiosRequestConfig = {
|
||||||
|
baseURL: API_BASE_URL,
|
||||||
|
responseType: 'json',
|
||||||
|
withCredentials: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default apiConfig;
|
||||||
@ -4,7 +4,7 @@ import { FaMoon, FaSun } from 'react-icons/fa';
|
|||||||
|
|
||||||
type ColorModeSwitcherProps = Omit<IconButtonProps, 'aria-label'>;
|
type ColorModeSwitcherProps = Omit<IconButtonProps, 'aria-label'>;
|
||||||
|
|
||||||
export const ColorModeSwitcher: React.FC<ColorModeSwitcherProps> = props => {
|
const ColorModeSwitcher: React.FC<ColorModeSwitcherProps> = props => {
|
||||||
const { toggleColorMode } = useColorMode();
|
const { toggleColorMode } = useColorMode();
|
||||||
const text = useColorModeValue('dark', 'light');
|
const text = useColorModeValue('dark', 'light');
|
||||||
const SwitchIcon = useColorModeValue(FaMoon, FaSun);
|
const SwitchIcon = useColorModeValue(FaMoon, FaSun);
|
||||||
@ -23,3 +23,5 @@ export const ColorModeSwitcher: React.FC<ColorModeSwitcherProps> = props => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default ColorModeSwitcher;
|
||||||
|
|||||||
3
src/components/ColorModeSwitcher/index.ts
Normal file
3
src/components/ColorModeSwitcher/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import ColorModeSwitcher from './ColorModeSwitcher';
|
||||||
|
|
||||||
|
export default ColorModeSwitcher;
|
||||||
@ -1,11 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Flex, Box, useColorMode } from '@chakra-ui/react';
|
|
||||||
import AppName from './AppName';
|
|
||||||
import UserInfo from './User/UserInfo';
|
|
||||||
import UserNotifications from './User/UserNotifications';
|
|
||||||
import NavMobile from '../Nav/Mobile/Nav';
|
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
|
import { Flex, Box, useColorMode } from '@chakra-ui/react';
|
||||||
|
import AppName from './AppName';
|
||||||
|
import UserInfo from './UserInfo';
|
||||||
|
import UserNotifications from './UserNotifications';
|
||||||
|
import NavMobile from 'components/Nav/Mobile';
|
||||||
|
|
||||||
const Header: React.FC = () => {
|
const Header: React.FC = () => {
|
||||||
const {
|
const {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import { MdSettings, MdExitToApp } from 'react-icons/md';
|
|||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import UserBadge from 'components/User/UserBadge';
|
import UserBadge from 'components/UserBadge';
|
||||||
import useLogoutQuery from 'hooks/useLogoutQuery';
|
import useLogoutQuery from 'hooks/useLogoutQuery';
|
||||||
|
|
||||||
const UserInfo: React.FC = () => {
|
const UserInfo: React.FC = () => {
|
||||||
3
src/components/Header/index.ts
Normal file
3
src/components/Header/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import Header from './Header';
|
||||||
|
|
||||||
|
export default Header;
|
||||||
@ -1,11 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Flex, Box } from '@chakra-ui/react';
|
|
||||||
import Header from 'components/Header/Header';
|
|
||||||
import NavDesktop from 'components/Nav/Desktop/Nav';
|
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
|
||||||
import { useErrorHandler } from 'react-error-boundary';
|
import { useErrorHandler } from 'react-error-boundary';
|
||||||
import { ColorModeSwitcher } from 'components/ColorModeSwitcher/ColorModeSwitcher';
|
import { Flex, Box } from '@chakra-ui/react';
|
||||||
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
|
import Header from 'components/Header';
|
||||||
|
import NavDesktop from 'components/Nav/Desktop';
|
||||||
|
import ColorModeSwitcher from 'components/ColorModeSwitcher';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
3
src/components/Layout/index.ts
Normal file
3
src/components/Layout/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import Layout from './Layout';
|
||||||
|
|
||||||
|
export default Layout;
|
||||||
@ -1,14 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Skeleton } from '@chakra-ui/skeleton';
|
|
||||||
import { Box } from '@chakra-ui/layout';
|
|
||||||
|
|
||||||
const LoadingPage: React.FC = () => {
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Skeleton height='20px' width='200px' mb='10' borderRadius='md' />
|
|
||||||
<Skeleton height='43px' width='400px' borderRadius='md' />
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default LoadingPage;
|
|
||||||
@ -1,9 +1,9 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Flex, Box, useColorMode } from '@chakra-ui/react';
|
|
||||||
import NavList from '../NavList';
|
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
|
||||||
import { observer } from 'mobx-react';
|
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
|
import React from 'react';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
import { Flex, Box, useColorMode } from '@chakra-ui/react';
|
||||||
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
|
import NavList from '../NavList';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
import { Box, useColorMode } from '@chakra-ui/react';
|
import { Box, useColorMode } from '@chakra-ui/react';
|
||||||
import type { LinkType } from 'interfaces';
|
import type { LinkType } from 'interfaces';
|
||||||
import { observer } from 'mobx-react';
|
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
|
|
||||||
type NavLinkPropsType = {
|
type NavLinkPropsType = {
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import React, { useCallback } from 'react';
|
import React, { useCallback } from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import NavLink from './NavLink';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
import { userHasRoles } from 'helpers';
|
import { userHasRoles } from 'helpers';
|
||||||
import { UserRoleEnum } from 'enums';
|
import { UserRoleEnum } from 'enums';
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { LinkType } from 'interfaces';
|
import { LinkType } from 'interfaces';
|
||||||
|
import NavLink from './NavLink';
|
||||||
|
|
||||||
type NavListPropsType = {
|
type NavListPropsType = {
|
||||||
links: LinkType[];
|
links: LinkType[];
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
|
import config from 'config';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Helmet from 'react-helmet';
|
import Helmet from 'react-helmet';
|
||||||
import Layout from '../Layout/Layout';
|
import { ErrorBoundary } from 'react-error-boundary';
|
||||||
import { Route, Redirect } from 'react-router-dom';
|
import { Route, Redirect } from 'react-router-dom';
|
||||||
import { IPrivateRouteProps } from 'interfaces';
|
import { IPrivateRouteProps } from 'interfaces';
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
import { ErrorBoundary } from 'react-error-boundary';
|
import Layout from 'components/Layout';
|
||||||
import ErrorFallback from '../ErrorFallback';
|
import ErrorFallback from 'components/ErrorFallback';
|
||||||
import config from 'config';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the user is loggedIn by reactive variable and if not,
|
* Checks if the user is loggedIn by reactive variable and if not,
|
||||||
|
|||||||
3
src/components/PrivateRoute/index.ts
Normal file
3
src/components/PrivateRoute/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import PrivateRoute from './PrivateRoute';
|
||||||
|
|
||||||
|
export default PrivateRoute;
|
||||||
@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import { ErrorBoundary } from 'react-error-boundary';
|
import { ErrorBoundary } from 'react-error-boundary';
|
||||||
import { Route } from 'react-router-dom';
|
import { Route } from 'react-router-dom';
|
||||||
import { IPublicRouteProps } from 'interfaces';
|
import { IPublicRouteProps } from 'interfaces';
|
||||||
import ErrorFallback from '../ErrorFallback';
|
import ErrorFallback from 'components/ErrorFallback';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render public page
|
* Render public page
|
||||||
|
|||||||
3
src/components/PublicRoute/index.ts
Normal file
3
src/components/PublicRoute/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import PublicRoute from './PublicRoute';
|
||||||
|
|
||||||
|
export default PublicRoute;
|
||||||
3
src/components/UserBadge/index.ts
Normal file
3
src/components/UserBadge/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import UserBadge from './UserBadge';
|
||||||
|
|
||||||
|
export default UserBadge;
|
||||||
3
src/pages/auth/components/AuthForm/index.ts
Normal file
3
src/pages/auth/components/AuthForm/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import AuthForm from './AuthForm';
|
||||||
|
|
||||||
|
export default AuthForm;
|
||||||
@ -6,7 +6,7 @@ import { IPageProps } from 'interfaces';
|
|||||||
import { Flex } from '@chakra-ui/react';
|
import { Flex } from '@chakra-ui/react';
|
||||||
import { useRootStore } from 'hooks/useRootStore';
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
|
|
||||||
import AuthForm from 'components/Forms/Auth/AuthForm';
|
import AuthForm from './components/AuthForm';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auth page
|
* Auth page
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Box, Skeleton, SkeletonCircle, Flex, Spinner } from '@chakra-ui/react';
|
import { Box, Skeleton, SkeletonCircle, Flex, Spinner } from '@chakra-ui/react';
|
||||||
|
|
||||||
const LoadingProfilePage = () => {
|
const LoadingPage = () => {
|
||||||
return (
|
return (
|
||||||
<Box maxW='900px'>
|
<Box maxW='900px'>
|
||||||
<Skeleton height='35px' width='250px' borderRadius='md' />
|
<Skeleton height='35px' width='250px' borderRadius='md' />
|
||||||
@ -21,4 +21,4 @@ const LoadingProfilePage = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default LoadingProfilePage;
|
export default LoadingPage;
|
||||||
3
src/pages/profile/components/LoadingPage/index.ts
Normal file
3
src/pages/profile/components/LoadingPage/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import LoadingPage from './LoadingPage';
|
||||||
|
|
||||||
|
export default LoadingPage;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
import UpdateUserContactsForm from './UpdateUserContactsForm';
|
||||||
|
|
||||||
|
export default UpdateUserContactsForm;
|
||||||
3
src/pages/profile/components/UserAccountInfo/index.ts
Normal file
3
src/pages/profile/components/UserAccountInfo/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import UserAccountInfo from './UserAccountInfo';
|
||||||
|
|
||||||
|
export default UserAccountInfo;
|
||||||
@ -17,10 +17,11 @@ import { IPageProps } from 'interfaces';
|
|||||||
import { useRootStore } from 'hooks/useRootStore';
|
import { useRootStore } from 'hooks/useRootStore';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
import UserBadge from 'components/User/UserBadge';
|
import UserBadge from 'components/UserBadge';
|
||||||
import LoadingProfilePage from 'components/Loading/LoadingProfilePage';
|
|
||||||
import UserAccountInfo from 'components/User/UserAccountInfo';
|
import LoadingPage from './components/LoadingPage';
|
||||||
import UpdateUserContactsForm from 'components/Forms/User/UpdateUserContactsForm';
|
import UserAccountInfo from './components/UserAccountInfo';
|
||||||
|
import UpdateUserContactsForm from './components/UpdateUserContactsForm';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Profile page
|
* Profile page
|
||||||
@ -37,7 +38,7 @@ const ProfilePage: React.FC<IPageProps> = ({ title }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (userStore.me === null) {
|
if (userStore.me === null) {
|
||||||
return <LoadingProfilePage />;
|
return <LoadingPage />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -1,5 +1,5 @@
|
|||||||
|
import apiConfig from 'api.config';
|
||||||
import { makeAutoObservable } from 'mobx';
|
import { makeAutoObservable } from 'mobx';
|
||||||
import { API_BASE_URL } from '../constants';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Services
|
* Services
|
||||||
@ -26,11 +26,7 @@ export default class RootStore {
|
|||||||
/**
|
/**
|
||||||
* Api service
|
* Api service
|
||||||
*/
|
*/
|
||||||
this.apiService = new ApiService(this, {
|
this.apiService = new ApiService(this, apiConfig);
|
||||||
baseURL: API_BASE_URL,
|
|
||||||
responseType: 'json',
|
|
||||||
withCredentials: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores
|
* Stores
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user