Skip to content

Commit

Permalink
feat: add checkbox to accept the terms
Browse files Browse the repository at this point in the history
  • Loading branch information
paabloLC committed Feb 4, 2025
1 parent 5f54377 commit eb6c334
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
44 changes: 40 additions & 4 deletions ui/components/auth/oss/auth-form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import { Link } from "@nextui-org/react";
import { Checkbox, Link } from "@nextui-org/react";
import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand All @@ -11,7 +11,12 @@ import { NotificationIcon, ProwlerExtended } from "@/components/icons";
import { ThemeSwitch } from "@/components/ThemeSwitch";
import { useToast } from "@/components/ui";
import { CustomButton, CustomInput } from "@/components/ui/custom";
import { Form } from "@/components/ui/form";
import {
Form,
FormControl,
FormField,
FormMessage,
} from "@/components/ui/form";
import { ApiError, authFormSchema } from "@/types";

export const AuthForm = ({
Expand Down Expand Up @@ -213,13 +218,44 @@ export const AuthForm = ({
isDisabled={invitationToken !== null && true}
/>
)}

{process.env.NEXT_PUBLIC_IS_CLOUD_ENV === "true" && (
<FormField
control={form.control}
name="termsAndConditions"
render={({ field }) => (
<>
<FormControl>
<Checkbox
isRequired
className="py-4"
size="sm"
checked={field.value}
onChange={(e) => field.onChange(e.target.checked)}
>
I agree with the&nbsp;
<Link
href="https://prowler.com/terms-of-service/"
size="sm"
target="_blank"
>
Terms of Service
</Link>
&nbsp;of Prowler
</Checkbox>
</FormControl>
<FormMessage className="text-system-error dark:text-system-error" />
</>
)}
/>
)}
</>
)}

{form.formState.errors?.email && (
{type === "sign-in" && form.formState.errors?.email && (
<div className="flex flex-row items-center gap-2 text-system-error">
<NotificationIcon size={16} />
<p className="text-s">No user found</p>
<p className="text-small">Invalid email or password</p>
</div>
)}

Expand Down
7 changes: 7 additions & 0 deletions ui/types/authFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const authFormSchema = (type: string) =>
invitationToken:
type === "sign-in" ? z.string().optional() : z.string().optional(),

termsAndConditions:
type === "sign-in" || process.env.NEXT_PUBLIC_IS_CLOUD_ENV !== "true"
? z.boolean().optional()
: z.boolean().refine((value) => value === true, {
message: "You must accept the terms and conditions.",
}),

// Fields for Sign In and Sign Up
email: z.string().email(),
password: z.string().min(12, {
Expand Down

0 comments on commit eb6c334

Please sign in to comment.