Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
faf95327f1 | ||
|
|
b4d8e32fdd | ||
|
|
96c74601c8 | ||
|
|
aba556618b | ||
|
|
ec79ea2771 | ||
|
|
376e3e9473 | ||
|
|
01ad88adf9 | ||
|
|
638d1dad52 | ||
|
|
dec17b537e | ||
|
|
2a3bbd30fb | ||
|
|
e0c97d9158 | ||
|
|
8db8fbb143 | ||
|
|
58e794372d | ||
|
|
4fc1aec66e | ||
|
|
4ac190f161 | ||
|
|
012d928120 | ||
|
|
b1de8cfdc1 | ||
|
|
90e00bc08c | ||
|
|
cfcddb55bb | ||
|
|
034a345521 | ||
|
|
504b1e2c8e | ||
|
|
60a054710a | ||
|
|
1b2d2dec7d | ||
|
|
e374829358 |
@@ -0,0 +1,316 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { apiFetch, ApiError, toFormData } from "@/lib/api";
|
||||
import { useList } from "@/lib/useResource";
|
||||
import { useToast } from "@/components/toast";
|
||||
import { DataTable, type Column } from "@/components/DataTable";
|
||||
import {
|
||||
Button,
|
||||
ConfirmDialog,
|
||||
Field,
|
||||
Input,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Textarea,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
import { pickUrl, IMAGE_KEYS } from "@/lib/media";
|
||||
|
||||
interface Announcement {
|
||||
id: number;
|
||||
title?: string;
|
||||
description?: string;
|
||||
link?: string;
|
||||
button_text?: string;
|
||||
start_date?: string | null;
|
||||
end_date?: string | null;
|
||||
image_id?: number | null;
|
||||
image?: unknown;
|
||||
}
|
||||
|
||||
// Datetime ISO string -> "YYYY-MM-DD" for a <input type="date">.
|
||||
function toDateInput(value?: string | null): string {
|
||||
return value ? value.slice(0, 10) : "";
|
||||
}
|
||||
|
||||
// "YYYY-MM-DD" Gregorian -> Persian display, or "—".
|
||||
function toFaDate(value?: string | null): string {
|
||||
if (!value) return "—";
|
||||
const d = value.slice(0, 10);
|
||||
try {
|
||||
return new Intl.DateTimeFormat("fa-IR").format(new Date(d));
|
||||
} catch {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
export default function AnnouncementsPage() {
|
||||
const { data, loading, error, reload } =
|
||||
useList<Announcement>("/announcements");
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<Announcement | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [title, setTitle] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [link, setLink] = useState("");
|
||||
const [buttonText, setButtonText] = useState("");
|
||||
const [startDate, setStartDate] = useState("");
|
||||
const [endDate, setEndDate] = useState("");
|
||||
const [imageId, setImageId] = useState<number | null>(null);
|
||||
const [imageFile, setImageFile] = useState<File | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [deleting, setDeleting] = useState<Announcement | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setTitle("");
|
||||
setDescription("");
|
||||
setLink("");
|
||||
setButtonText("");
|
||||
setStartDate("");
|
||||
setEndDate("");
|
||||
setImageId(null);
|
||||
setImageFile(null);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: Announcement) {
|
||||
setEditing(row);
|
||||
setTitle(row.title ?? "");
|
||||
setDescription(row.description ?? "");
|
||||
setLink(row.link ?? "");
|
||||
setButtonText(row.button_text ?? "");
|
||||
setStartDate(toDateInput(row.start_date));
|
||||
setEndDate(toDateInput(row.end_date));
|
||||
setImageId(row.image_id ?? null);
|
||||
setImageFile(null);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setSaving(true);
|
||||
try {
|
||||
// Multipart (the image is a file). Edit posts to /announcements/:id,
|
||||
// which the backend also accepts as a multipart update.
|
||||
const body = toFormData({
|
||||
title,
|
||||
description,
|
||||
link,
|
||||
button_text: buttonText,
|
||||
start_date: startDate,
|
||||
end_date: endDate,
|
||||
image_id: imageId,
|
||||
image: imageFile,
|
||||
});
|
||||
if (editing) {
|
||||
await apiFetch(`/announcements/${editing.id}`, { method: "POST", body });
|
||||
toast.success("اعلان ویرایش شد.");
|
||||
} else {
|
||||
await apiFetch("/announcements", { method: "POST", body });
|
||||
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(`/announcements/${deleting.id}`, { method: "DELETE" });
|
||||
toast.success("اعلان حذف شد.");
|
||||
setDeleting(null);
|
||||
reload();
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : "خطا در حذف");
|
||||
} finally {
|
||||
setRemoving(false);
|
||||
}
|
||||
}
|
||||
|
||||
const columns: Column<Announcement>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{
|
||||
key: "thumbnail",
|
||||
header: "تصویر",
|
||||
className: "w-20",
|
||||
render: (r) => (
|
||||
<MediaPreview kind="image" src={pickUrl(r, IMAGE_KEYS)} label={r.title} />
|
||||
),
|
||||
},
|
||||
{ key: "title", header: "عنوان", render: (r) => r.title ?? "—" },
|
||||
{
|
||||
key: "link",
|
||||
header: "لینک",
|
||||
render: (r) =>
|
||||
r.link ? (
|
||||
<span dir="ltr" className="block max-w-[12rem] truncate">
|
||||
{r.link}
|
||||
</span>
|
||||
) : (
|
||||
"—"
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "start_date",
|
||||
header: "تاریخ شروع",
|
||||
render: (r) => toFaDate(r.start_date),
|
||||
className: "w-32",
|
||||
},
|
||||
{
|
||||
key: "end_date",
|
||||
header: "تاریخ پایان",
|
||||
render: (r) => toFaDate(r.end_date),
|
||||
className: "w-32",
|
||||
},
|
||||
];
|
||||
|
||||
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="announcement-form" type="submit" loading={saving}>
|
||||
ذخیره
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form
|
||||
id="announcement-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="تصویر" hint="انتخاب از کتابخانه یا بارگذاری تصویر جدید">
|
||||
<ImagePicker
|
||||
imageId={imageId}
|
||||
onPickId={setImageId}
|
||||
file={imageFile}
|
||||
onPickFile={setImageFile}
|
||||
existingUrl={editing ? pickUrl(editing, IMAGE_KEYS) : null}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="لینک">
|
||||
<Input
|
||||
value={link}
|
||||
onChange={(e) => setLink(e.target.value)}
|
||||
placeholder="https://"
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="متن دکمه" hint="اختیاری">
|
||||
<Input
|
||||
value={buttonText}
|
||||
onChange={(e) => setButtonText(e.target.value)}
|
||||
placeholder="مثلاً مشاهده"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<Field label="تاریخ شروع">
|
||||
<Input
|
||||
type="date"
|
||||
value={startDate}
|
||||
onChange={(e) => setStartDate(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
<Field label="تاریخ پایان">
|
||||
<Input
|
||||
type="date"
|
||||
value={endDate}
|
||||
onChange={(e) => setEndDate(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleting}
|
||||
message={`آیا از حذف «${deleting?.title}» مطمئن هستید؟`}
|
||||
loading={removing}
|
||||
onConfirm={confirmDelete}
|
||||
onClose={() => setDeleting(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
"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,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Switch,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface BreathingColor {
|
||||
id: number;
|
||||
name?: string | null;
|
||||
colors: string[];
|
||||
order?: number;
|
||||
is_active?: boolean;
|
||||
}
|
||||
|
||||
function cssColor(c?: string): string {
|
||||
if (!c) return "transparent";
|
||||
const hex = c.replace("#", "");
|
||||
if (hex.length === 8) return `#${hex.slice(2)}${hex.slice(0, 2)}`;
|
||||
return `#${hex}`;
|
||||
}
|
||||
|
||||
function gradientStyle(colors: string[]): React.CSSProperties {
|
||||
const cs = (colors.length ? colors : ["#00000000"]).map(cssColor);
|
||||
if (cs.length === 1) return { background: cs[0] };
|
||||
return { background: `linear-gradient(135deg, ${cs.join(", ")})` };
|
||||
}
|
||||
|
||||
export default function BreathingColorsPage() {
|
||||
const { data, loading, error, reload } =
|
||||
useList<BreathingColor>("/breathing-colors?include_inactive=1");
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<BreathingColor | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [order, setOrder] = useState("");
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
const [colors, setColors] = useState<string[]>(["#5360FC"]);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [deleting, setDeleting] = useState<BreathingColor | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setName("");
|
||||
setOrder("");
|
||||
setIsActive(true);
|
||||
setColors(["#5360FC"]);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: BreathingColor) {
|
||||
setEditing(row);
|
||||
setName(row.name ?? "");
|
||||
setOrder(row.order != null ? String(row.order) : "");
|
||||
setIsActive(row.is_active ?? true);
|
||||
setColors(Array.isArray(row.colors) && row.colors.length ? row.colors : ["#5360FC"]);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
const clean = colors.map((c) => c.trim()).filter(Boolean);
|
||||
if (!clean.length) {
|
||||
toast.error("حداقل یک رنگ وارد کنید.");
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
const payload = {
|
||||
name: name || null,
|
||||
colors: clean,
|
||||
order: order === "" ? undefined : Number(order),
|
||||
is_active: isActive,
|
||||
};
|
||||
if (editing) {
|
||||
await apiFetch(`/breathing-colors/${editing.id}`, { method: "PUT", body: payload });
|
||||
toast.success("رنگ ویرایش شد.");
|
||||
} else {
|
||||
await apiFetch("/breathing-colors", { 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(`/breathing-colors/${deleting.id}`, { method: "DELETE" });
|
||||
toast.success("رنگ حذف شد.");
|
||||
setDeleting(null);
|
||||
reload();
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : "خطا در حذف");
|
||||
} finally {
|
||||
setRemoving(false);
|
||||
}
|
||||
}
|
||||
|
||||
const columns: Column<BreathingColor>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{
|
||||
key: "preview",
|
||||
header: "رنگ",
|
||||
className: "w-24",
|
||||
render: (r) => (
|
||||
<span
|
||||
className="inline-block h-7 w-12 rounded-md border border-border"
|
||||
style={gradientStyle(r.colors ?? [])}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{ key: "name", header: "نام", render: (r) => r.name || "—" },
|
||||
{
|
||||
key: "codes",
|
||||
header: "کدها",
|
||||
render: (r) => (
|
||||
<span dir="ltr" className="text-xs text-muted">
|
||||
{(r.colors ?? []).join("، ")}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{ key: "order", header: "ترتیب", render: (r) => toFa(r.order ?? 0), className: "w-20" },
|
||||
{
|
||||
key: "is_active",
|
||||
header: "وضعیت",
|
||||
className: "w-24",
|
||||
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="bc-form" type="submit" loading={saving}>
|
||||
ذخیره
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="bc-form" onSubmit={save} className="flex flex-col gap-4">
|
||||
<Field label="نام">
|
||||
<Input
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="مثلاً بنفش"
|
||||
autoFocus
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="رنگها" hint="یک رنگ = تکرنگ، چند رنگ = گرادینت.">
|
||||
<div className="mb-2 flex items-center gap-2">
|
||||
<span className="text-xs text-muted">پیشنمایش:</span>
|
||||
<span
|
||||
className="h-9 w-20 rounded-lg border border-border"
|
||||
style={gradientStyle(colors)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
{colors.map((c, i) => (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={cssColor(c)}
|
||||
onChange={(e) =>
|
||||
setColors((prev) => prev.map((x, j) => (j === i ? e.target.value : x)))
|
||||
}
|
||||
className="h-9 w-10 cursor-pointer rounded border border-border bg-transparent"
|
||||
/>
|
||||
<Input
|
||||
value={c}
|
||||
onChange={(e) =>
|
||||
setColors((prev) => prev.map((x, j) => (j === i ? e.target.value : x)))
|
||||
}
|
||||
placeholder="#RRGGBB"
|
||||
dir="ltr"
|
||||
/>
|
||||
{colors.length > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
className="text-danger"
|
||||
onClick={() => setColors((prev) => prev.filter((_, j) => j !== i))}
|
||||
>
|
||||
✕
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => setColors((prev) => [...prev, "#5360FC"])}
|
||||
>
|
||||
+ افزودن رنگ
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Field>
|
||||
|
||||
<Field label="ترتیب">
|
||||
<Input
|
||||
type="number"
|
||||
value={order}
|
||||
onChange={(e) => setOrder(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Switch checked={isActive} onChange={setIsActive} label="فعال" />
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleting}
|
||||
message={`آیا از حذف این رنگ مطمئن هستید؟`}
|
||||
loading={removing}
|
||||
onConfirm={confirmDelete}
|
||||
onClose={() => setDeleting(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -26,6 +26,29 @@ interface BreathingTemplate {
|
||||
duration?: number;
|
||||
description?: string;
|
||||
image_id?: number;
|
||||
breathing_color_id?: number | null;
|
||||
breathing_color?: BreathingColor | null;
|
||||
}
|
||||
|
||||
interface BreathingColor {
|
||||
id: number;
|
||||
name?: string | null;
|
||||
colors: string[];
|
||||
}
|
||||
|
||||
// "#AARRGGBB" (ARGB) or "#RRGGBB" → a CSS color string.
|
||||
function cssColor(c?: string): string {
|
||||
if (!c) return "transparent";
|
||||
const hex = c.replace("#", "");
|
||||
if (hex.length === 8) return `#${hex.slice(2)}${hex.slice(0, 2)}`; // ARGB→RGB(drop alpha)
|
||||
return `#${hex}`;
|
||||
}
|
||||
|
||||
// Linear gradient (or solid) preview for a list of colors.
|
||||
function gradientStyle(colors: string[]): React.CSSProperties {
|
||||
const cs = (colors.length ? colors : ["#00000000"]).map(cssColor);
|
||||
if (cs.length === 1) return { background: cs[0] };
|
||||
return { background: `linear-gradient(135deg, ${cs.join(", ")})` };
|
||||
}
|
||||
|
||||
interface BreathingForm {
|
||||
@@ -57,11 +80,13 @@ function numOrUndefined(v: string): number | undefined {
|
||||
export default function BreathingPage() {
|
||||
const { data, loading, error, reload } =
|
||||
useList<BreathingTemplate>("/breathing-templates");
|
||||
const { data: palette } = useList<BreathingColor>("/breathing-colors");
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<BreathingTemplate | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [form, setForm] = useState<BreathingForm>(emptyForm);
|
||||
const [breathingColorId, setBreathingColorId] = useState<number | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [deleting, setDeleting] = useState<BreathingTemplate | null>(null);
|
||||
@@ -74,6 +99,7 @@ export default function BreathingPage() {
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setForm(emptyForm);
|
||||
setBreathingColorId(null);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: BreathingTemplate) {
|
||||
@@ -87,6 +113,7 @@ export default function BreathingPage() {
|
||||
description: row.description ?? "",
|
||||
image_id: row.image_id != null ? String(row.image_id) : "",
|
||||
});
|
||||
setBreathingColorId(row.breathing_color_id ?? null);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
@@ -102,6 +129,8 @@ export default function BreathingPage() {
|
||||
duration: numOrUndefined(form.duration),
|
||||
description: form.description,
|
||||
image_id: numOrUndefined(form.image_id),
|
||||
// Send null (not undefined) so choosing "بدون رنگ" actually clears it.
|
||||
breathing_color_id: breathingColorId,
|
||||
};
|
||||
if (editing) {
|
||||
// Update is JSON on /breathing-templates/:id
|
||||
@@ -167,6 +196,21 @@ export default function BreathingPage() {
|
||||
header: "مدت زمان",
|
||||
render: (r) => (r.duration != null ? formatDuration(r.duration) : "—"),
|
||||
},
|
||||
{
|
||||
key: "color",
|
||||
header: "رنگ",
|
||||
className: "w-20",
|
||||
render: (r) =>
|
||||
r.breathing_color?.colors?.length ? (
|
||||
<span
|
||||
className="inline-block h-6 w-10 rounded-md border border-border"
|
||||
style={gradientStyle(r.breathing_color.colors)}
|
||||
title={r.breathing_color.name ?? ""}
|
||||
/>
|
||||
) : (
|
||||
"—"
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -288,6 +332,44 @@ export default function BreathingPage() {
|
||||
placeholder="توضیح کوتاه درباره قالب"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field
|
||||
label="رنگ تمرین"
|
||||
hint={
|
||||
palette.length
|
||||
? "یک رنگ از پالت انتخاب کنید (در «رنگهای تنفس» مدیریت میشود)."
|
||||
: "هنوز رنگی در «رنگهای تنفس» تعریف نشده است."
|
||||
}
|
||||
>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{/* "no color" option */}
|
||||
<button
|
||||
type="button"
|
||||
title="بدون رنگ"
|
||||
onClick={() => setBreathingColorId(null)}
|
||||
className={`flex h-9 w-9 items-center justify-center rounded-full border-2 text-muted ${
|
||||
breathingColorId === null ? "border-primary ring-2 ring-primary/40" : "border-border"
|
||||
}`}
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
{palette.map((p) => {
|
||||
const selected = breathingColorId === p.id;
|
||||
return (
|
||||
<button
|
||||
key={p.id}
|
||||
type="button"
|
||||
title={p.name ?? ""}
|
||||
onClick={() => setBreathingColorId(p.id)}
|
||||
style={gradientStyle(p.colors)}
|
||||
className={`h-9 w-9 rounded-full border-2 transition ${
|
||||
selected ? "border-primary ring-2 ring-primary/40" : "border-border"
|
||||
}`}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</Field>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ interface Category {
|
||||
id: number;
|
||||
name: string;
|
||||
type: CategoryType;
|
||||
order?: number;
|
||||
description?: string | null;
|
||||
icon?: string | null;
|
||||
subcategories_count?: number;
|
||||
@@ -56,6 +57,7 @@ export default function CategoriesPage() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [type, setType] = useState<CategoryType>("media");
|
||||
const [order, setOrder] = useState("0");
|
||||
const [description, setDescription] = useState("");
|
||||
const [icon, setIcon] = useState<File | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
@@ -67,6 +69,7 @@ export default function CategoriesPage() {
|
||||
setEditing(null);
|
||||
setName("");
|
||||
setType(typeFilter);
|
||||
setOrder("0");
|
||||
setDescription("");
|
||||
setIcon(null);
|
||||
setOpen(true);
|
||||
@@ -75,6 +78,7 @@ export default function CategoriesPage() {
|
||||
setEditing(row);
|
||||
setName(row.name ?? "");
|
||||
setType(row.type ?? "media");
|
||||
setOrder(String(row.order ?? 0));
|
||||
setDescription(row.description ?? "");
|
||||
setIcon(null);
|
||||
setOpen(true);
|
||||
@@ -84,12 +88,25 @@ export default function CategoriesPage() {
|
||||
e.preventDefault();
|
||||
setSaving(true);
|
||||
try {
|
||||
// Playlist categories live in the music_categories table, so their writes
|
||||
// go to /music-categories (image is the `image` field, not `icon`).
|
||||
const targetType = editing ? editing.type : type;
|
||||
if (targetType === "playlist") {
|
||||
const body = toFormData({ name, description, order, image: icon });
|
||||
if (editing) {
|
||||
await apiFetch(`/music-categories/${editing.id}`, { method: "POST", body });
|
||||
toast.success("دستهبندی ویرایش شد.");
|
||||
} else {
|
||||
await apiFetch("/music-categories", { method: "POST", body });
|
||||
toast.success("دستهبندی افزوده شد.");
|
||||
}
|
||||
} else if (editing) {
|
||||
// Icon is a file, so update goes through POST + Laravel method spoofing.
|
||||
const body = toFormData({
|
||||
_method: "PUT",
|
||||
name,
|
||||
type,
|
||||
order,
|
||||
description,
|
||||
icon,
|
||||
});
|
||||
@@ -98,7 +115,7 @@ export default function CategoriesPage() {
|
||||
} else {
|
||||
await apiFetch("/categories", {
|
||||
method: "POST",
|
||||
body: toFormData({ name, type, description, icon }),
|
||||
body: toFormData({ name, type, order, description, icon }),
|
||||
});
|
||||
toast.success("دستهبندی افزوده شد.");
|
||||
}
|
||||
@@ -115,7 +132,11 @@ export default function CategoriesPage() {
|
||||
if (!deleting) return;
|
||||
setRemoving(true);
|
||||
try {
|
||||
await apiFetch(`/categories/${deleting.id}`, { method: "DELETE" });
|
||||
const path =
|
||||
deleting.type === "playlist"
|
||||
? `/music-categories/${deleting.id}`
|
||||
: `/categories/${deleting.id}`;
|
||||
await apiFetch(path, { method: "DELETE" });
|
||||
toast.success("دستهبندی حذف شد.");
|
||||
setDeleting(null);
|
||||
reload();
|
||||
@@ -135,6 +156,12 @@ export default function CategoriesPage() {
|
||||
<MediaPreview kind="image" src={pickUrl(r, ICON_KEYS)} label={r.name} />
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "order",
|
||||
header: "ترتیب",
|
||||
render: (r) => toFa(r.order ?? 0),
|
||||
className: "w-20",
|
||||
},
|
||||
{ key: "name", header: "نام دستهبندی" },
|
||||
{
|
||||
key: "type",
|
||||
@@ -249,6 +276,15 @@ export default function CategoriesPage() {
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="ترتیب" hint="عدد کوچکتر بالاتر نمایش داده میشود.">
|
||||
<Input
|
||||
type="number"
|
||||
value={order}
|
||||
onChange={(e) => setOrder(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="توضیحات">
|
||||
<Textarea
|
||||
value={description}
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
"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,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Switch,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface FaqCategory {
|
||||
id: number;
|
||||
name?: string;
|
||||
order?: number;
|
||||
is_active?: boolean;
|
||||
faqs_count?: number;
|
||||
}
|
||||
|
||||
export default function FaqCategoriesPage() {
|
||||
const { data, loading, error, reload } = useList<FaqCategory>(
|
||||
"/faq-categories?include_inactive=1",
|
||||
);
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<FaqCategory | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [order, setOrder] = useState("");
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [deleting, setDeleting] = useState<FaqCategory | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setName("");
|
||||
setOrder("");
|
||||
setIsActive(true);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: FaqCategory) {
|
||||
setEditing(row);
|
||||
setName(row.name ?? "");
|
||||
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 {
|
||||
const body = {
|
||||
name,
|
||||
order: order === "" ? undefined : Number(order),
|
||||
is_active: isActive,
|
||||
};
|
||||
if (editing) {
|
||||
await apiFetch(`/faq-categories/${editing.id}`, { method: "PUT", body });
|
||||
toast.success("دستهبندی ویرایش شد.");
|
||||
} else {
|
||||
await apiFetch("/faq-categories", { method: "POST", body });
|
||||
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(`/faq-categories/${deleting.id}`, { method: "DELETE" });
|
||||
toast.success("دستهبندی حذف شد.");
|
||||
setDeleting(null);
|
||||
reload();
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : "خطا در حذف");
|
||||
} finally {
|
||||
setRemoving(false);
|
||||
}
|
||||
}
|
||||
|
||||
const columns: Column<FaqCategory>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{ key: "name", header: "نام" },
|
||||
{
|
||||
key: "faqs_count",
|
||||
header: "تعداد پرسش",
|
||||
render: (r) => toFa(r.faqs_count ?? 0),
|
||||
className: "w-28",
|
||||
},
|
||||
{ key: "order", header: "ترتیب", render: (r) => toFa(r.order ?? 0), className: "w-20" },
|
||||
{
|
||||
key: "is_active",
|
||||
header: "وضعیت",
|
||||
className: "w-24",
|
||||
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="faq-cat-form" type="submit" loading={saving}>
|
||||
ذخیره
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="faq-cat-form" onSubmit={save} className="flex flex-col gap-4">
|
||||
<Field label="نام" required>
|
||||
<Input
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="مثلاً حساب کاربری"
|
||||
required
|
||||
autoFocus
|
||||
/>
|
||||
</Field>
|
||||
<Field label="ترتیب">
|
||||
<Input
|
||||
type="number"
|
||||
value={order}
|
||||
onChange={(e) => setOrder(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
<Switch checked={isActive} onChange={setIsActive} label="فعال" />
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleting}
|
||||
message={`آیا از حذف «${deleting?.name ?? ""}» مطمئن هستید؟`}
|
||||
loading={removing}
|
||||
onConfirm={confirmDelete}
|
||||
onClose={() => setDeleting(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo, 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,
|
||||
Select,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Switch,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface Faq {
|
||||
id: number;
|
||||
faq_category_id?: number;
|
||||
question?: string;
|
||||
answer?: string;
|
||||
order?: number;
|
||||
is_active?: boolean;
|
||||
category_name?: string;
|
||||
}
|
||||
|
||||
interface FaqCategory {
|
||||
id: number;
|
||||
name?: string;
|
||||
faqs?: Faq[];
|
||||
}
|
||||
|
||||
export default function FaqsPage() {
|
||||
// /faqs returns categories each with their faqs; flatten for the table.
|
||||
const { data: grouped, loading, error, reload } = useList<FaqCategory>(
|
||||
"/faqs?include_inactive=1",
|
||||
);
|
||||
const { data: categories } = useList<FaqCategory>("/faq-categories?include_inactive=1");
|
||||
const toast = useToast();
|
||||
|
||||
const rows = useMemo<Faq[]>(
|
||||
() =>
|
||||
grouped.flatMap((c) =>
|
||||
(c.faqs ?? []).map((f) => ({ ...f, category_name: c.name })),
|
||||
),
|
||||
[grouped],
|
||||
);
|
||||
|
||||
const [editing, setEditing] = useState<Faq | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [categoryId, setCategoryId] = useState("");
|
||||
const [question, setQuestion] = useState("");
|
||||
const [answer, setAnswer] = useState("");
|
||||
const [order, setOrder] = useState("");
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [deleting, setDeleting] = useState<Faq | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setCategoryId(categories[0] ? String(categories[0].id) : "");
|
||||
setQuestion("");
|
||||
setAnswer("");
|
||||
setOrder("");
|
||||
setIsActive(true);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: Faq) {
|
||||
setEditing(row);
|
||||
setCategoryId(row.faq_category_id != null ? String(row.faq_category_id) : "");
|
||||
setQuestion(row.question ?? "");
|
||||
setAnswer(row.answer ?? "");
|
||||
setOrder(row.order != null ? String(row.order) : "");
|
||||
setIsActive(row.is_active ?? true);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!categoryId) {
|
||||
toast.error("دستهبندی را انتخاب کنید.");
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
const body = {
|
||||
faq_category_id: Number(categoryId),
|
||||
question,
|
||||
answer,
|
||||
order: order === "" ? undefined : Number(order),
|
||||
is_active: isActive,
|
||||
};
|
||||
if (editing) {
|
||||
await apiFetch(`/faqs/${editing.id}`, { method: "PUT", body });
|
||||
toast.success("پرسش ویرایش شد.");
|
||||
} else {
|
||||
await apiFetch("/faqs", { method: "POST", body });
|
||||
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(`/faqs/${deleting.id}`, { method: "DELETE" });
|
||||
toast.success("پرسش حذف شد.");
|
||||
setDeleting(null);
|
||||
reload();
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : "خطا در حذف");
|
||||
} finally {
|
||||
setRemoving(false);
|
||||
}
|
||||
}
|
||||
|
||||
const columns: Column<Faq>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{ key: "category", header: "دستهبندی", render: (r) => r.category_name ?? "—" },
|
||||
{ key: "question", header: "پرسش", render: (r) => r.question ?? "—" },
|
||||
{
|
||||
key: "answer",
|
||||
header: "پاسخ",
|
||||
render: (r) =>
|
||||
r.answer ? (
|
||||
<span className="line-clamp-1 max-w-md text-muted">{r.answer}</span>
|
||||
) : (
|
||||
"—"
|
||||
),
|
||||
},
|
||||
{ key: "order", header: "ترتیب", render: (r) => toFa(r.order ?? 0), className: "w-20" },
|
||||
{
|
||||
key: "is_active",
|
||||
header: "وضعیت",
|
||||
className: "w-24",
|
||||
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={rows}
|
||||
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="faq-form" type="submit" loading={saving}>
|
||||
ذخیره
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="faq-form" onSubmit={save} className="flex flex-col gap-4">
|
||||
<Field label="دستهبندی" required>
|
||||
<Select value={categoryId} onChange={(e) => setCategoryId(e.target.value)}>
|
||||
<option value="">— انتخاب دستهبندی —</option>
|
||||
{categories.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.name ?? `#${c.id}`}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</Field>
|
||||
<Field label="پرسش" required>
|
||||
<Input
|
||||
value={question}
|
||||
onChange={(e) => setQuestion(e.target.value)}
|
||||
placeholder="مثلاً چطور رمز عبورم را تغییر دهم؟"
|
||||
required
|
||||
autoFocus
|
||||
/>
|
||||
</Field>
|
||||
<Field label="پاسخ" required>
|
||||
<Textarea
|
||||
value={answer}
|
||||
onChange={(e) => setAnswer(e.target.value)}
|
||||
placeholder="پاسخ کامل پرسش"
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
<Field label="ترتیب">
|
||||
<Input
|
||||
type="number"
|
||||
value={order}
|
||||
onChange={(e) => setOrder(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
<Switch checked={isActive} onChange={setIsActive} label="فعال" />
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleting}
|
||||
message={`آیا از حذف این پرسش مطمئن هستید؟`}
|
||||
loading={removing}
|
||||
onConfirm={confirmDelete}
|
||||
onClose={() => setDeleting(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -34,6 +34,8 @@ interface Media {
|
||||
caption?: string;
|
||||
// The API returns a `categories` array (many-to-many).
|
||||
categories?: Category[];
|
||||
// The API returns `sub_categories` (snake_case); keep the other casings as fallbacks.
|
||||
sub_categories?: Category[];
|
||||
subcategories?: Category[];
|
||||
subCategories?: Category[];
|
||||
type?: string;
|
||||
@@ -142,7 +144,9 @@ export default function MediaPage() {
|
||||
setCaption(row.caption ?? "");
|
||||
setCategoryIds((row.categories ?? []).map((c) => c.id));
|
||||
setSubcategoryIds(
|
||||
(row.subcategories ?? row.subCategories ?? []).map((c) => c.id),
|
||||
(row.sub_categories ?? row.subcategories ?? row.subCategories ?? []).map(
|
||||
(c) => c.id,
|
||||
),
|
||||
);
|
||||
setType(row.type ?? "audio");
|
||||
setDuration(row.duration != null ? String(row.duration) : "");
|
||||
|
||||
@@ -17,6 +17,9 @@ import {
|
||||
PageHeader,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { pickUrl, IMAGE_KEYS } from "@/lib/media";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface MusicCategory {
|
||||
@@ -25,6 +28,8 @@ interface MusicCategory {
|
||||
description?: string;
|
||||
order?: number;
|
||||
is_active?: boolean;
|
||||
image_id?: number | null;
|
||||
image?: unknown;
|
||||
}
|
||||
|
||||
export default function MusicCategoriesPage() {
|
||||
@@ -39,7 +44,8 @@ export default function MusicCategoriesPage() {
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [order, setOrder] = useState("");
|
||||
const [imageId, setImageId] = useState("");
|
||||
const [imageId, setImageId] = useState<number | null>(null);
|
||||
const [imageFile, setImageFile] = useState<File | null>(null);
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
|
||||
const [deleting, setDeleting] = useState<MusicCategory | null>(null);
|
||||
@@ -50,7 +56,8 @@ export default function MusicCategoriesPage() {
|
||||
setName("");
|
||||
setDescription("");
|
||||
setOrder("");
|
||||
setImageId("");
|
||||
setImageId(null);
|
||||
setImageFile(null);
|
||||
setIsActive(true);
|
||||
setOpen(true);
|
||||
}
|
||||
@@ -59,7 +66,8 @@ export default function MusicCategoriesPage() {
|
||||
setName(row.name ?? "");
|
||||
setDescription(row.description ?? "");
|
||||
setOrder(row.order != null ? String(row.order) : "");
|
||||
setImageId("");
|
||||
setImageId(row.image_id ?? null);
|
||||
setImageFile(null);
|
||||
setIsActive(row.is_active ?? true);
|
||||
setOpen(true);
|
||||
}
|
||||
@@ -69,15 +77,17 @@ export default function MusicCategoriesPage() {
|
||||
setSaving(true);
|
||||
try {
|
||||
if (editing) {
|
||||
// Update is JSON on /music-categories/:id
|
||||
// Update is multipart (POST) so an image file can be uploaded.
|
||||
await apiFetch(`/music-categories/${editing.id}`, {
|
||||
method: "PUT",
|
||||
body: {
|
||||
method: "POST",
|
||||
body: toFormData({
|
||||
name,
|
||||
description,
|
||||
order: order === "" ? undefined : Number(order),
|
||||
is_active: isActive,
|
||||
},
|
||||
image_id: imageId,
|
||||
image: imageFile,
|
||||
}),
|
||||
});
|
||||
toast.success("دستهبندی ویرایش شد.");
|
||||
} else {
|
||||
@@ -88,8 +98,9 @@ export default function MusicCategoriesPage() {
|
||||
name,
|
||||
description,
|
||||
order,
|
||||
image_id: imageId,
|
||||
is_active: isActive,
|
||||
image_id: imageId,
|
||||
image: imageFile,
|
||||
}),
|
||||
});
|
||||
toast.success("دستهبندی افزوده شد.");
|
||||
@@ -120,6 +131,14 @@ export default function MusicCategoriesPage() {
|
||||
|
||||
const columns: Column<MusicCategory>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-24" },
|
||||
{
|
||||
key: "image",
|
||||
header: "تصویر",
|
||||
className: "w-20",
|
||||
render: (r) => (
|
||||
<MediaPreview kind="image" src={pickUrl(r, IMAGE_KEYS)} label={r.name} />
|
||||
),
|
||||
},
|
||||
{ key: "name", header: "نام" },
|
||||
{
|
||||
key: "description",
|
||||
@@ -223,16 +242,15 @@ export default function MusicCategoriesPage() {
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
{!editing && (
|
||||
<Field label="شناسه تصویر">
|
||||
<Input
|
||||
value={imageId}
|
||||
onChange={(e) => setImageId(e.target.value)}
|
||||
dir="ltr"
|
||||
placeholder="image_id"
|
||||
<Field label="تصویر">
|
||||
<ImagePicker
|
||||
imageId={imageId}
|
||||
onPickId={setImageId}
|
||||
file={imageFile}
|
||||
onPickFile={setImageFile}
|
||||
existingUrl={editing ? pickUrl(editing, IMAGE_KEYS) : null}
|
||||
/>
|
||||
</Field>
|
||||
)}
|
||||
<Switch checked={isActive} onChange={setIsActive} label="فعال" />
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useList } from "@/lib/useResource";
|
||||
import { useToast } from "@/components/toast";
|
||||
import { DataTable, type Column } from "@/components/DataTable";
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
ConfirmDialog,
|
||||
Field,
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
Textarea,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Switch,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
@@ -28,6 +30,7 @@ interface Playlist {
|
||||
image?: unknown;
|
||||
detail_image_id?: number | null;
|
||||
detail_image?: unknown;
|
||||
is_premium?: boolean;
|
||||
}
|
||||
|
||||
interface MusicCategory {
|
||||
@@ -53,6 +56,7 @@ export default function MusicPlaylistsPage() {
|
||||
const [imageFile, setImageFile] = useState<File | null>(null);
|
||||
const [detailImageId, setDetailImageId] = useState<number | null>(null);
|
||||
const [detailImageFile, setDetailImageFile] = useState<File | null>(null);
|
||||
const [isPremium, setIsPremium] = useState(false);
|
||||
|
||||
const [deleting, setDeleting] = useState<Playlist | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
@@ -71,6 +75,7 @@ export default function MusicPlaylistsPage() {
|
||||
setImageFile(null);
|
||||
setDetailImageId(null);
|
||||
setDetailImageFile(null);
|
||||
setIsPremium(false);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: Playlist) {
|
||||
@@ -83,6 +88,7 @@ export default function MusicPlaylistsPage() {
|
||||
setImageFile(null);
|
||||
setDetailImageId(row.detail_image_id ?? null);
|
||||
setDetailImageFile(null);
|
||||
setIsPremium(row.is_premium ?? false);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
@@ -101,6 +107,7 @@ export default function MusicPlaylistsPage() {
|
||||
image: imageFile,
|
||||
detail_image_id: detailImageId,
|
||||
detail_image: detailImageFile,
|
||||
is_premium: isPremium,
|
||||
}),
|
||||
});
|
||||
toast.success("پلیلیست ویرایش شد.");
|
||||
@@ -117,6 +124,7 @@ export default function MusicPlaylistsPage() {
|
||||
image: imageFile,
|
||||
detail_image_id: detailImageId,
|
||||
detail_image: detailImageFile,
|
||||
is_premium: isPremium,
|
||||
}),
|
||||
});
|
||||
toast.success("پلیلیست افزوده شد.");
|
||||
@@ -161,6 +169,17 @@ export default function MusicPlaylistsPage() {
|
||||
header: "توضیحات",
|
||||
render: (r) => r.description ?? "—",
|
||||
},
|
||||
{
|
||||
key: "is_premium",
|
||||
header: "ویژه",
|
||||
className: "w-20",
|
||||
render: (r) =>
|
||||
r.is_premium ? (
|
||||
<Badge tone="primary">ویژه</Badge>
|
||||
) : (
|
||||
<Badge tone="neutral">رایگان</Badge>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -257,6 +276,8 @@ export default function MusicPlaylistsPage() {
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Switch checked={isPremium} onChange={setIsPremium} label="ویژه (پرمیوم)" />
|
||||
|
||||
{!editing && (
|
||||
<>
|
||||
<Field label="دستهبندیها">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { apiFetch, ApiError, toFormData } from "@/lib/api";
|
||||
import { useList } from "@/lib/useResource";
|
||||
import { useList, usePaginated } from "@/lib/useResource";
|
||||
import { useToast } from "@/components/toast";
|
||||
import { DataTable, type Column } from "@/components/DataTable";
|
||||
import {
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
Select,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Pagination,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { formatMinutes, fileNameToTitle } from "@/lib/utils";
|
||||
@@ -20,6 +21,14 @@ import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
import { pickUrl, SOUND_KEYS, IMAGE_KEYS } from "@/lib/media";
|
||||
|
||||
interface Playlist {
|
||||
id: number;
|
||||
name?: string;
|
||||
// Some endpoints nest the playlist's sub-categories; key casing varies.
|
||||
subcategories?: Playlist[];
|
||||
subCategories?: Playlist[];
|
||||
}
|
||||
|
||||
interface Track {
|
||||
id: number;
|
||||
title?: string;
|
||||
@@ -28,15 +37,17 @@ interface Track {
|
||||
type?: string;
|
||||
playlist_id?: number;
|
||||
image_id?: number | null;
|
||||
}
|
||||
|
||||
interface Playlist {
|
||||
id: number;
|
||||
name?: string;
|
||||
// A track belongs to many playlists; the /music row embeds them as an array.
|
||||
playlists?: Playlist[];
|
||||
// Sub-categories may also be embedded directly on the track (key casing varies).
|
||||
subcategories?: Playlist[];
|
||||
subCategories?: Playlist[];
|
||||
sub_categories?: Playlist[];
|
||||
}
|
||||
|
||||
export default function MusicTracksPage() {
|
||||
const { data, loading, error, reload } = useList<Track>("/music");
|
||||
const { data, meta, page, setPage, loading, error, reload } =
|
||||
usePaginated<Track>("/music", { perPage: 20 });
|
||||
const { data: playlists } = useList<Playlist>("/music-playlists");
|
||||
const toast = useToast();
|
||||
|
||||
@@ -56,6 +67,26 @@ export default function MusicTracksPage() {
|
||||
const [deleting, setDeleting] = useState<Track | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
|
||||
// A track belongs to many playlists — list their names.
|
||||
function playlistName(r: Track): string {
|
||||
const names = (r.playlists ?? []).map((p) => p.name).filter(Boolean);
|
||||
return names.length ? (names as string[]).join("، ") : "—";
|
||||
}
|
||||
|
||||
// Sub-categories may sit on the track directly or come through its playlists;
|
||||
// key casing varies between endpoints, so gather from every shape.
|
||||
function subCategoryNames(r: Track): string {
|
||||
const subs: Playlist[] = [
|
||||
...(r.subcategories ?? r.subCategories ?? r.sub_categories ?? []),
|
||||
...(r.playlists ?? []).flatMap(
|
||||
(p) => p.subcategories ?? p.subCategories ?? [],
|
||||
),
|
||||
];
|
||||
const names = subs.map((s) => s.name).filter(Boolean) as string[];
|
||||
const unique = Array.from(new Set(names));
|
||||
return unique.length ? unique.join("، ") : "—";
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
setTitle("");
|
||||
setArtist("");
|
||||
@@ -163,6 +194,16 @@ export default function MusicTracksPage() {
|
||||
},
|
||||
{ key: "title", header: "عنوان" },
|
||||
{ key: "artist", header: "هنرمند", render: (r) => r.artist ?? "—" },
|
||||
{
|
||||
key: "playlist",
|
||||
header: "پلیلیست",
|
||||
render: (r) => playlistName(r),
|
||||
},
|
||||
{
|
||||
key: "subcategory",
|
||||
header: "زیردسته",
|
||||
render: (r) => subCategoryNames(r),
|
||||
},
|
||||
{
|
||||
key: "duration",
|
||||
header: "مدت زمان",
|
||||
@@ -217,6 +258,15 @@ export default function MusicTracksPage() {
|
||||
)}
|
||||
/>
|
||||
|
||||
{meta && (
|
||||
<Pagination
|
||||
page={page}
|
||||
lastPage={meta.last_page}
|
||||
total={meta.total}
|
||||
onChange={setPage}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
Input,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Select,
|
||||
Switch,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
@@ -20,22 +21,62 @@ import { toFa } from "@/lib/utils";
|
||||
import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { pickUrl, SOUND_KEYS, VIDEO_KEYS, IMAGE_KEYS } from "@/lib/media";
|
||||
|
||||
interface Theme {
|
||||
id: number;
|
||||
key: string;
|
||||
name: string;
|
||||
colors: Record<string, string>;
|
||||
}
|
||||
|
||||
interface Scene {
|
||||
id: number;
|
||||
name: string;
|
||||
order?: number;
|
||||
is_active?: boolean;
|
||||
is_premium?: boolean;
|
||||
theme_id?: number | null;
|
||||
theme?: Theme | null;
|
||||
}
|
||||
|
||||
// "#FF156395" (ARGB) or "#156395" → a CSS color the browser understands.
|
||||
function cssColor(c?: string): string {
|
||||
if (!c) return "transparent";
|
||||
const hex = c.replace("#", "");
|
||||
if (hex.length === 8) return `#${hex.slice(2)}${hex.slice(0, 2)}`; // ARGB → RGBA
|
||||
return `#${hex}`;
|
||||
}
|
||||
|
||||
function ThemeSwatch({ theme }: { theme?: Theme | null }) {
|
||||
if (!theme) return <span className="text-muted">—</span>;
|
||||
const keys = ["themeUp", "themeDown", "lightColorGradient", "darkColorGradient"];
|
||||
return (
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="inline-flex overflow-hidden rounded-full border border-border">
|
||||
{keys.map((k) => (
|
||||
<span
|
||||
key={k}
|
||||
className="h-4 w-4"
|
||||
style={{ backgroundColor: cssColor(theme.colors?.[k]) }}
|
||||
/>
|
||||
))}
|
||||
</span>
|
||||
{theme.name}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ScenesPage() {
|
||||
const { data, loading, error, reload } = useList<Scene>("/scenes");
|
||||
const { data: themes } = useList<Theme>("/themes");
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<Scene | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [order, setOrder] = useState("");
|
||||
const [themeId, setThemeId] = useState("");
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
const [isPremium, setIsPremium] = useState(false);
|
||||
const [image, setImage] = useState<File | null>(null);
|
||||
const [video, setVideo] = useState<File | null>(null);
|
||||
const [sound, setSound] = useState<File | null>(null);
|
||||
@@ -48,7 +89,9 @@ export default function ScenesPage() {
|
||||
setEditing(null);
|
||||
setName("");
|
||||
setOrder("");
|
||||
setThemeId("");
|
||||
setIsActive(true);
|
||||
setIsPremium(false);
|
||||
setImage(null);
|
||||
setVideo(null);
|
||||
setSound(null);
|
||||
@@ -58,7 +101,9 @@ export default function ScenesPage() {
|
||||
setEditing(row);
|
||||
setName(row.name ?? "");
|
||||
setOrder(row.order != null ? String(row.order) : "");
|
||||
setThemeId(row.theme_id != null ? String(row.theme_id) : "");
|
||||
setIsActive(!!row.is_active);
|
||||
setIsPremium(!!row.is_premium);
|
||||
setImage(null);
|
||||
setVideo(null);
|
||||
setSound(null);
|
||||
@@ -73,7 +118,9 @@ export default function ScenesPage() {
|
||||
const body = toFormData({
|
||||
name,
|
||||
order,
|
||||
theme_id: themeId,
|
||||
is_active: isActive,
|
||||
is_premium: isPremium,
|
||||
image,
|
||||
video,
|
||||
sound,
|
||||
@@ -112,6 +159,11 @@ export default function ScenesPage() {
|
||||
const columns: Column<Scene>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-24" },
|
||||
{ key: "name", header: "نام صحنه" },
|
||||
{
|
||||
key: "theme",
|
||||
header: "قالب رنگی",
|
||||
render: (r) => <ThemeSwatch theme={r.theme} />,
|
||||
},
|
||||
{
|
||||
key: "image",
|
||||
header: "تصویر",
|
||||
@@ -153,6 +205,17 @@ export default function ScenesPage() {
|
||||
),
|
||||
className: "w-28",
|
||||
},
|
||||
{
|
||||
key: "is_premium",
|
||||
header: "نوع",
|
||||
render: (r) =>
|
||||
r.is_premium ? (
|
||||
<Badge tone="primary">ویژه</Badge>
|
||||
) : (
|
||||
<Badge tone="neutral">رایگان</Badge>
|
||||
),
|
||||
className: "w-24",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -236,8 +299,28 @@ export default function ScenesPage() {
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="قالب رنگی">
|
||||
<Select value={themeId} onChange={(e) => setThemeId(e.target.value)}>
|
||||
<option value="">— بدون قالب —</option>
|
||||
{themes.map((t) => (
|
||||
<option key={t.id} value={t.id}>
|
||||
{t.name}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
{themeId && (
|
||||
<div className="mt-2">
|
||||
<ThemeSwatch
|
||||
theme={themes.find((t) => String(t.id) === themeId) ?? null}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Field>
|
||||
|
||||
<Switch checked={isActive} onChange={setIsActive} label="فعال" />
|
||||
|
||||
<Switch checked={isPremium} onChange={setIsPremium} label="ویژه (پولی)" />
|
||||
|
||||
<Field
|
||||
label="تصویر"
|
||||
hint={editing ? "در صورت عدم انتخاب، تصویر قبلی حفظ میشود." : undefined}
|
||||
|
||||
@@ -16,6 +16,9 @@ import {
|
||||
Textarea,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { pickUrl, IMAGE_KEYS } from "@/lib/media";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface SliderAction {
|
||||
@@ -29,10 +32,12 @@ interface Slider {
|
||||
description?: string;
|
||||
url?: string;
|
||||
action?: SliderAction;
|
||||
image_id?: number | null;
|
||||
image?: unknown;
|
||||
}
|
||||
|
||||
const ACTION_TYPES = [
|
||||
{ value: "screen", label: "صفحه (screen)" },
|
||||
{ value: "navigation", label: "صفحه (navigation)" },
|
||||
{ value: "link", label: "لینک (link)" },
|
||||
];
|
||||
|
||||
@@ -46,7 +51,9 @@ export default function SlidersPage() {
|
||||
const [description, setDescription] = useState("");
|
||||
const [url, setUrl] = useState("");
|
||||
const [actionPath, setActionPath] = useState("");
|
||||
const [actionType, setActionType] = useState("screen");
|
||||
const [actionType, setActionType] = useState("navigation");
|
||||
const [imageId, setImageId] = useState<number | null>(null);
|
||||
const [imageFile, setImageFile] = useState<File | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [deleting, setDeleting] = useState<Slider | null>(null);
|
||||
@@ -58,7 +65,9 @@ export default function SlidersPage() {
|
||||
setDescription("");
|
||||
setUrl("");
|
||||
setActionPath("");
|
||||
setActionType("screen");
|
||||
setActionType("navigation");
|
||||
setImageId(null);
|
||||
setImageFile(null);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: Slider) {
|
||||
@@ -67,7 +76,9 @@ export default function SlidersPage() {
|
||||
setDescription(row.description ?? "");
|
||||
setUrl(row.url ?? "");
|
||||
setActionPath(row.action?.path ?? "");
|
||||
setActionType(row.action?.type ?? "screen");
|
||||
setActionType(row.action?.type ?? "navigation");
|
||||
setImageId(row.image_id ?? null);
|
||||
setImageFile(null);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
@@ -75,30 +86,23 @@ export default function SlidersPage() {
|
||||
e.preventDefault();
|
||||
setSaving(true);
|
||||
try {
|
||||
if (editing) {
|
||||
// Update is JSON on /slider/:id with a nested action object.
|
||||
await apiFetch(`/slider/${editing.id}`, {
|
||||
method: "PUT",
|
||||
body: {
|
||||
// Multipart for both (so an image file can be uploaded). Bracket keys
|
||||
// build the nested action object; update uses POST /slider/:id.
|
||||
const body = toFormData({
|
||||
title,
|
||||
description,
|
||||
url,
|
||||
action: { path: actionPath, type: actionType },
|
||||
},
|
||||
});
|
||||
toast.success("اسلایدر ویرایش شد.");
|
||||
} else {
|
||||
// Create is multipart with literal bracket keys for the nested action.
|
||||
await apiFetch("/slider", {
|
||||
method: "POST",
|
||||
body: toFormData({
|
||||
title,
|
||||
description,
|
||||
"action[path]": actionPath,
|
||||
"action[type]": actionType,
|
||||
url,
|
||||
}),
|
||||
image_id: imageId,
|
||||
image: imageFile,
|
||||
});
|
||||
if (editing) {
|
||||
await apiFetch(`/slider/${editing.id}`, { method: "POST", body });
|
||||
toast.success("اسلایدر ویرایش شد.");
|
||||
} else {
|
||||
await apiFetch("/slider", { method: "POST", body });
|
||||
await apiFetch("/slider", { method: "POST", body });
|
||||
toast.success("اسلایدر افزوده شد.");
|
||||
}
|
||||
setOpen(false);
|
||||
@@ -127,6 +131,14 @@ export default function SlidersPage() {
|
||||
|
||||
const columns: Column<Slider>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-24" },
|
||||
{
|
||||
key: "image",
|
||||
header: "تصویر",
|
||||
className: "w-20",
|
||||
render: (r) => (
|
||||
<MediaPreview kind="image" src={pickUrl(r, IMAGE_KEYS)} label={r.title} />
|
||||
),
|
||||
},
|
||||
{ key: "title", header: "عنوان", render: (r) => r.title ?? "—" },
|
||||
{
|
||||
key: "description",
|
||||
@@ -224,6 +236,16 @@ export default function SlidersPage() {
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="تصویر">
|
||||
<ImagePicker
|
||||
imageId={imageId}
|
||||
onPickId={setImageId}
|
||||
file={imageFile}
|
||||
onPickFile={setImageFile}
|
||||
existingUrl={editing ? pickUrl(editing, IMAGE_KEYS) : null}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="توضیحات">
|
||||
<Textarea
|
||||
value={description}
|
||||
@@ -232,6 +254,16 @@ export default function SlidersPage() {
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="تصویر" hint="انتخاب از کتابخانه یا بارگذاری تصویر جدید">
|
||||
<ImagePicker
|
||||
imageId={imageId}
|
||||
onPickId={setImageId}
|
||||
file={imageFile}
|
||||
onPickFile={setImageFile}
|
||||
existingUrl={editing ? pickUrl(editing, IMAGE_KEYS) : null}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="آدرس (URL)">
|
||||
<Input
|
||||
value={url}
|
||||
|
||||
@@ -20,9 +20,21 @@ import {
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface SurveyTag {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface SurveyOption {
|
||||
id?: number;
|
||||
label?: string;
|
||||
tags?: SurveyTag[];
|
||||
}
|
||||
|
||||
// Form-side option: tags edited as a comma-separated string.
|
||||
interface OptionDraft {
|
||||
label: string;
|
||||
tags: string;
|
||||
}
|
||||
|
||||
interface SurveyQuestion {
|
||||
@@ -54,7 +66,9 @@ export default function SurveysPage() {
|
||||
const [type, setType] = useState("single");
|
||||
const [order, setOrder] = useState("0");
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
const [options, setOptions] = useState<string[]>([""]);
|
||||
const [options, setOptions] = useState<OptionDraft[]>([
|
||||
{ label: "", tags: "" },
|
||||
]);
|
||||
|
||||
const [deleting, setDeleting] = useState<SurveyQuestion | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
@@ -66,7 +80,7 @@ export default function SurveysPage() {
|
||||
setType("single");
|
||||
setOrder("0");
|
||||
setIsActive(true);
|
||||
setOptions([""]);
|
||||
setOptions([{ label: "", tags: "" }]);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
@@ -79,17 +93,22 @@ export default function SurveysPage() {
|
||||
setIsActive(row.is_active ?? true);
|
||||
setOptions(
|
||||
row.options && row.options.length
|
||||
? row.options.map((o) => o.label ?? "")
|
||||
: [""],
|
||||
? row.options.map((o) => ({
|
||||
label: o.label ?? "",
|
||||
tags: (o.tags ?? []).map((t) => t.name).join("، "),
|
||||
}))
|
||||
: [{ label: "", tags: "" }],
|
||||
);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
function setOptionAt(index: number, value: string) {
|
||||
setOptions((prev) => prev.map((o, i) => (i === index ? value : o)));
|
||||
function setOptionAt(index: number, patch: Partial<OptionDraft>) {
|
||||
setOptions((prev) =>
|
||||
prev.map((o, i) => (i === index ? { ...o, ...patch } : o)),
|
||||
);
|
||||
}
|
||||
function addOption() {
|
||||
setOptions((prev) => [...prev, ""]);
|
||||
setOptions((prev) => [...prev, { label: "", tags: "" }]);
|
||||
}
|
||||
function removeOption(index: number) {
|
||||
setOptions((prev) =>
|
||||
@@ -108,9 +127,15 @@ export default function SurveysPage() {
|
||||
order: Number(order),
|
||||
is_active: isActive,
|
||||
options: options
|
||||
.map((label) => label.trim())
|
||||
.filter((label) => label !== "")
|
||||
.map((label) => ({ label })),
|
||||
.map((o) => ({ label: o.label.trim(), tagsRaw: o.tags }))
|
||||
.filter((o) => o.label !== "")
|
||||
.map((o) => ({
|
||||
label: o.label,
|
||||
tags: o.tagsRaw
|
||||
.split(/[,،]/)
|
||||
.map((t) => t.trim())
|
||||
.filter((t) => t !== ""),
|
||||
})),
|
||||
};
|
||||
if (editing) {
|
||||
await apiFetch(`/survey-questions/${editing.id}`, {
|
||||
@@ -283,12 +308,22 @@ export default function SurveysPage() {
|
||||
</Button>
|
||||
</div>
|
||||
{options.map((opt, i) => (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<div
|
||||
key={i}
|
||||
className="flex items-start gap-2 rounded-lg border border-border p-2"
|
||||
>
|
||||
<div className="flex flex-1 flex-col gap-2">
|
||||
<Input
|
||||
value={opt}
|
||||
onChange={(e) => setOptionAt(i, e.target.value)}
|
||||
value={opt.label}
|
||||
onChange={(e) => setOptionAt(i, { label: e.target.value })}
|
||||
placeholder={`گزینه ${toFa(i + 1)}`}
|
||||
/>
|
||||
<Input
|
||||
value={opt.tags}
|
||||
onChange={(e) => setOptionAt(i, { tags: e.target.value })}
|
||||
placeholder="برچسبها (با کاما جدا کنید) — برای پیشنهاد محتوا"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
"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,
|
||||
Field,
|
||||
Input,
|
||||
Switch,
|
||||
Modal,
|
||||
PageHeader,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface Theme {
|
||||
id: number;
|
||||
key: string;
|
||||
name: string;
|
||||
colors: Record<string, string>;
|
||||
order?: number;
|
||||
is_active?: boolean;
|
||||
}
|
||||
|
||||
// "#FF156395" (ARGB) or "#156395" → a CSS color the browser understands.
|
||||
function cssColor(c?: string): string {
|
||||
if (!c) return "transparent";
|
||||
const hex = c.replace("#", "");
|
||||
if (hex.length === 8) return `#${hex.slice(2)}${hex.slice(0, 2)}`; // ARGB → RGBA
|
||||
return `#${hex}`;
|
||||
}
|
||||
|
||||
// The RGB part for a native <input type="color"> (which can't represent alpha).
|
||||
function toNativeRgb(argb?: string): string {
|
||||
const hex = (argb ?? "").replace("#", "");
|
||||
if (hex.length === 8) return `#${hex.slice(2)}`;
|
||||
if (hex.length === 6) return `#${hex}`;
|
||||
return "#000000";
|
||||
}
|
||||
|
||||
// Editable color cell: a native picker for the RGB part (preserving any alpha)
|
||||
// plus a free-text field for full ARGB control.
|
||||
function ColorInput({
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (v: string) => void;
|
||||
}) {
|
||||
const hex = (value ?? "").replace("#", "");
|
||||
const alpha = hex.length === 8 ? hex.slice(0, 2) : "";
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
aria-label="انتخاب رنگ"
|
||||
value={toNativeRgb(value)}
|
||||
onChange={(e) =>
|
||||
onChange(`#${alpha}${e.target.value.replace("#", "")}`.toUpperCase())
|
||||
}
|
||||
className="h-9 w-9 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0.5"
|
||||
/>
|
||||
<Input
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
dir="ltr"
|
||||
className="font-mono"
|
||||
placeholder="#FFFFFFFF"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ThemesPage() {
|
||||
// include_inactive so the editor also lists themes that are turned off.
|
||||
const { data, loading, error, reload } = useList<Theme>("/themes", {
|
||||
include_inactive: 1,
|
||||
});
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<Theme | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [name, setName] = useState("");
|
||||
const [order, setOrder] = useState("");
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
const [colors, setColors] = useState<Record<string, string>>({});
|
||||
|
||||
function openEdit(row: Theme) {
|
||||
setEditing(row);
|
||||
setName(row.name ?? "");
|
||||
setOrder(row.order != null ? String(row.order) : "");
|
||||
setIsActive(row.is_active ?? true);
|
||||
// Clone so edits don't mutate the loaded row before saving.
|
||||
setColors({ ...(row.colors ?? {}) });
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
function setColor(key: string, value: string) {
|
||||
setColors((prev) => ({ ...prev, [key]: value }));
|
||||
}
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!editing) return;
|
||||
setSaving(true);
|
||||
try {
|
||||
await apiFetch(`/themes/${editing.id}`, {
|
||||
method: "PUT",
|
||||
body: {
|
||||
name,
|
||||
order: order === "" ? undefined : Number(order),
|
||||
is_active: isActive,
|
||||
colors,
|
||||
},
|
||||
});
|
||||
toast.success("تم ویرایش شد.");
|
||||
setOpen(false);
|
||||
reload();
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : "خطا در ذخیرهسازی");
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
const swatchKeys = [
|
||||
"themeUp",
|
||||
"themeDown",
|
||||
"lightColorGradient",
|
||||
"darkColorGradient",
|
||||
];
|
||||
|
||||
const columns: Column<Theme>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{
|
||||
key: "preview",
|
||||
header: "پیشنمایش",
|
||||
render: (r) => (
|
||||
<span className="inline-flex overflow-hidden rounded-full border border-border">
|
||||
{swatchKeys.map((k) => (
|
||||
<span
|
||||
key={k}
|
||||
className="h-5 w-5"
|
||||
style={{ backgroundColor: cssColor(r.colors?.[k]) }}
|
||||
/>
|
||||
))}
|
||||
</span>
|
||||
),
|
||||
className: "w-32",
|
||||
},
|
||||
{ key: "name", header: "نام" },
|
||||
{
|
||||
key: "key",
|
||||
header: "کلید",
|
||||
render: (r) => <span dir="ltr" className="font-mono">{r.key}</span>,
|
||||
className: "w-28",
|
||||
},
|
||||
{
|
||||
key: "order",
|
||||
header: "ترتیب",
|
||||
render: (r) => toFa(r.order ?? 0),
|
||||
className: "w-20",
|
||||
},
|
||||
{
|
||||
key: "is_active",
|
||||
header: "وضعیت",
|
||||
render: (r) =>
|
||||
r.is_active ? (
|
||||
<Badge tone="success">فعال</Badge>
|
||||
) : (
|
||||
<Badge>غیرفعال</Badge>
|
||||
),
|
||||
className: "w-24",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<PageHeader
|
||||
title="تمها"
|
||||
subtitle="ویرایش رنگهای تمهای صحنه"
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
rows={data}
|
||||
loading={loading}
|
||||
error={error}
|
||||
onRetry={reload}
|
||||
emptyMessage="هنوز تمی ثبت نشده است."
|
||||
actions={(row) => (
|
||||
<Button variant="ghost" onClick={() => openEdit(row)} aria-label="ویرایش">
|
||||
<EditIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
title={editing ? `ویرایش تم «${editing.name}»` : "ویرایش تم"}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="secondary" onClick={() => setOpen(false)}>
|
||||
انصراف
|
||||
</Button>
|
||||
<Button form="theme-form" type="submit" loading={saving}>
|
||||
ذخیره
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="theme-form" onSubmit={save} className="flex flex-col gap-4">
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<Field label="نام" required>
|
||||
<Input
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
<Field label="ترتیب">
|
||||
<Input
|
||||
type="number"
|
||||
value={order}
|
||||
onChange={(e) => setOrder(e.target.value)}
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<Field label="فعال">
|
||||
<Switch checked={isActive} onChange={setIsActive} />
|
||||
</Field>
|
||||
|
||||
<div className="border-t border-border pt-4">
|
||||
<p className="mb-3 text-sm font-medium text-foreground">رنگها</p>
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
||||
{Object.keys(colors).map((key) => (
|
||||
<Field key={key} label={key}>
|
||||
<ColorInput
|
||||
value={colors[key] ?? ""}
|
||||
onChange={(v) => setColor(key, v)}
|
||||
/>
|
||||
</Field>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { apiFetch, getApproToken } from "@/lib/api";
|
||||
import { APPRO_BASE_URL, MEDITATION_BASE_URL } from "@/lib/config";
|
||||
import { usePaginated } from "@/lib/useResource";
|
||||
import { DataTable, type Column } from "@/components/DataTable";
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Pagination,
|
||||
Select,
|
||||
Spinner,
|
||||
} from "@/components/ui";
|
||||
import { EyeIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
interface MeditationUser {
|
||||
id: number;
|
||||
full_name?: string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
age?: number | null;
|
||||
gender?: number | null;
|
||||
email?: string | null;
|
||||
mobile?: string | null;
|
||||
identifier?: string | null;
|
||||
created_at?: string;
|
||||
answers_count?: number;
|
||||
questions_answered?: number;
|
||||
}
|
||||
|
||||
interface ApproUser {
|
||||
id: number;
|
||||
uuid?: string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
full_name?: string;
|
||||
age?: number | null;
|
||||
gender?: number | null;
|
||||
email?: string | null;
|
||||
mobile?: string | null;
|
||||
birthday?: string | null;
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
interface SurveyAnswerItem {
|
||||
question_id: number;
|
||||
question?: string;
|
||||
type?: string;
|
||||
answers: { option_id: number; label: string }[];
|
||||
}
|
||||
|
||||
interface DetailData {
|
||||
appro: ApproUser | null;
|
||||
survey_answers: SurveyAnswerItem[];
|
||||
answers_count?: number;
|
||||
questions_answered?: number;
|
||||
}
|
||||
|
||||
const GENDER_LABELS: Record<number, string> = {
|
||||
1: "مرد",
|
||||
2: "زن",
|
||||
};
|
||||
|
||||
function faDate(value?: string): string {
|
||||
if (!value) return "—";
|
||||
try {
|
||||
return toFa(new Date(value).toLocaleDateString("fa-IR"));
|
||||
} catch {
|
||||
return "—";
|
||||
}
|
||||
}
|
||||
|
||||
export default function UsersPage() {
|
||||
const [answered, setAnswered] = useState<string>("");
|
||||
const { data, meta, page, setPage, loading, error, reload } =
|
||||
usePaginated<MeditationUser>("/admin/survey-users", {
|
||||
perPage: 20,
|
||||
query: answered ? { answered } : undefined,
|
||||
});
|
||||
|
||||
const [detailUser, setDetailUser] = useState<MeditationUser | null>(null);
|
||||
const [detailData, setDetailData] = useState<DetailData | null>(null);
|
||||
const [detailOpen, setDetailOpen] = useState(false);
|
||||
const [detailLoading, setDetailLoading] = useState(false);
|
||||
|
||||
async function openDetail(user: MeditationUser) {
|
||||
setDetailOpen(true);
|
||||
setDetailLoading(true);
|
||||
setDetailUser(user);
|
||||
setDetailData(null);
|
||||
|
||||
const [appro, survey] = await Promise.all([
|
||||
user.mobile
|
||||
? apiFetch<{ data: ApproUser[] }>("/admin/users", {
|
||||
query: { mobile: user.mobile, per_page: 1 },
|
||||
baseUrl: APPRO_BASE_URL,
|
||||
headers: { Authorization: `Bearer ${getApproToken()}` },
|
||||
}).then((r) => r.data?.[0] ?? null)
|
||||
: Promise.resolve(null),
|
||||
apiFetch<{ survey_answers: SurveyAnswerItem[]; answers_count?: number; questions_answered?: number }>(
|
||||
`/admin/survey-users/${user.identifier || user.id}`,
|
||||
{ baseUrl: MEDITATION_BASE_URL },
|
||||
).catch(() => ({ survey_answers: [], answers_count: undefined, questions_answered: undefined })),
|
||||
]);
|
||||
|
||||
// Sync approagency data back to meditation DB if user has null fields
|
||||
if (appro && user.mobile && (!user.first_name || user.age == null || user.gender == null)) {
|
||||
apiFetch(`/admin/survey-users/${user.identifier || user.id}`, {
|
||||
method: "PATCH",
|
||||
baseUrl: MEDITATION_BASE_URL,
|
||||
body: {
|
||||
first_name: appro.first_name,
|
||||
last_name: appro.last_name,
|
||||
age: appro.age,
|
||||
gender: appro.gender,
|
||||
birthday: appro.birthday,
|
||||
identifier: appro.uuid,
|
||||
email: appro.email,
|
||||
},
|
||||
}).catch(() => {}); // fire-and-forget
|
||||
}
|
||||
|
||||
setDetailData({
|
||||
appro,
|
||||
survey_answers: survey.survey_answers ?? [],
|
||||
answers_count: survey.answers_count,
|
||||
questions_answered: survey.questions_answered,
|
||||
});
|
||||
setDetailLoading(false);
|
||||
}
|
||||
|
||||
const columns: Column<MeditationUser>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{
|
||||
key: "full_name",
|
||||
header: "نام",
|
||||
render: (r) => r.full_name || [r.first_name, r.last_name].filter(Boolean).join(" ") || "—",
|
||||
},
|
||||
{
|
||||
key: "questions_answered",
|
||||
header: "پاسخ به سوالات",
|
||||
className: "w-32",
|
||||
render: (r) =>
|
||||
r.questions_answered != null ? toFa(r.questions_answered) : "—",
|
||||
},
|
||||
{
|
||||
key: "created_at",
|
||||
header: "تاریخ ثبتنام",
|
||||
className: "w-32",
|
||||
render: (r) => faDate(r.created_at),
|
||||
},
|
||||
];
|
||||
|
||||
const a = detailData?.appro;
|
||||
const s = detailData;
|
||||
const userName = a
|
||||
? a.full_name || [a.first_name, a.last_name].filter(Boolean).join(" ") || ""
|
||||
: detailUser
|
||||
? detailUser.full_name || [detailUser.first_name, detailUser.last_name].filter(Boolean).join(" ") || ""
|
||||
: "";
|
||||
|
||||
return (
|
||||
<div>
|
||||
<PageHeader
|
||||
title="کاربران نظرسنجی"
|
||||
subtitle="فهرست کاربران و پاسخهای نظرسنجی آنها"
|
||||
/>
|
||||
|
||||
<div className="mb-4 flex items-center gap-3">
|
||||
<label className="text-sm text-muted">فیلتر:</label>
|
||||
<Select value={answered} onChange={(e) => { setAnswered(e.target.value); setPage(1); }}>
|
||||
<option value="">همه کاربران</option>
|
||||
<option value="1">پاسخ دادهاند</option>
|
||||
<option value="0">پاسخ ندادهاند</option>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
rows={data}
|
||||
loading={loading}
|
||||
error={error}
|
||||
onRetry={reload}
|
||||
emptyTitle="کاربری یافت نشد"
|
||||
emptyMessage="هنوز کاربری در نظرسنجی شرکت نکرده است."
|
||||
actions={(row) => (
|
||||
<Button variant="ghost" onClick={() => openDetail(row)} aria-label="جزئیات">
|
||||
<EyeIcon className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
/>
|
||||
|
||||
{meta && (
|
||||
<Pagination
|
||||
page={page}
|
||||
lastPage={meta.last_page}
|
||||
total={meta.total}
|
||||
onChange={setPage}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Modal
|
||||
open={detailOpen}
|
||||
onClose={() => setDetailOpen(false)}
|
||||
title={userName ? `جزئیات کاربر — ${userName}` : "جزئیات کاربر"}
|
||||
footer={
|
||||
<Button variant="secondary" onClick={() => setDetailOpen(false)}>
|
||||
بستن
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{detailLoading && (
|
||||
<div className="flex justify-center py-8">
|
||||
<Spinner className="h-6 w-6" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{s && !detailLoading && (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Card>
|
||||
<p className="text-sm text-muted">نام</p>
|
||||
<p className="mt-1 font-bold text-foreground">{userName || "—"}</p>
|
||||
</Card>
|
||||
<Card>
|
||||
<p className="text-sm text-muted">سن</p>
|
||||
<p className="mt-1 font-bold text-foreground">
|
||||
{(a?.age ?? detailUser?.age) != null ? toFa(a?.age ?? detailUser!.age!) : "—"}
|
||||
</p>
|
||||
</Card>
|
||||
<Card>
|
||||
<p className="text-sm text-muted">جنسیت</p>
|
||||
<p className="mt-1 font-bold text-foreground">
|
||||
{(a?.gender ?? detailUser?.gender) != null
|
||||
? GENDER_LABELS[a?.gender ?? detailUser!.gender!] ?? "—"
|
||||
: "—"}
|
||||
</p>
|
||||
</Card>
|
||||
<Card>
|
||||
<p className="text-sm text-muted">تاریخ تولد</p>
|
||||
<p className="mt-1 font-bold text-foreground">
|
||||
{a?.birthday ? faDate(a.birthday) : "—"}
|
||||
</p>
|
||||
</Card>
|
||||
<Card>
|
||||
<p className="text-sm text-muted">ایمیل</p>
|
||||
<p className="mt-1 font-bold text-foreground" dir="ltr">
|
||||
{(a?.email ?? detailUser?.email) || "—"}
|
||||
</p>
|
||||
</Card>
|
||||
<Card>
|
||||
<p className="text-sm text-muted">موبایل</p>
|
||||
<p className="mt-1 font-bold text-foreground" dir="ltr">
|
||||
{detailUser?.mobile || "—"}
|
||||
</p>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Card>
|
||||
<p className="text-sm text-muted">تعداد پاسخها</p>
|
||||
<p className="mt-1 font-bold text-foreground">
|
||||
{s.answers_count != null ? toFa(s.answers_count) : "—"}
|
||||
</p>
|
||||
</Card>
|
||||
<Card>
|
||||
<p className="text-sm text-muted">سوالات پاسخ داده شده</p>
|
||||
<p className="mt-1 font-bold text-foreground">
|
||||
{s.questions_answered != null ? toFa(s.questions_answered) : "—"}
|
||||
</p>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{s.survey_answers.length > 0 ? (
|
||||
<div>
|
||||
<h3 className="mb-3 text-sm font-bold text-foreground">
|
||||
پاسخهای نظرسنجی
|
||||
</h3>
|
||||
<div className="flex flex-col gap-2">
|
||||
{s.survey_answers.map((item) => (
|
||||
<div
|
||||
key={item.question_id}
|
||||
className="rounded-xl border border-border p-3"
|
||||
>
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{item.question}
|
||||
</p>
|
||||
<div className="mt-1 flex flex-wrap gap-1">
|
||||
{item.answers.map((a) => (
|
||||
<Badge key={a.option_id} tone="primary">
|
||||
{a.label}
|
||||
</Badge>
|
||||
))}
|
||||
{item.answers.length === 0 && (
|
||||
<span className="text-xs text-muted">بدون پاسخ</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-center text-sm text-muted">
|
||||
این کاربر هنوز به هیچ سوالی پاسخ نداده است.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { apiFetch, ApiError, toFormData } from "@/lib/api";
|
||||
import { useList } from "@/lib/useResource";
|
||||
import { useToast } from "@/components/toast";
|
||||
import { DataTable, type Column } from "@/components/DataTable";
|
||||
import {
|
||||
Button,
|
||||
ConfirmDialog,
|
||||
Field,
|
||||
Input,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Textarea,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { toFa } from "@/lib/utils";
|
||||
import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
import { pickUrl, IMAGE_KEYS } from "@/lib/media";
|
||||
|
||||
interface AppVersion {
|
||||
id: number;
|
||||
title?: string;
|
||||
description?: string;
|
||||
version_name?: string;
|
||||
version_code?: number;
|
||||
link?: string;
|
||||
button_text?: string;
|
||||
image_id?: number | null;
|
||||
image?: unknown;
|
||||
}
|
||||
|
||||
export default function VersionsPage() {
|
||||
const { data, loading, error, reload } = useList<AppVersion>("/versions");
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<AppVersion | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [title, setTitle] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [versionName, setVersionName] = useState("");
|
||||
const [versionCode, setVersionCode] = useState("");
|
||||
const [link, setLink] = useState("");
|
||||
const [buttonText, setButtonText] = useState("");
|
||||
const [imageId, setImageId] = useState<number | null>(null);
|
||||
const [imageFile, setImageFile] = useState<File | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const [deleting, setDeleting] = useState<AppVersion | null>(null);
|
||||
const [removing, setRemoving] = useState(false);
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setTitle("");
|
||||
setDescription("");
|
||||
setVersionName("");
|
||||
setVersionCode("");
|
||||
setLink("");
|
||||
setButtonText("");
|
||||
setImageId(null);
|
||||
setImageFile(null);
|
||||
setOpen(true);
|
||||
}
|
||||
function openEdit(row: AppVersion) {
|
||||
setEditing(row);
|
||||
setTitle(row.title ?? "");
|
||||
setDescription(row.description ?? "");
|
||||
setVersionName(row.version_name ?? "");
|
||||
setVersionCode(row.version_code != null ? String(row.version_code) : "");
|
||||
setLink(row.link ?? "");
|
||||
setButtonText(row.button_text ?? "");
|
||||
setImageId(row.image_id ?? null);
|
||||
setImageFile(null);
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setSaving(true);
|
||||
try {
|
||||
// Multipart (the image is a file). Edit posts to /versions/:id, which the
|
||||
// backend also accepts as a multipart update.
|
||||
const body = toFormData({
|
||||
title,
|
||||
description,
|
||||
version_name: versionName,
|
||||
version_code: versionCode,
|
||||
link,
|
||||
button_text: buttonText,
|
||||
image_id: imageId,
|
||||
image: imageFile,
|
||||
});
|
||||
if (editing) {
|
||||
await apiFetch(`/versions/${editing.id}`, { method: "POST", body });
|
||||
toast.success("نسخه ویرایش شد.");
|
||||
} else {
|
||||
await apiFetch("/versions", { method: "POST", body });
|
||||
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(`/versions/${deleting.id}`, { method: "DELETE" });
|
||||
toast.success("نسخه حذف شد.");
|
||||
setDeleting(null);
|
||||
reload();
|
||||
} catch (err) {
|
||||
toast.error(err instanceof ApiError ? err.message : "خطا در حذف");
|
||||
} finally {
|
||||
setRemoving(false);
|
||||
}
|
||||
}
|
||||
|
||||
const columns: Column<AppVersion>[] = [
|
||||
{ key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-20" },
|
||||
{
|
||||
key: "thumbnail",
|
||||
header: "تصویر",
|
||||
className: "w-20",
|
||||
render: (r) => (
|
||||
<MediaPreview kind="image" src={pickUrl(r, IMAGE_KEYS)} label={r.title} />
|
||||
),
|
||||
},
|
||||
{ key: "title", header: "عنوان", render: (r) => r.title ?? "—" },
|
||||
{
|
||||
key: "version_name",
|
||||
header: "نام نسخه",
|
||||
render: (r) => (
|
||||
<span dir="ltr" className="block">
|
||||
{r.version_name ?? "—"}
|
||||
</span>
|
||||
),
|
||||
className: "w-28",
|
||||
},
|
||||
{
|
||||
key: "version_code",
|
||||
header: "کد نسخه",
|
||||
render: (r) => (r.version_code != null ? toFa(r.version_code) : "—"),
|
||||
className: "w-24",
|
||||
},
|
||||
{
|
||||
key: "link",
|
||||
header: "لینک",
|
||||
render: (r) =>
|
||||
r.link ? (
|
||||
<span dir="ltr" className="block max-w-[12rem] truncate">
|
||||
{r.link}
|
||||
</span>
|
||||
) : (
|
||||
"—"
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
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="version-form" type="submit" loading={saving}>
|
||||
ذخیره
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="version-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="تصویر" hint="انتخاب از کتابخانه یا بارگذاری تصویر جدید">
|
||||
<ImagePicker
|
||||
imageId={imageId}
|
||||
onPickId={setImageId}
|
||||
file={imageFile}
|
||||
onPickFile={setImageFile}
|
||||
existingUrl={editing ? pickUrl(editing, IMAGE_KEYS) : null}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<Field label="نام نسخه" required>
|
||||
<Input
|
||||
value={versionName}
|
||||
onChange={(e) => setVersionName(e.target.value)}
|
||||
placeholder="1.2.0"
|
||||
dir="ltr"
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
<Field label="کد نسخه" required>
|
||||
<Input
|
||||
type="number"
|
||||
value={versionCode}
|
||||
onChange={(e) => setVersionCode(e.target.value)}
|
||||
placeholder="42"
|
||||
dir="ltr"
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<Field label="لینک">
|
||||
<Input
|
||||
value={link}
|
||||
onChange={(e) => setLink(e.target.value)}
|
||||
placeholder="https://"
|
||||
dir="ltr"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="متن دکمه" hint="اختیاری">
|
||||
<Input
|
||||
value={buttonText}
|
||||
onChange={(e) => setButtonText(e.target.value)}
|
||||
placeholder="مثلاً بهروزرسانی"
|
||||
/>
|
||||
</Field>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<ConfirmDialog
|
||||
open={!!deleting}
|
||||
message={`آیا از حذف «${deleting?.title}» مطمئن هستید؟`}
|
||||
loading={removing}
|
||||
onConfirm={confirmDelete}
|
||||
onClose={() => setDeleting(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ export const metadata: Metadata = {
|
||||
|
||||
// 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){}})();`;
|
||||
const noFlashTheme = `(function(){try{var t=localStorage.getItem('aram_theme');if(t==='dark'||(t!=='light'&&(t='system',window.matchMedia('(prefers-color-scheme: dark)').matches))){document.documentElement.classList.add('dark');}}catch(e){}})();`;
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
|
||||
@@ -1,21 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { useTheme } from "@/lib/theme";
|
||||
import { SunIcon, MoonIcon } from "./icons";
|
||||
import { SunIcon, MoonIcon, MonitorIcon } from "./icons";
|
||||
|
||||
const LABELS = {
|
||||
light: "حالت روشن",
|
||||
dark: "حالت تاریک",
|
||||
system: "حالت سیستم",
|
||||
};
|
||||
|
||||
const ICONS = {
|
||||
light: SunIcon,
|
||||
dark: MoonIcon,
|
||||
system: MonitorIcon,
|
||||
};
|
||||
|
||||
export function ThemeToggle({ className }: { className?: string }) {
|
||||
const { theme, toggle } = useTheme();
|
||||
const dark = theme === "dark";
|
||||
const Icon = ICONS[theme];
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggle}
|
||||
aria-label={dark ? "حالت روشن" : "حالت تاریک"}
|
||||
title={dark ? "حالت روشن" : "حالت تاریک"}
|
||||
aria-label={LABELS[theme]}
|
||||
title={LABELS[theme]}
|
||||
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" />}
|
||||
<Icon className="h-5 w-5" />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -196,3 +196,17 @@ export const TagIcon = (p: IconProps) => (
|
||||
<circle cx="7.5" cy="7.5" r="1.2" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const UserIcon = (p: IconProps) => (
|
||||
<svg {...base(p)}>
|
||||
<circle cx="12" cy="8" r="4" />
|
||||
<path d="M6 21v-2a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v2" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const MonitorIcon = (p: IconProps) => (
|
||||
<svg {...base(p)}>
|
||||
<rect x="2" y="3" width="20" height="14" rx="2" />
|
||||
<path d="M8 21h8M12 17v4" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
+39
-1
@@ -8,7 +8,7 @@ import {
|
||||
type TextareaHTMLAttributes,
|
||||
useEffect,
|
||||
} from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { cn, toFa } from "@/lib/utils";
|
||||
import { CloseIcon, SpinnerIcon } from "./icons";
|
||||
|
||||
/* ------------------------------- Button -------------------------------- */
|
||||
@@ -192,6 +192,44 @@ export function Badge({
|
||||
);
|
||||
}
|
||||
|
||||
export function Pagination({
|
||||
page,
|
||||
lastPage,
|
||||
total,
|
||||
onChange,
|
||||
}: {
|
||||
page: number;
|
||||
lastPage: number;
|
||||
total?: number;
|
||||
onChange: (p: number) => void;
|
||||
}) {
|
||||
if (lastPage <= 1) return null;
|
||||
return (
|
||||
<div className="mt-4 flex items-center justify-between gap-3 text-sm">
|
||||
<span className="text-muted">
|
||||
{total != null && `${toFa(total)} مورد · `}
|
||||
صفحه {toFa(page)} از {toFa(lastPage)}
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => onChange(page - 1)}
|
||||
disabled={page <= 1}
|
||||
>
|
||||
قبلی
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => onChange(page + 1)}
|
||||
disabled={page >= lastPage}
|
||||
>
|
||||
بعدی
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function EmptyState({
|
||||
title,
|
||||
message,
|
||||
|
||||
+27
-2
@@ -1,7 +1,11 @@
|
||||
// Thin fetch wrapper for the meditation API. The app is a static SPA, so every
|
||||
// call runs in the browser and carries the bearer token from localStorage.
|
||||
|
||||
import { MEDITATION_BASE_URL, TOKEN_STORAGE_KEY } from "./config";
|
||||
import {
|
||||
APPRO_TOKEN_STORAGE_KEY,
|
||||
MEDITATION_BASE_URL,
|
||||
TOKEN_STORAGE_KEY,
|
||||
} from "./config";
|
||||
|
||||
export class ApiError extends Error {
|
||||
status: number;
|
||||
@@ -29,6 +33,21 @@ export function clearToken() {
|
||||
window.localStorage.removeItem(TOKEN_STORAGE_KEY);
|
||||
}
|
||||
|
||||
export function getApproToken(): string | null {
|
||||
if (typeof window === "undefined") return null;
|
||||
return window.localStorage.getItem(APPRO_TOKEN_STORAGE_KEY);
|
||||
}
|
||||
|
||||
export function setApproToken(token: string) {
|
||||
if (typeof window === "undefined") return;
|
||||
window.localStorage.setItem(APPRO_TOKEN_STORAGE_KEY, token);
|
||||
}
|
||||
|
||||
export function clearApproToken() {
|
||||
if (typeof window === "undefined") return;
|
||||
window.localStorage.removeItem(APPRO_TOKEN_STORAGE_KEY);
|
||||
}
|
||||
|
||||
type Query = Record<string, string | number | boolean | undefined | null>;
|
||||
|
||||
interface RequestOptions {
|
||||
@@ -40,6 +59,8 @@ interface RequestOptions {
|
||||
baseUrl?: string;
|
||||
// Skip attaching the bearer token (used by the login calls).
|
||||
auth?: boolean;
|
||||
// Extra headers to merge into the request.
|
||||
headers?: Record<string, string>;
|
||||
}
|
||||
|
||||
function buildUrl(path: string, query?: Query, baseUrl = MEDITATION_BASE_URL) {
|
||||
@@ -60,7 +81,7 @@ export async function apiFetch<T = unknown>(
|
||||
path: string,
|
||||
options: RequestOptions = {},
|
||||
): Promise<T> {
|
||||
const { method = "GET", body, query, baseUrl, auth = true } = options;
|
||||
const { method = "GET", body, query, baseUrl, auth = true, headers: extraHeaders } = options;
|
||||
|
||||
const headers: Record<string, string> = { Accept: "application/json" };
|
||||
|
||||
@@ -69,6 +90,10 @@ export async function apiFetch<T = unknown>(
|
||||
if (token) headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
if (extraHeaders) {
|
||||
Object.assign(headers, extraHeaders);
|
||||
}
|
||||
|
||||
let payload: BodyInit | undefined;
|
||||
if (body instanceof FormData) {
|
||||
payload = body; // browser sets multipart Content-Type + boundary
|
||||
|
||||
+6
-8
@@ -13,7 +13,6 @@ import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
import { APPRO_BASE_URL, MEDITATION_BASE_URL, PACKAGE_NAME } from "./config";
|
||||
@@ -21,8 +20,10 @@ import {
|
||||
ApiError,
|
||||
apiFetch,
|
||||
clearToken,
|
||||
clearApproToken,
|
||||
getToken,
|
||||
setToken,
|
||||
setApproToken,
|
||||
toFormData,
|
||||
} from "./api";
|
||||
|
||||
@@ -73,16 +74,12 @@ async function meditationLogin(approoToken: string): Promise<string> {
|
||||
}
|
||||
|
||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const [token, setTokenState] = useState<string | null>(null);
|
||||
const [ready, setReady] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setTokenState(getToken());
|
||||
setReady(true);
|
||||
}, []);
|
||||
const [token, setTokenState] = useState<string | null>(() => getToken());
|
||||
const [ready] = useState(true);
|
||||
|
||||
const login = useCallback(async (identifier: string, password: string) => {
|
||||
const approoToken = await approAgencyLogin(identifier, password);
|
||||
setApproToken(approoToken);
|
||||
const medToken = await meditationLogin(approoToken);
|
||||
setToken(medToken);
|
||||
setTokenState(medToken);
|
||||
@@ -90,6 +87,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
const logout = useCallback(() => {
|
||||
clearToken();
|
||||
clearApproToken();
|
||||
setTokenState(null);
|
||||
}, []);
|
||||
|
||||
|
||||
+2
-1
@@ -19,5 +19,6 @@ export const ASSET_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_ASSET_BASE_URL ??
|
||||
MEDITATION_BASE_URL.replace(/\/api\/?$/, "");
|
||||
|
||||
// localStorage key for the meditation bearer token.
|
||||
// localStorage keys for the meditation bearer token and approagency token.
|
||||
export const TOKEN_STORAGE_KEY = "meditation_admin_token";
|
||||
export const APPRO_TOKEN_STORAGE_KEY = "approagency_admin_token";
|
||||
|
||||
+29
-1
@@ -14,6 +14,7 @@ import {
|
||||
TagIcon,
|
||||
TimerIcon,
|
||||
TrophyIcon,
|
||||
UserIcon,
|
||||
WorryIcon,
|
||||
} from "@/components/icons";
|
||||
|
||||
@@ -72,6 +73,7 @@ export const NAV: NavSection[] = [
|
||||
items: [
|
||||
{ href: "/dashboard/scenes", label: "صحنهها" },
|
||||
{ href: "/dashboard/scenes/settings", label: "تنظیمات صحنه" },
|
||||
{ href: "/dashboard/themes", label: "تمها" },
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -79,6 +81,16 @@ export const NAV: NavSection[] = [
|
||||
icon: SliderIcon,
|
||||
items: [{ href: "/dashboard/sliders", label: "اسلایدرها" }],
|
||||
},
|
||||
{
|
||||
label: "اعلانها",
|
||||
icon: SliderIcon,
|
||||
items: [{ href: "/dashboard/announcements", label: "اعلانها" }],
|
||||
},
|
||||
{
|
||||
label: "نسخهها",
|
||||
icon: SliderIcon,
|
||||
items: [{ href: "/dashboard/versions", label: "نسخههای برنامه" }],
|
||||
},
|
||||
{
|
||||
label: "تصاویر",
|
||||
icon: ImageIcon,
|
||||
@@ -87,7 +99,10 @@ export const NAV: NavSection[] = [
|
||||
{
|
||||
label: "تمرین تنفس",
|
||||
icon: BreathIcon,
|
||||
items: [{ href: "/dashboard/breathing", label: "قالبهای تنفس" }],
|
||||
items: [
|
||||
{ href: "/dashboard/breathing", label: "قالبهای تنفس" },
|
||||
{ href: "/dashboard/breathing/colors", label: "رنگهای تنفس" },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "پرسشها",
|
||||
@@ -99,6 +114,11 @@ export const NAV: NavSection[] = [
|
||||
icon: SurveyIcon,
|
||||
items: [{ href: "/dashboard/surveys", label: "پرسشهای نظرسنجی" }],
|
||||
},
|
||||
{
|
||||
label: "کاربران",
|
||||
icon: UserIcon,
|
||||
items: [{ href: "/dashboard/users", label: "کاربران نظرسنجی" }],
|
||||
},
|
||||
{
|
||||
label: "گفتگو با مشاور",
|
||||
icon: ChatIcon,
|
||||
@@ -127,4 +147,12 @@ export const NAV: NavSection[] = [
|
||||
{ href: "/dashboard/app-feedback", label: "نظرات و ایدهها برنامه" },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "سوالات متداول",
|
||||
icon: QuestionIcon,
|
||||
items: [
|
||||
{ href: "/dashboard/faq", label: "پرسشها" },
|
||||
{ href: "/dashboard/faq/categories", label: "دستهبندیها" },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
+68
-24
@@ -1,59 +1,103 @@
|
||||
"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.
|
||||
// Light / dark / system theme state. The actual `.dark` class is set on <html>
|
||||
// by an inline script in the root layout (before paint) and kept in sync here.
|
||||
// Preference persists in localStorage.
|
||||
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
export const THEME_STORAGE_KEY = "aram_theme";
|
||||
type Theme = "light" | "dark";
|
||||
export type Theme = "light" | "dark" | "system";
|
||||
|
||||
interface ThemeApi {
|
||||
theme: Theme;
|
||||
resolved: "light" | "dark";
|
||||
toggle: () => void;
|
||||
setTheme: (t: Theme) => void;
|
||||
}
|
||||
|
||||
const ThemeContext = createContext<ThemeApi | null>(null);
|
||||
|
||||
function applyClass(theme: Theme) {
|
||||
document.documentElement.classList.toggle("dark", theme === "dark");
|
||||
function isSystemDark(): boolean {
|
||||
if (typeof window === "undefined") return false;
|
||||
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
}
|
||||
|
||||
function applyClass(resolved: "light" | "dark") {
|
||||
document.documentElement.classList.toggle("dark", resolved === "dark");
|
||||
}
|
||||
|
||||
function readStorage(): Theme {
|
||||
if (typeof window === "undefined") return "system";
|
||||
try {
|
||||
const t = localStorage.getItem(THEME_STORAGE_KEY);
|
||||
if (t === "light" || t === "dark" || t === "system") return t;
|
||||
} catch { /* private mode */ }
|
||||
return "system";
|
||||
}
|
||||
|
||||
function resolve(theme: Theme): "light" | "dark" {
|
||||
return theme === "system" ? (isSystemDark() ? "dark" : "light") : theme;
|
||||
}
|
||||
|
||||
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||
const [theme, setThemeState] = useState<Theme>("light");
|
||||
const [theme, setThemeState] = useState<Theme>("system");
|
||||
const [resolved, setResolved] = useState<"light" | "dark">("light");
|
||||
const mqRef = useRef<MediaQueryList | null>(null);
|
||||
|
||||
// Read whatever the no-flash script already decided.
|
||||
// Apply theme to <html> and update resolved state.
|
||||
const apply = useCallback((t: Theme) => {
|
||||
const r = resolve(t);
|
||||
applyClass(r);
|
||||
setResolved(r);
|
||||
}, []);
|
||||
|
||||
// On mount: read preference, apply, listen to system changes.
|
||||
useEffect(() => {
|
||||
const isDark = document.documentElement.classList.contains("dark");
|
||||
setThemeState(isDark ? "dark" : "light");
|
||||
}, []);
|
||||
|
||||
const setTheme = useCallback((t: Theme) => {
|
||||
const t = readStorage();
|
||||
setThemeState(t);
|
||||
applyClass(t);
|
||||
try {
|
||||
window.localStorage.setItem(THEME_STORAGE_KEY, t);
|
||||
} catch {
|
||||
/* ignore (private mode) */
|
||||
apply(t);
|
||||
|
||||
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
mqRef.current = mq;
|
||||
|
||||
const handler = () => {
|
||||
// Re-read theme from state (via ref won't work for closures, so re-read localStorage).
|
||||
const current = readStorage();
|
||||
if (current === "system") {
|
||||
apply("system");
|
||||
}
|
||||
}, []);
|
||||
};
|
||||
mq.addEventListener("change", handler);
|
||||
return () => mq.removeEventListener("change", handler);
|
||||
}, [apply]);
|
||||
|
||||
const setTheme = useCallback(
|
||||
(t: Theme) => {
|
||||
setThemeState(t);
|
||||
apply(t);
|
||||
try {
|
||||
localStorage.setItem(THEME_STORAGE_KEY, t);
|
||||
} catch { /* private mode */ }
|
||||
},
|
||||
[apply],
|
||||
);
|
||||
|
||||
const toggle = useCallback(() => {
|
||||
setTheme(
|
||||
document.documentElement.classList.contains("dark") ? "light" : "dark",
|
||||
);
|
||||
}, [setTheme]);
|
||||
const order: Theme[] = ["light", "dark", "system"];
|
||||
const next = order[(order.indexOf(theme) + 1) % order.length];
|
||||
setTheme(next);
|
||||
}, [theme, setTheme]);
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={{ theme, toggle, setTheme }}>
|
||||
<ThemeContext.Provider value={{ theme, resolved, toggle, setTheme }}>
|
||||
{children}
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
|
||||
@@ -51,6 +51,73 @@ export function useList<T = unknown>(
|
||||
return { data, loading, error, reload };
|
||||
}
|
||||
|
||||
export interface PageMeta {
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
per_page: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
// Paginated GET-list hook for Laravel paginator responses
|
||||
// ({ data, current_page, last_page, per_page, total }).
|
||||
export function usePaginated<T = unknown>(
|
||||
path: string | null,
|
||||
options?: { perPage?: number; query?: Query },
|
||||
): {
|
||||
data: T[];
|
||||
meta: PageMeta | null;
|
||||
page: number;
|
||||
setPage: (p: number) => void;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
reload: () => void;
|
||||
} {
|
||||
const perPage = options?.perPage ?? 20;
|
||||
const query = options?.query;
|
||||
const [page, setPage] = useState(1);
|
||||
const [data, setData] = useState<T[]>([]);
|
||||
const [meta, setMeta] = useState<PageMeta | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const queryKey = JSON.stringify(query ?? {});
|
||||
|
||||
const reload = useCallback(() => {
|
||||
if (!path) {
|
||||
setData([]);
|
||||
setMeta(null);
|
||||
setLoading(false);
|
||||
setError(null);
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
apiFetch(path, { query: { ...query, page, per_page: perPage } })
|
||||
.then((res) => {
|
||||
const r = (res ?? {}) as Record<string, unknown>;
|
||||
const rows = Array.isArray(r.data) ? (r.data as T[]) : [];
|
||||
setData(rows);
|
||||
setMeta({
|
||||
current_page: Number(r.current_page ?? page),
|
||||
last_page: Number(r.last_page ?? 1),
|
||||
per_page: Number(r.per_page ?? perPage),
|
||||
total: Number(r.total ?? rows.length),
|
||||
});
|
||||
})
|
||||
.catch((e: unknown) => {
|
||||
setError(e instanceof ApiError ? e.message : "خطا در دریافت اطلاعات");
|
||||
setData([]);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [path, page, perPage, queryKey]);
|
||||
|
||||
useEffect(() => {
|
||||
reload();
|
||||
}, [reload]);
|
||||
|
||||
return { data, meta, page, setPage, loading, error, reload };
|
||||
}
|
||||
|
||||
// Single-record GET hook.
|
||||
export function useItem<T = unknown>(path: string | null): {
|
||||
data: T | null;
|
||||
|
||||
Generated
+59
-15
@@ -67,7 +67,6 @@
|
||||
"integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.29.7",
|
||||
"@babel/generator": "^7.29.7",
|
||||
@@ -277,10 +276,32 @@
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/core": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.1.tgz",
|
||||
"integrity": "sha512-RSvbQmHzdKzNsLYa/wHrbc3KN4sYLKAdPZxqiM2HATqv/SBk2/ENSHpvXGaLOMcsAyz0poEGqkmmKYG3OWiJEQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/wasi-threads": "1.2.2",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.1.tgz",
|
||||
"integrity": "sha512-vgj7R3y3Wgx24IQaGPA/R6YFXLHVMOZ0uVEyIQPaWs+rd1AzfEMXlAC22FYwO1XkKR6NPsq7mUandH8oIRdZFw==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/wasi-threads": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz",
|
||||
"integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==",
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.2.tgz",
|
||||
"integrity": "sha512-c95qOXkHdydNKhscBTebqEC1CVAZpyqOfVfBzQ1qgzyl3gfeldUjIggDbIZgDKsHLgnsM+igH7TJ/eAasaVuMA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
@@ -1560,7 +1581,6 @@
|
||||
"integrity": "sha512-esJiCAnl0kfpNdE69f3So4WJUXy95dLZydX0KwK46riIHDzHM7O9Vtf9xCHW0PXIqvgqNrswl522kA/5yx+F4w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"csstype": "^3.2.2"
|
||||
}
|
||||
@@ -1620,7 +1640,6 @@
|
||||
"integrity": "sha512-A0M6ua6H252bVjPvvtSgl2QA4+ET9S5Mtkb2GDyTxIhH/C4qDItT7RQNO5PhMC6NXGYXOR9dIalcDDgBKT7oFA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "8.60.1",
|
||||
"@typescript-eslint/types": "8.60.1",
|
||||
@@ -2142,6 +2161,40 @@
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@unrs/resolver-binding-wasm32-wasi/node_modules/@emnapi/core": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz",
|
||||
"integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/wasi-threads": "1.2.1",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@unrs/resolver-binding-wasm32-wasi/node_modules/@emnapi/runtime": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz",
|
||||
"integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@unrs/resolver-binding-wasm32-wasi/node_modules/@emnapi/wasi-threads": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz",
|
||||
"integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@unrs/resolver-binding-win32-arm64-msvc": {
|
||||
"version": "1.12.2",
|
||||
"resolved": "https://registry.npmjs.org/@unrs/resolver-binding-win32-arm64-msvc/-/resolver-binding-win32-arm64-msvc-1.12.2.tgz",
|
||||
@@ -2190,7 +2243,6 @@
|
||||
"integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@@ -2534,7 +2586,6 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"baseline-browser-mapping": "^2.10.12",
|
||||
"caniuse-lite": "^1.0.30001782",
|
||||
@@ -3102,7 +3153,6 @@
|
||||
"integrity": "sha512-XoMjdBOwe/esVgEvLmNsD3IRHkm7fbKIUGvrleloJXUZgDHig2IPWNniv+GwjyJXzuNqVjlr5+4yVUZjycJwfQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.8.0",
|
||||
"@eslint-community/regexpp": "^4.12.1",
|
||||
@@ -3288,7 +3338,6 @@
|
||||
"integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@rtsao/scc": "^1.1.0",
|
||||
"array-includes": "^3.1.9",
|
||||
@@ -5475,7 +5524,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-19.2.4.tgz",
|
||||
"integrity": "sha512-9nfp2hYpCwOjAN+8TZFGhtWEwgvWHXqESH8qT89AT/lWklpLON22Lc8pEtnpsZz7VmawabSU0gCjnj8aC0euHQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
@@ -5485,7 +5533,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.4.tgz",
|
||||
"integrity": "sha512-AXJdLo8kgMbimY95O2aKQqsz2iWi9jMgKJhRBAxECE4IFxfcazB2LmzloIoibJI3C12IlY20+KFaLv+71bUJeQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"scheduler": "^0.27.0"
|
||||
},
|
||||
@@ -6177,7 +6224,6 @@
|
||||
"integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -6340,7 +6386,6 @@
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
@@ -6619,7 +6664,6 @@
|
||||
"integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
|
||||
+4
-1
@@ -22,7 +22,10 @@ DEPLOY_USER="${DEPLOY_USER:-ubuntu}"
|
||||
DEPLOY_PATH="${DEPLOY_PATH:-/var/www/aramland-admin}"
|
||||
DEPLOY_PASSWORD="${DEPLOY_PASSWORD:-}"
|
||||
|
||||
echo "▸ Building locally…"
|
||||
echo "▸ Building locally (clean)…"
|
||||
# Remove caches so the production build never type-checks a stale `.next/dev`
|
||||
# validator (tsconfig includes .next/dev/types) and never ships stale out/ files.
|
||||
rm -rf .next out
|
||||
npm run build
|
||||
|
||||
if [ ! -d out ]; then
|
||||
|
||||
Reference in New Issue
Block a user