diff --git a/src/components/common/Header/Header.tsx b/src/components/common/Header/Header.tsx index d1cad0746..7e6978d03 100644 --- a/src/components/common/Header/Header.tsx +++ b/src/components/common/Header/Header.tsx @@ -1,5 +1,6 @@ import classNames from 'classnames' import React, { memo, useEffect, useState } from 'react' +import { useModalCommon } from 'src/components/hooks/useModalCommon' import { isMobile } from 'src/utils/funtion.utils' import ModalAuthenticate from '../ModalAuthenticate/ModalAuthenticate' import HeaderHighLight from './components/HeaderHighLight/HeaderHighLight' @@ -8,13 +9,10 @@ import HeaderSubMenu from './components/HeaderSubMenu/HeaderSubMenu' import HeaderSubMenuMobile from './components/HeaderSubMenuMobile/HeaderSubMenuMobile' import s from './Header.module.scss' -interface Props { - className?: string - children?: any -} -const Header = memo(({ }: Props) => { +const Header = memo(() => { const [isFullHeader, setIsFullHeader] = useState(true) + const { visible: visibleModalAuthen, closeModal: closeModalAuthen, openModal: openModalAuthen } = useModalCommon({ initialValue: true }) useEffect(() => { window.addEventListener('scroll', handleScroll) @@ -37,12 +35,13 @@ const Header = memo(({ }: Props) => {
- +
- + visible = {visibleModalAuthen.toString()} + ) }) diff --git a/src/components/common/Header/components/HeaderMenu/HeaderMenu.tsx b/src/components/common/Header/components/HeaderMenu/HeaderMenu.tsx index 8f19b11e8..a5ef71951 100644 --- a/src/components/common/Header/components/HeaderMenu/HeaderMenu.tsx +++ b/src/components/common/Header/components/HeaderMenu/HeaderMenu.tsx @@ -1,30 +1,35 @@ import classNames from 'classnames' import Link from 'next/link' -import { memo } from 'react' +import { memo, useMemo } from 'react' import InputSearch from 'src/components/common/InputSearch/InputSearch' import MenuDropdown from 'src/components/common/MenuDropdown/MenuDropdown' import { IconBuy, IconHeart, IconHistory, IconUser } from 'src/components/icons' import { ACCOUNT_TAB, QUERY_KEY, ROUTE } from 'src/utils/constanst.utils' import s from './HeaderMenu.module.scss' -const OPTION_MENU = [ - { - link: ROUTE.ACCOUNT, - name: 'Account', - }, - { - link: '/', - name: 'Logout', - }, - -] - interface Props { children?: any, isFull: boolean, + openModalAuthen: () => void, } -const HeaderMenu = memo(({ isFull }: Props) => { +const HeaderMenu = memo(({ isFull, openModalAuthen }: Props) => { + const optionMenu = useMemo(() => [ + { + onClick: openModalAuthen, + name: 'Login (Demo)', + }, + { + link: ROUTE.ACCOUNT, + name: 'Account', + }, + { + link: '/', + name: 'Logout', + }, + + ], [openModalAuthen]) + return (
@@ -54,7 +59,7 @@ const HeaderMenu = memo(({ isFull }: Props) => {
  • - +
  • + : + + + {item.name} + + }
  • ) } diff --git a/src/components/common/ModalAuthenticate/ModalAuthenticate.module.scss b/src/components/common/ModalAuthenticate/ModalAuthenticate.module.scss index 040e74bd2..775e283c3 100644 --- a/src/components/common/ModalAuthenticate/ModalAuthenticate.module.scss +++ b/src/components/common/ModalAuthenticate/ModalAuthenticate.module.scss @@ -1,4 +1,7 @@ .formAuthenticate { - @apply grid grid-cols-2 overflow-hidden; - width: 200%; + @apply overflow-hidden; + .inner { + @apply grid grid-cols-2 overflow-hidden; + width: 200%; + } } diff --git a/src/components/common/ModalAuthenticate/ModalAuthenticate.tsx b/src/components/common/ModalAuthenticate/ModalAuthenticate.tsx index 1486b2adf..f6c952bf2 100644 --- a/src/components/common/ModalAuthenticate/ModalAuthenticate.tsx +++ b/src/components/common/ModalAuthenticate/ModalAuthenticate.tsx @@ -1,9 +1,15 @@ import React, { useState } from 'react' +import ModalCommon from '../ModalCommon/ModalCommon' import FormLogin from './components/FormLogin/FormLogin' import FormRegister from './components/FormRegister/FormRegister' import s from './ModalAuthenticate.module.scss' -const ModalAuthenticate = () => { +interface Props { + visible: boolean, + closeModal: () => void, +} + +const ModalAuthenticate = ({ visible, closeModal }: Props) => { const [isLogin, setIsLogin] = useState(true) const onSwitch = () => { @@ -11,10 +17,15 @@ const ModalAuthenticate = () => { } return ( -
    - - -
    + +
    +
    + + +
    +
    +
    + ) } diff --git a/src/components/hooks/useModalCommon.tsx b/src/components/hooks/useModalCommon.tsx new file mode 100644 index 000000000..02626ce94 --- /dev/null +++ b/src/components/hooks/useModalCommon.tsx @@ -0,0 +1,23 @@ +import { useState } from 'react'; + +interface Props { + initialValue?: boolean, +} + +export const useModalCommon = ({ initialValue = false }: Props) => { + const [visible, setVisible] = useState(initialValue) + + const openModal = (e?: any) => { + e && e.stopPropagation() + setVisible(true) + } + + const closeModal = (e?: any) => { + e && e.stopPropagation() + setVisible(false) + } + + return { + visible, openModal, closeModal + } +};