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