Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): Add checkbox to accept terms and conditions #295

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e/courses/EnrollStudent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ test.describe.serial("Enroll student workflow", () => {
await page.getByLabel("Institutional ID").fill(studentInstitutionalID);
await page.getByLabel("Email").fill(studentEmail);
await page.getByLabel("Password").fill(studentPassword);
await page.getByLabel("Accept terms and conditions").check();
await page.getByRole("button", { name: "Submit" }).click();
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/courses/JoinCourse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ test.describe.serial("Join courses workflow", () => {
await page.getByLabel("Institutional ID").fill(studentInstitutionalID);
await page.getByLabel("Email").fill(studentEmail);
await page.getByLabel("Password").fill(studentPassword);

await page.getByLabel("Accept terms and conditions").check();
await page.getByRole("button", { name: "Submit" }).click();
await page.waitForURL(/\/login$/);
});
Expand Down
1 change: 1 addition & 0 deletions e2e/grades/grades-workflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ test.describe.serial("Grades workflow", () => {
await page.getByLabel("Institutional ID").fill(getRandomUniversityID());
await page.getByLabel("Email").fill(studentEmail);
await page.getByLabel("Password").fill(getDefaultPassword());
await page.getByLabel("Accept terms and conditions").check();
await page.getByRole("button", { name: "Submit" }).click();
});

Expand Down
8 changes: 8 additions & 0 deletions e2e/register/RegisterStudents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ test("The fields are validated", async ({ page }) => {
"Must contain at least one letter, one number and one special character"
)
).toBeVisible();
await expect(
page.getByText(
"You can't register without accepting the terms and conditions"
)
).toBeVisible();
});

test.describe.serial("Student registration", () => {
Expand All @@ -38,6 +43,7 @@ test.describe.serial("Student registration", () => {
await page.getByLabel("Email").fill(newStudentEmail);
await page.getByLabel("Institutional ID").fill(newStudentID);
await page.getByLabel("Password").fill(getDefaultPassword());
await page.getByLabel("Accept terms and conditions").check();
await page.getByRole("button", { name: "Submit" }).click();

await expect(
Expand All @@ -53,6 +59,7 @@ test.describe.serial("Student registration", () => {
await page.getByLabel("Email").fill(newStudentEmail);
await page.getByLabel("Institutional ID").fill(getRandomUniversityID());
await page.getByLabel("Password").fill(getDefaultPassword());
await page.getByLabel("Accept terms and conditions").check();
await page.getByRole("button", { name: "Submit" }).click();

await expect(
Expand All @@ -69,6 +76,7 @@ test.describe.serial("Student registration", () => {
await page.getByLabel("Email").fill(getRandomEmail());
await page.getByLabel("Institutional ID").fill(newStudentID);
await page.getByLabel("Password").fill(getDefaultPassword());
await page.getByLabel("Accept terms and conditions").check();
await page.getByRole("button", { name: "Submit" }).click();

await expect(
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@hookform/resolvers": "3.3.4",
"@radix-ui/react-alert-dialog": "1.0.5",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "1.0.5",
"@radix-ui/react-dropdown-menu": "2.0.6",
"@radix-ui/react-label": "2.0.2",
Expand Down
31 changes: 31 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/components/ui/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { cn } from "@/lib/utils";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import * as React from "react";

const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
className={cn("flex items-center justify-center text-current")}
>
<Check className="h-4 w-4" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));
Checkbox.displayName = CheckboxPrimitive.Root.displayName;

export { Checkbox };
47 changes: 45 additions & 2 deletions src/screens/session/register-student/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import {
Form,
FormControl,
Expand Down Expand Up @@ -30,7 +31,10 @@ const RegisterStudentSchema = z.object({
.regex(
/^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?])[A-Za-z\d[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]{8,}$/,
"Must contain at least one letter, one number and one special character"
)
),
accept_terms: z.boolean().refine((value) => !!value, {
message: "You can't register without accepting the terms and conditions"
})
});

export const RegisterStudentForm = () => {
Expand All @@ -43,7 +47,8 @@ export const RegisterStudentForm = () => {
full_name: "",
email: "",
institutional_id: "",
password: ""
password: "",
accept_terms: false
}
});

Expand Down Expand Up @@ -144,6 +149,44 @@ export const RegisterStudentForm = () => {
</FormItem>
)}
></FormField>
<FormField
control={form.control}
name="accept_terms"
render={({ field }) => (
<FormItem>
<div className="items-top flex space-x-2">
<FormControl>
<Checkbox
id="terms1"
checked={field.value}
onCheckedChange={() => field.onChange(!field.value)}
/>
</FormControl>
<div className="grid space-y-1.5">
<FormLabel htmlFor="terms1">
Accept terms and conditions
</FormLabel>
<p className="text-sm text-muted-foreground">
By checking this box, you agree to{" "}
<a
href="/POLITICA_TRATAMIENTO_INFORMACION_PROTECCION_DATOS_PERSONALES.pdf"
target="_blank"
rel="noreferrer,noopener"
className="text-red-upb underline"
>
our terms and conditions.
</a>
</p>
</div>
</div>
{form.formState.errors.accept_terms && (
<FormMessage>
{form.formState.errors.accept_terms.message}
</FormMessage>
)}
</FormItem>
)}
></FormField>
<Button
type="submit"
className="w-full"
Expand Down
Loading