@@ -20,13 +20,51 @@ export const SupportModal = ({ user }: { user: Profile | null }) => {
2020 const [ copied , setCopied ] = useState ( false ) ;
2121
2222 useEffect ( ( ) => {
23+ const checkShouldShowModal = ( ) => {
24+ try {
25+ const modalData = localStorage . getItem ( 'devb-support-modal' ) ;
26+
27+ if ( ! modalData ) {
28+ // First time visit - show modal
29+ return true ;
30+ }
31+
32+ const { timestamp } = JSON . parse ( modalData ) ;
33+ const oneDayInMs = 24 * 60 * 60 * 1000 ; // 1 day in milliseconds
34+ const now = Date . now ( ) ;
35+
36+ // Show modal if more than 1 day has passed
37+ return ( now - timestamp ) > oneDayInMs ;
38+ } catch ( error ) {
39+ // If there's any error with localStorage, show modal
40+ console . warn ( 'Error checking modal state:' , error ) ;
41+ return true ;
42+ }
43+ } ;
44+
2345 const timer = setTimeout ( ( ) => {
24- setOpen ( ! user ?. cached || false ) ;
46+ const shouldShow = checkShouldShowModal ( ) ;
47+ setOpen ( shouldShow && ( ! user ?. cached || false ) ) ;
2548 } , 4000 ) ;
2649
2750 return ( ) => clearTimeout ( timer ) ;
2851 } , [ user ] ) ;
2952
53+ const handleModalClose = ( isOpen : boolean ) => {
54+ setOpen ( isOpen ) ;
55+ if ( ! isOpen ) {
56+ try {
57+ // Save timestamp when modal is closed
58+ const modalData = {
59+ timestamp : Date . now ( ) ,
60+ } ;
61+ localStorage . setItem ( 'devb-support-modal' , JSON . stringify ( modalData ) ) ;
62+ } catch ( error ) {
63+ console . warn ( 'Error saving modal state:' , error ) ;
64+ }
65+ }
66+ } ;
67+
3068 const copyToClipboard = ( ) => {
3169 navigator . clipboard
3270 . writeText ( DEVB_INVITE_LINK )
@@ -44,7 +82,7 @@ export const SupportModal = ({ user }: { user: Profile | null }) => {
4482 } ;
4583
4684 return (
47- < Dialog open = { open } onOpenChange = { setOpen } >
85+ < Dialog open = { open } onOpenChange = { handleModalClose } >
4886 < DialogContent className = "sm:max-w-[700px] p-0 overflow-hidden border-black border-1 border-b-4 rounded-3xl" >
4987 < div className = "p-6 pt-8" >
5088 < div className = "bg-[#B9FF66] inline-block px-4 py-2 rounded-lg mb-4" >
0 commit comments