Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07cbeec816 | ||
|
|
4d67af0bfc |
@@ -0,0 +1,238 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { apiFetch, ApiError } from "@/lib/api";
|
||||
import { useList } from "@/lib/useResource";
|
||||
import { useToast } from "@/components/toast";
|
||||
import { DataTable, type Column } from "@/components/DataTable";
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
ConfirmDialog,
|
||||
Field,
|
||||
Input,
|
||||
Textarea,
|
||||
Switch,
|
||||
Modal,
|
||||
PageHeader,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface ChatTopic {
|
||||
id: number;
|
||||
title?: string;
|
||||
description?: string | null;
|
||||
order?: number | null;
|
||||
is_active?: boolean;
|
||||
}
|
||||
|
||||
export default function ChatTopicsPage() {
|
||||
const { data, loading, error, reload } = useList<ChatTopic>("/chat-topics");
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<ChatTopic | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [title, setTitle] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [order, setOrder] = useState("");
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
|
||||
const [deleting, setDeleting] = useState<ChatTopic | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setTitle("");
|
||||
setDescription("");
|
||||
setOrder("");
|
||||
setIsActive(true);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: ChatTopic) {
|
||||
setEditing(row);
|
||||
setTitle(row.title ?? "");
|
||||
setDescription(row.description ?? "");
|
||||
setOrder(row.order != null ? String(row.order) : "");
|
||||
setIsActive(row.is_active ?? true);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setSaving(true);
|
||||
try {
|
||||
// chat-topics is a JSON apiResource (no files).
|
||||
const payload = {
|
||||
title,
|
||||
description: description || null,
|
||||
order: order === "" ? null : Number(order),
|
||||
is_active: isActive,
|
||||
};
|
||||
if (editing) {
|
||||
await apiFetch(`/chat-topics/${editing.id}`, {
|
||||
method: "PUT",
|
||||
body: payload,
|
||||
});
|
||||
toast.success("موضوع ویرایش شد.");
|
||||
} else {
|
||||
await apiFetch("/chat-topics", { method: "POST", body: payload });
|
||||
toast.success("موضوع افزوده شد.");
|
||||
}
|
||||
setOpen(false);
|
||||
reload();
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : "خطا در ذخیرهسازی");
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmDelete() {
|
||||
if (!deleting) return;
|
||||
setRemoving(true);
|
||||
try {
|
||||
await apiFetch(`/chat-topics/${deleting.id}`, { method: "DELETE" });
|
||||
toast.success("موضوع حذف شد.");
|
||||
setDeleting(null);
|
||||
reload();
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : "خطا در حذف");
|
||||
} finally {
|
||||
setRemoving(false);
|
||||
}
|
||||
}
|
||||
|
||||
const columns: Column<ChatTopic>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{ key: "title", header: "عنوان", render: (r) => r.title ?? "—" },
|
||||
{
|
||||
key: "description",
|
||||
header: "توضیحات",
|
||||
render: (r) => r.description || "—",
|
||||
},
|
||||
{
|
||||
key: "order",
|
||||
header: "ترتیب",
|
||||
render: (r) => toFa(r.order ?? "—"),
|
||||
className: "w-20",
|
||||
},
|
||||
{
|
||||
key: "is_active",
|
||||
header: "وضعیت",
|
||||
render: (r) =>
|
||||
r.is_active ? (
|
||||
<Badge tone="success">فعال</Badge>
|
||||
) : (
|
||||
<Badge tone="neutral">غیرفعال</Badge>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<PageHeader
|
||||
title="موضوعات پیشنهادی گفتگو"
|
||||
subtitle="موضوعاتی که در بخش گفتگو با مشاور به کاربر پیشنهاد میشود"
|
||||
action={
|
||||
<Button icon={<PlusIcon className="h-4 w-4" />} onClick={openCreate}>
|
||||
موضوع جدید
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
rows={data}
|
||||
loading={loading}
|
||||
error={error}
|
||||
onRetry={reload}
|
||||
emptyMessage="هنوز موضوعی ثبت نشده است."
|
||||
emptyAction={
|
||||
<Button icon={<PlusIcon className="h-4 w-4" />} onClick={openCreate}>
|
||||
موضوع جدید
|
||||
</Button>
|
||||
}
|
||||
actions={(row) => (
|
||||
<>
|
||||
<Button variant="ghost" onClick={() => openEdit(row)} aria-label="ویرایش">
|
||||
<EditIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => setDeleting(row)}
|
||||
aria-label="حذف"
|
||||
className="text-danger"
|
||||
>
|
||||
<TrashIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
title={editing ? "ویرایش موضوع" : "موضوع جدید"}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="secondary" onClick={() => setOpen(false)}>
|
||||
انصراف
|
||||
</Button>
|
||||
<Button form="chat-topic-form" type="submit" loading={saving}>
|
||||
ذخیره
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="chat-topic-form" onSubmit={save} className="flex flex-col gap-4">
|
||||
<Field label="عنوان" required>
|
||||
<Input
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="مثلاً هیچ راه واحدی برای مدیتیشن وجود ندارد"
|
||||
required
|
||||
autoFocus
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="توضیحات">
|
||||
<Textarea
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="توضیح اختیاری درباره موضوع"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="ترتیب">
|
||||
<Input
|
||||
type="number"
|
||||
dir="ltr"
|
||||
value={order}
|
||||
onChange={(e) => setOrder(e.target.value)}
|
||||
placeholder="مثلاً ۱"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="وضعیت">
|
||||
<Switch
|
||||
checked={isActive}
|
||||
onChange={setIsActive}
|
||||
label={isActive ? "فعال" : "غیرفعال"}
|
||||
/>
|
||||
</Field>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleting}
|
||||
message={`آیا از حذف «${deleting?.title ?? ""}» مطمئن هستید؟`}
|
||||
loading={removing}
|
||||
onConfirm={confirmDelete}
|
||||
onClose={() => setDeleting(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { useRouter } from "next/navigation";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import { Sidebar } from "@/components/Sidebar";
|
||||
import { Spinner, Button } from "@/components/ui";
|
||||
import { ThemeToggle } from "@/components/ThemeToggle";
|
||||
import { LogoutIcon, MenuIcon, CloseIcon } from "@/components/icons";
|
||||
|
||||
export default function DashboardLayout({
|
||||
@@ -64,6 +65,7 @@ export default function DashboardLayout({
|
||||
{mobileOpen ? <CloseIcon /> : <MenuIcon />}
|
||||
</button>
|
||||
<div className="flex-1" />
|
||||
<ThemeToggle />
|
||||
<Button variant="ghost" icon={<LogoutIcon className="h-4 w-4" />} onClick={onLogout}>
|
||||
خروج
|
||||
</Button>
|
||||
|
||||
@@ -10,17 +10,26 @@ import {
|
||||
ConfirmDialog,
|
||||
Field,
|
||||
Input,
|
||||
Textarea,
|
||||
Modal,
|
||||
PageHeader,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { pickUrl } from "@/lib/media";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface Category {
|
||||
id: number;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
icon?: string | null;
|
||||
subcategories_count?: number;
|
||||
}
|
||||
|
||||
// The icon is a direct image-file field on the category (not an image_id ref).
|
||||
const ICON_KEYS = ["icon", "icon_url"];
|
||||
|
||||
export default function MediaCategoriesPage() {
|
||||
const { data, loading, error, reload } = useList<Category>("/categories");
|
||||
const toast = useToast();
|
||||
@@ -28,6 +37,8 @@ export default function MediaCategoriesPage() {
|
||||
const [editing, setEditing] = useState<Category | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [icon, setIcon] = useState<File | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [deleting, setDeleting] = useState<Category | null>(null);
|
||||
@@ -36,11 +47,15 @@ export default function MediaCategoriesPage() {
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setName("");
|
||||
setDescription("");
|
||||
setIcon(null);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: Category) {
|
||||
setEditing(row);
|
||||
setName(row.name);
|
||||
setName(row.name ?? "");
|
||||
setDescription(row.description ?? "");
|
||||
setIcon(null);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
@@ -49,17 +64,19 @@ export default function MediaCategoriesPage() {
|
||||
setSaving(true);
|
||||
try {
|
||||
if (editing) {
|
||||
// Update is JSON on /categories/:id
|
||||
await apiFetch(`/categories/${editing.id}`, {
|
||||
method: "PUT",
|
||||
body: { name },
|
||||
// Icon is a file, so update goes through POST + Laravel method spoofing.
|
||||
const body = toFormData({
|
||||
_method: "PUT",
|
||||
name,
|
||||
description,
|
||||
icon,
|
||||
});
|
||||
await apiFetch(`/categories/${editing.id}`, { method: "POST", body });
|
||||
toast.success("دستهبندی ویرایش شد.");
|
||||
} else {
|
||||
// Create is multipart on /categories
|
||||
await apiFetch("/categories", {
|
||||
method: "POST",
|
||||
body: toFormData({ name }),
|
||||
body: toFormData({ name, description, icon }),
|
||||
});
|
||||
toast.success("دستهبندی افزوده شد.");
|
||||
}
|
||||
@@ -88,8 +105,26 @@ export default function MediaCategoriesPage() {
|
||||
}
|
||||
|
||||
const columns: Column<Category>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-24" },
|
||||
{
|
||||
key: "icon",
|
||||
header: "آیکن",
|
||||
className: "w-20",
|
||||
render: (r) => (
|
||||
<MediaPreview kind="image" src={pickUrl(r, ICON_KEYS)} label={r.name} />
|
||||
),
|
||||
},
|
||||
{ key: "name", header: "نام دستهبندی" },
|
||||
{
|
||||
key: "description",
|
||||
header: "توضیحات",
|
||||
render: (r) => r.description || "—",
|
||||
},
|
||||
{
|
||||
key: "subcategories_count",
|
||||
header: "زیردستهها",
|
||||
render: (r) => toFa(r.subcategories_count ?? 0),
|
||||
className: "w-28",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -148,7 +183,7 @@ export default function MediaCategoriesPage() {
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="category-form" onSubmit={save}>
|
||||
<form id="category-form" onSubmit={save} className="flex flex-col gap-4">
|
||||
<Field label="نام دستهبندی" required>
|
||||
<Input
|
||||
value={name}
|
||||
@@ -158,6 +193,29 @@ export default function MediaCategoriesPage() {
|
||||
autoFocus
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="توضیحات">
|
||||
<Textarea
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="توضیح کوتاه درباره این دستهبندی"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field
|
||||
label="آیکن"
|
||||
hint={
|
||||
editing
|
||||
? "در صورت عدم انتخاب، آیکن فعلی حفظ میشود."
|
||||
: "یک تصویر برای نمایش دستهبندی انتخاب کنید."
|
||||
}
|
||||
>
|
||||
<Input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={(e) => setIcon(e.target.files?.[0] ?? null)}
|
||||
/>
|
||||
</Field>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
ConfirmDialog,
|
||||
Field,
|
||||
Input,
|
||||
Textarea,
|
||||
Select,
|
||||
Modal,
|
||||
PageHeader,
|
||||
@@ -25,6 +26,7 @@ interface Category {
|
||||
interface SubCategory {
|
||||
id: number;
|
||||
name?: string;
|
||||
description?: string | null;
|
||||
category_id?: number;
|
||||
category?: { id?: number; name?: string };
|
||||
}
|
||||
@@ -39,6 +41,7 @@ export default function SubCategoriesPage() {
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [categoryId, setCategoryId] = useState("");
|
||||
|
||||
const [deleting, setDeleting] = useState<SubCategory | null>(null);
|
||||
@@ -47,6 +50,7 @@ export default function SubCategoriesPage() {
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setName("");
|
||||
setDescription("");
|
||||
setCategoryId("");
|
||||
setOpen(true);
|
||||
}
|
||||
@@ -54,6 +58,7 @@ export default function SubCategoriesPage() {
|
||||
function openEdit(row: SubCategory) {
|
||||
setEditing(row);
|
||||
setName(row.name ?? "");
|
||||
setDescription(row.description ?? "");
|
||||
setCategoryId(
|
||||
row.category_id != null
|
||||
? String(row.category_id)
|
||||
@@ -72,14 +77,14 @@ export default function SubCategoriesPage() {
|
||||
// Update is JSON on /sub-categories/:id
|
||||
await apiFetch(`/sub-categories/${editing.id}`, {
|
||||
method: "PUT",
|
||||
body: { name, category_id: categoryId },
|
||||
body: { name, category_id: categoryId, description },
|
||||
});
|
||||
toast.success("زیردسته ویرایش شد.");
|
||||
} else {
|
||||
// Create is multipart on /sub-categories
|
||||
await apiFetch("/sub-categories", {
|
||||
method: "POST",
|
||||
body: toFormData({ category_id: categoryId, name }),
|
||||
body: toFormData({ category_id: categoryId, name, description }),
|
||||
});
|
||||
toast.success("زیردسته افزوده شد.");
|
||||
}
|
||||
@@ -115,6 +120,11 @@ export default function SubCategoriesPage() {
|
||||
header: "دستهبندی والد",
|
||||
render: (r) => r.category?.name ?? "—",
|
||||
},
|
||||
{
|
||||
key: "description",
|
||||
header: "توضیحات",
|
||||
render: (r) => r.description || "—",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -202,6 +212,14 @@ export default function SubCategoriesPage() {
|
||||
autoFocus
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="توضیحات">
|
||||
<Textarea
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="توضیح کوتاه درباره این زیردسته"
|
||||
/>
|
||||
</Field>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
|
||||
@@ -20,10 +20,17 @@ import { toFa } from "@/lib/utils";
|
||||
interface Question {
|
||||
id: number;
|
||||
title?: string;
|
||||
category?: string;
|
||||
// Submitted as a string (name); returned by the API as a related object.
|
||||
category?: { id?: number; name?: string } | string | null;
|
||||
tags?: string[] | string;
|
||||
}
|
||||
|
||||
function categoryName(c: Question["category"]): string {
|
||||
if (!c) return "";
|
||||
if (typeof c === "string") return c;
|
||||
return c.name ?? "";
|
||||
}
|
||||
|
||||
function asTags(value: Question["tags"]): string[] {
|
||||
if (Array.isArray(value)) return value.map((t) => String(t));
|
||||
if (typeof value === "string" && value.trim() !== "") {
|
||||
@@ -73,7 +80,7 @@ export default function QuestionsPage() {
|
||||
function openEdit(row: Question) {
|
||||
setEditing(row);
|
||||
setTitle(row.title ?? "");
|
||||
setCategory(row.category ?? "");
|
||||
setCategory(categoryName(row.category));
|
||||
setTagsInput(asTags(row.tags).join("، "));
|
||||
setOpen(true);
|
||||
}
|
||||
@@ -125,7 +132,7 @@ export default function QuestionsPage() {
|
||||
const columns: Column<Question>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{ key: "title", header: "عنوان", render: (r) => r.title ?? "—" },
|
||||
{ key: "category", header: "دسته", render: (r) => r.category ?? "—" },
|
||||
{ key: "category", header: "دسته", render: (r) => categoryName(r.category) || "—" },
|
||||
{
|
||||
key: "tags",
|
||||
header: "برچسبها",
|
||||
|
||||
+29
-1
@@ -1,10 +1,15 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
/* Enable class-based dark mode (toggle a `.dark` class on <html>). */
|
||||
@custom-variant dark (&:where(.dark, .dark *));
|
||||
|
||||
/* Persian admin theme — calm meditation palette, RTL-first. */
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--background: #f4f6fb;
|
||||
--surface: #ffffff;
|
||||
--surface-muted: #eef1f8;
|
||||
--surface-hover: #e2e6f2;
|
||||
--foreground: #1f2433;
|
||||
--muted: #6b7390;
|
||||
--border: #e1e5f0;
|
||||
@@ -14,12 +19,34 @@
|
||||
--danger: #e25b6e;
|
||||
--success: #2fb583;
|
||||
--ring: rgba(91, 110, 225, 0.35);
|
||||
--switch-off: #cdd3e6;
|
||||
--scroll-thumb: #cdd3e6;
|
||||
}
|
||||
|
||||
.dark {
|
||||
color-scheme: dark;
|
||||
--background: #0f1320;
|
||||
--surface: #181d2e;
|
||||
--surface-muted: #222840;
|
||||
--surface-hover: #2c3450;
|
||||
--foreground: #e7eaf3;
|
||||
--muted: #97a0bd;
|
||||
--border: #2c3450;
|
||||
--primary: #6f7ff0;
|
||||
--primary-hover: #5f6fe6;
|
||||
--primary-soft: #232a47;
|
||||
--danger: #f06b7d;
|
||||
--success: #3ec79a;
|
||||
--ring: rgba(111, 127, 240, 0.4);
|
||||
--switch-off: #3a4566;
|
||||
--scroll-thumb: #39425f;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-surface: var(--surface);
|
||||
--color-surface-muted: var(--surface-muted);
|
||||
--color-surface-hover: var(--surface-hover);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-border: var(--border);
|
||||
@@ -45,6 +72,7 @@ body {
|
||||
color: var(--foreground);
|
||||
font-family: var(--font-vazir), system-ui, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
transition: background-color 0.2s ease, color 0.2s ease;
|
||||
}
|
||||
|
||||
/* Persian digits feel native when the font handles them; keep tabular for tables. */
|
||||
@@ -58,7 +86,7 @@ table {
|
||||
height: 10px;
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #cdd3e6;
|
||||
background: var(--scroll-thumb);
|
||||
border-radius: 999px;
|
||||
}
|
||||
::-webkit-scrollbar-track {
|
||||
|
||||
+13
-1
@@ -14,13 +14,25 @@ export const metadata: Metadata = {
|
||||
description: "پنل مدیریت محتوای اپلیکیشن آرام جان",
|
||||
};
|
||||
|
||||
// Runs before paint to set the `.dark` class from saved preference / system,
|
||||
// avoiding a light flash on load. Kept inline + minimal on purpose.
|
||||
const noFlashTheme = `(function(){try{var t=localStorage.getItem('aram_theme');if(!t){t=window.matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';}if(t==='dark'){document.documentElement.classList.add('dark');}}catch(e){}})();`;
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="fa" dir="rtl" className={`${vazir.variable} h-full`}>
|
||||
<html
|
||||
lang="fa"
|
||||
dir="rtl"
|
||||
className={`${vazir.variable} h-full`}
|
||||
suppressHydrationWarning
|
||||
>
|
||||
<head>
|
||||
<script dangerouslySetInnerHTML={{ __html: noFlashTheme }} />
|
||||
</head>
|
||||
<body className="min-h-full">
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
|
||||
+5
-1
@@ -7,6 +7,7 @@ import { useToast } from "@/components/toast";
|
||||
import { ApiError } from "@/lib/api";
|
||||
import { Button, Field, Input } from "@/components/ui";
|
||||
import { Logo } from "@/components/Logo";
|
||||
import { ThemeToggle } from "@/components/ThemeToggle";
|
||||
|
||||
export default function LoginPage() {
|
||||
const { login, token, ready } = useAuth();
|
||||
@@ -39,7 +40,10 @@ export default function LoginPage() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-gradient-to-bl from-[#eef1fb] to-[#f6f3fb] p-4">
|
||||
<div className="relative flex min-h-screen items-center justify-center bg-gradient-to-bl from-[#eef1fb] to-[#f6f3fb] p-4 dark:from-[#11151f] dark:to-[#0d1018]">
|
||||
<div className="absolute top-4 left-4">
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
<div className="w-full max-w-md rounded-3xl border border-border bg-surface p-8 shadow-lg">
|
||||
<div className="mb-8 text-center">
|
||||
<div className="mx-auto mb-4 flex h-20 w-20 items-center justify-center rounded-2xl bg-primary-soft">
|
||||
|
||||
@@ -81,7 +81,7 @@ export function ImagePicker({
|
||||
انتخاب از کتابخانه
|
||||
</Button>
|
||||
|
||||
<label className="inline-flex cursor-pointer items-center justify-center gap-2 rounded-xl border border-border bg-surface-muted px-4 py-2 text-sm font-medium text-foreground transition hover:bg-[#e2e6f2]">
|
||||
<label className="inline-flex cursor-pointer items-center justify-center gap-2 rounded-xl border border-border bg-surface-muted px-4 py-2 text-sm font-medium text-foreground transition hover:bg-surface-hover">
|
||||
بارگذاری تصویر
|
||||
<input
|
||||
type="file"
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import { AuthProvider } from "@/lib/auth";
|
||||
import { ThemeProvider } from "@/lib/theme";
|
||||
import { ToastProvider } from "./toast";
|
||||
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<ToastProvider>
|
||||
<AuthProvider>{children}</AuthProvider>
|
||||
</ToastProvider>
|
||||
<ThemeProvider>
|
||||
<ToastProvider>
|
||||
<AuthProvider>{children}</AuthProvider>
|
||||
</ToastProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import { useTheme } from "@/lib/theme";
|
||||
import { SunIcon, MoonIcon } from "./icons";
|
||||
|
||||
export function ThemeToggle({ className }: { className?: string }) {
|
||||
const { theme, toggle } = useTheme();
|
||||
const dark = theme === "dark";
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggle}
|
||||
aria-label={dark ? "حالت روشن" : "حالت تاریک"}
|
||||
title={dark ? "حالت روشن" : "حالت تاریک"}
|
||||
className={`rounded-lg p-2 text-muted transition hover:bg-surface-muted hover:text-foreground ${className ?? ""}`}
|
||||
>
|
||||
{dark ? <SunIcon className="h-5 w-5" /> : <MoonIcon className="h-5 w-5" />}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -70,6 +70,19 @@ export const SearchIcon = (p: IconProps) => (
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const SunIcon = (p: IconProps) => (
|
||||
<svg {...base(p)}>
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const MoonIcon = (p: IconProps) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const LogoutIcon = (p: IconProps) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
|
||||
@@ -170,6 +183,13 @@ export const TrophyIcon = (p: IconProps) => (
|
||||
<path d="M17 5h3v2a3 3 0 0 1-3 3M7 5H4v2a3 3 0 0 0 3 3" />
|
||||
</svg>
|
||||
);
|
||||
export const ChatIcon = (p: IconProps) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M21 11.5a8.38 8.38 0 0 1-9 8.34 9.5 9.5 0 0 1-3.4-.5L3 21l1.66-4.5A8.38 8.38 0 0 1 4 12a8.5 8.5 0 0 1 9-8.45 8.38 8.38 0 0 1 8 7.95Z" />
|
||||
<path d="M8.5 12h.01M12 12h.01M15.5 12h.01" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const TagIcon = (p: IconProps) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M3 12V5a2 2 0 0 1 2-2h7l9 9-9 9-9-9Z" />
|
||||
|
||||
@@ -53,7 +53,7 @@ export function ToastProvider({ children }: { children: React.ReactNode }) {
|
||||
"min-w-64 rounded-xl px-4 py-3 text-sm text-white shadow-lg",
|
||||
t.kind === "success" && "bg-success",
|
||||
t.kind === "error" && "bg-danger",
|
||||
t.kind === "info" && "bg-foreground",
|
||||
t.kind === "info" && "bg-primary",
|
||||
)}
|
||||
>
|
||||
{t.message}
|
||||
|
||||
+4
-4
@@ -22,7 +22,7 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
const buttonVariants: Record<ButtonVariant, string> = {
|
||||
primary: "bg-primary text-white hover:bg-primary-hover",
|
||||
secondary:
|
||||
"bg-surface-muted text-foreground hover:bg-[#e2e6f2] border border-border",
|
||||
"bg-surface-muted text-foreground hover:bg-surface-hover border border-border",
|
||||
danger: "bg-danger text-white hover:opacity-90",
|
||||
ghost: "text-muted hover:bg-surface-muted",
|
||||
};
|
||||
@@ -115,7 +115,7 @@ export function Switch({
|
||||
<span
|
||||
className={cn(
|
||||
"relative h-6 w-11 rounded-full transition",
|
||||
checked ? "bg-primary" : "bg-[#cdd3e6]",
|
||||
checked ? "bg-primary" : "bg-[var(--switch-off)]",
|
||||
)}
|
||||
>
|
||||
<span
|
||||
@@ -182,8 +182,8 @@ export function Badge({
|
||||
className={cn(
|
||||
"inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",
|
||||
tone === "neutral" && "bg-surface-muted text-muted",
|
||||
tone === "success" && "bg-[#e3f6ee] text-success",
|
||||
tone === "danger" && "bg-[#fbe7ea] text-danger",
|
||||
tone === "success" && "bg-success/15 text-success",
|
||||
tone === "danger" && "bg-danger/15 text-danger",
|
||||
tone === "primary" && "bg-primary-soft text-primary",
|
||||
)}
|
||||
>
|
||||
|
||||
+5
-2
@@ -24,8 +24,8 @@ All meditation calls send `Authorization: Bearer <meditationToken>` and `Accept:
|
||||
- POST `/media/:id` — update (same multipart fields). Playable URL is in **`external_url`**; thumbnail in nested **`image.url`**.
|
||||
- GET `/media/popular`, `/media/recently-played`, `/media/saved`
|
||||
- POST `/media/:id/play`, `/media/:id/save`, `/media/:id/note`, `/media/:id/feedback` (stars, content)
|
||||
- Categories: GET/POST/PUT/DELETE `/categories` (multipart name)
|
||||
- Sub-categories: GET/POST `/sub-categories`, PUT/DELETE `/sub-categories/:id` (category_id, name)
|
||||
- Categories: GET `/categories`, POST `/categories` (multipart: name, description, `icon`(image file)), PUT `/categories/:id` (file → POST + `_method=PUT`), DELETE `/categories/:id`. Icon path in `icon`.
|
||||
- Sub-categories: GET/POST `/sub-categories` (category_id, name, description), PUT/DELETE `/sub-categories/:id` (json: category_id, name, description)
|
||||
|
||||
### Track (music)
|
||||
- Categories: GET `/music-categories/:id`, POST `/music-categories`, PUT/DELETE `/music-categories/:id` (name, description, order, image_id, is_active)
|
||||
@@ -75,6 +75,9 @@ All meditation calls send `Authorization: Bearer <meditationToken>` and `Accept:
|
||||
- Saves: POST `/saves/toggle`, `/saves/save`, `/saves/unsave`, `/saves/check` (type, id), GET `/saves/my-saved?type=`
|
||||
- Ratings: GET/POST/DELETE `/ratings/:type/:id` (stars), GET `/ratings/:type/:id/user`
|
||||
|
||||
### Chat topics (موضوعات پیشنهادی گفتگو با مشاور)
|
||||
- GET `/chat-topics`, GET `/chat-topics/:id`, POST `/chat-topics`, PUT/DELETE `/chat-topics/:id` (json: title, description, order, is_active)
|
||||
|
||||
### Misc
|
||||
- GET `/leader-board`
|
||||
- GET `/profile`
|
||||
|
||||
BIN
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
import type { ComponentType, SVGProps } from "react";
|
||||
import {
|
||||
BreathIcon,
|
||||
ChatIcon,
|
||||
HomeIcon,
|
||||
ImageIcon,
|
||||
MediaIcon,
|
||||
@@ -94,6 +95,11 @@ export const NAV: NavSection[] = [
|
||||
icon: SurveyIcon,
|
||||
items: [{ href: "/dashboard/surveys", label: "پرسشهای نظرسنجی" }],
|
||||
},
|
||||
{
|
||||
label: "گفتگو با مشاور",
|
||||
icon: ChatIcon,
|
||||
items: [{ href: "/dashboard/chat-topics", label: "موضوعات پیشنهادی" }],
|
||||
},
|
||||
{
|
||||
label: "حالوهوا",
|
||||
icon: MoodIcon,
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
"use client";
|
||||
|
||||
// Light/dark theme state. The actual `.dark` class is set on <html> by an inline
|
||||
// script in the root layout (before paint, to avoid a flash) and kept in sync
|
||||
// here. Preference persists in localStorage.
|
||||
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
export const THEME_STORAGE_KEY = "aram_theme";
|
||||
type Theme = "light" | "dark";
|
||||
|
||||
interface ThemeApi {
|
||||
theme: Theme;
|
||||
toggle: () => void;
|
||||
setTheme: (t: Theme) => void;
|
||||
}
|
||||
|
||||
const ThemeContext = createContext<ThemeApi | null>(null);
|
||||
|
||||
function applyClass(theme: Theme) {
|
||||
document.documentElement.classList.toggle("dark", theme === "dark");
|
||||
}
|
||||
|
||||
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||
const [theme, setThemeState] = useState<Theme>("light");
|
||||
|
||||
// Read whatever the no-flash script already decided.
|
||||
useEffect(() => {
|
||||
const isDark = document.documentElement.classList.contains("dark");
|
||||
setThemeState(isDark ? "dark" : "light");
|
||||
}, []);
|
||||
|
||||
const setTheme = useCallback((t: Theme) => {
|
||||
setThemeState(t);
|
||||
applyClass(t);
|
||||
try {
|
||||
window.localStorage.setItem(THEME_STORAGE_KEY, t);
|
||||
} catch {
|
||||
/* ignore (private mode) */
|
||||
}
|
||||
}, []);
|
||||
|
||||
const toggle = useCallback(() => {
|
||||
setTheme(
|
||||
document.documentElement.classList.contains("dark") ? "light" : "dark",
|
||||
);
|
||||
}, [setTheme]);
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={{ theme, toggle, setTheme }}>
|
||||
{children}
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useTheme(): ThemeApi {
|
||||
const ctx = useContext(ThemeContext);
|
||||
if (!ctx) throw new Error("useTheme must be used within <ThemeProvider>");
|
||||
return ctx;
|
||||
}
|
||||
Reference in New Issue
Block a user