Guest User

Untitled

a guest
Jun 2nd, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. "use client";
  2. import { useRouter } from "next/navigation";
  3. import { getUser } from "./../../server/utils/auth";
  4. import { useState, useEffect, useCallback } from "react";
  5. import { Breadcrumbs, BreadcrumbItem, Divider } from "@nextui-org/react";
  6. import { useLogStore } from "@/server/utils/store";
  7. import { SpinnerLoading } from "@/components/spinner";
  8.  
  9. export default function AccountPage() {
  10. const router = useRouter();
  11.  
  12. const fadeInAnimation = {
  13. animation: "fadeIn 0.25s forwards",
  14. opacity: 0,
  15. };
  16.  
  17. const [user, setUser] = useState(null);
  18. const [loading, setLoading] = useState(true);
  19. const isLoggedIn = useLogStore((state) => state.isLoggedIn);
  20.  
  21. const fetchUser = useCallback(async () => {
  22. try {
  23. if (isLoggedIn) {
  24. const userData = await getUser();
  25. setUser(userData);
  26. } else {
  27. setUser(null);
  28. }
  29. } catch (error) {
  30. console.error("Failed to fetch user:", error);
  31. } finally {
  32. setLoading(false);
  33. }
  34. }, [isLoggedIn]);
  35.  
  36. useEffect(() => {
  37. fetchUser();
  38. }, [fetchUser]);
  39.  
  40. useEffect(() => {
  41. if (!loading && !user) {
  42. router.push("/login");
  43. }
  44. }, [loading, user, router]);
  45.  
  46. if (loading) {
  47. return <SpinnerLoading />;
  48. }
  49.  
  50. if (!user) {
  51. return null;
  52. }
  53.  
  54. return (
  55. <div className="flex">
  56. <div className="grid w-[330px] 2xl:-[729px] xl:w-[729px] lg:w-[729px] md:w-[729px] sm:w-[520px]">
  57. <Breadcrumbs
  58. style={{
  59. ...fadeInAnimation,
  60. animationDelay: `${1 * 0.25}s`,
  61. }}
  62. className="mt-3 bg-zinc-800 rounded-md p-3 border-1.5 border-neutral-700"
  63. >
  64. <BreadcrumbItem href="/">
  65. <svg
  66. xmlns="http://www.w3.org/2000/svg"
  67. className="mb-0.5"
  68. viewBox="0 0 576 512"
  69. width={16}
  70. height={16}
  71. >
  72. <path
  73. fill="currentColor"
  74. d="M575.8 255.5c0 18-15 32.1-32 32.1h-32l.7 160.2c0 2.7-.2 5.4-.5 8.1V472c0 22.1-17.9 40-40 40H456c-1.1 0-2.2 0-3.3-.1c-1.4 .1-2.8 .1-4.2 .1H416 392c-22.1 0-40-17.9-40-40V448 384c0-17.7-14.3-32-32-32H256c-17.7 0-32 14.3-32 32v64 24c0 22.1-17.9 40-40 40H160 128.1c-1.5 0-3-.1-4.5-.2c-1.2 .1-2.4 .2-3.6 .2H104c-22.1 0-40-17.9-40-40V360c0-.9 0-1.9 .1-2.8V287.6H32c-18 0-32-14-32-32.1c0-9 3-17 10-24L266.4 8c7-7 15-8 22-8s15 2 21 7L564.8 231.5c8 7 12 15 11 24z"
  75. />
  76. </svg>
  77. </BreadcrumbItem>{" "}
  78. <BreadcrumbItem href="/account">Account</BreadcrumbItem>
  79. </Breadcrumbs>
  80. <div className="mt-3 p-3">
  81. <Divider
  82. className="mb-3"
  83. style={{
  84. ...fadeInAnimation,
  85. animationDelay: `${1 * 0.35}s`,
  86. }}
  87. ></Divider>
  88. <div className="grid grid-cols-1 gap-2 md:grid-cols-4 lg:grid-cols-4 xl:grid-cols-4 2xl:grid-cols-4 sm:grid-cols-2">
  89. <div
  90. className="rounded-md bg-zinc-800 border-1.5 border-neutral-700 mt-3 flex hover:bg-neutral-800 duration-300 hover:cursor-pointer"
  91. key={"reset1"}
  92. style={{
  93. ...fadeInAnimation,
  94. animationDelay: `${1 * 0.45}s`,
  95. }}
  96. >
  97. <div className="ml-2 mr-2 grid mb-auto mt-auto">
  98. <div className="flex">
  99. <a
  100. href="/account/details"
  101. className="text-s text-sky-300 font-clean p-1"
  102. >
  103. {"Account Details"}
  104. </a>
  105. </div>
  106. </div>
  107. </div>
  108. <div
  109. className="rounded-md bg-zinc-800 border-1.5 border-neutral-700 mt-3 flex hover:bg-neutral-800 duration-300 hover:cursor-pointer"
  110. key={"reset2"}
  111. style={{
  112. ...fadeInAnimation,
  113. animationDelay: `${1 * 0.55}s`,
  114. }}
  115. >
  116. <div className="ml-2 mr-2 grid mb-auto mt-auto">
  117. <div className="flex">
  118. <a
  119. href="/account/payment"
  120. className="text-s text-sky-300 font-clean p-1"
  121. >
  122. {"Payment Methods"}
  123. </a>
  124. </div>
  125. </div>
  126. </div>
  127. <div
  128. className="rounded-md bg-zinc-800 border-1.5 border-neutral-700 mt-3 flex hover:bg-neutral-800 duration-300 hover:cursor-pointer"
  129. key={"reset3"}
  130. style={{
  131. ...fadeInAnimation,
  132. animationDelay: `${1 * 0.65}s`,
  133. }}
  134. >
  135. <div className="ml-2 mr-2 grid mb-auto mt-auto">
  136. <div className="flex">
  137. <a
  138. href="/account/security"
  139. className="text-s text-sky-300 font-clean p-1"
  140. >
  141. {"Password & Security"}
  142. </a>
  143. </div>
  144. </div>
  145. </div>
  146. <div
  147. className="rounded-md bg-zinc-800 border-1.5 border-neutral-700 mt-3 flex hover:bg-neutral-800 duration-300 hover:cursor-pointer"
  148. key={"reset4"}
  149. style={{
  150. ...fadeInAnimation,
  151. animationDelay: `${1 * 0.75}s`,
  152. }}
  153. >
  154. <div className="ml-2 mr-2 grid mb-auto mt-auto">
  155. <div className="flex">
  156. <a
  157. href="/account/creator"
  158. className="text-s text-sky-300 font-clean p-1"
  159. >
  160. {"Creator Program"}
  161. </a>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. <style jsx>{`
  169. @keyframes fadeIn {
  170. from {
  171. opacity: 0;
  172. }
  173. to {
  174. opacity: 1;
  175. }
  176. }
  177. `}</style>
  178. </div>
  179. );
  180. }
  181.  
Add Comment
Please, Sign In to add comment