Skip to content

Commit c04670b

Browse files
committed
Add useSelector hook to App.tsx and remove unused imports
1 parent 3405977 commit c04670b

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/App.tsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import './css/tailwind.css'
44

55
import { CheckIcon } from 'lucide-react'
66
import { useEffect, useState } from 'react'
7-
import { Provider } from 'react-redux'
7+
import { Provider, useSelector } from 'react-redux'
88
import { RouterProvider, createBrowserRouter, useLocation } from 'react-router-dom'
99
import store from './Redux/store'
1010
import { NormalButton } from './components/Button'
@@ -29,10 +29,11 @@ import ContactUs from './screens/More/ContactUs'
2929
import PrivacyPolicy from './screens/More/PrivacyPolicy'
3030
import TermsAndConditions from './screens/More/TermsAndConditions'
3131
import Profile from './screens/Profile/Profile'
32+
import { UserProfile } from './screens/Profile/utils'
3233
import Test from './screens/Test'
34+
import Transactions from './screens/Transactions/Transactions'
3335
import Video from './screens/Video'
3436
import Wallet from './screens/Wallet/Wallet'
35-
import Transactions from './screens/Transactions/Transactions'
3637

3738
const LiveVideo = lazyWithPreload(() => import('./screens/Live/LiveVideo'))
3839
const OrderStatus = lazyWithPreload(() => import('./screens/OrderStatus/OrderStatus'))
@@ -167,8 +168,7 @@ export function SubscriptionDrawer({
167168
setIsDrawerOpen: any
168169
}) {
169170
const [isLoading, setIsLoading] = useState(false)
170-
171-
// If the route is /orderStatus/:order_id, then disable the drawer
171+
const user: UserProfile = useSelector((state: any) => state.profile)
172172
const { pathname } = useLocation()
173173

174174
useEffect(() => {
@@ -177,6 +177,13 @@ export function SubscriptionDrawer({
177177
}
178178
}, [pathname])
179179

180+
useEffect(() => {
181+
const timer = setTimeout(() => {
182+
if (user) setIsOpened(user?.subscription_status?.status !== 'active')
183+
}, 3000)
184+
return () => clearTimeout(timer)
185+
}, [])
186+
180187
async function subscriptionAPI() {
181188
setIsLoading(true)
182189
const res = await callSubscription_f()
@@ -186,6 +193,8 @@ export function SubscriptionDrawer({
186193
setIsOpened(false)
187194
}
188195

196+
if (!user) return null
197+
189198
return (
190199
<Drawer open={isOpened} onClose={() => setIsOpened(false)}>
191200
<DrawerContent className='bg-black text-white outline-none'>

src/screens/Home/HomeScreen/subscriptionDrawerContext.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,8 @@ const SubscriptionDrawerContext = createContext<SubscriptionDrawerContextProps |
1212

1313
// Create a provider component
1414
export const SubscriptionDrawerProvider: FunctionComponent<{ children: ReactNode }> = ({ children }) => {
15-
const profile: UserProfile = useSelector((state: any) => state.profile)
1615
const [isOpened, setIsOpened] = useState(false)
1716

18-
useEffect(() => {
19-
const timer = setTimeout(() => {
20-
setIsOpened(profile?.subscription_status?.status !== 'active')
21-
}, 3000)
22-
23-
return () => clearTimeout(timer)
24-
}, [])
25-
2617
return (
2718
<SubscriptionDrawerContext.Provider value={{ isOpened, setIsOpened }}>
2819
{children}

0 commit comments

Comments
 (0)