refactor(SW-556): project specific fixes
This commit is contained in:
@@ -13,13 +13,8 @@ import Surprises from "../Surprises"
|
|||||||
|
|
||||||
import styles from "./current.module.css"
|
import styles from "./current.module.css"
|
||||||
|
|
||||||
type CurrentRewardsClientProps = {
|
import type { CurrentRewardsClientProps } from "@/types/components/blocks/currentRewards"
|
||||||
initialCurrentRewards: {
|
|
||||||
rewards: Reward[]
|
|
||||||
apiRewards: ApiReward[]
|
|
||||||
nextCursor: number | undefined
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default function ClientCurrentRewards({
|
export default function ClientCurrentRewards({
|
||||||
initialCurrentRewards,
|
initialCurrentRewards,
|
||||||
}: CurrentRewardsClientProps) {
|
}: CurrentRewardsClientProps) {
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import { useIntl } from "react-intl"
|
|||||||
|
|
||||||
import { benefits } from "@/constants/routes/myPages"
|
import { benefits } from "@/constants/routes/myPages"
|
||||||
import { trpc } from "@/lib/trpc/client"
|
import { trpc } from "@/lib/trpc/client"
|
||||||
import { ApiReward } from "@/server/routers/contentstack/reward/output"
|
|
||||||
|
|
||||||
import { ChevronRightSmallIcon, CloseLargeIcon } from "@/components/Icons"
|
import { ChevronRightSmallIcon, CloseLargeIcon } from "@/components/Icons"
|
||||||
import Image from "@/components/Image"
|
import Image from "@/components/Image"
|
||||||
import Button from "@/components/TempDesignSystem/Button"
|
import Button from "@/components/TempDesignSystem/Button"
|
||||||
|
import Link from "@/components/TempDesignSystem/Link"
|
||||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||||
import CaptionLabel from "@/components/TempDesignSystem/Text/CaptionLabel"
|
import CaptionLabel from "@/components/TempDesignSystem/Text/CaptionLabel"
|
||||||
@@ -20,9 +20,7 @@ import useLang from "@/hooks/useLang"
|
|||||||
|
|
||||||
import styles from "./surprises.module.css"
|
import styles from "./surprises.module.css"
|
||||||
|
|
||||||
interface SurprisesProps {
|
import type { SurprisesProps } from "@/types/components/blocks/surprises"
|
||||||
surprises: ApiReward[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Surprises({ surprises }: SurprisesProps) {
|
export default function Surprises({ surprises }: SurprisesProps) {
|
||||||
const lang = useLang()
|
const lang = useLang()
|
||||||
@@ -32,17 +30,38 @@ export default function Surprises({ surprises }: SurprisesProps) {
|
|||||||
const update = trpc.contentstack.rewards.update.useMutation()
|
const update = trpc.contentstack.rewards.update.useMutation()
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
|
|
||||||
if (!surprises.length) return null
|
if (!surprises.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
function showSurprise(n: number) {
|
function showSurprise(n: number) {
|
||||||
setSelectedSurprise((surprise) => surprise + n)
|
setSelectedSurprise((surprise) => surprise + n)
|
||||||
}
|
}
|
||||||
|
|
||||||
function viewRewards(id?: string) {
|
function viewRewards(id?: string) {
|
||||||
if (!id) return
|
if (!id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
update.mutate({ id })
|
update.mutate({ id })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closeModal(close: VoidFunction) {
|
||||||
|
viewRewards()
|
||||||
|
toast.success(
|
||||||
|
<>
|
||||||
|
{intl.formatMessage(
|
||||||
|
{ id: "Gift(s) added to your benefits" },
|
||||||
|
{ amount: surprises.length }
|
||||||
|
)}
|
||||||
|
<br />
|
||||||
|
<Link href={benefits[lang]}>
|
||||||
|
{intl.formatMessage({ id: "Go to My Benefits" })}
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
const surprise = surprises[selectedSurprise]
|
const surprise = surprises[selectedSurprise]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -69,22 +88,7 @@ export default function Surprises({ surprises }: SurprisesProps) {
|
|||||||
</CaptionLabel>
|
</CaptionLabel>
|
||||||
)}
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => closeModal(close)}
|
||||||
viewRewards()
|
|
||||||
toast.success(
|
|
||||||
<>
|
|
||||||
{intl.formatMessage(
|
|
||||||
{ id: "Gift(s) added to your benefits" },
|
|
||||||
{ amount: surprises.length }
|
|
||||||
)}
|
|
||||||
<br />
|
|
||||||
<a href={benefits[lang]}>
|
|
||||||
{intl.formatMessage({ id: "Go to My Benefits" })}
|
|
||||||
</a>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
close()
|
|
||||||
}}
|
|
||||||
type="button"
|
type="button"
|
||||||
className={styles.close}
|
className={styles.close}
|
||||||
>
|
>
|
||||||
@@ -113,7 +117,7 @@ export default function Surprises({ surprises }: SurprisesProps) {
|
|||||||
variant="icon"
|
variant="icon"
|
||||||
intent="tertiary"
|
intent="tertiary"
|
||||||
disabled={selectedSurprise === 0}
|
disabled={selectedSurprise === 0}
|
||||||
onClick={() => showSurprise(-1)}
|
onPress={() => showSurprise(-1)}
|
||||||
size="small"
|
size="small"
|
||||||
>
|
>
|
||||||
<ChevronRightSmallIcon
|
<ChevronRightSmallIcon
|
||||||
@@ -128,7 +132,7 @@ export default function Surprises({ surprises }: SurprisesProps) {
|
|||||||
variant="icon"
|
variant="icon"
|
||||||
intent="tertiary"
|
intent="tertiary"
|
||||||
disabled={selectedSurprise === surprises.length - 1}
|
disabled={selectedSurprise === surprises.length - 1}
|
||||||
onClick={() => showSurprise(1)}
|
onPress={() => showSurprise(1)}
|
||||||
size="small"
|
size="small"
|
||||||
>
|
>
|
||||||
{intl.formatMessage({ id: "Next" })}
|
{intl.formatMessage({ id: "Next" })}
|
||||||
|
|||||||
9
types/components/blocks/currentRewards.ts
Normal file
9
types/components/blocks/currentRewards.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { ApiReward, Reward } from "@/server/routers/contentstack/reward/output"
|
||||||
|
|
||||||
|
export type CurrentRewardsClientProps = {
|
||||||
|
initialCurrentRewards: {
|
||||||
|
rewards: Reward[]
|
||||||
|
apiRewards: ApiReward[]
|
||||||
|
nextCursor: number | undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
5
types/components/blocks/surprises.ts
Normal file
5
types/components/blocks/surprises.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { ApiReward } from "@/server/routers/contentstack/reward/output"
|
||||||
|
|
||||||
|
export interface SurprisesProps {
|
||||||
|
surprises: ApiReward[]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user