import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Form, FormControl, FormDescription, 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 { Pencil, CheckIcon, ChevronsUpDown, PenBoxIcon } from "lucide-react"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { ScrollArea } from "@/components/ui/scroll-area"; import { z } from "zod"; import { Switch } from "@/components/ui/switch"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; const UpdateBackupSchema = z.object({ destinationId: z.string().min(1, "Destination required"), schedule: z.string().min(1, "Schedule (Cron) required"), prefix: z.string().min(1, "Prefix required"), enabled: z.boolean(), database: z.string().min(1, "Database required"), }); type UpdateBackup = z.infer; interface Props { backupId: string; refetch: () => void; } export const UpdateBackup = ({ backupId, refetch }: Props) => { const { data, isLoading } = api.destination.all.useQuery(); const { data: backup } = api.backup.one.useQuery( { backupId, }, { enabled: !!backupId, }, ); const { mutateAsync, isLoading: isLoadingUpdate } = api.backup.update.useMutation(); const form = useForm({ defaultValues: { database: "", destinationId: "", enabled: true, prefix: "/", schedule: "", }, resolver: zodResolver(UpdateBackupSchema), }); useEffect(() => { if (backup) { form.reset({ database: backup.database, destinationId: backup.destinationId, enabled: backup.enabled || false, prefix: backup.prefix, schedule: backup.schedule, }); } }, [form, form.reset, backup]); const onSubmit = async (data: UpdateBackup) => { await mutateAsync({ backupId, destinationId: data.destinationId, prefix: data.prefix, schedule: data.schedule, enabled: data.enabled, database: data.database, }) .then(async () => { toast.success("Backup Updated"); refetch(); }) .catch(() => { toast.error("Error to update the backup"); }); }; return ( Update Backup Update the backup
( Destination {isLoading && ( Loading Destinations.... )} No destinations found. {data?.map((destination) => ( { form.setValue( "destinationId", destination.destinationId, ); }} > {destination.name} ))} )} /> { return ( Database ); }} /> { return ( Schedule (Cron) ); }} /> { return ( Prefix Destination Use if you want to storage in a specific path of your destination/bucket ); }} /> (
Enabled Enable or disable the backup
)} />
); };