linkn to my catalogue in header ser menu
This commit is contained in:
@@ -2,15 +2,12 @@ import { removeRefreshToken, removeToken } from "@/config/func";
|
|||||||
import { Paths } from "@/config/Paths";
|
import { Paths } from "@/config/Paths";
|
||||||
import { useAuth } from "@/context/AuthContext";
|
import { useAuth } from "@/context/AuthContext";
|
||||||
import { useGetBusiness } from "@/pages/business/hooks/useBusinessData";
|
import { useGetBusiness } from "@/pages/business/hooks/useBusinessData";
|
||||||
import {
|
import { getAdminFullName, type BusinessType } from "@/pages/business/types/Types";
|
||||||
getAdminFullName,
|
|
||||||
type BusinessType,
|
|
||||||
} from "@/pages/business/types/Types";
|
|
||||||
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react";
|
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react";
|
||||||
import { ArrowDown2, CloseCircle, Logout } from "iconsax-react";
|
import { ArrowDown2, CloseCircle, DocumentText, Logout } from "iconsax-react";
|
||||||
import { useState, type FC } from "react";
|
import { useEffect, useState, type FC } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router-dom";
|
import { Link, useLocation } from "react-router-dom";
|
||||||
|
|
||||||
type BusinessLogoProps = {
|
type BusinessLogoProps = {
|
||||||
business: BusinessType;
|
business: BusinessType;
|
||||||
@@ -23,25 +20,18 @@ const BusinessLogo: FC<BusinessLogoProps> = ({ business, size = "sm" }) => {
|
|||||||
|
|
||||||
if (business.logoUrl) {
|
if (business.logoUrl) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={`${sizeClass} rounded-full overflow-hidden bg-description`}>
|
||||||
className={`${sizeClass} rounded-full overflow-hidden bg-description`}
|
|
||||||
>
|
|
||||||
<img src={business.logoUrl} className="size-full object-cover" alt="" />
|
<img src={business.logoUrl} className="size-full object-cover" alt="" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <div className={`${sizeClass} rounded-full pt-[2px] bg-secondary flex items-center justify-center font-medium text-desc leading-none select-none`}>{initial}</div>;
|
||||||
<div
|
|
||||||
className={`${sizeClass} rounded-full pt-[2px] bg-secondary flex items-center justify-center font-medium text-desc leading-none select-none`}
|
|
||||||
>
|
|
||||||
{initial}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const HeaderUserMenu: FC = () => {
|
const HeaderUserMenu: FC = () => {
|
||||||
const [popoverKey, setPopoverKey] = useState(0);
|
const [popoverKey, setPopoverKey] = useState(0);
|
||||||
|
const location = useLocation();
|
||||||
const { t } = useTranslation("global");
|
const { t } = useTranslation("global");
|
||||||
const { data: businessResponse } = useGetBusiness();
|
const { data: businessResponse } = useGetBusiness();
|
||||||
const { refreshAuth } = useAuth();
|
const { refreshAuth } = useAuth();
|
||||||
@@ -50,6 +40,12 @@ const HeaderUserMenu: FC = () => {
|
|||||||
const admin = business?.admin;
|
const admin = business?.admin;
|
||||||
const adminName = getAdminFullName(admin);
|
const adminName = getAdminFullName(admin);
|
||||||
|
|
||||||
|
const closePopover = () => setPopoverKey((key) => key + 1);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setPopoverKey((key) => key + 1);
|
||||||
|
}, [location.pathname]);
|
||||||
|
|
||||||
if (!business) return null;
|
if (!business) return null;
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
@@ -59,8 +55,6 @@ const HeaderUserMenu: FC = () => {
|
|||||||
window.location.href = Paths.home;
|
window.location.href = Paths.home;
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeMobilePanel = () => setPopoverKey((key) => key + 1);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover className="relative" key={popoverKey}>
|
<Popover className="relative" key={popoverKey}>
|
||||||
<PopoverButton className="flex items-center gap-2 outline-none">
|
<PopoverButton className="flex items-center gap-2 outline-none">
|
||||||
@@ -78,32 +72,25 @@ const HeaderUserMenu: FC = () => {
|
|||||||
anchor="bottom"
|
anchor="bottom"
|
||||||
className="flex xl:ml-6 overflow-auto flex-col gap-3 bg-white boxShadow xl:mt-7 z-30 py-4 text-xs rounded-2.5 xl:w-[300px] -mt-[50px] w-full fixed xl:h-fit h-full shadow-md"
|
className="flex xl:ml-6 overflow-auto flex-col gap-3 bg-white boxShadow xl:mt-7 z-30 py-4 text-xs rounded-2.5 xl:w-[300px] -mt-[50px] w-full fixed xl:h-fit h-full shadow-md"
|
||||||
>
|
>
|
||||||
<button
|
<button type="button" className="absolute xl:hidden top-6 left-6" onClick={closePopover}>
|
||||||
type="button"
|
|
||||||
className="absolute xl:hidden top-6 left-6"
|
|
||||||
onClick={closeMobilePanel}
|
|
||||||
>
|
|
||||||
<CloseCircle size={20} color="#da2129" />
|
<CloseCircle size={20} color="#da2129" />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<Link
|
<Link to={`${Paths.catalog.business}${business.slug}`} onClick={closePopover} className="flex flex-col gap-2 items-center justify-center border-b border-[#EAEDF5] pb-4">
|
||||||
to={`${Paths.catalog.business}${business.slug}`}
|
|
||||||
className="flex flex-col gap-2 items-center justify-center border-b border-[#EAEDF5] pb-4"
|
|
||||||
>
|
|
||||||
<BusinessLogo business={business} size="lg" />
|
<BusinessLogo business={business} size="lg" />
|
||||||
<div>{adminName}</div>
|
<div>{adminName}</div>
|
||||||
<div className="text-description">{business.name}</div>
|
<div className="text-description">{business.name}</div>
|
||||||
{admin?.phone ? (
|
{admin?.phone ? <div className="text-description">{admin.phone}</div> : null}
|
||||||
<div className="text-description">{admin.phone}</div>
|
|
||||||
) : null}
|
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<div className="px-6 mt-2">
|
<div className="px-6 mt-2">
|
||||||
<button
|
<Link to={Paths.catalog.list} onClick={closePopover} className="flex gap-2 items-center cursor-pointer">
|
||||||
type="button"
|
<DocumentText size={20} color="black" />
|
||||||
onClick={handleLogout}
|
<span>{t("sidebar.catalog")}</span>
|
||||||
className="flex gap-2 items-center cursor-pointer"
|
</Link>
|
||||||
>
|
</div>
|
||||||
|
<div className="px-6 mt-2">
|
||||||
|
<button type="button" onClick={handleLogout} className="flex gap-2 items-center cursor-pointer">
|
||||||
<Logout size={20} color="#da2129" />
|
<Logout size={20} color="#da2129" />
|
||||||
<span>{t("sidebar.logout")}</span>
|
<span>{t("sidebar.logout")}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user