feat: integrate sonner for toast notifications and enhance UI feedback
Added the sonner library for toast notifications across various components, improving user feedback for actions such as saving settings, syncing rules, and handling errors. Updated the layout to include a Toaster component for consistent notification display. Refactored alert messages in the backups, gre, and filters pages to utilize the new notification system, enhancing overall user experience.
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
||||
import { Flag, countryName } from "@/components/flag"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { requestJson } from "@/shared/api/http-client"
|
||||
import { toast } from "sonner"
|
||||
|
||||
// ─── types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -1722,7 +1723,6 @@ function AddRuleSheet({
|
||||
() => !(initialForm?.targets?.length),
|
||||
)
|
||||
const [testTelegramBusy, setTestTelegramBusy] = useState(false)
|
||||
const [testTelegramHint, setTestTelegramHint] = useState<string | null>(null)
|
||||
|
||||
const targets = typeTargets[form.type]
|
||||
const conditions = TYPE_CONDITIONS[form.type]
|
||||
@@ -1817,7 +1817,6 @@ function AddRuleSheet({
|
||||
const handleTestRuleTelegram = async () => {
|
||||
if (!onTestRuleTelegram || !canSave || testTelegramBusy || testTelegramDisabled) return
|
||||
setTestTelegramBusy(true)
|
||||
setTestTelegramHint(null)
|
||||
try {
|
||||
const conditionLine = conditionDisplay || summarizeConditionsUi(form.conditions)
|
||||
await onTestRuleTelegram({
|
||||
@@ -1828,10 +1827,9 @@ function AddRuleSheet({
|
||||
cooldown: form.cooldown,
|
||||
ruleChatId: form.chatId.trim(),
|
||||
})
|
||||
setTestTelegramHint("__ok__")
|
||||
window.setTimeout(() => setTestTelegramHint(null), 5000)
|
||||
toast.success("Тестовое сообщение отправлено в Telegram.")
|
||||
} catch (e) {
|
||||
setTestTelegramHint(e instanceof Error ? e.message : "Не удалось отправить тест")
|
||||
toast.error(e instanceof Error ? e.message : "Не удалось отправить тест")
|
||||
} finally {
|
||||
setTestTelegramBusy(false)
|
||||
}
|
||||
@@ -2327,21 +2325,6 @@ function AddRuleSheet({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isLive && onTestRuleTelegram && testTelegramHint ? (
|
||||
<div
|
||||
className={cn(
|
||||
"shrink-0 px-6 py-2.5 text-xs border-t",
|
||||
testTelegramHint === "__ok__"
|
||||
? "text-emerald-700 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20"
|
||||
: "text-destructive bg-destructive/5 border-destructive/20",
|
||||
)}
|
||||
>
|
||||
{testTelegramHint === "__ok__"
|
||||
? "Тестовое сообщение отправлено в Telegram."
|
||||
: testTelegramHint}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* ── fixed footer ── */}
|
||||
<SheetFooter className="shrink-0 px-6 py-4 border-t flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:justify-stretch">
|
||||
<Button variant="outline" className="w-full sm:flex-1 min-h-9" onClick={onClose}>
|
||||
|
||||
Reference in New Issue
Block a user