@@ -5,12 +5,15 @@ import GroupCard, { GroupCardSkeleton } from '@/components/GroupCard/GroupCard';
55import Link from 'next/link' ;
66import { useEffect , useState } from 'react' ;
77import { GiftExchangeWithMemberCount } from '../types/giftExchange' ;
8+ import { useToast } from '@/hooks/use-toast' ;
9+ import { ToastVariants } from '@/components/Toast/Toast.enum' ;
810
911export default function Dashboard ( ) {
1012 const [ giftExchanges , setGiftExchanges ] = useState <
1113 GiftExchangeWithMemberCount [ ]
1214 > ( [ ] ) ;
1315 const [ isLoading , setIsLoading ] = useState ( true ) ;
16+ const { toast } = useToast ( ) ;
1417
1518 useEffect ( ( ) => {
1619 async function fetchGiftExchanges ( ) {
@@ -28,6 +31,39 @@ export default function Dashboard() {
2831
2932 const data = await response . json ( ) ;
3033 setGiftExchanges ( data ) ;
34+
35+ const today = new Date ( ) ;
36+ for ( const exchange of data ) {
37+ const drawingDate = new Date ( exchange . drawing_date ) ;
38+ const timeDifference = drawingDate . getTime ( ) - today . getTime ( ) ;
39+ const dayDifference = Math . ceil (
40+ timeDifference / ( 1000 * 60 * 60 * 24 ) ,
41+ ) ;
42+
43+ if ( dayDifference > 0 && dayDifference <= 3 ) {
44+ toast ( {
45+ variant : ToastVariants . Warning ,
46+ title : `Upcoming Draw - ${ exchange . name } ` ,
47+ description : `The draw is in ${ dayDifference } day${ dayDifference < 2 ? '' : 's' } !` ,
48+ group : exchange . gift_exchange_id ,
49+ } ) ;
50+ } else if ( dayDifference === 0 ) {
51+ toast ( {
52+ variant : ToastVariants . Success ,
53+ title : `Draw Today - ${ exchange . name } ` ,
54+ description : `Go to your group to initiate the gift exchange draw.` ,
55+ group : exchange . gift_exchange_id ,
56+ } ) ;
57+ } else if ( dayDifference < 0 ) {
58+ toast ( {
59+ variant : ToastVariants . Error ,
60+ title : `Draw date has passed - ${ exchange . name } ` ,
61+ description :
62+ 'Your Secret Santas are still secret! Please draw now or reschedule drawing date.' ,
63+ group : exchange . gift_exchange_id ,
64+ } ) ;
65+ }
66+ }
3167 } catch ( error ) {
3268 console . error ( 'Failed to fetch gift exchanges:' , error ) ;
3369 } finally {
0 commit comments