From cb4f9fbb42bfa41db738e540ea293f14126dab6c Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Mon, 18 Aug 2025 19:40:49 +0100 Subject: [PATCH] fixed selected subscription page --- .../profile_complete/ProfileCompleteCom.jsx | 11 +- src/component/subscribe/Subscribe.jsx | 110 ++++++------------ src/component/subscription/Subscription.jsx | 4 +- src/views/ProductPage.jsx | 5 +- 4 files changed, 51 insertions(+), 79 deletions(-) diff --git a/src/component/profile_complete/ProfileCompleteCom.jsx b/src/component/profile_complete/ProfileCompleteCom.jsx index ecd0698..fa185a4 100644 --- a/src/component/profile_complete/ProfileCompleteCom.jsx +++ b/src/component/profile_complete/ProfileCompleteCom.jsx @@ -8,7 +8,9 @@ import getImage from "../../utils/getImage"; import { IoMdArrowDropdown } from "react-icons/io"; import { completeProfile, getCommonPractice } from '../../services/services'; import siteLinks from "../../links/siteLinks"; -import { useNavigate } from "react-router-dom"; +import { useLocation, useNavigate } from "react-router-dom"; +import { updateUserDetails } from "../../store/UserDetails"; +import { useDispatch } from "react-redux"; // const validationSchema = Yup.object().shape({ @@ -26,8 +28,12 @@ import { useNavigate } from "react-router-dom"; export default function ProfileCompleteCom(){ + const dispatch = useDispatch() + const navigate = useNavigate() + const {state:{redirectLink}} = useLocation() + const [practices, setPractices] = useState([]) const [initialValues, setInitialValues] = useState({ @@ -61,8 +67,9 @@ export default function ProfileCompleteCom(){ if(res.data.resultCode != '0'){ throw({message: res?.data?.resultDescription}) } + dispatch(updateUserDetails({profile_completed: res?.data?.profile_completed })); setTimeout(()=>{ - navigate(siteLinks.home) + navigate(redirectLink) },2000) // console.log('res', res) } diff --git a/src/component/subscribe/Subscribe.jsx b/src/component/subscribe/Subscribe.jsx index 4b216cc..e2a6f06 100644 --- a/src/component/subscribe/Subscribe.jsx +++ b/src/component/subscribe/Subscribe.jsx @@ -5,96 +5,60 @@ import { getSubscriptions } from '../../services/services'; import { useQuery } from '@tanstack/react-query'; import queryKeys from '../../services/queryKeys'; import siteLinks from "../../links/siteLinks"; -import { Link, useNavigate } from 'react-router-dom' +import { Link, useLocation } from 'react-router-dom' import SubscribeNewCard from "./SubscribeNewCard"; import SubscribePreviousCard from "./SubscribePreviousCard"; import SubcribePaymentOptions from "./SubcribePaymentOptions"; export default function Subscribe() { - const navigate = useNavigate() - const pricingFields ={ - starter: { name: 'Starter', price: 5.99, active: true }, - basic: { name: 'Basic', price: 12.99, active: true }, - premium: { name: 'Premium', price: 20.00, active: true }, - } - const {data, isFetching, isError, error} = useQuery({ - queryKey: queryKeys.subscriptions, - queryFn: () => { - let reqData = { - token: localStorage.getItem('token'), // USER TOKEN - uid: localStorage.getItem('uid') // USER UID - } - return getSubscriptions(reqData) - } - }) + const {state:{selectedSubscription}} = useLocation() - const currentSubscription = data?.data?.current_product - const otherSubscriptions = data?.data?.options - console.log('urlData', data?.data) - - const subscriptionSelection = otherSubscriptions?.starter; + // console.log('selectedSubscription', selectedSubscription) return ( <> - {isFetching ? - <> -
-

Loading...

-
- - : isError ? -
-

{error.message}

-
- : -
-
-
-
-
-
Current Subscription(s)
- {/*

{currentSubscription?.display_name}

*/} - +
+
+
+
+
+
Current Subscription(s)
+ {/*

{currentSubscription?.display_name}

*/} + - - + + -
-
- - <> - - -
-
-
-
-
{subscriptionSelection.display_name}
-

${subscriptionSelection.monthly}

-

/ Monthly

-
    - {subscriptionSelection?.items?.map(item =>( -
  • {item}
  • - ))} -
- {/*
*/} - {/* */} - {/*
*/} -
-
-
-
- - - -
- } +
+ + <> +
+
+
+
+
{selectedSubscription.display_name}
+

${selectedSubscription.monthly}

+

/ Monthly

+
    + {selectedSubscription?.items?.map(item =>( +
  • {item}
  • + ))} +
+ {/*
*/} + {/* */} + {/*
*/} +
+
+
+
+ +
) } \ No newline at end of file diff --git a/src/component/subscription/Subscription.jsx b/src/component/subscription/Subscription.jsx index d1ece8d..006f1bc 100644 --- a/src/component/subscription/Subscription.jsx +++ b/src/component/subscription/Subscription.jsx @@ -28,7 +28,7 @@ export default function Subscription() { const currentSubscription = data?.data?.current_product const otherSubscriptions = data?.data?.options - console.log('urlData', data?.data) + // console.log('urlData', data?.data) return ( <> @@ -73,7 +73,7 @@ export default function Subscription() { ))}
- +
diff --git a/src/views/ProductPage.jsx b/src/views/ProductPage.jsx index 097feea..63f482d 100644 --- a/src/views/ProductPage.jsx +++ b/src/views/ProductPage.jsx @@ -2,18 +2,19 @@ import React, { useEffect } from 'react' import ProductFactory from '../component/product/ProductFactory' import { useSelector } from 'react-redux'; import siteLinks from '../links/siteLinks'; -import { useNavigate } from 'react-router-dom'; +import { useLocation, useNavigate } from 'react-router-dom'; export default function ProductPage() { const navigate = useNavigate() + let {pathname} = useLocation() const { userDetails: { profile_completed }} = useSelector((state) => state?.userDetails); // CHECKS IF USER Details are avaliable, to determine if user is active useEffect(()=>{ if(!profile_completed){ - navigate(siteLinks.profile_complete, {replace: true, state:{profile_completed: false}}) + navigate(siteLinks.profile_complete, {replace: true, state:{redirectLink: pathname}}) } },[]) -- 2.34.1