mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-04 09:46:40 +00:00
refactor contexts, format zod errors, and more refactoring
This commit is contained in:
@@ -5,7 +5,7 @@ import { ChevronDownIcon } from "@radix-ui/react-icons";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { toast } from "@/hooks/use-toast";
|
||||
import { toast } from "@/hooks/useToast";
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import {
|
||||
Form,
|
||||
@@ -78,7 +78,7 @@ export function CreateSiteForm() {
|
||||
setKeypair(generatedKeypair);
|
||||
setIsLoading(false);
|
||||
|
||||
api.get(`/org/${orgId}/pickSiteDefaults`)
|
||||
api.get(`/org/${orgId}/pick-site-defaults`)
|
||||
.catch((e) => {
|
||||
toast({
|
||||
title: "Error creating site...",
|
||||
|
||||
@@ -15,6 +15,8 @@ import {
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useSiteContext } from "@app/hooks/useSiteContext";
|
||||
import { useForm } from "react-hook-form";
|
||||
import api from "@app/api";
|
||||
import { useToast } from "@app/hooks/useToast";
|
||||
|
||||
const GeneralFormSchema = z.object({
|
||||
name: z.string(),
|
||||
@@ -24,6 +26,7 @@ type GeneralFormValues = z.infer<typeof GeneralFormSchema>;
|
||||
|
||||
export function GeneralForm() {
|
||||
const { site, updateSite } = useSiteContext();
|
||||
const { toast } = useToast();
|
||||
|
||||
const form = useForm<GeneralFormValues>({
|
||||
resolver: zodResolver(GeneralFormSchema),
|
||||
@@ -34,7 +37,21 @@ export function GeneralForm() {
|
||||
});
|
||||
|
||||
async function onSubmit(data: GeneralFormValues) {
|
||||
await updateSite({ name: data.name });
|
||||
updateSite({ name: data.name });
|
||||
|
||||
await api
|
||||
.post(`/site/${site?.siteId}`, {
|
||||
name: data.name,
|
||||
})
|
||||
.catch((e) => {
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Failed to update site",
|
||||
description:
|
||||
e.message ||
|
||||
"An error occurred while updating the site.",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -92,7 +92,7 @@ export const columns: ColumnDef<SiteRow>[] = [
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem>
|
||||
<Link
|
||||
href={`/${siteRow.orgId}/settings/sites/${siteRow.id}`}
|
||||
href={`/${siteRow.orgId}/settings/sites/${siteRow.nice}`}
|
||||
>
|
||||
View settings
|
||||
</Link>
|
||||
|
||||
Reference in New Issue
Block a user