diff --git a/apps/schools/domains/circle/components/circleList/index.tsx b/apps/schools/domains/circle/components/circleList/index.tsx index 00118a0f..83b7faaf 100644 --- a/apps/schools/domains/circle/components/circleList/index.tsx +++ b/apps/schools/domains/circle/components/circleList/index.tsx @@ -13,6 +13,7 @@ import EmptyWrapper from '@domains/common/components/containers/EmptyWrapper' import { mapReturnedData } from '@domains/common/redux/utils' import { HighlightText } from '@domains/common/components/table/forming' import { getVarsForAddressColumn } from '@domains/common/utils/geo' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export function CircleList() { const [searchRequestText, setSearchRequestText] = useState('') @@ -37,7 +38,7 @@ export function CircleList() { pageTitle={'Кружки'} data={circles} isLoading={isFetching} - handleRunTask={() => router.push('/circle/create')} + handleRunTask={() => router.push(RoutePath[AppRoutes.CIRCLE_CREATE])} searchTrigger={searchRequestText} >
@@ -46,7 +47,7 @@ export function CircleList() { type='schoolDefault' block className={styles.button} - onClick={() => router.push('/circle/create')} + onClick={() => router.push(RoutePath[AppRoutes.CIRCLE_CREATE])} > Добавить кружок @@ -59,7 +60,7 @@ export function CircleList() { ]} data={reformattedData} isLoading={isFetching} - mainRoute={'/circle'} + mainRoute={RoutePath[AppRoutes.CIRCLE_LIST]} searchFields={['name', 'address']} customFields={{ address: ({ text, searchText }) => { diff --git a/apps/schools/domains/circle/components/currentCircle/index.tsx b/apps/schools/domains/circle/components/currentCircle/index.tsx index 331b71f1..445718e9 100644 --- a/apps/schools/domains/circle/components/currentCircle/index.tsx +++ b/apps/schools/domains/circle/components/currentCircle/index.tsx @@ -25,6 +25,7 @@ import styles from './styles/styles.module.scss' import { getVarsForAddressColumn } from '@domains/common/utils/geo' import { QueryStatuses } from '@domains/common/constants/Enums' import { ErrorType } from '@store/commonApi' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' const CurrentCircle = () => { const [isModalVisible, setIsModalVisible] = useState(false) @@ -64,12 +65,12 @@ const CurrentCircle = () => { useEffect(() => { if (circleError && (circleError as ErrorType).status == 404) { - router.push('/circle') + router.push(RoutePath[AppRoutes.CIRCLE_LIST]) } }, [circleError]) if (isDeleteFinished.isSuccess) return null - if (uuid.length === 0) router.push('/404') + if (uuid.length === 0) router.push(RoutePath[AppRoutes.NOT_FOUND]) return ( <> @@ -138,7 +139,7 @@ const CurrentCircle = () => { ['Телефон родителя', 'parent_phones'], ]} data={reformattedData} - mainRoute={'/student'} + mainRoute={RoutePath[AppRoutes.STUDENT_LIST]} isLoading={isLoading} needNumbering={true} searchFields={['student_name', 'student_phone', 'parent_names', 'parent_phones']} @@ -151,7 +152,7 @@ const CurrentCircle = () => { actions={[ , @@ -174,7 +175,7 @@ const CurrentCircle = () => { setIsModalVisible={setIsModalVisible} titleText={'Удалить кружок?'} buttonText={'Удалить кружок'} - urlAfterDelete={'/circle'} + urlAfterDelete={RoutePath[AppRoutes.CIRCLE_LIST]} dataField={'circle_id'} /> diff --git a/apps/schools/domains/circle/components/map/confirmMap/index.tsx b/apps/schools/domains/circle/components/map/confirmMap/index.tsx index 979286fd..b39651b2 100644 --- a/apps/schools/domains/circle/components/map/confirmMap/index.tsx +++ b/apps/schools/domains/circle/components/map/confirmMap/index.tsx @@ -17,6 +17,7 @@ import { getUuidFromUrl } from '@domains/common/utils/getUuidFromUrl' import { mapSteps } from '@domains/circle/interfaces/mapStepsType' import { FormMapSteps } from '@domains/circle/constants/Enums' import router from 'next/router' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' interface MapComponentProps { mode: 'Change' | 'Create' @@ -175,11 +176,11 @@ const ConfirmMap = (props: MapComponentProps) => { onClick={() => { if (mode === 'Create') { handleSubmitCreateForm(organizationId, mainForm, mutation).then((isSucceed) => { - if (isSucceed) router.push('/circle') + if (isSucceed) router.push(RoutePath[AppRoutes.CIRCLE_LIST]) }) } else if (mode === 'Change') { handleSubmitUpdateForm(circleId, mainForm, mutation).then((isSucceed) => { - if (isSucceed) router.push(`/circle/${circleId}`) + if (isSucceed) router.push(`${RoutePath[AppRoutes.CIRCLE_LIST]}/${circleId}`) }) } }} diff --git a/apps/schools/domains/common/components/containers/ErrorLayout/index.tsx b/apps/schools/domains/common/components/containers/ErrorLayout/index.tsx index 0df534bf..8743fc3e 100644 --- a/apps/schools/domains/common/components/containers/ErrorLayout/index.tsx +++ b/apps/schools/domains/common/components/containers/ErrorLayout/index.tsx @@ -4,6 +4,7 @@ import Link from 'next/link' import { Row } from 'antd' import { CustomLogo } from '@domains/common/components/Logo' import getConfig from 'next/config' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' const { publicRuntimeConfig: { @@ -16,7 +17,7 @@ export const EmptyLayout: React.FC = (props) => { return (
- +
diff --git a/apps/schools/domains/common/constants/routerEnums.ts b/apps/schools/domains/common/constants/routerEnums.ts new file mode 100644 index 00000000..8f14da78 --- /dev/null +++ b/apps/schools/domains/common/constants/routerEnums.ts @@ -0,0 +1,37 @@ +export const enum AppRoutes { + AUTH = 'auth', + AUTH_SIGN_IN = 'auth_signin', + AUTH_REGISTER = 'auth_register', + AUTH_FORGOT = 'auth_forgot', + CIRCLE_LIST = 'circle', + CIRCLE_CREATE = 'circle_create', + EMPLOYEE_LIST = 'employee_list', + EMPLOYEE_CREATE = 'employee_create', + MAIN = 'main', + MOBILE_RECAPTCHA = 'mobile_recaptcha', + NOT_FOUND = 'not_found', + QUERY_LIST = 'query_list', + STUDENT_LIST = 'student_list', + STUDENT_CREATE = 'student_create', + USER_LIST = 'user_list', + USER_EDIT = 'user_edit', +} + +export const RoutePath: Record = { + [AppRoutes.AUTH]: '/auth', + [AppRoutes.AUTH_SIGN_IN]: '/auth/signin', + [AppRoutes.AUTH_REGISTER]: '/auth/register', + [AppRoutes.AUTH_FORGOT]: '/auth/forgot', + [AppRoutes.CIRCLE_LIST]: '/circle', + [AppRoutes.CIRCLE_CREATE]: '/circle/create', + [AppRoutes.EMPLOYEE_LIST]: '/employee', + [AppRoutes.EMPLOYEE_CREATE]: '/employee/create', + [AppRoutes.MAIN]: '/', + [AppRoutes.MOBILE_RECAPTCHA]: '/mobile-recaptcha', + [AppRoutes.NOT_FOUND]: '/404', + [AppRoutes.QUERY_LIST]: '/query', + [AppRoutes.STUDENT_LIST]: '/student', + [AppRoutes.STUDENT_CREATE]: '/student/create', + [AppRoutes.USER_LIST]: '/user', + [AppRoutes.USER_EDIT]: '/user/edit', +} diff --git a/apps/schools/domains/employee/components/changeEmployeeForm/index.tsx b/apps/schools/domains/employee/components/changeEmployeeForm/index.tsx index c1d63fdb..03b1bbd3 100644 --- a/apps/schools/domains/employee/components/changeEmployeeForm/index.tsx +++ b/apps/schools/domains/employee/components/changeEmployeeForm/index.tsx @@ -16,6 +16,7 @@ import { useGetEmployeeQuery, useUpdateEmployeeByIdMutation } from '@domains/emp import { useChangeEmployeeFormValidators } from '@domains/employee/components/changeEmployeeForm/hooks' import { EMPLOYEE_NAME, EMPLOYEE_POSITION } from '@domains/employee/components/changeEmployeeForm/constants' import { handleSubmitForm } from '@domains/employee/handlers/employeePatch' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export function ChangeEmployeeForm() { const uuid = getUuidFromUrl() @@ -32,11 +33,11 @@ export function ChangeEmployeeForm() { useEffect(() => { if (employeeError && (employeeError as ErrorType).status == 404) { - router.push('/employee') + router.push(RoutePath[AppRoutes.EMPLOYEE_LIST]) } }, [employeeError]) - if (uuid.length === 0) router.push('/404') + if (uuid.length === 0) router.push(RoutePath[AppRoutes.NOT_FOUND]) const validationCheck = () => { setIsFormValid(isValidFormCheck(form, [], initialValues)) @@ -59,7 +60,7 @@ export function ChangeEmployeeForm() { onValuesChange={validationCheck} onFinish={() => { handleSubmitForm(uuid[0], form, mutation).then((isSuccess) => { - if (isSuccess) router.push(`/employee/${uuid[0]}`) + if (isSuccess) router.push(`${RoutePath[AppRoutes.EMPLOYEE_LIST]}/${uuid[0]}`) }) }} layout='vertical' @@ -95,7 +96,7 @@ export function ChangeEmployeeForm() { type='schoolDefaultAuto' antdType={'default'} block - onClick={() => router.push(`/employee/${uuid[0]}`)} + onClick={() => router.push(`${RoutePath[AppRoutes.EMPLOYEE_LIST]}/${uuid[0]}`)} > Отменить diff --git a/apps/schools/domains/employee/components/createEmployeeForm/index.tsx b/apps/schools/domains/employee/components/createEmployeeForm/index.tsx index a4766017..01834f6a 100644 --- a/apps/schools/domains/employee/components/createEmployeeForm/index.tsx +++ b/apps/schools/domains/employee/components/createEmployeeForm/index.tsx @@ -7,7 +7,7 @@ import { useCreateEmployeeFormValidators } from './hooks' import { useInviteEmployeeMutation } from '@domains/organization/redux/organizationApi' import { useOrganization } from '@domains/organization/providers/organizationProvider' import { handleSubmitForm } from '@domains/employee/handlers/employeeCreate' -import { useRouter } from 'next/router' +import router, { useRouter } from 'next/router' import { WithTooltip } from '@domains/common/components/tooltip/withTooltip' import { TOOLTIP_MARGIN } from '@domains/employee/components/createEmployeeForm/styles/styles' import { isValidFormCheck } from '@domains/common/utils/form' @@ -17,6 +17,7 @@ import { EMPLOYEE_PHONE, EMPLOYEE_POSITION, } from '@domains/employee/components/createEmployeeForm/constants' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export const CreateEmployeeForm = () => { const validators = useCreateEmployeeFormValidators() @@ -39,7 +40,7 @@ export const CreateEmployeeForm = () => { onValuesChange={validationCheck} onFinish={() => { handleSubmitForm(organizationId, form, mutation).then((isSucceed) => { - if (isSucceed) router.push('/employee') + if (isSucceed) router.push(RoutePath[AppRoutes.EMPLOYEE_LIST]) }) }} layout='vertical' diff --git a/apps/schools/domains/employee/components/currentEmployee/index.tsx b/apps/schools/domains/employee/components/currentEmployee/index.tsx index 9dd3d2f6..6426be7c 100644 --- a/apps/schools/domains/employee/components/currentEmployee/index.tsx +++ b/apps/schools/domains/employee/components/currentEmployee/index.tsx @@ -13,6 +13,7 @@ import { Field } from '@domains/common/components/field' import { ActionBar } from '@domains/common/components/stickyBlock/actionBar' import DeleteModal from '@domains/common/components/deleteModal' import { useDeleteEmployeeByIdMutation, useGetEmployeeQuery } from '@domains/employee/redux/employeeApi' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' const CurrentEmployee = () => { const [isModalVisible, setIsModalVisible] = useState(false) @@ -29,12 +30,12 @@ const CurrentEmployee = () => { useEffect(() => { if (employeeError && (employeeError as ErrorType).status == 404) { - router.push('/employee') + router.push(RoutePath[AppRoutes.EMPLOYEE_LIST]) } }, [employeeError]) if (isDeleteFinished.isSuccess) return null - if (uuid.length === 0) router.push('/404') + if (uuid.length === 0) router.push(RoutePath[AppRoutes.NOT_FOUND]) return isLoading ? ( @@ -70,7 +71,9 @@ const CurrentEmployee = () => { , @@ -95,7 +98,7 @@ const CurrentEmployee = () => { setIsModalVisible={setIsModalVisible} titleText={'Удалить сотрудника?'} buttonText={'Удалить сотрудника'} - urlAfterDelete={'/employee'} + urlAfterDelete={RoutePath[AppRoutes.EMPLOYEE_LIST]} dataField={'employee_id'} /> diff --git a/apps/schools/domains/employee/components/employeeList/index.tsx b/apps/schools/domains/employee/components/employeeList/index.tsx index 1bbffab1..9aaccc0e 100644 --- a/apps/schools/domains/employee/components/employeeList/index.tsx +++ b/apps/schools/domains/employee/components/employeeList/index.tsx @@ -10,6 +10,7 @@ import { createSearchTextForRequest } from '@domains/common/utils/searchText' import { GetListEmployee } from '@domains/employee/redux/interfaces' import { RowType } from '@domains/employee/components/employeeList/interfaces' import { searchColumns } from '@domains/employee/components/employeeList/constants' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export function EmployeeList() { const [searchRequestText, setSearchRequestText] = useState('') @@ -29,7 +30,7 @@ export function EmployeeList() { block style={{ width: '14%' }} className={styles.button} - onClick={() => router.push('/employee/create')} + onClick={() => router.push(RoutePath[AppRoutes.EMPLOYEE_CREATE])} > Добавить сотрудника @@ -42,7 +43,7 @@ export function EmployeeList() { ]} data={data} isLoading={isLoading} - mainRoute={'/employee'} + mainRoute={RoutePath[AppRoutes.EMPLOYEE_LIST]} searchFields={searchColumns} searchRequestText={searchRequestText} setSearchRequestText={setSearchRequestText} diff --git a/apps/schools/domains/organization/providers/organizationProvider.tsx b/apps/schools/domains/organization/providers/organizationProvider.tsx index 36e0ca46..afc87eb2 100644 --- a/apps/schools/domains/organization/providers/organizationProvider.tsx +++ b/apps/schools/domains/organization/providers/organizationProvider.tsx @@ -3,6 +3,7 @@ import { useRouter } from 'next/router' import { useGetAllOrganizationsQuery } from '../redux/organizationApi' import { OrganizationInfo } from '../interfaces/organizationProvider' import { EventKey, useEventBus } from '@domains/common/providers/eventBusProvider' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export const UUID_REGEXP = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i @@ -65,7 +66,11 @@ export const OrganizationProvider: React.FC = ({ chil } if (data.count === 0) { - if (!router.asPath.endsWith('/user') && !router.asPath.includes('/auth/')) router.push('/user') + if ( + !router.asPath.endsWith(RoutePath[AppRoutes.USER_LIST]) && + !router.asPath.includes(`${RoutePath[AppRoutes.AUTH]}/`) + ) + router.push(RoutePath[AppRoutes.USER_LIST]) } else { const firstOrganization = data?.results[0] if (organizationId === '' && firstOrganization && firstOrganization.id) { diff --git a/apps/schools/domains/query/components/queryList/index.tsx b/apps/schools/domains/query/components/queryList/index.tsx index 9492609f..87e2df4d 100644 --- a/apps/schools/domains/query/components/queryList/index.tsx +++ b/apps/schools/domains/query/components/queryList/index.tsx @@ -21,6 +21,7 @@ import { BubbleFilter } from '@domains/common/components/bubbleFilter' import { BubbleFilterListItem } from '@domains/common/components/bubbleFilter/interface' import { useQueryState } from 'next-usequerystate' import { parseAsArrayOf, parseAsString } from 'next-usequerystate' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export function QueryList() { const [searchRequestText, setSearchRequestText] = useState('') @@ -144,7 +145,7 @@ export function QueryList() { ]} data={reformattedData} isLoading={isQueriesLoading} - mainRoute={'/query'} + mainRoute={RoutePath[AppRoutes.QUERY_LIST]} searchFields={[ 'created_at', 'student_name', diff --git a/apps/schools/domains/student/components/changeStudentForm/index.tsx b/apps/schools/domains/student/components/changeStudentForm/index.tsx index 393c480a..92ff5801 100644 --- a/apps/schools/domains/student/components/changeStudentForm/index.tsx +++ b/apps/schools/domains/student/components/changeStudentForm/index.tsx @@ -16,6 +16,7 @@ import { handleSubmitForm } from '@domains/student/handlers/studentPatch' import { useUpdateStudentByIdMutation } from '@domains/student/redux/studentApi' import { useChangeStudentFormValidators } from '@domains/student/components/changeStudentForm/hooks' import { ErrorType } from '@store/commonApi' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export function ChangeStudentForm() { const uuid = getUuidFromUrl() @@ -31,11 +32,11 @@ export function ChangeStudentForm() { useEffect(() => { if (studentError && (studentError as ErrorType).status == 404) { - router.push('/student') + router.push(RoutePath[AppRoutes.STUDENT_LIST]) } }, [studentError]) - if (uuid.length === 0) router.push('/404') + if (uuid.length === 0) router.push(RoutePath[AppRoutes.NOT_FOUND]) const validationCheck = () => { setIsFormValid(isValidFormCheck(form, [], initialValues)) @@ -58,7 +59,7 @@ export function ChangeStudentForm() { onValuesChange={validationCheck} onFinish={() => { handleSubmitForm(uuid[0], form, mutation).then((isSuccess) => { - if (isSuccess) router.push(`/student/${uuid[0]}`) + if (isSuccess) router.push(`${RoutePath[AppRoutes.STUDENT_LIST]}/${uuid[0]}`) }) }} layout='vertical' @@ -83,7 +84,7 @@ export function ChangeStudentForm() { type='schoolDefaultAuto' antdType={'default'} block - onClick={() => router.push(`/student/${uuid[0]}`)} + onClick={() => router.push(`${RoutePath[AppRoutes.STUDENT_LIST]}/${uuid[0]}`)} > Отменить diff --git a/apps/schools/domains/student/components/createStudentForm/index.tsx b/apps/schools/domains/student/components/createStudentForm/index.tsx index cfdb61e5..37c8a23e 100644 --- a/apps/schools/domains/student/components/createStudentForm/index.tsx +++ b/apps/schools/domains/student/components/createStudentForm/index.tsx @@ -21,6 +21,7 @@ import { TOOLTIP_MARGIN_TOP } from '@domains/student/components/createStudentFor import { Select } from '@domains/common/components/select' import router from 'next/router' import { DROPDOWN_STYLE } from '@domains/common/components/containers/BaseLayoutComponents/OrganizationSelect/styles/styles' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export const CreateStudentForm = () => { const validators = useCreateStudentFormValidators() @@ -56,7 +57,7 @@ export const CreateStudentForm = () => { localStorage.removeItem(PARENT_PHONE) localStorage.removeItem(PARENT_EMAIL) localStorage.removeItem(STUDENT_PHONE) - router.push('/student') + router.push(RoutePath[AppRoutes.STUDENT_LIST]) } }) }} @@ -168,7 +169,7 @@ export const CreateStudentForm = () => { type='schoolDefault' block className={styles.button} - onClick={() => router.push('/circle/create')} + onClick={() => router.push(RoutePath[AppRoutes.CIRCLE_CREATE])} > Добавить кружок diff --git a/apps/schools/domains/student/components/currentStudent/index.tsx b/apps/schools/domains/student/components/currentStudent/index.tsx index 921f201b..f58e3c18 100644 --- a/apps/schools/domains/student/components/currentStudent/index.tsx +++ b/apps/schools/domains/student/components/currentStudent/index.tsx @@ -19,6 +19,7 @@ import { GetStudent } from '@domains/common/redux/serializers' import { useOrganization } from '@domains/organization/providers/organizationProvider' import parentAcceptedPhone from '@public/icons/parentAcceptedMobile.svg' import parentDeclinedPhone from '@public/icons/parentDeclinedMobile.svg' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' const CurrentStudent = () => { const [isModalVisible, setIsModalVisible] = useState(false) @@ -34,7 +35,7 @@ const CurrentStudent = () => { useEffect(() => { if (studentError && ((studentError as ErrorType).status == 404 || (studentError as ErrorType).status == 403)) { - router.push('/student') + router.push(RoutePath[AppRoutes.STUDENT_LIST]) } }, [studentError]) @@ -65,7 +66,7 @@ const CurrentStudent = () => { }, [studentInfoAdditional]) if (isDeleteFinished.isSuccess) return null - if (uuid.length === 0) router.push('/404') + if (uuid.length === 0) router.push(RoutePath[AppRoutes.NOT_FOUND]) return ( { , @@ -161,7 +166,7 @@ const CurrentStudent = () => { setIsModalVisible={setIsModalVisible} titleText={'Удалить обучающегося?'} buttonText={'Удалить обучающегося'} - urlAfterDelete={'/student'} + urlAfterDelete={RoutePath[AppRoutes.STUDENT_LIST]} dataField={'student_id'} /> diff --git a/apps/schools/domains/student/components/studentList/index.tsx b/apps/schools/domains/student/components/studentList/index.tsx index cf76e1a4..e491ed46 100644 --- a/apps/schools/domains/student/components/studentList/index.tsx +++ b/apps/schools/domains/student/components/studentList/index.tsx @@ -11,6 +11,7 @@ import { searchInvitesColumns, searchStudentsColumns } from './constants' import { useGetAllStudentInvitationsQuery, useGetAllStudentsQuery } from '@domains/organization/redux/organizationApi' import { QueryStatuses } from '@domains/common/constants/Enums' import EmptyWrapper from '@domains/common/components/containers/EmptyWrapper' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export function StudentList() { const [searchRequestText, setSearchRequestText] = useState('') @@ -64,7 +65,7 @@ export function StudentList() { pageTitle={'Обучающиеся'} data={data} isLoading={isLoadingStudents || isLoadingInvites} - handleRunTask={() => router.push('/student/create')} + handleRunTask={() => router.push(RoutePath[AppRoutes.STUDENT_CREATE])} searchTrigger={searchRequestText} >
@@ -74,7 +75,7 @@ export function StudentList() { block style={{ width: '14%' }} className={styles.button} - onClick={() => router.push('/student/create')} + onClick={() => router.push(RoutePath[AppRoutes.STUDENT_CREATE])} > Добавить обучающегося @@ -89,7 +90,7 @@ export function StudentList() { filterFields={['circle_name']} data={data} isLoading={isLoadingInvites || isLoadingStudents} - mainRoute={'/student'} + mainRoute={RoutePath[AppRoutes.STUDENT_LIST]} searchFields={['student_name', 'student_phone', 'parent_phone', 'circle_name']} searchRequestText={searchRequestText} setSearchRequestText={setSearchRequestText} diff --git a/apps/schools/domains/user/components/auth/headerActions/index.tsx b/apps/schools/domains/user/components/auth/headerActions/index.tsx index 3b8bda7a..d8258f24 100644 --- a/apps/schools/domains/user/components/auth/headerActions/index.tsx +++ b/apps/schools/domains/user/components/auth/headerActions/index.tsx @@ -4,6 +4,7 @@ import React from 'react' import styles from './styles/styles.module.scss' import { ITabsActionsProps } from './interfaces' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export const TabsAuthAction: React.FC = (props) => { const { currentActiveKey, title } = props @@ -26,8 +27,8 @@ export const TabsAuthAction: React.FC = (props) => { ) : ( <> - - + + )} diff --git a/apps/schools/domains/user/components/auth/sharedForms/ValidatePhoneForm.tsx b/apps/schools/domains/user/components/auth/sharedForms/ValidatePhoneForm.tsx index b11b654b..84fbacc1 100644 --- a/apps/schools/domains/user/components/auth/sharedForms/ValidatePhoneForm.tsx +++ b/apps/schools/domains/user/components/auth/sharedForms/ValidatePhoneForm.tsx @@ -26,7 +26,7 @@ export const ValidatePhoneForm: React.FC = ({ onFinish, const [smsCode, setSmsCode] = useState('') const [isPhoneVisible, setIsPhoneVisible] = useState(false) const [phoneValidateError, setPhoneValidateError] = useState(null) - const PhoneToggleLabel = isPhoneVisible ? 'Показать' : 'Скрыть' + const PhoneToggleLabel = isPhoneVisible ? 'Скрыть' : 'Показать' const SMS_VALIDATOR = useCallback( () => ({ diff --git a/apps/schools/domains/user/components/auth/signInForm/index.tsx b/apps/schools/domains/user/components/auth/signInForm/index.tsx index 9bc01c47..97c71bcb 100644 --- a/apps/schools/domains/user/components/auth/signInForm/index.tsx +++ b/apps/schools/domains/user/components/auth/signInForm/index.tsx @@ -8,6 +8,7 @@ import { Button } from '@domains/common/components/button' import { loginHandler } from '@domains/user/handlers/auth/signin' import { useLoginMutation } from '@domains/user/redux/authenticationApi' import { useSignInFormValidators } from './hooks' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export const SignInForm = (): React.ReactElement => { const validators = useSignInFormValidators() @@ -61,7 +62,7 @@ export const SignInForm = (): React.ReactElement => { Забыли пароль?  - Router.push('/auth/forgot')}> + Router.push(RoutePath[AppRoutes.AUTH_REGISTER])}> {'Сбросить'} diff --git a/apps/schools/domains/user/components/profile/profileEdit/index.tsx b/apps/schools/domains/user/components/profile/profileEdit/index.tsx index f5301e83..0b6ec5aa 100644 --- a/apps/schools/domains/user/components/profile/profileEdit/index.tsx +++ b/apps/schools/domains/user/components/profile/profileEdit/index.tsx @@ -14,6 +14,7 @@ import { useChangeUserProfileFormValidators } from '@domains/user/components/pro import { useUpdateEmployeeProfileByIdMutation } from '@domains/employee/redux/employeeApi' import { handleSubmitForm } from '@domains/user/handlers/profile/profileEdit' import { EventKey, useEventBus } from '@domains/common/providers/eventBusProvider' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export function ProfileEdit() { const { emit } = useEventBus() @@ -52,7 +53,7 @@ export function ProfileEdit() { handleSubmitForm(user.employee_profile?.id ?? '', form, mutation).then((isSuccess) => { if (isSuccess) { emit(EventKey.RefetchProfileQuery) - router.push('/user') + router.push(RoutePath[AppRoutes.USER_LIST]) } }) }} @@ -81,7 +82,7 @@ export function ProfileEdit() { - Сбросить пароль + Сбросить пароль @@ -93,7 +94,7 @@ export function ProfileEdit() { type='schoolDefaultAuto' antdType={'default'} block - onClick={() => router.push('/user')} + onClick={() => router.push(RoutePath[AppRoutes.USER_LIST])} > Отменить diff --git a/apps/schools/domains/user/components/profile/profileInfo/index.tsx b/apps/schools/domains/user/components/profile/profileInfo/index.tsx index ae2bfb6e..090a8fc4 100644 --- a/apps/schools/domains/user/components/profile/profileInfo/index.tsx +++ b/apps/schools/domains/user/components/profile/profileInfo/index.tsx @@ -8,6 +8,7 @@ import duckEmptyPage from '@public/image/duckEmptyPage.svg' import { useUserProfile } from '@domains/user/providers/authProvider' import { useLazyGetAllEmployeesQuery } from '@domains/employee/redux/employeeApi' import { Field } from '@domains/common/components/field' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export function ProfileInfo() { const { user } = useUserProfile() @@ -54,7 +55,7 @@ export function ProfileInfo() { )) )} - diff --git a/apps/schools/domains/user/handlers/auth/forgot.ts b/apps/schools/domains/user/handlers/auth/forgot.ts index 3785af7d..a813185b 100644 --- a/apps/schools/domains/user/handlers/auth/forgot.ts +++ b/apps/schools/domains/user/handlers/auth/forgot.ts @@ -1,6 +1,7 @@ import { message } from 'antd' import Router from 'next/router' import { PleaseReloadPageMsg, SuccessResetPasswordMsg } from '@domains/user/components/auth/constants/message' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export async function resetHandler( password: string, @@ -12,7 +13,7 @@ export async function resetHandler( let response = await reset({ token, password }) if ('data' in response) { message.success(SuccessResetPasswordMsg) - Router.push('../auth/signin') + Router.push(RoutePath[AppRoutes.AUTH_SIGN_IN]) onFinish('userID') } else if (response.error?.status === 401) { message.error(PleaseReloadPageMsg) diff --git a/apps/schools/domains/user/handlers/auth/register.ts b/apps/schools/domains/user/handlers/auth/register.ts index aeea662c..17542557 100644 --- a/apps/schools/domains/user/handlers/auth/register.ts +++ b/apps/schools/domains/user/handlers/auth/register.ts @@ -12,6 +12,7 @@ import { } from '@domains/user/components/auth/constants/message' import { withLoadingMessage } from '@domains/common/utils/loading' import Cookies from 'universal-cookie' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export async function tokenHandler( recaptchaToken: string, @@ -42,7 +43,7 @@ export async function tokenHandler( }) if ('data' in response) { localStorage.setItem('token', response.data.token) - Router.push(`/auth/${nextUrl}?token=${37128937218937}`) + Router.push(`${RoutePath[AppRoutes.AUTH]}/${nextUrl}?token=${37128937218937}`) onFinish() } else { message.error(PleaseReloadPageMsg) diff --git a/apps/schools/domains/user/providers/authProvider.tsx b/apps/schools/domains/user/providers/authProvider.tsx index a5edf1a5..ff942eed 100644 --- a/apps/schools/domains/user/providers/authProvider.tsx +++ b/apps/schools/domains/user/providers/authProvider.tsx @@ -4,6 +4,7 @@ import { useGetUserQuery } from '../redux/authenticationApi' import Cookies from 'universal-cookie' import { GetUserProfiles } from '@domains/user/redux/interfaces' import { EventKey, useEventBus } from '@domains/common/providers/eventBusProvider' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export const UserProfileContext = createContext<{ token: string @@ -35,14 +36,14 @@ export const AuthProvider: React.FC = ({ children }) => { refetch() }) - if (router.pathname === '/mobile-recaptcha') return + if (router.pathname === RoutePath[AppRoutes.MOBILE_RECAPTCHA]) return const jwtToken = typeof window !== 'undefined' ? cookies.get('jwtToken') : null if (jwtToken) { setToken(jwtToken) } else { - router.push('/auth/signin') + router.push(RoutePath[AppRoutes.AUTH_SIGN_IN]) } return () => { @@ -55,10 +56,10 @@ export const AuthProvider: React.FC = ({ children }) => { }, [data]) useEffect(() => { - if (router.pathname === '/mobile-recaptcha') return + if (router.pathname === RoutePath[AppRoutes.MOBILE_RECAPTCHA]) return if (error !== undefined && 'data' in error) { - router.push('/auth/signin') + router.push(RoutePath[AppRoutes.AUTH_SIGN_IN]) } }, [error]) diff --git a/apps/schools/pages/404.tsx b/apps/schools/pages/404.tsx index c0f85d36..ea0ed139 100644 --- a/apps/schools/pages/404.tsx +++ b/apps/schools/pages/404.tsx @@ -5,28 +5,28 @@ import Head from 'next/head' import { SharedErrorPage } from '@domains/common/components/errors' import router from 'next/router' import ducks from '@public/image/404Ducks.svg' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' -const imageWidthPercent = 0.6; +const imageWidthPercent = 0.6 export default function Custom404() { const [windowSize, setWindowSize] = useState({ width: 0, height: 0, - }); + }) useEffect(() => { function handleResize() { setWindowSize({ width: window.innerWidth, height: window.innerHeight, - }); + }) } - window.addEventListener('resize', handleResize); - handleResize(); - return () => window.removeEventListener('resize', handleResize); + window.addEventListener('resize', handleResize) + handleResize() + return () => window.removeEventListener('resize', handleResize) }, []) - return ( <> @@ -39,7 +39,7 @@ export default function Custom404() { image={ducks} imageWidth={windowSize.width * imageWidthPercent} handleRunTask={() => { - router.push('/') + router.push(RoutePath[AppRoutes.MAIN]) }} /> diff --git a/apps/schools/pages/_app.tsx b/apps/schools/pages/_app.tsx index 5b772b46..92d00c26 100644 --- a/apps/schools/pages/_app.tsx +++ b/apps/schools/pages/_app.tsx @@ -12,6 +12,7 @@ import { BaseLayout } from '@domains/common/components/containers/BaseLayoutComp import { LayoutContextProvider } from '@domains/user/providers/baseLayoutProvider' import { message } from 'antd' import { EventBusProvider } from '@domains/common/providers/eventBusProvider' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' export interface ContainerPage extends React.FC { container: React.FC @@ -30,7 +31,7 @@ function MyApp({ Component, pageProps }: CustomAppProps): JSX.Element { const LayoutComponent = Component.container || BaseLayout const router = useRouter() - if (router.pathname === '/mobile-recaptcha') + if (router.pathname === RoutePath[AppRoutes.MOBILE_RECAPTCHA]) return ( diff --git a/apps/schools/pages/auth/forgot.tsx b/apps/schools/pages/auth/forgot.tsx index 52d9cf77..33c0549d 100644 --- a/apps/schools/pages/auth/forgot.tsx +++ b/apps/schools/pages/auth/forgot.tsx @@ -4,21 +4,17 @@ import React, { useState } from 'react' import { Dictionary } from '@reduxjs/toolkit' import { ContainerPage } from '../_app' -import AuthLayout, { - IAuthLayoutProps, -} from '../../domains/user/components/auth/containers/AuthLayout' +import AuthLayout, { IAuthLayoutProps } from '../../domains/user/components/auth/containers/AuthLayout' import { InputPhoneForm } from '../../domains/user/components/auth/sharedForms/InputPhoneForm' import { ValidatePhoneForm } from '../../domains/user/components/auth/sharedForms/ValidatePhoneForm' import { ResetForm } from '../../domains/user/components/auth/resetForm' import { FormContainer } from '../../domains/user/components/auth/formContainer' import { CENTRALIZED } from '../../domains/common/components/styles/constantStyles' import { Row } from 'antd' -import { - ResetDescription, - ResetPhoneButtonLabel, -} from '../../domains/user/components/auth/constants/labels' +import { ResetDescription, ResetPhoneButtonLabel } from '../../domains/user/components/auth/constants/labels' import { TabsAuthAction } from '../../domains/user/components/auth/headerActions' import { FirebaseReCaptcha } from '../../domains/user/providers/firebaseReCaptchaProvider' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' const ResetPage: ContainerPage = (props) => { const [step, setStep] = useState('inputPhone') @@ -26,10 +22,7 @@ const ResetPage: ContainerPage = (props) => { const steps: Dictionary = { inputPhone: ( <> - + setStep('validatePhone')} @@ -42,34 +35,29 @@ const ResetPage: ContainerPage = (props) => { ), validatePhone: ( <> - + setStep('reset')} onReset={() => { setStep('inputPhone') - Router.push('/auth/forgot') + Router.push(RoutePath[AppRoutes.AUTH_FORGOT]) }} onError={() => { setStep('inputPhone') - Router.push('/auth/forgot') + Router.push(RoutePath[AppRoutes.AUTH_FORGOT]) }} /> ), reset: ( <> - + {}} onError={() => { setStep('inputPhone') - Router.push('/auth/forgot')}} + Router.push(RoutePath[AppRoutes.AUTH_FORGOT]) + }} /> ), diff --git a/apps/schools/pages/auth/register.tsx b/apps/schools/pages/auth/register.tsx index 8aa20446..887bc244 100644 --- a/apps/schools/pages/auth/register.tsx +++ b/apps/schools/pages/auth/register.tsx @@ -4,9 +4,7 @@ import React, { useState } from 'react' import { Dictionary } from '@reduxjs/toolkit' import { ContainerPage } from '../_app' -import AuthLayout, { - IAuthLayoutProps, -} from '../../domains/user/components/auth/containers/AuthLayout' +import AuthLayout, { IAuthLayoutProps } from '../../domains/user/components/auth/containers/AuthLayout' import { FormContainer } from '../../domains/user/components/auth/formContainer' import { InputPhoneForm } from '../../domains/user/components/auth/sharedForms/InputPhoneForm' import { TabsAuthAction } from '../../domains/user/components/auth/headerActions' @@ -19,6 +17,7 @@ import { RegistrationPhoneButtonLabel, } from '../../domains/user/components/auth/constants/labels' import { FirebaseReCaptcha } from '../../domains/user/providers/firebaseReCaptchaProvider' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' const RegisterPage: ContainerPage = (props) => { const [step, setStep] = useState('inputPhone') @@ -26,7 +25,7 @@ const RegisterPage: ContainerPage = (props) => { const steps: Dictionary = { inputPhone: ( <> - + = (props) => { ), validatePhone: ( <> - + setStep('register')} onReset={() => { setStep('inputPhone') - Router.push('/auth/register') + Router.push(RoutePath[AppRoutes.AUTH_REGISTER]) }} onError={() => { setStep('inputPhone') - Router.push('/auth/register') + Router.push(RoutePath[AppRoutes.AUTH_REGISTER]) }} /> ), register: ( <> - + window.location.href = '/'} + onFinish={() => (window.location.href = '/')} onError={() => { setStep('inputPhone') - Router.push('/auth/register') + Router.push(RoutePath[AppRoutes.AUTH_REGISTER]) }} /> @@ -77,9 +73,7 @@ const RegisterPage: ContainerPage = (props) => { - - {steps[step]} - + {steps[step]} diff --git a/apps/schools/pages/index.tsx b/apps/schools/pages/index.tsx index d61a47ac..b5b5ab34 100644 --- a/apps/schools/pages/index.tsx +++ b/apps/schools/pages/index.tsx @@ -1,14 +1,14 @@ import { useRouter } from 'next/router' import React, { useEffect } from 'react' -import { useOrganization } from "@domains/organization/providers/organizationProvider"; - +import { useOrganization } from '@domains/organization/providers/organizationProvider' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' const IndexPage = () => { const router = useRouter() const organization = useOrganization() useEffect(() => { - router.push('/query') + router.push(RoutePath[AppRoutes.QUERY_LIST]) }, [organization, router]) return <> } diff --git a/apps/schools/pages/logout.tsx b/apps/schools/pages/logout.tsx index c35ea389..12734160 100644 --- a/apps/schools/pages/logout.tsx +++ b/apps/schools/pages/logout.tsx @@ -1,14 +1,14 @@ import React, { useEffect } from 'react' -import {useUserProfile} from "@domains/user/providers/authProvider"; -import router from "next/router"; - +import { useUserProfile } from '@domains/user/providers/authProvider' +import Router from 'next/router' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' const LogoutPage = () => { - const {logout} = useUserProfile() + const { logout } = useUserProfile() useEffect(() => { - logout(); - router.push('auth/signin'); + logout() + Router.push(RoutePath[AppRoutes.AUTH_SIGN_IN]) }, []) return <> diff --git a/apps/schools/store/middlewares.ts b/apps/schools/store/middlewares.ts index a1efec2a..b905cfe0 100644 --- a/apps/schools/store/middlewares.ts +++ b/apps/schools/store/middlewares.ts @@ -1,6 +1,7 @@ import { isRejected, Middleware, MiddlewareAPI } from '@reduxjs/toolkit' import { message } from 'antd' import router from 'next/router' +import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' interface ErrorCodes { [status: number]: string | { [code: string]: string } @@ -36,7 +37,7 @@ interface Action { } export const rtkQueryErrorLogger: Middleware = (api: MiddlewareAPI) => (next) => (action: Action) => { - if (router.pathname === '/mobile-recaptcha') return next(action) + if (router.pathname === RoutePath[AppRoutes.MOBILE_RECAPTCHA]) return next(action) if (isRejected()(action)) { const { status, data } = action.payload // TODO: if some query or mutation is invalid it will fail on this line. We should think is it ok.