diff --git a/src/pages/Settings.jsx b/src/pages/Settings.jsx index 7570925..426a36c 100644 --- a/src/pages/Settings.jsx +++ b/src/pages/Settings.jsx @@ -1,6 +1,6 @@ import { useState, useEffect } from "react" import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query" -import { ArrowLeft, Bell, MessageCircle, Globe, Save, Copy, Check } from "lucide-react" +import { ArrowLeft, Bell, MessageCircle, Globe, Save, Copy, Check, User, Sun, Moon } from "lucide-react" import { Link } from "react-router-dom" import { profileApi } from "../api/profile" import Navigation from "../components/Navigation" @@ -27,9 +27,12 @@ const TIMEZONES = [ export default function Settings() { const queryClient = useQueryClient() const [copied, setCopied] = useState(false) + const [username, setUsername] = useState("") const [chatId, setChatId] = useState("") const [notificationsEnabled, setNotificationsEnabled] = useState(true) const [timezone, setTimezone] = useState("Europe/Moscow") + const [morningTime, setMorningTime] = useState("09:00") + const [eveningTime, setEveningTime] = useState("21:00") const [hasChanges, setHasChanges] = useState(false) const { data: profile, isLoading } = useQuery({ @@ -39,21 +42,27 @@ export default function Settings() { useEffect(() => { if (profile) { + setUsername(profile.username || "") setChatId(profile.telegram_chat_id?.toString() || "") setNotificationsEnabled(profile.notifications_enabled ?? true) setTimezone(profile.timezone || "Europe/Moscow") + setMorningTime(profile.morning_reminder_time || "09:00") + setEveningTime(profile.evening_reminder_time || "21:00") } }, [profile]) useEffect(() => { if (profile) { const changed = + username !== (profile.username || "") || (chatId !== (profile.telegram_chat_id?.toString() || "")) || notificationsEnabled !== (profile.notifications_enabled ?? true) || - timezone !== (profile.timezone || "Europe/Moscow") + timezone !== (profile.timezone || "Europe/Moscow") || + morningTime !== (profile.morning_reminder_time || "09:00") || + eveningTime !== (profile.evening_reminder_time || "21:00") setHasChanges(changed) } - }, [chatId, notificationsEnabled, timezone, profile]) + }, [username, chatId, notificationsEnabled, timezone, morningTime, eveningTime, profile]) const mutation = useMutation({ mutationFn: profileApi.update, @@ -67,6 +76,12 @@ export default function Settings() { const data = { notifications_enabled: notificationsEnabled, timezone: timezone, + morning_reminder_time: morningTime, + evening_reminder_time: eveningTime, + } + + if (username && username !== profile?.username) { + data.username = username } if (chatId) { @@ -77,7 +92,7 @@ export default function Settings() { } const copyInstruction = () => { - navigator.clipboard.writeText("@PulseNotifyBot") + navigator.clipboard.writeText("@pulse_tracking_bot") setCopied(true) setTimeout(() => setCopied(false), 2000) } @@ -103,6 +118,32 @@ export default function Settings() {
+ {/* Profile Section */} +
+
+
+ +
+
+

Профиль

+

Основная информация

+
+
+ +
+ + setUsername(e.target.value)} + placeholder="Ваше имя" + className="input" + /> +
+
+ {/* Telegram Section */}
@@ -125,7 +166,7 @@ export default function Settings() { className="flex items-center gap-2 text-sm font-medium text-blue-600 hover:text-blue-700" > {copied ? : } - {copied ? "Скопировано!" : "@PulseNotifyBot"} + {copied ? "Скопировано!" : "@pulse_tracking_bot"}

2. Скопируй Chat ID из ответа бота и вставь ниже @@ -155,23 +196,61 @@ export default function Settings() {

Уведомления

-

Настрой push-уведомления

+

Настрой ежедневные уведомления

- +
+ + + {notificationsEnabled && ( + <> +
+ +
+ +

Задачи и привычки на сегодня

+
+ setMorningTime(e.target.value)} + className="px-3 py-1.5 border border-gray-200 rounded-lg text-sm" + /> +
+ +
+ +
+ +

Итоги дня: выполнено / осталось

+
+ setEveningTime(e.target.value)} + className="px-3 py-1.5 border border-gray-200 rounded-lg text-sm" + /> +
+ + )} +
{/* Timezone Section */}