campain list
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
hamid zarghami
2026-07-04 16:13:18 +03:30
parent 9f18e33ef6
commit 57284c0641
2 changed files with 84 additions and 10 deletions
@@ -1,11 +1,18 @@
import Status from "@/components/Status";
import type { ColumnType } from "@/components/types/TableTypes";
import { formatOptionalDate } from "@/helpers/func";
import { formatFaNumber, formatOptionalDate, formatPrice } from "@/helpers/func";
import type { Campaign } from "../types/Types";
const getGroupNames = (groups: Campaign["groups"]) => {
if (!groups?.length) return "-";
return groups.map((group) => (typeof group === "string" ? group : group.name)).join(" ، ");
return groups
.map((group) => {
if (typeof group === "string") return group;
const count = group.count != null ? ` (${formatFaNumber(group.count)})` : "";
return `${group.name}${count}`;
})
.join(" ، ");
};
const sentTypeLabels: Record<string, string> = {
@@ -13,6 +20,25 @@ const sentTypeLabels: Record<string, string> = {
sms: "پیامک",
};
const statusLabels: Record<string, string> = {
pending: "در انتظار",
processing: "در حال ارسال",
completed: "تکمیل شده",
failed: "ناموفق",
partial: "ناقص",
};
const getStatusVariant = (status: string): "success" | "error" | "warning" | "info" | "pending" => {
const variantMap: Record<string, "success" | "error" | "warning" | "info" | "pending"> = {
pending: "pending",
processing: "info",
completed: "success",
failed: "error",
partial: "warning",
};
return variantMap[status] || "pending";
};
export const getCampaignTableColumns = (): ColumnType<Campaign>[] => {
return [
{
@@ -40,15 +66,49 @@ export const getCampaignTableColumns = (): ColumnType<Campaign>[] => {
title: "گروه‌ها",
render: (item: Campaign) => getGroupNames(item.groups),
},
{
key: "status",
title: "وضعیت",
render: (item: Campaign) => (
<Status variant={getStatusVariant(item.status)} label={statusLabels[item.status] || item.status} />
),
},
{
key: "totalCount",
title: "تعداد کل",
render: (item: Campaign) => formatFaNumber(item.totalCount),
},
{
key: "sentCount",
title: "ارسال موفق",
render: (item: Campaign) => formatFaNumber(item.sentCount),
},
{
key: "failedCount",
title: "ارسال ناموفق",
render: (item: Campaign) => formatFaNumber(item.failedCount),
},
{
key: "totalCost",
title: "هزینه کل",
render: (item: Campaign) => formatPrice(item.totalCost),
},
{
key: "refunded",
title: "بازگشتی",
render: (item: Campaign) => formatPrice(item.refunded),
},
{
key: "createdAt",
title: "تاریخ ایجاد",
render: (item: Campaign) => formatOptionalDate(item.createdAt),
render: (item: Campaign) =>
formatOptionalDate(item.createdAt, {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
}),
},
// {
// key: "actions",
// title: "",
// render: (item: Campaign) => (onDelete ? <TrashWithConfrim onDelete={() => onDelete(item.id)} isloading={isDeleting} /> : null),
// },
];
};
+16 -2
View File
@@ -3,16 +3,30 @@ import type { IResponse } from "@/types/response.types";
export type CampaignSentType = "push" | "sms";
export type CampaignStatus = "pending" | "processing" | "completed" | "failed" | "partial";
export type CampaignGroup = UserGroup & {
restaurant?: string;
count?: number;
};
export type Campaign = {
id: string;
createdAt: string;
updatedAt: string;
deletedAt: string | null;
restaurant?: string;
title: string;
groups: UserGroup[] | string[];
groups: CampaignGroup[] | string[];
sentType: CampaignSentType;
discountCode: string;
ocasion: string;
ocasion?: string;
totalCount: number;
totalCost: number;
refunded: number;
sentCount: number;
failedCount: number;
status: CampaignStatus | string;
};
export type PaginationMeta = {