/* eslint-disable react-hooks/rules-of-hooks */ import { useRef } from 'react'; import { Button, FormControl, FormHelperText, FormLabel, Input, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, Text, Textarea, VStack, useColorModeValue, useToast } from '@chakra-ui/react'; import { Field, Form, Formik } from 'formik'; import { getRandomAccessPointName } from '@/lib/utils'; import { useAuthContext } from '@/contexts/AuthContext'; import { AccessPoint, Location } from '@/types'; import { Select } from 'chakra-react-select'; export default function CreateAccessPointDialog({ isOpen, onClose, location, onCreate, accessPoints }: { isOpen: boolean; onClose: () => void; location: Location; onCreate: (location: any) => void; accessPoints: AccessPoint[]; }) { const toast = useToast(); const initialRef = useRef(null); const finalRef = useRef(null); const { user } = useAuthContext(); const namePlaceholder = getRandomAccessPointName(); return ( <> { user.getIdToken().then((token: any) => { fetch(`/api/v1/locations/${location.id}/access-points`, { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }, body: JSON.stringify({ name: values.name, description: values.description, locationId: location.id, templateId: values.template?.value || null }) }) .then((res) => { if (res.status === 200) { return res.json(); } else { return res.json().then((json) => { throw new Error(json.message); }); } }) .then((data) => { toast({ title: data.message, status: 'success', duration: 5000, isClosable: true }); actions.resetForm(); onClose(); onCreate(data.accessPointId); }) .catch((error) => { toast({ title: 'There was an error creating the access point.', description: error.message, status: 'error', duration: 5000, isClosable: true }); }) .finally(() => { actions.setSubmitting(false); }); }); }} > {(props) => (
New Access Point {({ field, form }: any) => ( Name )} {({ field, form }: any) => ( Copy Configuration from Access Point