Header.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use client'
  2. import { BsCaretDownFill } from "react-icons/bs";
  3. import { useSession, signIn, signOut } from "next-auth/react"
  4. import { createRef, useEffect, useState } from "react";
  5. import { trpc } from "@/lib/trpc";
  6. import Cookies from 'js-cookie';
  7. import { useAtomValue } from "jotai";
  8. import { instantDataAtom, stepsNodesAtom } from "../store";
  9. import { exportFlowToDocx } from "../export";
  10. import { BsCloudDownload } from "react-icons/bs";
  11. import { useQueryClient } from "@tanstack/react-query";
  12. export default function Header() {
  13. const { data: session, status } = useSession()
  14. const queryClient = useQueryClient()
  15. const logOut = async () => {
  16. await fetch("https://beta.api.cocorobo.cn/api/logout", {
  17. method: "POST", credentials: 'include'
  18. });
  19. await queryClient.invalidateQueries({ queryKey: ['auth'] })
  20. await signOut({ redirect: false })
  21. }
  22. return (
  23. <div className="navbar shrink-0 bg-base-100 shadow-xl rounded-box justify-center relative">
  24. {/* <div className="dropdown">
  25. <div tabIndex={0} role="button" className="btn btn-sm btn-wide btn-ghost">选择对话<BsCaretDownFill /></div>
  26. <ul tabIndex={0} className="dropdown-content menu bg-base-100 rounded-box z-[2] w-52 p-2 shadow">
  27. <li><a>Item 1</a></li>
  28. <li><a>Item 2</a></li>
  29. </ul>
  30. </div> */}
  31. <div className="absolute right-4 flex items-center">
  32. {status === 'authenticated'
  33. ? (
  34. <div className="flex gap-2 items-center">
  35. <p>Hi, </p>
  36. <div className="dropdown dropdown-bottom dropdown-end">
  37. <label tabIndex={0} className="btn btn-sm m-1">{session.user?.name}</label>
  38. <ul tabIndex={0} className="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52">
  39. <li><a onClick={logOut}>退出登录</a></li>
  40. </ul>
  41. </div>
  42. </div>
  43. ) : null
  44. }
  45. </div>
  46. </div >
  47. )
  48. }