Spaces:
Running
Running
Ashraf Al-Kassem commited on
Commit ·
66154ca
1
Parent(s): 4bffb79
Refactor Template Details validation to use sonner toast
Browse files
frontend/src/app/(dashboard)/templates/[slug]/page.tsx
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
| 21 |
} from "lucide-react";
|
| 22 |
import { cn } from "@/lib/utils";
|
| 23 |
import { getTemplate, cloneTemplate, type TemplateDetail } from "@/lib/templates-api";
|
|
|
|
| 24 |
|
| 25 |
const NODE_TYPE_ICONS: Record<string, React.ReactNode> = {
|
| 26 |
MESSAGE_INBOUND: <MessageSquare className="w-4 h-4" />,
|
|
@@ -139,18 +140,18 @@ export default function TemplateDetailPage() {
|
|
| 139 |
(v) => v.required && !variableValues[v.key] && !v.default_value
|
| 140 |
);
|
| 141 |
if (missingVars.length > 0) {
|
| 142 |
-
|
| 143 |
return;
|
| 144 |
}
|
| 145 |
setCloning(true);
|
| 146 |
-
setError("");
|
| 147 |
const hasVars = Object.keys(variableValues).length > 0;
|
| 148 |
const res = await cloneTemplate(slug, undefined, hasVars ? variableValues : undefined);
|
| 149 |
if (res.success && res.data) {
|
| 150 |
setCloneSuccess(true);
|
|
|
|
| 151 |
setTimeout(() => router.push(res.data!.redirect_path), 1000);
|
| 152 |
} else {
|
| 153 |
-
|
| 154 |
}
|
| 155 |
setCloning(false);
|
| 156 |
};
|
|
@@ -332,10 +333,6 @@ export default function TemplateDetailPage() {
|
|
| 332 |
</div>
|
| 333 |
)}
|
| 334 |
|
| 335 |
-
{error && (
|
| 336 |
-
<p className="text-xs text-red-600 text-center">{error}</p>
|
| 337 |
-
)}
|
| 338 |
-
|
| 339 |
<Link
|
| 340 |
href="/templates"
|
| 341 |
className="block text-center text-sm text-muted-foreground hover:text-foreground transition-colors"
|
|
|
|
| 21 |
} from "lucide-react";
|
| 22 |
import { cn } from "@/lib/utils";
|
| 23 |
import { getTemplate, cloneTemplate, type TemplateDetail } from "@/lib/templates-api";
|
| 24 |
+
import { toast } from "sonner";
|
| 25 |
|
| 26 |
const NODE_TYPE_ICONS: Record<string, React.ReactNode> = {
|
| 27 |
MESSAGE_INBOUND: <MessageSquare className="w-4 h-4" />,
|
|
|
|
| 140 |
(v) => v.required && !variableValues[v.key] && !v.default_value
|
| 141 |
);
|
| 142 |
if (missingVars.length > 0) {
|
| 143 |
+
toast.error(`Please fill in: ${missingVars.map((v) => v.label).join(", ")}`);
|
| 144 |
return;
|
| 145 |
}
|
| 146 |
setCloning(true);
|
|
|
|
| 147 |
const hasVars = Object.keys(variableValues).length > 0;
|
| 148 |
const res = await cloneTemplate(slug, undefined, hasVars ? variableValues : undefined);
|
| 149 |
if (res.success && res.data) {
|
| 150 |
setCloneSuccess(true);
|
| 151 |
+
toast.success("Template cloned successfully");
|
| 152 |
setTimeout(() => router.push(res.data!.redirect_path), 1000);
|
| 153 |
} else {
|
| 154 |
+
toast.error(res.error ?? "Failed to clone template.");
|
| 155 |
}
|
| 156 |
setCloning(false);
|
| 157 |
};
|
|
|
|
| 333 |
</div>
|
| 334 |
)}
|
| 335 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
<Link
|
| 337 |
href="/templates"
|
| 338 |
className="block text-center text-sm text-muted-foreground hover:text-foreground transition-colors"
|