This commit is contained in:
@@ -1,11 +1,18 @@
|
|||||||
|
import Status from "@/components/Status";
|
||||||
import type { ColumnType } from "@/components/types/TableTypes";
|
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";
|
import type { Campaign } from "../types/Types";
|
||||||
|
|
||||||
const getGroupNames = (groups: Campaign["groups"]) => {
|
const getGroupNames = (groups: Campaign["groups"]) => {
|
||||||
if (!groups?.length) return "-";
|
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> = {
|
const sentTypeLabels: Record<string, string> = {
|
||||||
@@ -13,6 +20,25 @@ const sentTypeLabels: Record<string, string> = {
|
|||||||
sms: "پیامک",
|
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>[] => {
|
export const getCampaignTableColumns = (): ColumnType<Campaign>[] => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -40,15 +66,49 @@ export const getCampaignTableColumns = (): ColumnType<Campaign>[] => {
|
|||||||
title: "گروهها",
|
title: "گروهها",
|
||||||
render: (item: Campaign) => getGroupNames(item.groups),
|
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",
|
key: "createdAt",
|
||||||
title: "تاریخ ایجاد",
|
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),
|
|
||||||
// },
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,16 +3,30 @@ import type { IResponse } from "@/types/response.types";
|
|||||||
|
|
||||||
export type CampaignSentType = "push" | "sms";
|
export type CampaignSentType = "push" | "sms";
|
||||||
|
|
||||||
|
export type CampaignStatus = "pending" | "processing" | "completed" | "failed" | "partial";
|
||||||
|
|
||||||
|
export type CampaignGroup = UserGroup & {
|
||||||
|
restaurant?: string;
|
||||||
|
count?: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type Campaign = {
|
export type Campaign = {
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
deletedAt: string | null;
|
deletedAt: string | null;
|
||||||
|
restaurant?: string;
|
||||||
title: string;
|
title: string;
|
||||||
groups: UserGroup[] | string[];
|
groups: CampaignGroup[] | string[];
|
||||||
sentType: CampaignSentType;
|
sentType: CampaignSentType;
|
||||||
discountCode: string;
|
discountCode: string;
|
||||||
ocasion: string;
|
ocasion?: string;
|
||||||
|
totalCount: number;
|
||||||
|
totalCost: number;
|
||||||
|
refunded: number;
|
||||||
|
sentCount: number;
|
||||||
|
failedCount: number;
|
||||||
|
status: CampaignStatus | string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PaginationMeta = {
|
export type PaginationMeta = {
|
||||||
|
|||||||
Reference in New Issue
Block a user