Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring components #229

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
<head>
<link rel="icon" href="/icon.png" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Личный кабинет студента Московского Политеха" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="manifest" href="manifest.json">

<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;400;500;600;700&display=swap"
rel="stylesheet" />
rel="stylesheet" />
<title>Личный кабинет</title>
</head>

<body>
<noscript>Чтобы это приложение работало, вам необходимо включить JavaScript</noscript>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('service-worker.js', { scope: '/'}).then(function (registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function (err) {
console.log('ServiceWorker registration failed: ', err);
}).catch(function (err) {
console.log(err)
});
});
} else {
console.log('service worker is not supported');
}
</script>
<noscript>Чтобы это приложение работало, вам необходимо включить JavaScript</noscript>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
<script>
// if ('serviceWorker' in navigator) {
// window.addEventListener('load', function () {
// navigator.serviceWorker.register('service-worker.js', { scope: '/' }).then(function (registration) {
// console.log('ServiceWorker registration successful with scope: ', registration.scope);
// }, function (err) {
// console.log('ServiceWorker registration failed: ', err);
// }).catch(function (err) {
// console.log(err)
// });
// });
// } else {
// console.log('service worker is not supported');
// }
</script>
</body>

</html>
</html>
45 changes: 0 additions & 45 deletions public/index.html

This file was deleted.

65 changes: 0 additions & 65 deletions public/service-worker.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/routes/general-routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { IColors } from '@consts'
import { IColors } from '@shared/constants/consts'
import { LazyExoticComponent } from 'react'

import LoginPage from '@pages/login'
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { isProduction } from '@consts'
import { isProduction } from '@shared/constants/consts'
import FullTimePartTimeFormPage from '@pages/applications/pages/campus-management/full-time-part-time-form'
import PageIsNotReady from '@pages/page-is-not-ready'
import { BiCheckCircle, BiIdCard, BiInfoCircle } from 'react-icons/bi'
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes/teacher-routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
WorkTransfer,
} from './pages'

import { isProduction, OLD_LK_URL } from '@consts'
import { isProduction, OLD_LK_URL } from '@shared/constants/consts'
import DismissalBufferPage from '@pages/hr-applications/pages/buffer-dismissal'
import React from 'react'
import { BiBookReader, BiGroup, BiHeadphone, BiIdCard, BiNotification } from 'react-icons/bi'
Expand Down
9 changes: 6 additions & 3 deletions src/entities/menu/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { AdminLinks, User } from '@api/model'
import { IRoute, IRoutes } from '@app/routes/general-routes'
import { hiddenRoutes, privateRoutes } from '@app/routes/routes'
import { teachersHiddenRoutes, teachersPrivateRoutes } from '@app/routes/teacher-routes'
import { MenuType, REQUIRED_LEFTSIDE_BAR_CONFIG, REQUIRED_TEACHER_LEFTSIDE_BAR_CONFIG } from '@consts'
import { MenuType, REQUIRED_LEFTSIDE_BAR_CONFIG, REQUIRED_TEACHER_LEFTSIDE_BAR_CONFIG } from '@shared/constants/consts'
import { SettingsType } from '@entities/settings/model'
import { useStore } from 'effector-react/compat'
import { createEvent, createStore } from 'effector'
import findRoutesByConfig from '../lib/find-routes-by-config'
import { LocalStorageKey } from '@shared/constants/local-storage'

