import ModalSettings from "@/components/ModalSettings"; import Button from "@/components/ui/Button"; import { withTitle } from "@/constructors/Component"; import { UrlsTitle } from "@/enums/urls"; import { useAppContext } from "@/providers/AuthProvider"; import apiClient from "@/services/api"; import { cn } from "@/utils/class-merge"; import { ArrowRightStartOnRectangleIcon, Cog8ToothIcon } from "@heroicons/react/24/outline"; import { FunctionComponent } from "preact"; import { useLocation } from "preact-iso"; import { useEffect, useState } from "preact/hooks"; import classes from "./profile_settings.module.scss"; interface UserProfile { username: string; status: string; telegram_notifications: boolean; telegram_chat_id: string | null; current_xp: string; xp_for_next_status: string; } interface UserSettings { profile: UserProfile; } const ProfileSettings: FunctionComponent = () => { const { isLoggedIn } = useAppContext(); const { route } = useLocation(); const [userData, setUserData] = useState({ username: "", status: "", current_xp: "", xp_for_next_status: "", telegram_notifications: false, telegram_chat_id: "", }); const [isSettingsOpen, setIsSettingsOpen] = useState(false); const fetchUserData = async () => { try { const response = await apiClient("/api/settings/view_settings/", { method: "GET" }, isLoggedIn); setUserData(response.profile); } catch (error) { console.error("Failed to fetch user data:", error); } }; useEffect(() => { if (isLoggedIn.value) { fetchUserData(); } }, [isLoggedIn.value]); const handleLogout = async () => { try { await apiClient("/api/settings/logout/", { method: "POST", needsCsrf: true }, isLoggedIn); isLoggedIn.value = false; localStorage.removeItem("loggedIn"); localStorage.removeItem("user"); route("/login", true); } catch (error) { console.error("Logout failed:", error); } }; return (
"Аватар"

{userData.username}

{userData.status}

{userData.current_xp}/{userData.xp_for_next_status}
); }; export default withTitle(UrlsTitle.PROFILE, ProfileSettings);