diff --git a/client/src/Components/v2/design-elements/BasePage.tsx b/client/src/Components/v2/design-elements/BasePage.tsx
index ec429d5f6..48c836e54 100644
--- a/client/src/Components/v2/design-elements/BasePage.tsx
+++ b/client/src/Components/v2/design-elements/BasePage.tsx
@@ -177,7 +177,7 @@ export const MonitorBasePageWithStates = ({
error={error}
{...props}
>
- {priorityFallback}
+ {priorityFallback}
);
}
diff --git a/client/src/Components/v2/design-elements/BulletPointCheck.tsx b/client/src/Components/v2/design-elements/BulletPointCheck.tsx
index 2893ee4c2..4bd1ddf3c 100644
--- a/client/src/Components/v2/design-elements/BulletPointCheck.tsx
+++ b/client/src/Components/v2/design-elements/BulletPointCheck.tsx
@@ -27,6 +27,7 @@ export const BulletPointCheck = ({
{
+ const defaults: SetNewPasswordFormData = {
+ password: "",
+ confirm: "",
+ };
+
+ return {
+ schema: setNewPasswordSchema,
+ defaults,
+ };
+};
diff --git a/client/src/Pages/Auth/SetNewPassword/index.tsx b/client/src/Pages/Auth/SetNewPassword/index.tsx
index 804881546..09bd565f1 100644
--- a/client/src/Pages/Auth/SetNewPassword/index.tsx
+++ b/client/src/Pages/Auth/SetNewPassword/index.tsx
@@ -7,56 +7,125 @@ import { Button, TextField } from "@/Components/v2/inputs";
import Stack from "@mui/material/Stack";
import { useTheme } from "@mui/material/styles";
import { useTranslation } from "react-i18next";
+import { useForm, Controller } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
+import { useSetNewPasswordForm } from "@/Hooks/useSetNewPasswordForm";
+import type { SetNewPasswordFormData } from "@/Validation/setNewPassword";
+import { specialCharPattern } from "@/Validation/patterns";
+import { useParams, useNavigate } from "react-router-dom";
+import { usePost } from "@/Hooks/UseApi";
+import { useDispatch } from "react-redux";
+import { setAuthState } from "@/Features/Auth/authSlice";
const SetNewPasswordPage = () => {
const theme = useTheme();
const { t } = useTranslation();
+ const { token } = useParams<{ token: string }>();
+ const navigate = useNavigate();
+ const dispatch = useDispatch();
+ const { post, loading } = usePost();
+
+ const { schema, defaults } = useSetNewPasswordForm();
+
+ const { control, handleSubmit, watch } = useForm({
+ resolver: zodResolver(schema),
+ defaultValues: defaults,
+ });
+
+ const password = watch("password");
+ const confirm = watch("confirm");
+
+ const getVariant = (condition: boolean): "success" | "info" => {
+ return condition ? "success" : "info";
+ };
+
+ const hasLength = password.length >= 8;
+ const hasSpecial = specialCharPattern.test(password);
+ const hasNumber = /\d/.test(password);
+ const hasUppercase = /[A-Z]/.test(password);
+ const hasLowercase = /[a-z]/.test(password);
+ const passwordsMatch = password.length > 0 && password === confirm;
+
+ const onSubmit = async (data: SetNewPasswordFormData) => {
+ if (loading) return;
+
+ const result = await post("/auth/recovery/reset", {
+ password: data.password,
+ recoveryToken: token,
+ });
+
+ if (result?.success) {
+ dispatch(setAuthState(result));
+ navigate("/uptime");
+ }
+ };
return (
- (
+
+ )}
/>
- (
+
+ )}
/>
diff --git a/client/src/Validation/setNewPassword.ts b/client/src/Validation/setNewPassword.ts
new file mode 100644
index 000000000..26e13beb2
--- /dev/null
+++ b/client/src/Validation/setNewPassword.ts
@@ -0,0 +1,24 @@
+import { z } from "zod";
+import { specialCharPattern } from "@/Validation/patterns";
+
+export const setNewPasswordSchema = z
+ .object({
+ password: z
+ .string()
+ .min(1, "Password is required")
+ .min(8, "Password must be at least 8 characters")
+ .refine((val) => /[A-Z]/.test(val), "Password must contain an uppercase letter")
+ .refine((val) => /[a-z]/.test(val), "Password must contain a lowercase letter")
+ .refine((val) => /\d/.test(val), "Password must contain a number")
+ .refine(
+ (val) => specialCharPattern.test(val),
+ "Password must contain a special character"
+ ),
+ confirm: z.string().min(1, "Please confirm your password"),
+ })
+ .refine((data) => data.password === data.confirm, {
+ message: "Passwords do not match",
+ path: ["confirm"],
+ });
+
+export type SetNewPasswordFormData = z.infer;