export interface Menu {
allRoutes: IRoutes | null
Expand All @@ -25,7 +26,7 @@ export const DEFAULT_MOBILE_CONFIG = ['home', 'schedule', 'chat', 'all', 'profil
const getLeftsideBarConfig = (user: User | null, _adminLinks?: boolean): MenuType => {
if (!user) return []

const localSettings = JSON.parse(localStorage.getItem('new-settings') || '{}') as SettingsType
const localSettings = JSON.parse(localStorage.getItem(LocalStorageKey.NewSettings) || '{}') as SettingsType
const settingsMenuData =
(localSettings[user.id]['settings-customize-menu']?.property.pages as unknown as string[]) ??
REQUIRED_LEFTSIDE_BAR_CONFIG
Expand Down Expand Up @@ -111,7 +112,9 @@ const $menu = createStore<Menu>(DEFAULT_STORE)
),
homeRoutes: findRoutesByConfig(
homeRoutes ??
(JSON.parse(localStorage.getItem('home-routes') ?? JSON.stringify(DEFAULT_HOME_CONFIG)) as string[]),
(JSON.parse(
localStorage.getItem(LocalStorageKey.HomeRoutes) ?? JSON.stringify(DEFAULT_HOME_CONFIG),
) as string[]),
user?.user_status === 'staff'
? { ...filterTeachersPrivateRoutes(adminLinks), ...teachersHiddenRoutes() }
: { ...privateRoutes(), ...hiddenRoutes() },
Expand Down
2 changes: 1 addition & 1 deletion src/entities/settings/lib/get-default-settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ThemeType, REQUIRED_LEFTSIDE_BAR_CONFIG } from '@consts'
import { ThemeType, REQUIRED_LEFTSIDE_BAR_CONFIG } from '@shared/constants/consts'
import { NameSettings, Param, SettingsType } from '../model'

const generateDefaultSettings = () => {
Expand Down
9 changes: 5 additions & 4 deletions src/entities/settings/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useStore } from 'effector-react/compat'
import { createEvent, createStore } from 'effector'
import { createEffect } from 'effector'
import { ThemeType } from '@consts'
import { ThemeType } from '@shared/constants/consts'
import getDefaultSettings from '../lib/get-default-settings'
import { LocalStorageKey } from '@shared/constants/local-storage'

export enum NameSettings {
'settings-home-page' = 'settings-home-page',
Expand Down Expand Up @@ -51,7 +52,7 @@ const getLocalSettingsFx = createEffect((userId: string): Param => {
currentUser = userId
// TODO: change logic so that it supports an update of settings config.
// Now doesn't update local storage if u add something to object of default settings
const localSettings = JSON.parse(localStorage.getItem('new-settings') ?? '{}')[currentUser] as Param
const localSettings = JSON.parse(localStorage.getItem(LocalStorageKey.NewSettings) ?? '{}')[currentUser] as Param
return localSettings ?? getDefaultSettings(userId)[userId]
})

Expand Down Expand Up @@ -97,9 +98,9 @@ const $settingsStore = createStore<SettingsStore>(DEFAULT_STORE)

$settingsStore.watch((state) => {
if (state !== DEFAULT_STORE && !!currentUser) {
const allSettings = JSON.parse(localStorage.getItem('new-settings') ?? JSON.stringify({}))
const allSettings = JSON.parse(localStorage.getItem(LocalStorageKey.NewSettings) ?? JSON.stringify({}))
allSettings[currentUser] = state.settings[currentUser]
localStorage.setItem('new-settings', JSON.stringify(allSettings))
localStorage.setItem(LocalStorageKey.NewSettings, JSON.stringify(allSettings))
}
})

Expand Down
6 changes: 4 additions & 2 deletions src/entities/user/lib/jwt-token.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { LocalStorageKey } from '@shared/constants/local-storage'

export const getJwtToken = () => {
return localStorage.getItem('jwt')
return localStorage.getItem(LocalStorageKey.JWT)
}

export const setJwtToken = (token: string) => {
return localStorage.setItem('jwt', token)
return localStorage.setItem(LocalStorageKey.JWT, token)
}

export const parseJwt = (token: string) => {
Expand Down
21 changes: 11 additions & 10 deletions src/entities/user/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ADName, User, UserToken } from '@api/model'
import axios from 'axios'
import clearAllStores from '../lib/clear-all-stores'
import createFullName from '@features/home/lib/create-full-name'
import { LocalStorageKey } from '@shared/constants/local-storage'

interface UserStore {
currentUser: User | null
Expand All @@ -17,8 +18,8 @@ interface UserStore {

// In effector chat core-team describe something like this code (Perhaps a better solution can be found)
// TODO: ask about token expires (Looks like it won't expire)
const tokenInStorage = JSON.parse(localStorage.getItem('token') ?? 'null')
const savePasswordInStorage = () => JSON.parse(localStorage.getItem('savePassword') ?? 'true')
const tokenInStorage = JSON.parse(localStorage.getItem(LocalStorageKey.Token) ?? 'null')
const savePasswordInStorage = () => JSON.parse(localStorage.getItem(LocalStorageKey.SavePassword) ?? 'true')

const getUserTokenFx = createEffect<LoginData, UserToken>(async (params: LoginData) => {
try {
Expand All @@ -35,11 +36,11 @@ const getUserTokenFx = createEffect<LoginData, UserToken>(async (params: LoginDa
} catch {}

if (savePasswordInStorage()) {
localStorage.setItem('token', JSON.stringify(tokenResponse.data))
localStorage.setItem('jwt', JSON.stringify(tokenResponse.data.jwt))
localStorage.setItem(LocalStorageKey.Token, JSON.stringify(tokenResponse.data))
localStorage.setItem(LocalStorageKey.JWT, JSON.stringify(tokenResponse.data.jwt))
} else {
sessionStorage.setItem('token', JSON.stringify(tokenResponse.data))
sessionStorage.setItem('jwt', JSON.stringify(tokenResponse.data.jwt))
sessionStorage.setItem(LocalStorageKey.Token, JSON.stringify(tokenResponse.data))
sessionStorage.setItem(LocalStorageKey.JWT, JSON.stringify(tokenResponse.data.jwt))
}
return tokenResponse.data
} catch (e) {
Expand Down Expand Up @@ -93,18 +94,18 @@ const useUser = () => {

const logoutFx = createEffect(() => {
if (savePasswordInStorage()) {
localStorage.removeItem('token')
localStorage.removeItem(LocalStorageKey.Token)
} else {
sessionStorage.removeItem('token')
sessionStorage.removeItem(LocalStorageKey.Token)
}

clearAllStores()
})

const changeSavePasswordFunc = (savePassword?: boolean) => {
const localStorageValue = localStorage.getItem('savePassword')
const localStorageValue = localStorage.getItem(LocalStorageKey.SavePassword)
const value = savePassword ?? JSON.parse(localStorageValue ?? 'true')
localStorage.setItem('savePassword', value.toString())
localStorage.setItem(LocalStorageKey.SavePassword, value.toString())

return value
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/acad-performance/lib/find-percentage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GradeByScore } from '@consts'
import { GradeByScore } from '@shared/constants/consts'
import { AcadPerformance } from '@api/model/acad-performance'

function findPercentage(data: AcadPerformance[], circleMode = 0): number {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IGrade } from '@api/model/acad-performance'
import { ColorsByGrade } from '@consts'
import { ColorsByGrade } from '@shared/constants/consts'

const findProgressBarColor = (grade: keyof IGrade): string => {
return !!grade ? ColorsByGrade[grade] || ColorsByGrade.default : 'var(--grey)'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IGrade } from '@api/model/acad-performance'
import { WidthByGrade } from '@consts'
import { WidthByGrade } from '@shared/constants/consts'

const findProgressBarWidth = (grade: keyof IGrade) => {
return grade ? WidthByGrade[grade] || WidthByGrade.default : 0
Expand Down
2 changes: 1 addition & 1 deletion src/features/acad-performance/ui/atoms/subject-checker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IGrade } from '@api/model/acad-performance'
import { GradeByScore } from '@consts'
import { GradeByScore } from '@shared/constants/consts'
import findProgressBarColor from '@features/acad-performance/lib/find-progress-bar-color'
import React from 'react'
import { FiCheck, FiX } from 'react-icons/fi'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useModal } from 'widgets'
import { SubjectModal } from '.'
import { SubjectCheker } from '../atoms'
import ProgressBar from '@shared/ui/progress-bar'
import { GradeByScore, WidthByGrade } from '@shared/consts'
import { GradeByScore, WidthByGrade } from '@shared/constants/consts'
import findProgressBarColor from '@features/acad-performance/lib/find-progress-bar-color'

interface Props {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AcadPerformance } from '@api/model/acad-performance'
import { Title } from '@ui/atoms'
import KeyValue from '@ui/atoms/key-value'
import { KeyValue } from '@ui/atoms/key-value'
import findSemestr from '@utils/find-semestr'
import localizeDate from '@utils/localize-date'
import React from 'react'
Expand Down
2 changes: 1 addition & 1 deletion src/features/all-pages/lib/add-page-to-sidebar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ADDITIONAL_MENU_ITEMS_LIMIT_SIZE, REQUIRED_LEFTSIDE_BAR_CONFIG } from '@consts'
import { ADDITIONAL_MENU_ITEMS_LIMIT_SIZE, REQUIRED_LEFTSIDE_BAR_CONFIG } from '@shared/constants/consts'
import { popUpMessageModel } from '@entities/pop-up-message'
import { settingsModel } from '@entities/settings'

Expand Down
2 changes: 1 addition & 1 deletion src/features/all-pages/ui/atoms/icon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors, IColors } from '@consts'
import { Colors, IColors } from '@shared/constants/consts'
import React from 'react'
import styled from 'styled-components'

Expand Down
Loading