|
1
|
import { AdminCampaign } from "@medusajs/types" |
|
2
|
import { isAfter, isBefore } from "date-fns" |
|
3
|
|
|
4
|
export function campaignStatus(campaign: AdminCampaign) { |
|
5
|
if (campaign.ends_at) { |
|
6
|
if (isBefore(new Date(campaign.ends_at), new Date())) { |
|
7
|
return "expired" |
|
8
|
} |
|
9
|
} |
|
10
|
|
|
11
|
if (campaign.starts_at) { |
|
12
|
if (isAfter(new Date(campaign.starts_at), new Date())) { |
|
13
|
return "scheduled" |
|
14
|
} |
|
15
|
} |
|
16
|
|
|
17
|
return "active" |
|
18
|
} |
|
19
|
|
|
20
|
export const statusColor = (status: string) => { |
|
21
|
switch (status) { |
|
22
|
case "expired": |
|
23
|
return "red" |
|
24
|
case "scheduled": |
|
25
|
return "orange" |
|
26
|
case "active": |
|
27
|
return "green" |
|
28
|
default: |
|
29
|
return "grey" |
|
30
|
} |
|
31
|
} |