import { Box, Button, Card, Chip, Divider, Typography } from '@mui/joy' import moment from 'moment' import { useContext, useEffect, useState } from 'react' import { UserContext } from '../../contexts/UserContext' import { CreateLongLiveToken, DeleteLongLiveToken, GetLongLiveTokens, } from '../../utils/Fetcher' import { isPlusAccount } from '../../utils/Helpers' import TextModal from '../Modals/Inputs/TextModal' const APITokenSettings = () => { const [tokens, setTokens] = useState([]) const [isGetTokenNameModalOpen, setIsGetTokenNameModalOpen] = useState(false) const { userProfile, setUserProfile } = useContext(UserContext) useEffect(() => { GetLongLiveTokens().then(resp => { resp.json().then(data => { setTokens(data.res) }) }) }, []) const handleSaveToken = name => { CreateLongLiveToken(name).then(resp => { if (resp.ok) { resp.json().then(data => { // add the token to the list: console.log(data) const newTokens = [...tokens] newTokens.push(data.res) setTokens(newTokens) }) } }) } return (
Access Token Create token to use with the API to update things that trigger task or chores {!isPlusAccount(userProfile) && ( Not available in Basic Plan )} {tokens.map(token => ( {token.name} {moment(token.createdAt).fromNow()}( {moment(token.createdAt).format('lll')}) {token.token && ( )} ))} { setIsGetTokenNameModalOpen(false) }} okText={'Generate Token'} onSave={handleSaveToken} />
) } export default APITokenSettings