chore: changes for setup provider's workflow

This commit is contained in:
Pablo Lara
2024-11-24 10:25:30 +01:00
parent f45edc18a9
commit 520a5fc756
4 changed files with 45 additions and 10 deletions
@@ -60,7 +60,9 @@ export const ConnectAccountForm = () => {
if (data?.errors && data.errors.length > 0) {
data.errors.forEach((error: ApiError) => {
const errorMessage = error.detail;
switch (error.source.pointer) {
const pointer = error.source?.pointer;
switch (pointer) {
case "/data/attributes/provider":
form.setError("providerType", {
type: "server",
@@ -7,7 +7,7 @@ import { useForm } from "react-hook-form";
import { z } from "zod";
import { scanOnDemand } from "@/actions/scans/scans";
import { RocketIcon, ScheduleIcon } from "@/components/icons";
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
@@ -51,7 +51,7 @@ export const LaunchScanForm = ({
},
});
const isLoading = form.formState.isSubmitting;
// const isLoading = form.formState.isSubmitting;
const onSubmitClient = async (values: FormValues) => {
const formData = new FormData();
@@ -94,10 +94,11 @@ export const LaunchScanForm = ({
>
<div className="text-left">
<div className="text-2xl font-bold leading-9 text-default-foreground">
Launch scan
Scan started
</div>
<div className="py-2 text-default-500">
Launch the scan now or schedule it for a later date and time.
The scan has just started. From now on, a new scan will be launched
every 24 hours, starting from this moment.
</div>
</div>
@@ -116,7 +117,7 @@ export const LaunchScanForm = ({
<input type="hidden" name="providerId" value={providerId} />
<input type="hidden" name="providerType" value={providerType} />
<div className="flex w-full justify-end sm:space-x-6">
{/* <div className="flex w-full justify-end sm:space-x-6">
<CustomButton
type="submit"
ariaLabel={"Save"}
@@ -142,6 +143,18 @@ export const LaunchScanForm = ({
>
{isLoading ? <>Loading</> : <span>Start now</span>}
</CustomButton>
</div> */}
<div className="flex w-full items-center justify-end">
<CustomButton
asLink="/scans"
ariaLabel="Go to Scans page"
variant="solid"
color="action"
size="md"
endContent={<AddIcon size={20} />}
>
Go to Scans
</CustomButton>
</div>
</form>
</Form>
@@ -12,6 +12,7 @@ import {
checkConnectionProvider,
deleteCredentials,
} from "@/actions/providers";
import { scanOnDemand } from "@/actions/scans";
import { getTask } from "@/actions/task/tasks";
import { CheckIcon, SaveIcon } from "@/components/icons";
import { useToast } from "@/components/ui";
@@ -115,9 +116,26 @@ export const TestConnectionForm = ({
});
if (connected) {
router.push(
`/providers/launch-scan?type=${providerType}&id=${providerId}`,
);
try {
const data = await scanOnDemand(formData);
if (data.error) {
setApiErrorMessage(data.error);
form.setError("providerId", {
type: "server",
message: data.error,
});
} else {
router.push(
`/providers/launch-scan?type=${providerType}&id=${providerId}`,
);
}
} catch (error) {
form.setError("providerId", {
type: "server",
message: "An unexpected error occurred. Please try again.",
});
}
} else {
setConnectionStatus({
connected: false,
@@ -127,9 +127,11 @@ export const ColumnGetScans: ColumnDef<ScanProps>[] = [
const {
attributes: { name },
} = getScanData(row);
if (name.length === 0) {
if (!name || name.length === 0) {
return <span className="font-medium">-</span>;
}
return <span className="font-medium">{name}</span>;
},
},