-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from Marx-wrld/Account-section-build
Account section build
- Loading branch information
Showing
18 changed files
with
257 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"use client"; | ||
|
||
import Button from "@/components/Button"; | ||
import useSubscribeModal from "@/hooks/useSubscribeModal"; | ||
import { useUser } from "@/hooks/useUser"; | ||
import { postData } from "@/libs/helpers"; | ||
import { useRouter } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
import toast from "react-hot-toast"; | ||
|
||
const AccountContent = () => { | ||
const router = useRouter(); | ||
const subscribeModal = useSubscribeModal(); | ||
const { isLoading, subscription, user } = useUser(); | ||
|
||
const [loading, setLoading] = useState(false); | ||
|
||
useEffect(() => { | ||
if (!isLoading && !user) { | ||
router.replace('/'); | ||
} | ||
}, [isLoading, user, router]); | ||
|
||
const redirectToCustomerPortal = async () => { | ||
setLoading(true); | ||
try{ | ||
const { url, error } = await postData({ | ||
url: '/api/create-portal-link' | ||
}); | ||
window.location.assign(url); | ||
} catch (error) { | ||
if (error) { | ||
toast.error((error as Error).message); | ||
} | ||
} | ||
setLoading(false); | ||
} | ||
|
||
return ( | ||
<div className="mb-7 px-6"> | ||
{!subscription && ( | ||
<div className="flex flex-col gap-y-4"> | ||
<p>No active plan</p> | ||
<Button | ||
onClick={subscribeModal.onOpen} | ||
className="w-[300px]" | ||
> | ||
Subscribe | ||
</Button> | ||
</div> | ||
)} | ||
{subscription && ( | ||
<div className="flex flex-col gap-y-4"> | ||
<p> | ||
You are currently on the <b>{subscription?.prices?.products?.name}plan.</b> | ||
</p> | ||
|
||
<Button | ||
disabled={loading || isLoading} | ||
onClick={redirectToCustomerPortal} | ||
className="w-[300px]" | ||
> | ||
Open customer portal | ||
</Button> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default AccountContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//Adding loading and error handling to our app (getSongs) | ||
|
||
"use client"; | ||
|
||
import Box from "@/components/Box"; | ||
|
||
const Error = () => { | ||
return ( | ||
<Box className=" | ||
h-full | ||
flex | ||
items-center | ||
justify-center | ||
"> | ||
<div className=" | ||
text-neutral-400 | ||
"> | ||
Something went wrong! | ||
</div> | ||
</Box> | ||
); | ||
} | ||
|
||
export default Error; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use client"; | ||
|
||
import Box from "@/components/Box"; | ||
import { BounceLoader } from "react-spinners"; | ||
|
||
const loading = () => { | ||
return ( | ||
<Box className=" | ||
h-full | ||
flex | ||
items-center | ||
justify-center | ||
"> | ||
<BounceLoader color="#22c55e" size={40} /> | ||
</Box> | ||
); | ||
} | ||
|
||
export default loading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Header from "@/components/Header"; | ||
import AccountContent from "./components/AccountContent"; | ||
|
||
const Account = () => { | ||
return ( | ||
<div className=" | ||
bg-neutral-900 | ||
rounded-lg | ||
h-full | ||
w-full | ||
overflow-hidden | ||
overflow-y-auto | ||
"> | ||
<Header className=" | ||
from-bg-neutral-900 | ||
"> | ||
<div className=" | ||
mb-2 | ||
flex | ||
flex-col | ||
gap-y-6 | ||
"> | ||
<h1 className=" | ||
text-white | ||
text-3xl | ||
font-semibold | ||
"> | ||
Account Settings | ||
</h1> | ||
</div> | ||
</Header> | ||
<AccountContent /> | ||
</div> | ||
); | ||
} | ||
|
||
export default Account; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.