11import { useState , useEffect , useCallback , useRef , useMemo } from 'react'
22import { toast } from 'sonner'
3- import { Link , useLocation } from 'react-router-dom'
3+ import { useLocation } from 'react-router-dom'
44import { useAuthStore } from '../../stores/useAuthStore'
55import { createPortal } from 'react-dom'
66import {
@@ -54,11 +54,12 @@ interface RedemptionModalProps {
5454 reward : Reward
5555 spendablePoints : number
5656 onClose : ( ) => void
57+ onGoToMissions : ( ) => void
5758}
5859
5960type SheetState = 'confirm' | 'loading' | 'success' | 'error'
6061
61- function RedemptionModal ( { reward, spendablePoints, onClose } : RedemptionModalProps ) {
62+ function RedemptionModal ( { reward, spendablePoints, onClose, onGoToMissions } : RedemptionModalProps ) {
6263 const { redeemReward } = useRewardsStore ( )
6364 const [ sheetState , setSheetState ] = useState < SheetState > ( 'confirm' )
6465 const [ errorMessage , setErrorMessage ] = useState < string > ( '' )
@@ -144,13 +145,13 @@ function RedemptionModal({ reward, spendablePoints, onClose }: RedemptionModalPr
144145 </ p >
145146 < p className = "text-[12px] text-red/80" >
146147 You need { ( reward . points_cost - spendablePoints ) . toLocaleString ( ) } more points to redeem this item. Earn more by completing{ ' ' }
147- < Link
148- to = "/rewards"
148+ < button
149+ onClick = { ( ) => { handleClose ( ) ; onGoToMissions ( ) } }
149150 className = "font-semibold underline underline-offset-2"
150151 style = { { color : 'rgb(var(--color-primary))' } }
151152 >
152153 Missions
153- </ Link >
154+ </ button >
154155 !
155156 </ p >
156157 </ div >
@@ -975,15 +976,18 @@ const TABS = [
975976
976977export default function Rewards ( ) {
977978 const location = useLocation ( )
978- const initialExpandId = ( location . state as { expandMissionId ?: string } | null ) ?. expandMissionId
979+ const locationState = location . state as { expandMissionId ?: string ; tab ?: string } | null
980+ const initialExpandId = locationState ?. expandMissionId
979981 const { user } = useAuthStore ( )
980982 const { spendablePoints, loadTotalPoints } = usePointsStore ( )
981983 const { rewards, allRewards, fetchRewards, isLoading } = useRewardsStore ( )
982984 const [ selectedReward , setSelectedReward ] = useState < Reward | null > ( null )
983985 const [ selectedReceipt , setSelectedReceipt ] = useState < RewardRedemption | null > ( null )
984986 const [ activeTab , setActiveTab ] = useState < typeof TABS [ number ] [ 'id' ] > ( 'redeem' )
985987 const [ comingSoonFeature , setComingSoonFeature ] = useState < string | null > ( null )
986- const [ mainTab , setMainTab ] = useState < 'redeem' | 'missions' > ( 'missions' )
988+ const [ mainTab , setMainTab ] = useState < 'redeem' | 'missions' > (
989+ locationState ?. tab === 'missions' ? 'missions' : 'redeem'
990+ )
987991 const [ missionFilter , setMissionFilter ] = useState < MissionFilterId > ( 'all' )
988992
989993 useEffect ( ( ) => {
@@ -1065,7 +1069,7 @@ export default function Rewards() {
10651069 { /* ── Segmented Toggle: Missions / Redeem ── */ }
10661070 < div className = "pt-4 pb-2 px-4 pointer-events-auto" >
10671071 < div className = "inline-flex w-full gap-2 max-w-4xl mx-auto" >
1068- { ( [ 'missions ' , 'redeem ' ] as const ) . map ( ( t ) => (
1072+ { ( [ 'redeem ' , 'missions ' ] as const ) . map ( ( t ) => (
10691073 < button
10701074 key = { t }
10711075 onClick = { ( ) => setMainTab ( t ) }
@@ -1150,6 +1154,21 @@ export default function Rewards() {
11501154 ) ) }
11511155 </ motion . div >
11521156 ) }
1157+
1158+ { /* ── Missions CTA ── */ }
1159+ < div className = "mt-5 bg-slate-100 rounded-2xl px-4 py-4 flex items-center justify-center gap-2" >
1160+ < StarOutline color = "#F8C630" size = { 16 } />
1161+ < p className = "text-md3-body-md text-slate-700 font-proxima" >
1162+ Earn more XP, Go on a{ ' ' }
1163+ < button
1164+ onClick = { ( ) => setMainTab ( 'missions' ) }
1165+ className = "font-bold underline underline-offset-2"
1166+ style = { { color : 'rgb(var(--color-primary))' } }
1167+ >
1168+ Mission!
1169+ </ button >
1170+ </ p >
1171+ </ div >
11531172 </ >
11541173 ) : activeTab === 'receipts' ? (
11551174 < ClaimReceiptsTab onSelectReceipt = { setSelectedReceipt } />
@@ -1161,6 +1180,7 @@ export default function Rewards() {
11611180 reward = { selectedReward }
11621181 spendablePoints = { spendablePoints }
11631182 onClose = { handleSheetClose }
1183+ onGoToMissions = { ( ) => { handleSheetClose ( ) ; setMainTab ( 'missions' ) } }
11641184 />
11651185 ) }
11661186
0 commit comments