|
|
@@ -1,6 +1,5 @@
|
|
|
"use client";
|
|
|
|
|
|
-import { Popover, PopoverTrigger, PopoverContent } from "@heroui/popover";
|
|
|
import { useDisclosure } from "@heroui/react";
|
|
|
import { AnimatePresence, motion } from "framer-motion";
|
|
|
import clsx from "clsx";
|
|
|
@@ -10,7 +9,6 @@ import { Avatar } from "@heroui/avatar";
|
|
|
import { useForm } from "react-hook-form";
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
|
import { useCustomToast } from '@/utils/hooks/useToast';
|
|
|
-import { useMediaQuery } from "@utils/hooks/useMediaQueryHook";
|
|
|
import { useBodyScrollLock } from "@utils/hooks/useBodyScrollLock";
|
|
|
import OpenAuth from "../OpenAuth";
|
|
|
import { isObject } from '@/utils/type-guards';
|
|
|
@@ -52,20 +50,11 @@ export default function CredentialModal({
|
|
|
const router = useRouter();
|
|
|
const dispatch = useAppDispatch();
|
|
|
const { showToast } = useCustomToast();
|
|
|
- const isDesktop = useMediaQuery("(min-width: 1024px)");
|
|
|
+
|
|
|
const { resetGuestToken } = useGuestCartToken();
|
|
|
|
|
|
- useBodyScrollLock(finalIsOpen && !isDesktop);
|
|
|
+ useBodyScrollLock(finalIsOpen );
|
|
|
|
|
|
- const finalOnOpenChange = (open: boolean) => {
|
|
|
- if (isControlled) {
|
|
|
- if (open) onOpen?.();
|
|
|
- else onClose?.();
|
|
|
- } else {
|
|
|
- if (open) internalOnOpen();
|
|
|
- else internalOnClose();
|
|
|
- }
|
|
|
- };
|
|
|
|
|
|
const {
|
|
|
handleSubmit,
|
|
|
@@ -105,33 +94,33 @@ export default function CredentialModal({
|
|
|
|
|
|
const innerContent = (_onClose?: () => void) => (
|
|
|
<div className={clsx("flex w-full flex-col rounded-md py-4", {
|
|
|
- "gap-y-6": !!session?.user || (!session?.user && isDesktop),
|
|
|
- "gap-y-10": !session?.user && !isDesktop,
|
|
|
+ "gap-y-6": !!session?.user,
|
|
|
+ "gap-y-10": !session?.user,
|
|
|
})}>
|
|
|
{isObject(session?.user) ? (
|
|
|
<>
|
|
|
<header>
|
|
|
- <div className={clsx("flex flex-col gap-3", !isDesktop && "items-center justify-center")}>
|
|
|
- <div className={clsx("flex gap-3", !isDesktop ? "flex-col items-center" : "items-center")}>
|
|
|
+ <div className={clsx("flex flex-col gap-3", "items-center justify-center")}>
|
|
|
+ <div className={clsx("flex gap-3", "flex-col items-center")}>
|
|
|
<Avatar
|
|
|
isBordered
|
|
|
showFallback
|
|
|
color="default"
|
|
|
- icon={<OpenAuth className={clsx(isDesktop ? "h-8" : "h-12 w-12")} />}
|
|
|
- size={isDesktop ? "md" : "lg"}
|
|
|
- className={clsx(!isDesktop && "h-24 w-24 text-large")}
|
|
|
+ icon={<OpenAuth className={clsx("h-12 w-12")} />}
|
|
|
+ size={"lg"}
|
|
|
+ className={clsx( "h-24 w-24 text-large")}
|
|
|
/>
|
|
|
- <div className={clsx("flex flex-col justify-center", !isDesktop ? "items-center gap-1" : "items-start")}>
|
|
|
- <h4 className={clsx("leading-none dark:text-white", isDesktop ? "font-semibold text-default-500 text-small" : "text-xl font-bold text-black")}>
|
|
|
+ <div className={clsx("flex flex-col justify-center", "items-center gap-1")}>
|
|
|
+ <h4 className={clsx("leading-none dark:text-white", "text-xl font-bold text-black")}>
|
|
|
{session?.user?.name}
|
|
|
</h4>
|
|
|
- <h5 className={clsx("tracking-tight dark:text-white", isDesktop ? "text-default-500 text-small" : "text-sm text-gray-500")}>
|
|
|
+ <h5 className={clsx("tracking-tight dark:text-white", "text-sm text-gray-500")}>
|
|
|
{session?.user?.email}
|
|
|
</h5>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <p className={clsx("text-default-500 dark:text-white", isDesktop ? "text-small pl-px" : "text-center mt-2")}>
|
|
|
+ <p className={clsx("text-default-500 dark:text-white", "text-center mt-2")}>
|
|
|
Manage Cart, Orders
|
|
|
<span aria-label="confetti" className="px-2" role="img">
|
|
|
🎉
|
|
|
@@ -141,12 +130,12 @@ export default function CredentialModal({
|
|
|
</header>
|
|
|
|
|
|
<footer>
|
|
|
- <form onSubmit={handleSubmit(onSubmit)} className={clsx(!isDesktop && "flex justify-center")}>
|
|
|
+ <form onSubmit={handleSubmit(onSubmit)} className={clsx("flex justify-center")}>
|
|
|
<button
|
|
|
className={clsx(
|
|
|
"rounded-full bg-gray-800 px-5 py-2.5 text-sm font-medium text-white hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700",
|
|
|
isSubmitting ? " cursor-not-allowed" : " cursor-pointer",
|
|
|
- isDesktop ? "w-full" : "w-40 min-w-[150px] mt-2"
|
|
|
+ "w-40 min-w-[150px] mt-2"
|
|
|
)}
|
|
|
type="submit"
|
|
|
>
|
|
|
@@ -166,14 +155,12 @@ export default function CredentialModal({
|
|
|
</>
|
|
|
) : (
|
|
|
<>
|
|
|
- <header className={clsx({ "text-center": !isDesktop })}>
|
|
|
+ <header className="text-center">
|
|
|
<div className="flex flex-col gap-y-2">
|
|
|
- <h4 className={clsx("font-bold leading-none text-black dark:text-white",
|
|
|
- isDesktop ? "text-xl" : "text-3xl")}>
|
|
|
+ <h4 className="font-bold leading-none text-black dark:text-white text-3xl">
|
|
|
Welcome Guest
|
|
|
</h4>
|
|
|
- <p className={clsx("text-default-500 dark:text-neutral-400",
|
|
|
- isDesktop ? "text-sm" : "text-lg")}>
|
|
|
+ <p className="text-default-500 dark:text-neutral-400 text-lg">
|
|
|
Manage Cart, Orders
|
|
|
<span aria-label="confetti" className="px-2" role="img">
|
|
|
🎉
|
|
|
@@ -218,31 +205,6 @@ export default function CredentialModal({
|
|
|
</div>
|
|
|
);
|
|
|
|
|
|
- if (isDesktop) {
|
|
|
- return (
|
|
|
- <Popover
|
|
|
- backdrop="opaque"
|
|
|
- isOpen={finalIsOpen}
|
|
|
- onOpenChange={finalOnOpenChange}
|
|
|
- defaultOpen={false}
|
|
|
- color="default"
|
|
|
- placement="bottom-end"
|
|
|
- >
|
|
|
- <PopoverTrigger>
|
|
|
- <button
|
|
|
- type="button"
|
|
|
- aria-label="Open account"
|
|
|
- className={clsx(className, "cursor-pointer bg-transparent")}
|
|
|
- >
|
|
|
- {children ? children : <OpenAuth />}
|
|
|
- </button>
|
|
|
- </PopoverTrigger>
|
|
|
- <PopoverContent className="min-w-[300px] px-4">
|
|
|
- {innerContent(finalOnClose)}
|
|
|
- </PopoverContent>
|
|
|
- </Popover>
|
|
|
- );
|
|
|
- }
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
@@ -263,7 +225,7 @@ export default function CredentialModal({
|
|
|
animate={{ opacity: 1 }}
|
|
|
exit={{ opacity: 0 }}
|
|
|
onClick={finalOnClose}
|
|
|
- className="fixed inset-0 z-40 bg-transparent lg:hidden"
|
|
|
+ className="fixed inset-0 z-40 bg-transparent"
|
|
|
style={{ top: "68px", bottom: "64px" }}
|
|
|
/>
|
|
|
|
|
|
@@ -284,6 +246,14 @@ export default function CredentialModal({
|
|
|
<div className="flex flex-col gap-1 border-b border-neutral-100 p-4 dark:border-neutral-800">
|
|
|
<div className="flex items-center justify-between">
|
|
|
<p className="text-xl font-semibold dark:text-white">Account</p>
|
|
|
+ <button
|
|
|
+ aria-label="Close account"
|
|
|
+ className="rounded-full p-1 hover:bg-neutral-100 "
|
|
|
+ onClick={finalOnClose}
|
|
|
+ type="button"
|
|
|
+ >
|
|
|
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" aria-hidden="true" data-slot="icon" className="h-6 transition-all ease-in-out hover:scale-110"><path strokeLinecap="round" strokeLinejoin="round" d="M6 18 18 6M6 6l12 12"></path></svg>
|
|
|
+ </button>
|
|
|
</div>
|
|
|
</div>
|
|
|
|