chore: remove unused filter modal
remove old cms model refactor reward types
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { Reward } from "@/types/components/myPages/rewards"
|
||||
import type { ComparisonLevel } from "@/types/components/overviewTable"
|
||||
import type { CMSReward } from "@/types/trpc/routers/contentstack/reward"
|
||||
|
||||
export function getGroupedRewards(levels: ComparisonLevel[]) {
|
||||
const allRewards = levels
|
||||
@@ -8,7 +8,7 @@ export function getGroupedRewards(levels: ComparisonLevel[]) {
|
||||
})
|
||||
.flat()
|
||||
|
||||
const mappedRewards = allRewards.reduce<Record<string, Reward[]>>(
|
||||
const mappedRewards = allRewards.reduce<Record<string, CMSReward[]>>(
|
||||
(acc, curr) => {
|
||||
const taxonomiTerm = curr.taxonomies.find((tax) => tax.term_uid)?.term_uid
|
||||
|
||||
@@ -38,10 +38,8 @@ export function findAvailableRewards(
|
||||
return level.rewards.find((r) => allRewardIds.includes(r.reward_id))
|
||||
}
|
||||
|
||||
export function getGroupedLabelAndDescription(rewards: Reward[]) {
|
||||
const reward = rewards.find(
|
||||
(reward) => !!(reward.grouped_label && reward.grouped_label)
|
||||
)
|
||||
export function getGroupedLabelAndDescription(rewards: CMSReward[]) {
|
||||
const reward = rewards.find((reward) => !!reward.grouped_label)
|
||||
return {
|
||||
label: reward?.grouped_label ?? "",
|
||||
description: reward?.grouped_description ?? "",
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
import {
|
||||
RESTAURANT_REWARD_IDS,
|
||||
REWARD_CATEGORIES,
|
||||
REWARD_IDS,
|
||||
} from "@/constants/rewards"
|
||||
import { RESTAURANT_REWARD_IDS, REWARD_IDS } from "@/constants/rewards"
|
||||
import { dt } from "@/lib/dt"
|
||||
|
||||
import type { Dayjs } from "dayjs"
|
||||
|
||||
import type {
|
||||
RestaurantRewardId,
|
||||
RewardCategory,
|
||||
RewardId,
|
||||
} from "@/types/components/myPages/rewards"
|
||||
import type {
|
||||
ApiReward,
|
||||
RedeemableCoupon,
|
||||
RedeemLocation,
|
||||
} from "@/server/routers/contentstack/reward/output"
|
||||
SurpriseReward,
|
||||
} from "@/types/trpc/routers/contentstack/reward"
|
||||
|
||||
export {
|
||||
getEarliestExpirationDate,
|
||||
getFirstRedeemableCoupon,
|
||||
getRedeemableRewards,
|
||||
getReedemableCoupons,
|
||||
getUnwrappedSurpriseRewards,
|
||||
isOnSiteTierReward,
|
||||
isRestaurantOnSiteTierReward,
|
||||
isRestaurantReward,
|
||||
isRewardCategory,
|
||||
isSurpriseReward,
|
||||
isTierType,
|
||||
isValidRewardId,
|
||||
redeemLocationIsOnSite,
|
||||
@@ -39,10 +37,6 @@ function isRestaurantReward(rewardId: string): rewardId is RestaurantRewardId {
|
||||
return RESTAURANT_REWARD_IDS.some((id) => id === rewardId)
|
||||
}
|
||||
|
||||
function isRewardCategory(value: string): value is RewardCategory {
|
||||
return REWARD_CATEGORIES.some((category) => category === value)
|
||||
}
|
||||
|
||||
function redeemLocationIsOnSite(
|
||||
location: RedeemLocation
|
||||
): location is "On-site" {
|
||||
@@ -94,3 +88,37 @@ function getEarliestExpirationDate(reward: ApiReward) {
|
||||
return earliestDate.isBefore(expiresAtDate) ? earliestDate : expiresAtDate
|
||||
}, null)
|
||||
}
|
||||
|
||||
function isSurpriseReward(reward: ApiReward): reward is SurpriseReward {
|
||||
return reward.rewardType === "Surprise"
|
||||
}
|
||||
|
||||
function getUnwrappedSurpriseRewards(rewards: ApiReward[]) {
|
||||
return rewards
|
||||
.filter(isSurpriseReward)
|
||||
.filter((reward) => getReedemableCoupons(reward).length)
|
||||
.filter((reward) => {
|
||||
const unwrappedCoupons =
|
||||
reward.coupon.filter((coupon) => !coupon.unwrapped) || []
|
||||
|
||||
return unwrappedCoupons.length
|
||||
})
|
||||
}
|
||||
|
||||
function getRedeemableRewards(rewards: ApiReward[]) {
|
||||
return rewards
|
||||
.filter((reward) => {
|
||||
if ("coupon" in reward && reward.coupon.length > 0) {
|
||||
if (reward.coupon.every((coupon) => coupon.state === "redeemed")) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
.filter((reward) => {
|
||||
if (isSurpriseReward(reward)) {
|
||||
return !reward.coupon.some(({ unwrapped }) => !unwrapped)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user