import { AlertBlock } from "@/components/shared/alert-block"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; const addDestination = z.object({ name: z.string().min(1, "Name is required"), accessKeyId: z.string(), secretAccessKey: z.string(), bucket: z.string(), region: z.string(), endpoint: z.string(), }); type AddDestination = z.infer; export const AddDestination = () => { const utils = api.useUtils(); const { mutateAsync, isError, error, isLoading } = api.destination.create.useMutation(); const { mutateAsync: testConnection, isLoading: isLoadingConnection } = api.destination.testConnection.useMutation(); const form = useForm({ defaultValues: { accessKeyId: "", bucket: "", name: "", region: "", secretAccessKey: "", endpoint: "", }, resolver: zodResolver(addDestination), }); useEffect(() => { form.reset(); }, [form, form.reset, form.formState.isSubmitSuccessful]); const onSubmit = async (data: AddDestination) => { await mutateAsync({ accessKey: data.accessKeyId, bucket: data.bucket, endpoint: data.endpoint, name: data.name, region: data.region, secretAccessKey: data.secretAccessKey, }) .then(async () => { toast.success("Destination Created"); await utils.destination.all.invalidate(); }) .catch(() => { toast.error("Error to create the Destination"); }); }; return ( Add Destination In this section you can add destinations for your backups. {isError && {error?.message}}
{ return ( Name ); }} /> { return ( Access Key Id ); }} /> (
Secret Access Key
)} /> (
Bucket
)} /> (
Region
)} /> ( Endpoint )} />
); };