import React, { useState } from "react"; import { Button } from '../ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui/card"; import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "../ui/select"; import { Input } from "../ui/input"; import { Label } from "../ui/label"; import { Loader2 } from "lucide-react"; import { useToast } from "../ui/toast"; export default function NewDroplet() { const { showToast } = useToast(); const [isLoading, setIsLoading] = useState(false); const [formData, setFormData] = useState({ name: "", region: "", size: "", image: "", backups: false, ipv6: true, monitoring: false }); const regions = [ { value: "nyc1", label: "New York 1" }, { value: "nyc3", label: "New York 3" }, { value: "sfo3", label: "San Francisco 3" }, { value: "ams3", label: "Amsterdam 3" }, ]; const sizes = [ { value: "s-1vcpu-1gb", label: "1 vCPU, 1GB RAM" }, { value: "s-1vcpu-2gb", label: "1 vCPU, 2GB RAM" }, { value: "s-2vcpu-2gb", label: "2 vCPU, 2GB RAM" }, ]; const images = [ { value: "ubuntu-22-04-x64", label: "Ubuntu 22.04" }, { value: "ubuntu-20-04-x64", label: "Ubuntu 20.04" }, { value: "debian-11-x64", label: "Debian 11" }, ]; const handleChange = (e) => { const { name, value, type, checked } = e.target; setFormData(prev => ({ ...prev, [name]: type === 'checkbox' ? checked : value })); }; const handleSelectChange = (name, value) => { setFormData(prev => ({ ...prev, [name]: value })); }; const handleSubmit = async (e) => { e.preventDefault(); setIsLoading(true); try { const response = await fetch("https://api.digitalocean.com/v2/droplets", { method: "POST", headers: { "Content-Type": "application/json", "Authorization": "Bearer dop_v1_b6a075ece5786faf7c58d21761dbf95d47af372da062d68a870ce2a0bae51adf" }, body: JSON.stringify({ ...formData, ssh_keys: [47441478] }) }); const data = await response.json(); if (response.ok) { showToast(`Droplet ${formData.name} created successfully!`, { type: 'success' }); // Reset form setFormData({ name: "", region: "nyc3", size: "s-1vcpu-1gb", image: "ubuntu-22-04-x64", backups: false, ipv6: true, monitoring: false }); } else { throw new Error(data.message || "Failed to create droplet"); } } catch (error) { showToast(error.message, { type: 'error' }); } finally { setIsLoading(false); } }; return ( Create New Droplet Configure your new cloud server
); }