fix: fix account paths, fix local userData after login

This commit is contained in:
SD 2024-10-29 21:57:45 +04:00
parent cd44c9f1a1
commit 5b8ba1b5c4
5 changed files with 16 additions and 18 deletions

View File

@ -1,6 +1,6 @@
'use client' 'use client'
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useState } from 'react';
import { ProfileData, ProfileRequest } from '../../types/profile'; import { ProfileData, ProfileRequest } from '../../types/profile';
import { getPersonalData, setPersonData } from '../profile'; import { getPersonalData, setPersonData } from '../profile';
import { useLocalStorage } from '../../hooks/useLocalStorage'; import { useLocalStorage } from '../../hooks/useLocalStorage';
@ -18,7 +18,7 @@ export const useProfileSettings = (locale: string) => {
setProfileSettings(data); setProfileSettings(data);
}) })
.catch((err) => { .catch((err) => {
console.log(err);
}) })
.finally(() => { .finally(() => {
setFetchLoading(false); setFetchLoading(false);

View File

@ -18,7 +18,7 @@ export default function Messages({ params: { locale } }: { params: { locale: str
<div className="messages-session"> <div className="messages-session">
<Link <Link
className="card-profile" className="card-profile"
href={'1' as any} href={'messages/1' as any}
> >
<div className="card-profile__header"> <div className="card-profile__header">
<div className="card-profile__header__portrait"> <div className="card-profile__header__portrait">
@ -42,7 +42,7 @@ export default function Messages({ params: { locale } }: { params: { locale: str
</Link> </Link>
<Link <Link
className="card-profile" className="card-profile"
href={'2' as any} href={'messages/2' as any}
> >
<div className="card-profile__header"> <div className="card-profile__header">
<div className="card-profile__header__portrait"> <div className="card-profile__header__portrait">
@ -63,7 +63,7 @@ export default function Messages({ params: { locale } }: { params: { locale: str
</Link> </Link>
<Link <Link
className="card-profile" className="card-profile"
href={'3' as any} href={'messages/3' as any}
> >
<div className="card-profile__header"> <div className="card-profile__header">
<div className="card-profile__header__portrait"> <div className="card-profile__header__portrait">

View File

@ -1,8 +1,8 @@
'use client'; 'use client';
import React, { FC, useEffect, useState } from 'react'; import React, { FC, useEffect, useState } from 'react';
import { Button, Form, message, Upload } from 'antd'; import { Form, message, Upload } from 'antd';
import type { GetProp, UploadFile, UploadProps } from 'antd'; import type { UploadFile } from 'antd';
import ImgCrop from 'antd-img-crop'; import ImgCrop from 'antd-img-crop';
import { CameraOutlined, DeleteOutlined } from '@ant-design/icons'; import { CameraOutlined, DeleteOutlined } from '@ant-design/icons';
import { useRouter } from '../../navigation'; import { useRouter } from '../../navigation';
@ -12,17 +12,14 @@ import { validateImage } from '../../utils/account';
import { useProfileSettings } from '../../actions/hooks/useProfileSettings'; import { useProfileSettings } from '../../actions/hooks/useProfileSettings';
import { CustomInput } from '../view/CustomInput'; import { CustomInput } from '../view/CustomInput';
import { OutlinedButton } from '../view/OutlinedButton'; import { OutlinedButton } from '../view/OutlinedButton';
import {FilledButton, FilledSquareButton, FilledYellowButton} from '../view/FilledButton'; import { FilledSquareButton, FilledYellowButton } from '../view/FilledButton';
import { DeleteAccountModal } from '../Modals/DeleteAccountModal'; import { DeleteAccountModal } from '../Modals/DeleteAccountModal';
import { Loader } from '../view/Loader'; import { Loader } from '../view/Loader';
import {ButtonProps} from "antd/es/button/button";
type ProfileSettingsProps = { type ProfileSettingsProps = {
locale: string; locale: string;
}; };
type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
export const ProfileSettings: FC<ProfileSettingsProps> = ({ locale }) => { export const ProfileSettings: FC<ProfileSettingsProps> = ({ locale }) => {
const [form] = Form.useForm<ProfileRequest>(); const [form] = Form.useForm<ProfileRequest>();
const { profileSettings, fetchProfileSettings, save, fetchLoading } = useProfileSettings(locale); const { profileSettings, fetchProfileSettings, save, fetchLoading } = useProfileSettings(locale);
@ -58,7 +55,7 @@ export const ProfileSettings: FC<ProfileSettingsProps> = ({ locale }) => {
const onSaveProfile = () => { const onSaveProfile = () => {
form.validateFields() form.validateFields()
.then(({ login, surname, username }) => { .then(({ login, surname, username }) => {
const { phone, role, languagesLinks } = profileSettings; const { phone, role, languagesLinks } = profileSettings || {};
const newProfile: ProfileRequest = { const newProfile: ProfileRequest = {
phone, phone,
role, role,
@ -75,7 +72,7 @@ export const ProfileSettings: FC<ProfileSettingsProps> = ({ locale }) => {
reader.readAsDataURL(photo as File); reader.readAsDataURL(photo as File);
reader.onloadend = () => { reader.onloadend = () => {
const newReg = new RegExp('data:image/(png|jpg|jpeg);base64,') const newReg = new RegExp('data:image/(png|jpg|jpeg);base64,')
newProfile.faceImage = reader.result.replace(newReg, ''); newProfile.faceImage = reader?.result?.replace(newReg, '');
newProfile.isFaceImageKeepExisting = false; newProfile.isFaceImageKeepExisting = false;
onSave(newProfile); onSave(newProfile);
@ -181,7 +178,7 @@ export const ProfileSettings: FC<ProfileSettingsProps> = ({ locale }) => {
> >
{i18nText('save', locale)} {i18nText('save', locale)}
</FilledYellowButton> </FilledYellowButton>
<OutlinedButton onClick={() => router.push('change-password')}> <OutlinedButton onClick={() => router.push('settings/change-password')}>
{i18nText('changePass', locale)} {i18nText('changePass', locale)}
</OutlinedButton> </OutlinedButton>
<OutlinedButton <OutlinedButton

View File

@ -14,7 +14,7 @@ import { useLocalStorage } from '../../../hooks/useLocalStorage';
import { AUTH_TOKEN_KEY, AUTH_USER } from '../../../constants/common'; import { AUTH_TOKEN_KEY, AUTH_USER } from '../../../constants/common';
import { getRecentSessions, getRequestedSessions, getUpcomingSessions } from '../../../actions/sessions'; import { getRecentSessions, getRequestedSessions, getUpcomingSessions } from '../../../actions/sessions';
import { Session, Sessions, SessionType } from '../../../types/sessions'; import { Session, Sessions, SessionType } from '../../../types/sessions';
import { useRouter } from '../../../navigation'; import { useRouter, usePathname } from '../../../navigation';
import { i18nText } from '../../../i18nKeys'; import { i18nText } from '../../../i18nKeys';
type SessionsTabsProps = { type SessionsTabsProps = {
@ -31,6 +31,7 @@ export const SessionsTabs = ({ locale, activeTab }: SessionsTabsProps) => {
const [userData] = useLocalStorage(AUTH_USER, ''); const [userData] = useLocalStorage(AUTH_USER, '');
const { id: userId = 0 } = userData ? JSON.parse(userData) : {}; const { id: userId = 0 } = userData ? JSON.parse(userData) : {};
const router = useRouter(); const router = useRouter();
const pathname = usePathname();
const fetchData = () => { const fetchData = () => {
setErrorData(undefined); setErrorData(undefined);
@ -66,7 +67,7 @@ export const SessionsTabs = ({ locale, activeTab }: SessionsTabsProps) => {
const onClickSession = (event: MouseEvent<HTMLDivElement>, id: number) => { const onClickSession = (event: MouseEvent<HTMLDivElement>, id: number) => {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
router.push(`${id}`); router.push(`${pathname}/${id}`);
}; };
const getChildren = (list?: Session[]) => ( const getChildren = (list?: Session[]) => (

View File

@ -6,7 +6,7 @@ import { AUTH_USER } from '../../../constants/common';
import { SocialConfig } from '../../../constants/social'; import { SocialConfig } from '../../../constants/social';
import { useOauthWindow } from '../../../hooks/useOauthWindow'; import { useOauthWindow } from '../../../hooks/useOauthWindow';
import { getAuth } from '../../../actions/auth'; import { getAuth } from '../../../actions/auth';
import { getPersonalData } from '../../../actions/profile'; import {getPersonalData, getUserData} from '../../../actions/profile';
import { CustomInput } from '../../view/CustomInput'; import { CustomInput } from '../../view/CustomInput';
import { CustomInputPassword } from '../../view/CustomInputPassword'; import { CustomInputPassword } from '../../view/CustomInputPassword';
import { FilledButton } from '../../view/FilledButton'; import { FilledButton } from '../../view/FilledButton';
@ -39,7 +39,7 @@ export const EnterContent: FC<EnterProps> = ({
getAuth(locale, { login, password }) getAuth(locale, { login, password })
.then((data) => { .then((data) => {
if (data.jwtToken) { if (data.jwtToken) {
getPersonalData(locale, data.jwtToken) getUserData(locale, data.jwtToken)
.then((profile) => { .then((profile) => {
localStorage.setItem(AUTH_USER, JSON.stringify(profile)); localStorage.setItem(AUTH_USER, JSON.stringify(profile));
updateToken(data.jwtToken); updateToken(data.jwtToken);