()
| 5 | import { getDateString } from "@/utils"; |
| 6 | |
| 7 | const AccountView = () => { |
| 8 | const { t } = useTranslation(); |
| 9 | const { data: session } = useSession(); |
| 10 | |
| 11 | const expired = session?.user?.subscription?.expireAt && session?.user?.subscription?.expireAt < Date.now(); |
| 12 | |
| 13 | return ( |
| 14 | <> |
| 15 | {!session && ( |
| 16 | <button |
| 17 | className="whitespace-nowrap rounded bg-indigo-600 px-2 py-1 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" |
| 18 | onClick={() => signIn()} |
| 19 | > |
| 20 | {t("common.sign-in")} |
| 21 | </button> |
| 22 | )} |
| 23 | {session?.user && ( |
| 24 | <div> |
| 25 | <div className="flex-col space-y-4 sm:space-y-0 sm:flex sm:flex-row justify-between"> |
| 26 | <div className="flex items-center space-x-2"> |
| 27 | {session.user.image && ( |
| 28 | <img |
| 29 | className="inline-block h-8 w-8 rounded-full hover:bg-gray-100 dark:hover:bg-zinc-700 cursor-pointer" |
| 30 | src={session.user.image} |
| 31 | alt="" |
| 32 | /> |
| 33 | )} |
| 34 | <span>{session.user.email ?? session.user.name}</span> |
| 35 | <Link |
| 36 | href="/api/auth/signout" |
| 37 | className="whitespace-nowrap rounded bg-indigo-600 px-2 py-1 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" |
| 38 | > |
| 39 | {t("common.sign-out")} |
| 40 | </Link> |
| 41 | </div> |
| 42 | <div className="flex text-base font-semibold tracking-tight items-center"> |
| 43 | {!!expired && ( |
| 44 | <span className="mr-2 rounded-full bg-yellow-50 px-3 py-1 font-medium text-yellow-700 ring-1 ring-inset ring-yellow-600/20"> |
| 45 | {t("setting.plan.expired")} |
| 46 | </span> |
| 47 | )} |
| 48 | <span |
| 49 | className={`${ |
| 50 | session?.user.subscription.plan == "PRO" |
| 51 | ? "ring-green-600/20 bg-green-50 text-green-700" |
| 52 | : "ring-gray-600/20 bg-gray-50 text-gray-700" |
| 53 | } rounded-full px-4 py-1.5 ring-1 ring-inset`} |
| 54 | > |
| 55 | {t(`setting.plan.${session.user.subscription.plan.toLowerCase()}`)} |
| 56 | </span> |
| 57 | <div className="ml-4"> |
| 58 | {t("setting.plan.n-question-per-month", { |
| 59 | count: session.user.subscription.quota, |
| 60 | })} |
| 61 | </div> |
| 62 | {session.user.subscription.plan === "PRO" && ( |
| 63 | <div className="ml-8"> |
| 64 | {getDateString(session.user.subscription.startAt)} |
nothing calls this directly
no test coverage detected