import {
Box,
Button,
chakra,
Flex,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
useColorModeValue,
useToast,
} from '@chakra-ui/react'
import { useState } from 'react'
import QRCode from 'react-qr-code'
import { fetchApiKeys } from '../../store/apiKeySlice'
import { gatewayService } from '../../services/gatewayService'
import { useAppDispatch } from '../../store/hooks'
const NewApiKeyGeneratedModal = ({
isOpen = false,
generatedApiKey,
onClose,
showQR = false,
...props
}) => {
const toast = useToast()
return (
Api Key Generated
{showQR && (
<>
Open the SMS Gateway App and scan this QR to get started
{' '}
>
)}
{generatedApiKey}
{'Save this key, it wont be shown again ;)'}
{' '}
)
}
export default function GenerateApiKey() {
const [generatedApiKey, setGeneratedApiKey] = useState(null)
const [generatingApiKey, setGeneratingApiKey] = useState(null)
const [showGeneratedApiKeyModal, setShowGeneratedApiKeyModal] =
useState(false)
const dispatch = useAppDispatch()
const generateApiKey = async () => {
setGeneratingApiKey(true)
const newApiKey = await gatewayService.generateApiKey()
setGeneratedApiKey(newApiKey)
setShowGeneratedApiKeyModal(true)
setGeneratingApiKey(false)
dispatch(fetchApiKeys())
}
return (
<>
{' '}
Generate Api Key and Register Device
{' '}
{generatedApiKey && (
<>
{
{
setShowGeneratedApiKeyModal(false)
}}
/>
}
>
)}
>
)
}