fix: new workspace dialog not closed when created
This commit is contained in:
@@ -47,6 +47,7 @@ function useCreateWorkspace() {
|
||||
throwOnError: true,
|
||||
},
|
||||
);
|
||||
setStatus({ type: "ok" });
|
||||
return workspace ?? null;
|
||||
} catch (error: unknown) {
|
||||
setStatus({ type: "error", error });
|
||||
|
@@ -6,7 +6,7 @@ import { Page } from "@/components/ui/page.tsx";
|
||||
import { SidebarProvider } from "@/components/ui/sidebar.tsx";
|
||||
import { Toaster } from "@/components/ui/toaster";
|
||||
import { Plus } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { useCallback, useState } from "react";
|
||||
import { WorkspaceTable } from "./workspace-table";
|
||||
import { NewWorkspaceDialog } from "./new-workspace-dialog";
|
||||
|
||||
@@ -31,6 +31,10 @@ function Main() {
|
||||
const [isNewWorkspaceDialogOpen, setIsNewWorkspaceDialogOpen] =
|
||||
useState(false);
|
||||
|
||||
const closeWorkspaceDialog = useCallback(() => {
|
||||
setIsNewWorkspaceDialogOpen(false);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={isNewWorkspaceDialogOpen}
|
||||
@@ -47,9 +51,7 @@ function Main() {
|
||||
<WorkspaceTable />
|
||||
</main>
|
||||
|
||||
<NewWorkspaceDialog
|
||||
onCreateSuccess={() => setIsNewWorkspaceDialogOpen(false)}
|
||||
/>
|
||||
<NewWorkspaceDialog onCreateSuccess={closeWorkspaceDialog} />
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
@@ -29,14 +29,16 @@ import { useForm } from "react-hook-form";
|
||||
import { nonempty, object, pattern, string, type Infer } from "superstruct";
|
||||
import { useCreateWorkspace } from "./api";
|
||||
|
||||
interface NewWorkspaceDialogProps {
|
||||
onCreateSuccess: () => void;
|
||||
}
|
||||
|
||||
const NewWorkspaceForm = object({
|
||||
workspaceName: pattern(string(), /^[\w-]+$/),
|
||||
imageId: nonempty(string()),
|
||||
});
|
||||
|
||||
function NewWorkspaceDialog({
|
||||
onCreateSuccess,
|
||||
}: { onCreateSuccess: () => void }) {
|
||||
function NewWorkspaceDialog({ onCreateSuccess }: NewWorkspaceDialogProps) {
|
||||
const { data: templateImages, isLoading, error } = useTemplateImages();
|
||||
const form = useForm({
|
||||
resolver: superstructResolver(NewWorkspaceForm),
|
||||
@@ -49,8 +51,6 @@ function NewWorkspaceDialog({
|
||||
const { toast } = useToast();
|
||||
const formRef = useRef<HTMLFormElement | null>(null);
|
||||
|
||||
const _onCreateSuccess = useCallback(onCreateSuccess, []);
|
||||
|
||||
useEffect(() => {
|
||||
switch (status.type) {
|
||||
case "error":
|
||||
@@ -70,12 +70,12 @@ function NewWorkspaceDialog({
|
||||
});
|
||||
break;
|
||||
case "ok":
|
||||
_onCreateSuccess();
|
||||
onCreateSuccess();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}, [status.type, toast, _onCreateSuccess]);
|
||||
}, [status.type, toast, onCreateSuccess]);
|
||||
|
||||
async function onSubmit(values: Infer<typeof NewWorkspaceForm>) {
|
||||
await createWorkspace({
|
||||
|
Reference in New Issue
Block a user