diff --git a/src/Profile.js b/src/Profile.js index 75ce354..9cf03cf 100644 --- a/src/Profile.js +++ b/src/Profile.js @@ -19,6 +19,10 @@ const Profile = () => { const [new_password, setnew_password] = useState(''); const [new_password_confirm, setnew_password_confirm] = useState(''); const [passwordError, setPasswordError] = useState(''); + const [showDescriptionModal, setShowDescriptionModal] = useState(false); + const [profileDescription, setProfileDescription] = useState(''); + const [descriptionError, setDescriptionError] = useState(''); + useEffect(() => { const checkSession = async () => { try { @@ -117,6 +121,36 @@ const Profile = () => { } }; + const saveProfileDescription = async (e) => { + e.preventDefault(); + setDescriptionError(''); + + try { + await axios.put('/api/users/change_description', + { new_description: profileDescription }, + { withCredentials: true } + ); + try { + const response = await axios.get('/api/users/me'); + setUser(response.data.display_name); + setUserName(response.data.username); + // Обновляем описание, если оно есть в ответе + if (response.data.description) { + setProfileDescription(response.data.description); + } + } catch (err) { + setError('Ошибка обновления данных профиля'); + } + + setShowDescriptionModal(false); // Закрываем модальное окно + + } catch (err) { + setDescriptionError( + err.response?.data?.detail || 'Ошибка при сохранении описания' + ); + } + }; + const OpenWindowDelete = () => { setShowConfirm(true); // Показываем окно подтверждения @@ -141,7 +175,23 @@ const Profile = () => { const closeWindowUserName = () => { setShowConfirmUserName(false); // Показываем окно подтверждения }; - + + const openDescriptionModal = async () => { + setDescriptionError(''); + try { + const response = await axios.get('/api/users/me'); + setProfileDescription(response.data.description || ''); + setShowDescriptionModal(true); + } catch (err) { + setError('Не удалось загрузить данные профиля'); + console.error('Ошибка загрузки данных пользователя:', err); + } + }; + + const closeDescriptionModal = () => { + setShowDescriptionModal(false); + setDescriptionError(''); + }; const deleteAccount = async () => { try { await axios.delete('/api/users/me', { withCredentials: true }); @@ -171,6 +221,13 @@ const Profile = () => {

{user}

+

Описание профиля

+
+ Добавьте краткое описание о себе, которое увидят другие пользователи. +
+
Логин

{userName}

@@ -178,9 +235,9 @@ const Profile = () => {

Изменить пароль

В целях безопасности мы рекомендуем выбрать пароль, который ещё не использовался вами в других учётных записях.
- - - + + + )} @@ -284,6 +341,48 @@ const Profile = () => { )} + {showDescriptionModal && ( +
+
+

{profileDescription ? 'Редактировать описание профиля' : 'Добавить описание профиля'}

+ + {descriptionError && ( +
+ {descriptionError} +
+ )} + +
+
+ +