chore: remove unused filter modal
remove old cms model refactor reward types
This commit is contained in:
@@ -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