"use client"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { scanOnDemand } from "@/actions/scans/scans"; import { AddIcon } from "@/components/icons"; import { CustomButton } from "@/components/ui/custom"; import { Form } from "@/components/ui/form"; import { ProviderProps } from "@/types"; // Asegúrate de importar la interfaz correcta import { launchScanFormSchema } from "@/types/formSchemas"; import { ProviderInfo } from "../../provider-info"; type FormValues = z.infer>; interface LaunchScanFormProps { searchParams: { type: string; id: string }; providerData: { data: { type: string; id: string; attributes: ProviderProps["attributes"]; }; }; } export const LaunchScanForm = ({ searchParams, providerData, }: LaunchScanFormProps) => { const providerType = searchParams.type; const providerId = searchParams.id; const [apiErrorMessage, setApiErrorMessage] = useState(null); const router = useRouter(); const formSchema = launchScanFormSchema(); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { providerId, providerType, scannerArgs: { checksToExecute: [], }, }, }); // const isLoading = form.formState.isSubmitting; const onSubmitClient = async (values: FormValues) => { const formData = new FormData(); formData.append("providerId", values.providerId); // Generate default scan name using provider type and current date const date = new Date(); const month = (date.getMonth() + 1).toString().padStart(2, "0"); const day = date.getDate().toString().padStart(2, "0"); const year = date.getFullYear(); const defaultScanName = `${providerType}:${month}/${day}/${year}`; formData.append("scanName", defaultScanName); try { const data = await scanOnDemand(formData); if (data.error) { setApiErrorMessage(data.error); form.setError("providerId", { type: "server", message: data.error, }); } else { router.push("/scans"); } } catch (error) { form.setError("providerId", { type: "server", message: "An unexpected error occurred. Please try again.", }); } }; return (
Scan started
The scan has just started. From now on, a new scan will be launched every 24 hours, starting from this moment.
{apiErrorMessage && (

{apiErrorMessage.toLowerCase()}

)} {/*
} isDisabled={true} > Schedule } > {isLoading ? <>Loading : Start now}
*/}
} > Go to Scans
); };