"use client" import { useSession } from "next-auth/react" import { useEffect, useState } from "react" import { Dialog, DialogTrigger, Modal, ModalOverlay, Popover, } from "react-aria-components" import { useIntl } from "react-intl" import { Avatar } from "@scandic-hotels/design-system/Avatar" import { Button } from "@scandic-hotels/design-system/Button" import { Divider } from "@scandic-hotels/design-system/Divider" import SkeletonShimmer from "@scandic-hotels/design-system/SkeletonShimmer" import { Typography } from "@scandic-hotels/design-system/Typography" import { trpc } from "@scandic-hotels/trpc/client" import useLang from "@/hooks/useLang" import { getInitials } from "../utils" import styles from "./user-menu.module.css" export function UserMenu({ isMobile = false }: { isMobile?: boolean }) { const intl = useIntl() const lang = useLang() const session = useSession() const [loginLink, setLoginLink] = useState(`/${lang}/login`) const { data: profileData, isLoading, isSuccess, isError, } = trpc.partner.sas.getEuroBonusProfile.useQuery(undefined, { enabled: session.status === "authenticated", }) useEffect(() => { setLoginLink(`/${lang}/login?redirectTo=${window?.location.href}`) }, [lang, setLoginLink]) const firstName = profileData?.firstName const lastName = profileData?.lastName return (
{(session.status === "loading" || isLoading) && (isMobile ? ( ) : ( ))} {(session.status === "unauthenticated" || isError) && ( {isMobile ? null : ( {intl.formatMessage({ id: "partnerSas.menu.login", defaultMessage: "Log in", })} )} )} {session.status === "authenticated" && isSuccess && profileData && (
{isMobile ? ( {({ close }) => ( <> )} ) : ( )}
)}
) } function UserMenuContent({ firstName, lastName, points, isMobile, }: { firstName?: string lastName?: string points?: number isMobile?: boolean }) { const intl = useIntl() const lang = useLang() return ( <>
{isMobile && (

{intl.formatMessage( { id: "partnerSas.mobileMenu.greeting", defaultMessage: `Hi {fName} {lName}!`, }, { fName: firstName, lName: lastName } )}

)}

{intl.formatMessage({ id: "partnerSas.menu.ebPointsTitle", defaultMessage: "EB Points", })} {/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */} {"ยท"} {intl.formatMessage( { id: "partnerSas.menu.ebPoints", defaultMessage: "{points} points", }, { points: points, } )}

{/* Link triggers rsc which doesn't reload complete page and shows logged in even after logout */} {intl.formatMessage({ id: "common.logOut", defaultMessage: "Log out", })} ) }