-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor aws set provider workflow
- Loading branch information
Showing
8 changed files
with
174 additions
and
88 deletions.
There are no files selected for viewing
31 changes: 13 additions & 18 deletions
31
ui/app/(prowler)/providers/(set-up-provider)/add-credentials/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
import { redirect } from "next/navigation"; | ||
import React from "react"; | ||
|
||
import { | ||
ViaCredentialsForm, | ||
ViaRoleForm, | ||
} from "@/components/providers/workflow/forms"; | ||
import { SelectViaAWS } from "@/components/providers/workflow/forms/select-via-aws/select-via-aws"; | ||
|
||
interface Props { | ||
searchParams: { type: string; id: string; via?: string }; | ||
} | ||
|
||
export default function AddCredentialsPage({ searchParams }: Props) { | ||
if ( | ||
!searchParams.type || | ||
!searchParams.id || | ||
(searchParams.type === "aws" && !searchParams.via) | ||
) { | ||
redirect("/providers/connect-account"); | ||
} | ||
|
||
const useCredentialsForm = | ||
(searchParams.type === "aws" && searchParams.via === "credentials") || | ||
(searchParams.type !== "aws" && !searchParams.via); | ||
|
||
const useRoleForm = | ||
searchParams.type === "aws" && searchParams.via === "role"; | ||
|
||
return ( | ||
<> | ||
{useCredentialsForm && <ViaCredentialsForm searchParams={searchParams} />} | ||
{useRoleForm && <ViaRoleForm searchParams={searchParams} />} | ||
{searchParams.type === "aws" && !searchParams.via && ( | ||
<SelectViaAWS initialVia={searchParams.via} /> | ||
)} | ||
|
||
{((searchParams.type === "aws" && searchParams.via === "credentials") || | ||
searchParams.type !== "aws") && ( | ||
<ViaCredentialsForm searchParams={searchParams} /> | ||
)} | ||
|
||
{searchParams.type === "aws" && searchParams.via === "role" && ( | ||
<ViaRoleForm searchParams={searchParams} /> | ||
)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./select-via-aws"; |
38 changes: 38 additions & 0 deletions
38
ui/components/providers/workflow/forms/select-via-aws/select-via-aws.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
import { useForm } from "react-hook-form"; | ||
|
||
import { Form } from "@/components/ui/form"; | ||
|
||
import { RadioGroupAWSViaCredentialsForm } from "../radio-group-aws-via-credentials-form"; | ||
|
||
interface SelectViaAWSProps { | ||
initialVia?: string; | ||
} | ||
|
||
export const SelectViaAWS = ({ initialVia }: SelectViaAWSProps) => { | ||
const router = useRouter(); | ||
const form = useForm({ | ||
defaultValues: { | ||
awsCredentialsType: initialVia || "", | ||
}, | ||
}); | ||
|
||
const handleSelectionChange = (value: string) => { | ||
const url = new URL(window.location.href); | ||
url.searchParams.set("via", value); | ||
router.push(url.toString()); | ||
}; | ||
|
||
return ( | ||
<Form {...form}> | ||
<RadioGroupAWSViaCredentialsForm | ||
control={form.control} | ||
isInvalid={!!form.formState.errors.awsCredentialsType} | ||
errorMessage={form.formState.errors.awsCredentialsType?.message} | ||
onChange={handleSelectionChange} | ||
/> | ||
</Form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.