feat(SW-556): add surprise notification component
This commit is contained in:
@@ -17,3 +17,7 @@ export const rewardsCurrentInput = z.object({
|
||||
cursor: z.number().optional().default(0),
|
||||
lang: z.nativeEnum(Lang).optional(),
|
||||
})
|
||||
|
||||
export const rewardsUpdateInput = z.object({
|
||||
id: z.string(),
|
||||
})
|
||||
|
||||
@@ -2,10 +2,10 @@ import { z } from "zod"
|
||||
|
||||
import { MembershipLevelEnum } from "@/constants/membershipLevels"
|
||||
|
||||
export const validateApiRewardSchema = z.object({
|
||||
data: z.array(
|
||||
z
|
||||
.object({
|
||||
export const validateApiRewardSchema = z
|
||||
.object({
|
||||
data: z.array(
|
||||
z.object({
|
||||
title: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
type: z.string().optional(),
|
||||
@@ -16,9 +16,9 @@ export const validateApiRewardSchema = z.object({
|
||||
rewardType: z.string().optional(),
|
||||
rewardTierLevel: z.string().optional(),
|
||||
})
|
||||
.optional()
|
||||
),
|
||||
})
|
||||
),
|
||||
})
|
||||
.transform((data) => data.data)
|
||||
|
||||
enum TierKey {
|
||||
tier1 = MembershipLevelEnum.L1,
|
||||
@@ -37,19 +37,17 @@ export const validateApiTierRewardsSchema = z.record(
|
||||
return TierKey[data as unknown as Key]
|
||||
}),
|
||||
z.array(
|
||||
z
|
||||
.object({
|
||||
title: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
type: z.string().optional(),
|
||||
status: z.string().optional(),
|
||||
rewardId: z.string().optional(),
|
||||
redeemLocation: z.string().optional(),
|
||||
autoApplyReward: z.boolean().default(false),
|
||||
rewardType: z.string().optional(),
|
||||
rewardTierLevel: z.string().optional(),
|
||||
})
|
||||
.optional()
|
||||
z.object({
|
||||
title: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
type: z.string().optional(),
|
||||
status: z.string().optional(),
|
||||
rewardId: z.string().optional(),
|
||||
redeemLocation: z.string().optional(),
|
||||
autoApplyReward: z.boolean().default(false),
|
||||
rewardType: z.string().optional(),
|
||||
rewardTierLevel: z.string().optional(),
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
@@ -77,6 +75,8 @@ export const validateCmsRewardsSchema = z
|
||||
})
|
||||
.transform((data) => data.data.all_reward.items)
|
||||
|
||||
export type ApiReward = z.output<typeof validateApiRewardSchema>[0]
|
||||
|
||||
export type CmsRewardsResponse = z.input<typeof validateCmsRewardsSchema>
|
||||
|
||||
export type Reward = z.output<typeof validateCmsRewardsSchema>[0]
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
rewardsAllInput,
|
||||
rewardsByLevelInput,
|
||||
rewardsCurrentInput,
|
||||
rewardsUpdateInput,
|
||||
} from "./input"
|
||||
import {
|
||||
CmsRewardsResponse,
|
||||
@@ -242,10 +243,10 @@ export const rewardQueryRouter = router({
|
||||
return null
|
||||
}
|
||||
|
||||
const rewardIds = validatedApiRewards.data.data
|
||||
const rewardIds = validatedApiRewards.data
|
||||
.map((reward) => reward?.rewardId)
|
||||
.filter(Boolean)
|
||||
.sort() as string[]
|
||||
.filter((rewardId): rewardId is string => !!rewardId)
|
||||
.sort()
|
||||
|
||||
const slicedData = rewardIds.slice(cursor, limit + cursor)
|
||||
|
||||
@@ -259,8 +260,35 @@ export const rewardQueryRouter = router({
|
||||
limit + cursor < rewardIds.length ? limit + cursor : undefined
|
||||
|
||||
getCurrentRewardSuccessCounter.add(1)
|
||||
|
||||
return {
|
||||
rewards: cmsRewards,
|
||||
apiRewards: validatedApiRewards.data
|
||||
// FIXME: Remove these mocks before merging
|
||||
.concat([
|
||||
{
|
||||
autoApplyReward: false,
|
||||
title: "Free kids drink when staying",
|
||||
id: "fake-id",
|
||||
type: "surprise",
|
||||
status: "active",
|
||||
rewardId: "tier_free_kids_drink",
|
||||
redeemLocation: "On-site",
|
||||
rewardType: "Tier",
|
||||
rewardTierLevel: "L1",
|
||||
},
|
||||
{
|
||||
autoApplyReward: false,
|
||||
title: "Free kanelbulle",
|
||||
id: "fake-id-2",
|
||||
type: "surprise",
|
||||
status: "active",
|
||||
rewardId: "tier_free_kanelbulle",
|
||||
redeemLocation: "On-site",
|
||||
rewardType: "Tier",
|
||||
rewardTierLevel: "L1",
|
||||
},
|
||||
]),
|
||||
nextCursor,
|
||||
}
|
||||
}),
|
||||
@@ -374,4 +402,19 @@ export const rewardQueryRouter = router({
|
||||
getAllRewardSuccessCounter.add(1)
|
||||
return levelsWithRewards
|
||||
}),
|
||||
update: contentStackBaseWithProtectedProcedure
|
||||
.input(rewardsUpdateInput)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const response = await Promise.resolve({ ok: true })
|
||||
// const response = await api.post(api.endpoints.v1.rewards, {
|
||||
// body: {
|
||||
// ids: [input.id],
|
||||
// },
|
||||
// })
|
||||
if (!response.ok) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user