diff --git a/rsconcept/frontend/src/context/UserProfileContext.tsx b/rsconcept/frontend/src/context/UserProfileContext.tsx index fa7fcbc8..c467be5b 100644 --- a/rsconcept/frontend/src/context/UserProfileContext.tsx +++ b/rsconcept/frontend/src/context/UserProfileContext.tsx @@ -13,6 +13,7 @@ interface IUserProfileContext { loading: boolean; processing: boolean; error: ErrorData; + errorProcessing: ErrorData; setError: (error: ErrorData) => void; updateUser: (data: IUserUpdateData, callback?: DataCallback) => void; } @@ -37,6 +38,7 @@ export const UserProfileState = ({ children }: UserProfileStateProps) => { const [loading, setLoading] = useState(false); const [processing, setProcessing] = useState(false); const [error, setError] = useState(undefined); + const [errorProcessing, setErrorProcessing] = useState(undefined); const reload = useCallback(() => { setError(undefined); @@ -51,12 +53,12 @@ export const UserProfileState = ({ children }: UserProfileStateProps) => { const updateUser = useCallback( (data: IUserUpdateData, callback?: DataCallback) => { - setError(undefined); + setErrorProcessing(undefined); patchProfile({ data: data, showError: true, setLoading: setProcessing, - onError: setError, + onError: setErrorProcessing, onSuccess: newData => { setUser(newData); const libraryUser = users.find(item => item.id === user?.id); @@ -76,7 +78,7 @@ export const UserProfileState = ({ children }: UserProfileStateProps) => { }, [reload]); return ( - + {children} ); diff --git a/rsconcept/frontend/src/pages/RegisterPage.tsx b/rsconcept/frontend/src/pages/RegisterPage.tsx index ef45b3bf..0b77b348 100644 --- a/rsconcept/frontend/src/pages/RegisterPage.tsx +++ b/rsconcept/frontend/src/pages/RegisterPage.tsx @@ -1,16 +1,18 @@ 'use client'; +import axios from 'axios'; import clsx from 'clsx'; -import { useEffect, useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; import { toast } from 'react-toastify'; import { urls } from '@/app/urls'; import { IconHelp } from '@/components/Icons'; -import InfoError from '@/components/info/InfoError'; +import InfoError, { ErrorData } from '@/components/info/InfoError'; import Button from '@/components/ui/Button'; import Checkbox from '@/components/ui/Checkbox'; import FlexColumn from '@/components/ui/FlexColumn'; import Overlay from '@/components/ui/Overlay'; +import PrettyJson from '@/components/ui/PrettyJSON'; import SubmitButton from '@/components/ui/SubmitButton'; import TextInput from '@/components/ui/TextInput'; import TextURL from '@/components/ui/TextURL'; @@ -22,6 +24,24 @@ import { useConceptNavigation } from '@/context/NavigationContext'; import { IUserSignupData } from '@/models/user'; import { globals, patterns } from '@/utils/constants'; +function ProcessError({ error }: { error: ErrorData }): React.ReactElement { + if (axios.isAxiosError(error) && error.response && error.response.status === 400) { + if ('email' in error.response.data) { + return ( + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access +
{error.response.data.email}.
+ ); + } else { + return ( +
+ +
+ ); + } + } + return ; +} + function RegisterPage() { const router = useConceptNavigation(); const { user, signup, loading, error, setError } = useAuth(); @@ -35,6 +55,8 @@ function RegisterPage() { const [acceptPrivacy, setAcceptPrivacy] = useState(false); + const isValid = useMemo(() => acceptPrivacy && !!email && !!username, [acceptPrivacy, email, username]); + useEffect(() => { setError(undefined); }, [username, email, password, password2, setError]); @@ -83,8 +105,7 @@ function RegisterPage() { -

- используйте уникальный пароль

-

- портал функционирует в тестовом режиме

+ используйте уникальный пароль для каждого сайта
@@ -122,6 +143,15 @@ function RegisterPage() { +
+ + + + + электронная почта используется для восстановления пароля + +
+
- +
- {error ? : null} + {error ? : null} ); diff --git a/rsconcept/frontend/src/pages/UserProfilePage/EditorProfile.tsx b/rsconcept/frontend/src/pages/UserProfilePage/EditorProfile.tsx index f5c88bc2..bc94bc93 100644 --- a/rsconcept/frontend/src/pages/UserProfilePage/EditorProfile.tsx +++ b/rsconcept/frontend/src/pages/UserProfilePage/EditorProfile.tsx @@ -1,17 +1,31 @@ 'use client'; +import axios from 'axios'; import clsx from 'clsx'; import { useLayoutEffect, useMemo, useState } from 'react'; import { toast } from 'react-toastify'; +import InfoError, { ErrorData } from '@/components/info/InfoError'; import SubmitButton from '@/components/ui/SubmitButton'; import TextInput from '@/components/ui/TextInput'; import { useBlockNavigation } from '@/context/NavigationContext'; import { useUserProfile } from '@/context/UserProfileContext'; import { IUserUpdateData } from '@/models/user'; +function ProcessError({ error }: { error: ErrorData }): React.ReactElement { + if (axios.isAxiosError(error) && error.response && error.response.status === 400) { + if ('email' in error.response.data) { + return ( + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access +
{error.response.data.email}.
+ ); + } + } + return ; +} + function EditorProfile() { - const { updateUser, user, processing } = useUserProfile(); + const { updateUser, user, errorProcessing, processing } = useUserProfile(); const [username, setUsername] = useState(''); const [email, setEmail] = useState(''); @@ -47,7 +61,7 @@ function EditorProfile() { } return ( -
+ setEmail(event.target.value)} /> - + {errorProcessing ? : null} + ); } diff --git a/rsconcept/frontend/src/utils/constants.ts b/rsconcept/frontend/src/utils/constants.ts index 03502ba8..9086d417 100644 --- a/rsconcept/frontend/src/utils/constants.ts +++ b/rsconcept/frontend/src/utils/constants.ts @@ -113,6 +113,7 @@ export const storage = { export const globals = { tooltip: 'global_tooltip', password_tooltip: 'password_tooltip', + email_tooltip: 'email_tooltip', main_scroll: 'main_scroll', library_item_editor: 'library_item_editor', constituenta_editor: 'constituenta_editor'