"use client"; import { FC, Fragment, useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; import Link from "next/link"; import { usePathname, useSearchParams } from "next/navigation"; import { usePopper } from "react-popper"; import { LogOut } from "lucide-react"; import { Popover, Transition } from "@headlessui/react"; import { Avatar, Button } from "@plane/ui"; // helpers import { API_BASE_URL } from "@/helpers/common.helper"; import { queryParamGenerator } from "@/helpers/query-param-generator"; // hooks import { useUser } from "@/hooks/store"; // services import { AuthService } from "@/services/auth.service"; const authService = new AuthService(); export const UserAvatar: FC = observer(() => { const pathName = usePathname(); const searchParams = useSearchParams(); // query params const board = searchParams.get("board") || undefined; const labels = searchParams.get("labels") || undefined; const state = searchParams.get("state") || undefined; const priority = searchParams.get("priority") || undefined; const peekId = searchParams.get("peekId") || undefined; // hooks const { data: currentUser, signOut } = useUser(); // states const [csrfToken, setCsrfToken] = useState(undefined); const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); useEffect(() => { if (csrfToken === undefined) authService.requestCSRFToken().then((data) => data?.csrf_token && setCsrfToken(data.csrf_token)); }, [csrfToken]); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: "bottom-end", modifiers: [ { name: "offset", options: { offset: [0, 40], }, }, ], }); // derived values const { queryParam } = queryParamGenerator({ peekId, board, state, priority, labels }); return (
{currentUser?.id ? (
{csrfToken && (
)}
) : (
)}
); });