From 42eb79d81f51da8f640ce368115c01ed7cbe6bdd Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Sun, 25 Oct 2020 16:32:56 -0300 Subject: [PATCH] Correct UI State --- .../auth/LoginView.tsx | 86 ++++++++++--------- components/auth/index.ts | 1 + components/core/UserNav/UserNav.tsx | 12 ++- components/ui/Modal/Modal.tsx | 49 +++++++---- components/ui/context.tsx | 27 ++++++ 5 files changed, 115 insertions(+), 60 deletions(-) rename pages/login.tsx => components/auth/LoginView.tsx (50%) create mode 100644 components/auth/index.ts diff --git a/pages/login.tsx b/components/auth/LoginView.tsx similarity index 50% rename from pages/login.tsx rename to components/auth/LoginView.tsx index fd6e12687..fb7f99ada 100644 --- a/pages/login.tsx +++ b/components/auth/LoginView.tsx @@ -1,17 +1,22 @@ -import useSignup from '@lib/bigcommerce/use-signup' -import { Layout } from '@components/core' +import { FC, useEffect } from 'react' import { Logo, Modal, Button } from '@components/ui' +import useSignup from '@lib/bigcommerce/use-signup' import useLogin from '@lib/bigcommerce/use-login' import useLogout from '@lib/bigcommerce/use-logout' import useCustomer from '@lib/bigcommerce/use-customer' +import { useUI } from '@components/ui/context' -export default function Login() { +interface Props { + open: boolean +} + +const LoginView: FC = ({ open }) => { const signup = useSignup() const login = useLogin() const logout = useLogout() - // Data about the currently logged in customer, it will update - // automatically after a signup/login/logout - const { data } = useCustomer() + // // Data about the currently logged in customer, it will update + // // automatically after a signup/login/logout + // const { data } = useCustomer() // TODO: use this method. It can take more than 5 seconds to do a signup const handleSignup = async () => { // TODO: validate the password and email before calling the signup @@ -51,41 +56,44 @@ export default function Login() { } } + const { openModal, closeModal } = useUI() + useEffect(() => { + open ? openModal() : closeModal() + }, [open]) + return ( -
- {}}> -
-
- -
-
-
- -
-
- -
- - - Don't have an account? - {` `} - - Sign Up - - -
+ +
+
+
- -
+
+
+ +
+
+ +
+ + + Don't have an account? + {` `} + + Sign Up + + +
+
+
) } -Login.Layout = Layout +export default LoginView diff --git a/components/auth/index.ts b/components/auth/index.ts new file mode 100644 index 000000000..fa4dd296f --- /dev/null +++ b/components/auth/index.ts @@ -0,0 +1 @@ +export { default as LoginView } from './LoginView' diff --git a/components/core/UserNav/UserNav.tsx b/components/core/UserNav/UserNav.tsx index c1a67aa93..f129c4a2e 100644 --- a/components/core/UserNav/UserNav.tsx +++ b/components/core/UserNav/UserNav.tsx @@ -5,10 +5,11 @@ import { FC } from 'react' import { Heart, Bag } from '@components/icon' import { Avatar } from '@components/core' import { useUI } from '@components/ui/context' +import { LoginView } from '@components/auth' import DropdownMenu from './DropdownMenu' import { Menu } from '@headlessui/react' import useCart from '@lib/bigcommerce/cart/use-cart' - +import useCustomer from '@lib/bigcommerce/use-customer' interface Props { className?: string } @@ -19,9 +20,10 @@ const countItems = (count: number, items: any[]) => const UserNav: FC = ({ className, children, ...props }) => { const { data } = useCart() + const { data: customer } = useCustomer() + const { openSidebar, closeSidebar, displaySidebar } = useUI() const itemsCount = Object.values(data?.line_items ?? {}).reduce(countItems, 0) - return (