Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfcddb55bb | ||
|
|
034a345521 | ||
|
|
504b1e2c8e | ||
|
|
60a054710a | ||
|
|
1b2d2dec7d | ||
|
|
e374829358 | ||
|
|
7c6d16693c | ||
|
|
3cc1d1385c | ||
|
|
bd71076c72 | ||
|
|
944d3bc00a |
Regular → Executable
@@ -10,6 +10,7 @@ import {
|
||||
ConfirmDialog,
|
||||
Field,
|
||||
Input,
|
||||
Select,
|
||||
Textarea,
|
||||
Modal,
|
||||
PageHeader,
|
||||
@@ -19,24 +20,42 @@ import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { pickUrl } from "@/lib/media";
|
||||
import { toFa } from "@/lib/utils";
|
||||
|
||||
type CategoryType = "media" | "playlist" | "breathing_template";
|
||||
|
||||
interface Category {
|
||||
id: number;
|
||||
name: string;
|
||||
type: CategoryType;
|
||||
description?: string | null;
|
||||
icon?: string | null;
|
||||
subcategories_count?: number;
|
||||
}
|
||||
|
||||
// General category types, shared across media, playlists and breathing templates.
|
||||
const TYPE_OPTIONS: { value: CategoryType; label: string }[] = [
|
||||
{ value: "media", label: "رسانه" },
|
||||
{ value: "playlist", label: "پلیلیست" },
|
||||
{ value: "breathing_template", label: "قالب تنفس" },
|
||||
];
|
||||
|
||||
const TYPE_LABELS: Record<CategoryType, string> = Object.fromEntries(
|
||||
TYPE_OPTIONS.map((o) => [o.value, o.label]),
|
||||
) as Record<CategoryType, string>;
|
||||
|
||||
// The icon is a direct image-file field on the category (not an image_id ref).
|
||||
const ICON_KEYS = ["icon", "icon_url"];
|
||||
|
||||
export default function MediaCategoriesPage() {
|
||||
const { data, loading, error, reload } = useList<Category>("/categories");
|
||||
export default function CategoriesPage() {
|
||||
const [typeFilter, setTypeFilter] = useState<CategoryType>("media");
|
||||
const { data, loading, error, reload } = useList<Category>("/categories", {
|
||||
type: typeFilter,
|
||||
});
|
||||
const toast = useToast();
|
||||
|
||||
const [editing, setEditing] = useState<Category | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [type, setType] = useState<CategoryType>("media");
|
||||
const [description, setDescription] = useState("");
|
||||
const [icon, setIcon] = useState<File | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
@@ -47,6 +66,7 @@ export default function MediaCategoriesPage() {
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setName("");
|
||||
setType(typeFilter);
|
||||
setDescription("");
|
||||
setIcon(null);
|
||||
setOpen(true);
|
||||
@@ -54,6 +74,7 @@ export default function MediaCategoriesPage() {
|
||||
function openEdit(row: Category) {
|
||||
setEditing(row);
|
||||
setName(row.name ?? "");
|
||||
setType(row.type ?? "media");
|
||||
setDescription(row.description ?? "");
|
||||
setIcon(null);
|
||||
setOpen(true);
|
||||
@@ -68,6 +89,7 @@ export default function MediaCategoriesPage() {
|
||||
const body = toFormData({
|
||||
_method: "PUT",
|
||||
name,
|
||||
type,
|
||||
description,
|
||||
icon,
|
||||
});
|
||||
@@ -76,7 +98,7 @@ export default function MediaCategoriesPage() {
|
||||
} else {
|
||||
await apiFetch("/categories", {
|
||||
method: "POST",
|
||||
body: toFormData({ name, description, icon }),
|
||||
body: toFormData({ name, type, description, icon }),
|
||||
});
|
||||
toast.success("دستهبندی افزوده شد.");
|
||||
}
|
||||
@@ -114,6 +136,12 @@ export default function MediaCategoriesPage() {
|
||||
),
|
||||
},
|
||||
{ key: "name", header: "نام دستهبندی" },
|
||||
{
|
||||
key: "type",
|
||||
header: "نوع",
|
||||
render: (r) => TYPE_LABELS[r.type] ?? r.type,
|
||||
className: "w-28",
|
||||
},
|
||||
{
|
||||
key: "description",
|
||||
header: "توضیحات",
|
||||
@@ -130,12 +158,26 @@ export default function MediaCategoriesPage() {
|
||||
return (
|
||||
<div>
|
||||
<PageHeader
|
||||
title="دستهبندی رسانهها"
|
||||
subtitle="مدیریت دستهبندیهای اصلی محتوای صوتی و تصویری"
|
||||
title="دستهبندیها"
|
||||
subtitle="مدیریت دستهبندیهای عمومی رسانه، پلیلیست و قالب تنفس"
|
||||
action={
|
||||
<div className="flex items-center gap-3">
|
||||
<Select
|
||||
value={typeFilter}
|
||||
onChange={(e) => setTypeFilter(e.target.value as CategoryType)}
|
||||
aria-label="نوع دستهبندی"
|
||||
className="w-40"
|
||||
>
|
||||
{TYPE_OPTIONS.map((o) => (
|
||||
<option key={o.value} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
<Button icon={<PlusIcon className="h-4 w-4" />} onClick={openCreate}>
|
||||
دستهبندی جدید
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -184,6 +226,19 @@ export default function MediaCategoriesPage() {
|
||||
}
|
||||
>
|
||||
<form id="category-form" onSubmit={save} className="flex flex-col gap-4">
|
||||
<Field label="نوع" required>
|
||||
<Select
|
||||
value={type}
|
||||
onChange={(e) => setType(e.target.value as CategoryType)}
|
||||
>
|
||||
{TYPE_OPTIONS.map((o) => (
|
||||
<option key={o.value} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
<Field label="نام دستهبندی" required>
|
||||
<Input
|
||||
value={name}
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
Badge,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { formatMinutes } from "@/lib/utils";
|
||||
import { formatMinutes, fileNameToTitle } from "@/lib/utils";
|
||||
import { MediaPreview } from "@/components/MediaPreview";
|
||||
import { ImagePicker } from "@/components/ImagePicker";
|
||||
import { pickUrl, SOUND_KEYS, VIDEO_KEYS, IMAGE_KEYS } from "@/lib/media";
|
||||
@@ -85,7 +85,9 @@ function ChipMultiSelect({
|
||||
export default function MediaPage() {
|
||||
const [search, setSearch] = useState("");
|
||||
const { data, loading, error, reload } = useList<Media>("/media", { search });
|
||||
const { data: categories } = useList<Category>("/categories");
|
||||
const { data: categories } = useList<Category>("/categories", {
|
||||
type: "media",
|
||||
});
|
||||
const { data: subCategories } = useList<Category>("/sub-categories");
|
||||
const toast = useToast();
|
||||
|
||||
@@ -397,7 +399,12 @@ export default function MediaPage() {
|
||||
<Input
|
||||
type="file"
|
||||
accept="audio/*,video/*"
|
||||
onChange={(e) => setFile(e.target.files?.[0] ?? null)}
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0] ?? null;
|
||||
setFile(f);
|
||||
// Fill the title from the file name if still empty.
|
||||
if (f && !title.trim()) setTitle(fileNameToTitle(f.name));
|
||||
}}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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,13 +13,22 @@ import {
|
||||
Select,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Pagination,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
import { formatMinutes } from "@/lib/utils";
|
||||
import { formatMinutes, fileNameToTitle } from "@/lib/utils";
|
||||
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)}
|
||||
@@ -301,7 +351,12 @@ export default function MusicTracksPage() {
|
||||
<Input
|
||||
type="file"
|
||||
accept="audio/*"
|
||||
onChange={(e) => setFile(e.target.files?.[0] ?? null)}
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0] ?? null;
|
||||
setFile(f);
|
||||
// Fill the title from the file name if still empty.
|
||||
if (f && !title.trim()) setTitle(fileNameToTitle(f.name));
|
||||
}}
|
||||
required={!editing}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
Input,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Select,
|
||||
Switch,
|
||||
} from "@/components/ui";
|
||||
import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons";
|
||||
@@ -20,21 +21,59 @@ 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;
|
||||
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 [image, setImage] = useState<File | null>(null);
|
||||
const [video, setVideo] = useState<File | null>(null);
|
||||
@@ -48,6 +87,7 @@ export default function ScenesPage() {
|
||||
setEditing(null);
|
||||
setName("");
|
||||
setOrder("");
|
||||
setThemeId("");
|
||||
setIsActive(true);
|
||||
setImage(null);
|
||||
setVideo(null);
|
||||
@@ -58,6 +98,7 @@ 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);
|
||||
setImage(null);
|
||||
setVideo(null);
|
||||
@@ -73,6 +114,7 @@ export default function ScenesPage() {
|
||||
const body = toFormData({
|
||||
name,
|
||||
order,
|
||||
theme_id: themeId,
|
||||
is_active: isActive,
|
||||
image,
|
||||
video,
|
||||
@@ -112,6 +154,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: "تصویر",
|
||||
@@ -236,6 +283,24 @@ 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="فعال" />
|
||||
|
||||
<Field
|
||||
|
||||
@@ -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"
|
||||
|
||||
+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,
|
||||
|
||||
+9
-5
@@ -33,14 +33,18 @@ export const NAV: NavSection[] = [
|
||||
icon: HomeIcon,
|
||||
items: [{ href: "/dashboard", label: "خانه" }],
|
||||
},
|
||||
{
|
||||
label: "عمومی",
|
||||
icon: TagIcon,
|
||||
items: [
|
||||
{ href: "/dashboard/categories", label: "دستهبندیها" },
|
||||
{ href: "/dashboard/sub-categories", label: "زیردستهها" },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "رسانهها",
|
||||
icon: MediaIcon,
|
||||
items: [
|
||||
{ href: "/dashboard/media", label: "فهرست رسانهها" },
|
||||
{ href: "/dashboard/media/categories", label: "دستهبندیها" },
|
||||
{ href: "/dashboard/media/sub-categories", label: "زیردستهها" },
|
||||
],
|
||||
items: [{ href: "/dashboard/media", label: "فهرست رسانهها" }],
|
||||
},
|
||||
{
|
||||
label: "موسیقی",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -19,6 +19,16 @@ export function formatDuration(seconds?: number | null): string {
|
||||
return toFa(`${m}:${String(s).padStart(2, "0")}`);
|
||||
}
|
||||
|
||||
// Derive a clean title from an uploaded file name: drop the extension and turn
|
||||
// underscores/dashes into spaces (e.g. "morning_calm-01.mp3" -> "morning calm 01").
|
||||
export function fileNameToTitle(name: string): string {
|
||||
return name
|
||||
.replace(/\.[^./\\]+$/, "")
|
||||
.replace(/[_-]+/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
// Minutes -> Persian label. Media and music store `duration` in minutes.
|
||||
export function formatMinutes(minutes?: number | null): string {
|
||||
if (minutes === null || minutes === undefined) return "—";
|
||||
|
||||
Generated
+1
-24
@@ -277,30 +277,6 @@
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"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,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@emnapi/wasi-threads": "1.2.1",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"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==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"peer": 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",
|
||||
@@ -3312,6 +3288,7 @@
|
||||
"integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@rtsao/scc": "^1.1.0",
|
||||
"array-includes": "^3.1.9",
|
||||
|
||||
Regular → Executable
+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