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"; type Props = { onClose: Function; }; export default function NewTokenModal({ onClose }: Props) { 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("Creating..."); const { ok, data } = await addToken(token); toast.dismiss(load); if (ok) { toast.success(`Created!`); setNewToken((data as any).secretKey); } else toast.error(data as string); setSubmitLoader(false); } }; return ( {newToken ? (

Access Token Created

Your new token has been created. Please copy it and store it somewhere safe. You will not be able to see it again.

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

Create an Access Token

Name

setToken({ ...token, name: e.target.value })} placeholder="e.g. For the iOS shortcut" className="bg-base-200" />

Expires in

{token.expires === TokenExpiry.sevenDays && "7 Days"} {token.expires === TokenExpiry.oneMonth && "30 Days"} {token.expires === TokenExpiry.twoMonths && "60 Days"} {token.expires === TokenExpiry.threeMonths && "90 Days"} {token.expires === TokenExpiry.never && "No Expiration"}
)}
); }