import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { DialogFooter, DialogHeader } from "@/components/ui/dialog"; import { Form, FormField, FormItem, FormLabel, FormControl, FormDescription, FormMessage, } from "@/components/ui/form"; import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem, } from "@/components/ui/select"; import { ToastAction } from "@/components/ui/toast"; import { DialogContent, DialogTitle } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { LoadingSpinner } from "@/components/ui/loading-spinner"; import { useToast } from "@/hooks/use-toast"; import { useTemplateImages } from "@/templates/api"; import { superstructResolver } from "@hookform/resolvers/superstruct"; import { useRef, useEffect } from "react"; import { useForm } from "react-hook-form"; import { nonempty, object, pattern, string, type Infer } from "superstruct"; import { useCreateWorkspace, useWorkspaceRuntimes } from "./api"; import type { TemplateImage } from "@/templates/types"; import type { WorkspaceRuntime } from "./types"; import { API_ERROR_WORKSPACE_EXISTS, isApiErrorResponse } from "@/api"; interface NewWorkspaceDialogProps { onCreateSuccess: () => void; } const NewWorkspaceFormSchema = object({ workspaceName: pattern(string(), /^[\w-]+$/), image: nonempty(string()), runtime: nonempty(string()), }); function NewWorkspaceDialog({ onCreateSuccess }: NewWorkspaceDialogProps) { const { data: templateImages, isLoading: isLoadingImages, error, } = useTemplateImages(); const { data: runtimes, isLoading: isLoadingRuntimes } = useWorkspaceRuntimes(); const isLoading = isLoadingImages || isLoadingRuntimes; function content() { if (error) { console.log(error); return (
An error occurred when fetching available options.
); } if (isLoading) { return (No images found. Create and build a template, and the resulting image will show up here.