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

View File

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

View File

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

View File

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

View File

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