feat(dashboard): Discounts details + edits (#6547)
**What** - Discounts details page - Edit discount details - Edit discount configurations - `ListSummary` component **NOTE** - conditions edit form will be implemented in a separate PR - edit details from is missing metadata component which will be added later --- https://github.com/medusajs/medusa/assets/16856471/c878af4a-48c2-4c45-b824-662784c7a139
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Pick properties from an object and copy them to a new object
|
||||
* @param obj
|
||||
* @param keys
|
||||
*/
|
||||
export function pick(obj: Record<string, any>, keys: string[]) {
|
||||
const ret: Record<string, any> = {}
|
||||
|
||||
keys.forEach((k) => {
|
||||
if (k in obj) {
|
||||
ret[k] = obj[k]
|
||||
}
|
||||
})
|
||||
|
||||
return ret
|
||||
}
|
||||
@@ -728,3 +728,7 @@ export const currencies: Record<string, CurrencyInfo> = {
|
||||
decimal_digits: 0,
|
||||
},
|
||||
}
|
||||
|
||||
export function getCurrencySymbol(code: string) {
|
||||
return currencies[code.toUpperCase()].symbol_native
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Discount } from "@medusajs/medusa"
|
||||
import { end, parse } from "iso8601-duration"
|
||||
|
||||
export enum PromotionStatus {
|
||||
SCHEDULED = "SCHEDULED",
|
||||
EXPIRED = "EXPIRED",
|
||||
ACTIVE = "ACTIVE",
|
||||
DISABLED = "DISABLED",
|
||||
}
|
||||
|
||||
export const getDiscountStatus = (discount: Discount) => {
|
||||
if (discount.is_disabled) {
|
||||
return PromotionStatus.DISABLED
|
||||
}
|
||||
|
||||
const date = new Date()
|
||||
if (new Date(discount.starts_at) > date) {
|
||||
return PromotionStatus.SCHEDULED
|
||||
}
|
||||
|
||||
if (
|
||||
(discount.ends_at && new Date(discount.ends_at) < date) ||
|
||||
(discount.valid_duration &&
|
||||
date >
|
||||
end(parse(discount.valid_duration), new Date(discount.starts_at))) ||
|
||||
discount.usage_count === discount.usage_limit
|
||||
) {
|
||||
return PromotionStatus.EXPIRED
|
||||
}
|
||||
|
||||
return PromotionStatus.ACTIVE
|
||||
}
|
||||
Reference in New Issue
Block a user