import React, { useState } from "react"; import TextInput from "@/components/TextInput"; import { TokenExpiry } from "@/types/global"; import toast from "react-hot-toast"; import Modal from "../Modal"; import useTokenStore from "@/store/tokens"; import { dropdownTriggerer } from "@/lib/client/utils"; import Button from "../ui/Button"; import { useTranslation } from "next-i18next"; type Props = { onClose: Function; }; export default function NewTokenModal({ onClose }: Props) { const { t } = useTranslation(); const [newToken, setNewToken] = useState(""); const { addToken } = useTokenStore(); const initial = { name: "", expires: 0 as TokenExpiry, }; const [token, setToken] = useState(initial as any); const [submitLoader, setSubmitLoader] = useState(false); const submit = async () => { if (!submitLoader) { setSubmitLoader(true); const load = toast.loading(t("creating_token")); const { ok, data } = await addToken(token); toast.dismiss(load); if (ok) { toast.success(t("token_created")); setNewToken((data as any).secretKey); } else toast.error(data as string); setSubmitLoader(false); } }; const getLabel = (expiry: TokenExpiry) => { switch (expiry) { case TokenExpiry.sevenDays: return t("7_days"); case TokenExpiry.oneMonth: return t("30_days"); case TokenExpiry.twoMonths: return t("60_days"); case TokenExpiry.threeMonths: return t("90_days"); case TokenExpiry.never: return t("no_expiration"); } }; return ( {newToken ? (

{t("access_token_created")}

{t("token_creation_notice")}

{}} className="w-full" />
) : ( <>

{t("create_access_token")}

{t("name")}

setToken({ ...token, name: e.target.value })} placeholder={t("token_name_placeholder")} className="bg-base-200" />

{t("expires_in")}

)}
); }