improvement for the backend api
This commit is contained in:
@@ -18,7 +18,12 @@ import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { creativesApi } from "@/lib/api";
|
||||
import { formatNumber, formatMetric, truncate } from "@/lib/utils/format";
|
||||
import {
|
||||
formatNumber,
|
||||
formatMetric,
|
||||
truncate,
|
||||
formatDate,
|
||||
} from "@/lib/utils/format";
|
||||
import {
|
||||
Folder,
|
||||
Loader2,
|
||||
@@ -48,7 +53,7 @@ export default function CreativesPage() {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await creativesApi.list();
|
||||
setCreatives(response.data);
|
||||
setCreatives(response.creatives);
|
||||
} catch (err: any) {
|
||||
setError(err?.error?.message || "Ошибка загрузки креативов");
|
||||
} finally {
|
||||
@@ -56,9 +61,13 @@ export default function CreativesPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleArchive = async (id: string, isArchived: boolean) => {
|
||||
const handleArchive = async (
|
||||
id: string,
|
||||
currentStatus: "active" | "archived"
|
||||
) => {
|
||||
try {
|
||||
await creativesApi.update(id, { is_archived: !isArchived });
|
||||
const newStatus = currentStatus === "active" ? "archived" : "active";
|
||||
await creativesApi.update(id, { status: newStatus });
|
||||
loadCreatives();
|
||||
} catch (err: any) {
|
||||
alert(err?.error?.message || "Ошибка обновления креатива");
|
||||
@@ -77,8 +86,8 @@ export default function CreativesPage() {
|
||||
};
|
||||
|
||||
const filteredCreatives = creatives.filter((creative) => {
|
||||
if (activeTab === "active") return !creative.is_archived;
|
||||
if (activeTab === "archived") return creative.is_archived;
|
||||
if (activeTab === "active") return creative.status === "active";
|
||||
if (activeTab === "archived") return creative.status === "archived";
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -117,10 +126,10 @@ export default function CreativesPage() {
|
||||
>
|
||||
<TabsList>
|
||||
<TabsTrigger value="active">
|
||||
Активные ({creatives.filter((c) => !c.is_archived).length})
|
||||
Активные ({creatives.filter((c) => c.status === "active").length})
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="archived">
|
||||
Архив ({creatives.filter((c) => c.is_archived).length})
|
||||
Архив ({creatives.filter((c) => c.status === "archived").length})
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="all">Все ({creatives.length})</TabsTrigger>
|
||||
</TabsList>
|
||||
@@ -166,12 +175,12 @@ export default function CreativesPage() {
|
||||
<CardTitle className="truncate text-base">
|
||||
{creative.name}
|
||||
</CardTitle>
|
||||
{creative.is_archived && (
|
||||
{creative.status === "archived" && (
|
||||
<Badge variant="secondary">Архив</Badge>
|
||||
)}
|
||||
</div>
|
||||
<CardDescription className="text-xs">
|
||||
{creative.target_channel.title}
|
||||
{creative.target_channel_title}
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Folder className="h-5 w-5 text-muted-foreground shrink-0" />
|
||||
@@ -184,29 +193,21 @@ export default function CreativesPage() {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-2 text-center">
|
||||
<div className="grid grid-cols-2 gap-2 text-center">
|
||||
<div className="rounded-lg border bg-muted/50 p-2">
|
||||
<div className="text-sm font-medium">
|
||||
{formatNumber(creative.total_purchases)}
|
||||
{formatNumber(creative.placements_count)}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Закупов
|
||||
Размещений
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-lg border bg-muted/50 p-2">
|
||||
<div className="text-sm font-medium">
|
||||
{formatNumber(creative.total_subscriptions)}
|
||||
<div className="text-xs font-medium">
|
||||
{formatDate(creative.created_at)}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Подписчиков
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-lg border bg-muted/50 p-2">
|
||||
<div className="text-sm font-medium">
|
||||
₽{formatMetric(creative.avg_cpf)}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
CPF
|
||||
Создан
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -227,7 +228,7 @@ export default function CreativesPage() {
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
handleArchive(creative.id, creative.is_archived)
|
||||
handleArchive(creative.id, creative.status)
|
||||
}
|
||||
>
|
||||
<Archive className="h-4 w-4" />
|
||||
|
||||
Reference in New Issue
Block a user