Skip to content

Commit d28704e

Browse files
committed
fix: subscription route,pricing usecaseshandle, UI updates
1 parent 42ac347 commit d28704e

File tree

9 files changed

+70
-73
lines changed

9 files changed

+70
-73
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
VITE_APP_BACKEND_BASE_URL=""
2+
VITE_APP_FRONTEND_BASE_URL=""
3+
VITE_APP_ENV=development | production
4+
VITE_WS_URL=""

src/components/Pricing.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
import handleCheckout from "@/api/payment/handleCheckout";
22
import { Button } from "@/components/ui/button";
3+
import { useAuthStatus } from "@/hooks/useAuthStatus";
34
import { useSubscription } from "@/hooks/useSubscription";
4-
import { SVGProps, useEffect, useRef } from "react";
5+
import { SVGProps, useEffect, useState } from "react";
56
import toast from "react-hot-toast";
67
import { useLocation, useNavigate } from "react-router-dom";
78

89
export default function Pricing() {
910
const {isProUser}=useSubscription();
10-
const sessionUrl=useRef<string>("");
11+
const {status}=useAuthStatus();
12+
const [sessionUrl,setSessionUrl]=useState<string>("");
1113
const { search } = useLocation();
1214
const params = new URLSearchParams(search);
1315
const navigate = useNavigate();
1416
useEffect(() => {
15-
handleCheckout().then((redirect_url) => {
16-
console.log(redirect_url);
17-
sessionUrl.current = redirect_url;
18-
}).catch(() => {
19-
toast.error("Error in Generating you session Url");
20-
});
21-
}, []);
17+
if(status){
18+
handleCheckout().then((redirect_url) => {
19+
console.log(redirect_url);
20+
setSessionUrl(redirect_url);
21+
}).catch(() => {
22+
toast.error("Error in Generating you session Url");
23+
});
24+
}
25+
}, [status]);
2226
if (params.get("success") == "true") {
2327
toast.success("Payment SuccessFul");
2428
setTimeout(() => {
@@ -71,10 +75,14 @@ export default function Pricing() {
7175
<Button
7276
className="w-full bg-gradient-to-r from-pink-500 to-purple-500"
7377
onClick={() => {
74-
window.location.href=sessionUrl.current;
78+
if(!status){
79+
navigate("/login");
80+
}else{
81+
window.location.href=sessionUrl;
82+
}
7583
}}
7684
>
77-
{isProUser ? "Manage Subscription" : "Subscribe Now"}
85+
{ (status && isProUser) ? "Manage Subscription" : "Subscribe Now"}
7886
</Button>
7987
</div>
8088
</div>

src/components/Typing/Control.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import DashboardIcon from "./DashboardIcon";
23

34
const Control = () => {
45
return (
@@ -7,16 +8,17 @@ const Control = () => {
78
<img src="/logo.png" alt="Typesight Logo" className="h-10 w-10" />
89
TypeSight
910
</h1>
10-
<div className="flex justify-end gap-5">
11-
{/* <select className="px-3 rounded-xl bg-white text-black">
11+
<DashboardIcon />
12+
{/* <div className="flex justify-end gap-5">
13+
<select className="px-3 rounded-xl bg-white text-black">
1214
<option>30s</option>
1315
<option>60s</option>
14-
</select> */}
15-
{/* <select className="px-3 rounded-xl bg-white text-black">
16+
</select>
17+
<select className="px-3 rounded-xl bg-white text-black">
1618
<option>words</option>
1719
<option>sentences</option>
18-
</select> */}
19-
</div>
20+
</select>
21+
</div> */}
2022
</nav>
2123
);
2224
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useAuthStatus } from "@/hooks/useAuthStatus";
2+
import { SVGProps } from "react";
3+
import { useNavigate } from "react-router-dom";
4+
5+
const DashboardIcon = () => {
6+
const navigate = useNavigate();
7+
const { status, user } = useAuthStatus();
8+
return (
9+
<svg
10+
xmlns="http://www.w3.org/2000/svg"
11+
width="48"
12+
height="48"
13+
id="dashboard"
14+
onClick={() => {
15+
if(!status){
16+
navigate("/login");
17+
}else{
18+
navigate(`/dashboard/${user?.id}`);
19+
}
20+
}}
21+
className="cursor-pointer bg-white text-lg"
22+
>
23+
<path fill="none" d="M0 0h48v48H0z"></path>
24+
<path d="M6 26h16V6H6v20zm0 16h16V30H6v12zm20 0h16V22H26v20zm0-36v12h16V6H26z"></path>
25+
</svg>
26+
);
27+
};
28+
29+
export default DashboardIcon;

src/components/Typing/Typing.tsx

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/components/Typing/TypingFooter.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/lib/helpers/shufflewords.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import sentence from '@/lib/data/sentences.json';
44
export default function shuffleWords(preference: string) {
55
switch (preference) {
66
case 'words':
7-
return _.shuffle(word).slice(0, 50);
7+
return _.shuffle(word).slice(0, 70);
88
case 'sentences':
9-
return _.shuffle(sentence).slice(0, 50);
9+
return _.shuffle(sentence).slice(0, 70);
1010
default:
11-
return _.shuffle(word).slice(0, 50);
11+
return _.shuffle(word).slice(0, 70);
1212
}
1313
}

src/pages/Dashboard/DashBoard.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export default function Component() {
4545
<div className="flex flex-col flex-1">
4646
<header className="h-16 px-4 border-b shrink-0 md:px-6 flex items-center">
4747
<div className="flex items-center justify-end w-full gap-4 md:ml-auto md:gap-2 lg:gap-4">
48+
<Link
49+
className="text-gray-600 hover:text-gray-900 dark:text-gray-200"
50+
to="/test"
51+
>
52+
Test
53+
</Link>
4854
{!isProUser && (
4955
<Link
5056
className="text-gray-600 hover:text-gray-900 dark:text-gray-200"

src/redux-store/slices/subscriptionslice.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const initialState: SubscriptionState = {
2424
};
2525
export const getSubscriptionInfo = createAsyncThunk("mySubscription", async (_, { rejectWithValue }) => {
2626
try {
27-
const data = await axiosClient.get(`/mysubscription`);
27+
const data = await axiosClient.get(`/pro/mysubscription`);
2828
return data;
2929
} catch (error) {
3030
const err = error as AxiosError;
@@ -54,5 +54,4 @@ const resultSlice = createSlice({
5454
});
5555
},
5656
})
57-
5857
export default resultSlice.reducer;

0 commit comments

Comments
 (0)