Skip to content

Commit 552f702

Browse files
committed
Dashboard: Fix Import Engine form submit not working (#8064)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces a dialog for importing engine instances in the `ImportEngineButton` component, enhancing user interaction by managing the dialog state and updating UI elements. ### Detailed summary - Added `useState` to manage the dialog's open state. - Changed navigation from `router.push` to `router.refresh` after import. - Wrapped the dialog in a conditional open state. - Updated the layout and styling of the dialog content and links. - Modified form field styles for better UI consistency. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * New Features * Import dialog now closes automatically after a successful import and refreshes the current page. * Added an in-dialog warning beneath the URL field for clearer guidance. * Updated “Get started” link destination. * Style * Redesigned import dialog with improved layout, spacing, rounded content, and a bottom action bar; inputs use card styling. * Refined labels, placeholders, and header padding for clearer readability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 15f0839 commit 552f702

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/engine/(general)/import/import-engine-dialog.tsx

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ExternalLinkIcon,
99
} from "lucide-react";
1010
import Link from "next/link";
11+
import { useState } from "react";
1112
import { useForm } from "react-hook-form";
1213
import { toast } from "sonner";
1314
import { z } from "zod";
@@ -17,7 +18,6 @@ import {
1718
Dialog,
1819
DialogContent,
1920
DialogDescription,
20-
DialogFooter,
2121
DialogHeader,
2222
DialogTitle,
2323
DialogTrigger,
@@ -70,6 +70,7 @@ export function ImportEngineButton(props: {
7070
teamSlug: string;
7171
projectSlug: string;
7272
}) {
73+
const [isOpen, setIsOpen] = useState(false);
7374
const router = useDashboardRouter();
7475
const form = useForm<ImportEngineParams>({
7576
resolver: zodResolver(formSchema),
@@ -82,14 +83,15 @@ export function ImportEngineButton(props: {
8283
const importMutation = useMutation({
8384
mutationFn: async (importParams: ImportEngineParams) => {
8485
await importEngine({ ...importParams, teamIdOrSlug: props.teamSlug });
85-
router.push(`/team/${props.teamSlug}/${props.projectSlug}/engine`);
86+
router.refresh();
8687
},
8788
});
8889

8990
const onSubmit = async (data: ImportEngineParams) => {
9091
try {
9192
await importMutation.mutateAsync(data);
9293
toast.success("Engine imported successfully");
94+
setIsOpen(false);
9395
} catch (e) {
9496
const message = e instanceof Error ? e.message : undefined;
9597
toast.error(
@@ -102,42 +104,40 @@ export function ImportEngineButton(props: {
102104
};
103105

104106
return (
105-
<Form {...form}>
106-
<form onSubmit={form.handleSubmit(onSubmit)}>
107-
<Dialog>
108-
<DialogTrigger asChild>
109-
<Button
110-
className="gap-2 rounded-full bg-card"
111-
size="sm"
112-
variant="outline"
113-
>
114-
<ArrowDownToLineIcon className="size-3.5" />
115-
Import Engine
116-
</Button>
117-
</DialogTrigger>
107+
<Dialog open={isOpen} onOpenChange={setIsOpen}>
108+
<DialogTrigger asChild>
109+
<Button
110+
className="gap-2 rounded-full bg-card"
111+
size="sm"
112+
variant="outline"
113+
>
114+
<ArrowDownToLineIcon className="size-3.5" />
115+
Import Engine
116+
</Button>
117+
</DialogTrigger>
118118

119-
<DialogContent>
120-
<DialogHeader>
119+
<DialogContent className="p-0 rounded-lg overflow-hidden">
120+
<Form {...form}>
121+
<form onSubmit={form.handleSubmit(onSubmit)}>
122+
<DialogHeader className="p-4 lg:p-6">
121123
<DialogTitle>Import Engine Instance</DialogTitle>
122124
<DialogDescription>
123125
Import an Engine instance hosted on your infrastructure.
124126
</DialogDescription>
125127
</DialogHeader>
126128

127-
<div>
128-
<div>
129-
<Link
130-
className="flex items-center justify-between gap-2 rounded-lg border border-border bg-card p-3 text-sm hover:bg-accent"
131-
href="https://portal.thirdweb.com/infrastructure/engine/get-started"
132-
rel="noopener noreferrer"
133-
target="_blank"
134-
>
135-
Get help setting up Engine for free
136-
<ExternalLinkIcon className="size-4 text-muted-foreground" />
137-
</Link>
138-
</div>
129+
<div className="px-4 lg:px-6 pb-6">
130+
<Link
131+
className="mb-4 flex items-center justify-between gap-2 rounded-full border border-border bg-card p-3 text-sm hover:bg-accent"
132+
href="https://portal.thirdweb.com/engine/v2/get-started"
133+
rel="noopener noreferrer"
134+
target="_blank"
135+
>
136+
Get help setting up Engine for free
137+
<ExternalLinkIcon className="size-4 text-muted-foreground" />
138+
</Link>
139139

140-
<div className="mt-6 flex flex-col gap-4">
140+
<div className="space-y-5">
141141
<FormField
142142
control={form.control}
143143
name="name"
@@ -146,6 +146,7 @@ export function ImportEngineButton(props: {
146146
<FormLabel>Name</FormLabel>
147147
<FormControl>
148148
<Input
149+
className="bg-card"
149150
autoFocus
150151
placeholder="Enter a descriptive label"
151152
{...field}
@@ -164,6 +165,7 @@ export function ImportEngineButton(props: {
164165
<FormLabel>URL</FormLabel>
165166
<FormControl>
166167
<Input
168+
className="bg-card"
167169
placeholder="Enter your Engine URL"
168170
type="url"
169171
{...field}
@@ -182,19 +184,19 @@ export function ImportEngineButton(props: {
182184
</div>
183185
</div>
184186

185-
<DialogFooter>
186-
<Button className="min-w-28 gap-1.5 rounded-full" type="submit">
187+
<div className="border-t bg-card p-6 flex justify-end">
188+
<Button className="gap-2 rounded-full" type="submit">
187189
{importMutation.isPending ? (
188190
<Spinner className="size-4" />
189191
) : (
190192
<ArrowDownToLineIcon className="size-4" />
191193
)}
192194
Import
193195
</Button>
194-
</DialogFooter>
195-
</DialogContent>
196-
</Dialog>
197-
</form>
198-
</Form>
196+
</div>
197+
</form>
198+
</Form>
199+
</DialogContent>
200+
</Dialog>
199201
);
200202
}

0 commit comments

Comments
 (0)