diff --git a/frontend/src/components/pages/dashboard/changePassword/index.tsx b/frontend/src/components/pages/dashboard/changePassword/index.tsx new file mode 100644 index 0000000..437d5d1 --- /dev/null +++ b/frontend/src/components/pages/dashboard/changePassword/index.tsx @@ -0,0 +1,130 @@ +import { useState } from "react"; +import { IoMdEye, IoMdEyeOff } from "react-icons/io"; +import { SubmitHandler, useForm } from "react-hook-form"; + +type FormData = { + newPassword: string; + oldPassword: string; +}; + +const ChangePassword = () => { + const [togglePassword, setTogglePassword] = useState<{ + newPassword: boolean; + oldPassword: boolean; + }>({ + newPassword: false, + oldPassword: false, + }); + + const { + register, + handleSubmit, + watch, + formState: { errors }, + } = useForm({ mode: "onChange" }); + + const handleChangePassword: SubmitHandler = async (data) => { + console.log(data); + }; + + const handleTogglePassword = (type: string) => { + setTogglePassword((prev: any) => ({ + ...prev, + [type]: !prev[type], + })); + }; + + const oldPassword = watch("oldPassword"); + const newPassword = watch("newPassword"); + + const isFormValid = + oldPassword && + newPassword && + newPassword.length >= 6 && + newPassword !== oldPassword; + + return ( +
+
+

Change Password

+

Change your password carefully

+
+
+ + + {errors.oldPassword && ( +

+ {errors.oldPassword.message} +

+ )} + +
+
+ + + value !== oldPassword || + "New Password cannot be the same as the Old Password", + })} + className={`appearance-none dark:text-white rounded-md relative block w-full px-3 py-2 border ${ + errors.newPassword ? "border-red-500" : "border-gray-300" + } placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm`} + placeholder="Enter a new password" + /> + {errors.newPassword && ( +

+ {errors.newPassword.message} +

+ )} + +
+ +
+
+
+ ); +}; + +export default ChangePassword; diff --git a/frontend/src/components/pages/dashboard/index.tsx b/frontend/src/components/pages/dashboard/index.tsx index b2f09e3..89bdd4a 100644 --- a/frontend/src/components/pages/dashboard/index.tsx +++ b/frontend/src/components/pages/dashboard/index.tsx @@ -8,6 +8,7 @@ import PendingInvitation from "./invitation/PendingInvitation"; import { useRouter } from "next/router"; import LeaveRequests from "./leaveRequest/LeaveRequests"; import TopBar from "./navigationBars/TopBar"; +import ChangePassword from "./changePassword"; const Dashboard = () => { const [activeView, setActiveView] = useState(""); @@ -35,6 +36,7 @@ const Dashboard = () => { {activeView === "leave-requests" && } {activeView === "profile" && } {activeView === "payments" && } + {activeView === "change-password" && } diff --git a/frontend/src/components/pages/dashboard/navigationBars/Sidebar.tsx b/frontend/src/components/pages/dashboard/navigationBars/Sidebar.tsx index 81c2990..0e828c6 100644 --- a/frontend/src/components/pages/dashboard/navigationBars/Sidebar.tsx +++ b/frontend/src/components/pages/dashboard/navigationBars/Sidebar.tsx @@ -9,6 +9,7 @@ import { useLoggedInUserQuery, useLogoutUserMutation } from "@/features/user"; import { IUser } from "@/interfaces/user.interface"; import { CgProfile } from "react-icons/cg"; import { TbBrandTeams } from "react-icons/tb"; +import { RiLockPasswordFill } from "react-icons/ri"; import { MdInsertInvitation, MdOutlineLogout, @@ -124,6 +125,15 @@ const Sidebar = ({ setActiveView, activeView }: any) => { Payments + +