-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
345 additions
and
8 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,74 @@ | ||
import { SubmitHandler, useForm } from "react-hook-form"; | ||
import { yupResolver } from "@hookform/resolvers/yup"; | ||
|
||
import updatePasswordSchema from "../../schemas/updatepasswordSchema"; | ||
import Button from "../common/auth/Button"; | ||
import InputField from "../common/auth/InputField"; | ||
|
||
interface UpdatePasswordFormInputs { | ||
oldPassword: string; | ||
newPassword: string; | ||
confirmPassword: string; | ||
} | ||
|
||
interface PasswordUpdateFormProps { | ||
onSubmit: SubmitHandler<UpdatePasswordFormInputs>; | ||
onCancel: () => void; | ||
loading: boolean; | ||
} | ||
|
||
const PasswordUpdateForm: React.FC<PasswordUpdateFormProps> = ({ | ||
onSubmit, | ||
onCancel, | ||
loading, | ||
}) => { | ||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors }, | ||
} = useForm<UpdatePasswordFormInputs>({ | ||
resolver: yupResolver(updatePasswordSchema), | ||
}); | ||
|
||
return ( | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<InputField | ||
name="oldPassword" | ||
type="password" | ||
placeholder="Old Password" | ||
register={register} | ||
error={errors.oldPassword?.message} | ||
/> | ||
<InputField | ||
name="newPassword" | ||
type="password" | ||
placeholder="New Password" | ||
register={register} | ||
error={errors.newPassword?.message} | ||
/> | ||
<InputField | ||
name="confirmPassword" | ||
type="password" | ||
placeholder="Confirm Password" | ||
register={register} | ||
error={errors.newPassword?.message} | ||
/> | ||
<div className="mt-20 flex justify-center gap-10 w-full"> | ||
<Button | ||
text="Cancel" | ||
onClick={onCancel} | ||
className=" border-red-500 text-#DB4444 py-3 px-4 my-4 text-normal md:text-lg" | ||
data-testid="pw-cancel-btn" | ||
/> | ||
<Button | ||
text={loading ? "Loading..." : "Save Password"} | ||
className="bg-[#DB4444] text-white py-3 px-4 " | ||
disabled={loading} | ||
data-testid="pw-update-btn" | ||
/> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
export default PasswordUpdateForm; |
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,101 @@ | ||
import { useState } from "react"; | ||
import Modal from "react-modal"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { toast, ToastContainer } from "react-toastify"; | ||
|
||
import PasswordUpdateForm from "../components/password/passwordUpdate"; | ||
import { RootState } from "../redux/store"; | ||
import { updatePassword } from "../redux/api/updatePasswordApiSlice"; | ||
import Button from "../components/common/auth/Button"; | ||
|
||
Modal.setAppElement("#root"); | ||
|
||
const UpdatePasswordPage = () => { | ||
const [modalIsOpen, setModalIsOpen] = useState(false); | ||
const dispatch = useDispatch(); | ||
const loading = useSelector((state: RootState) => state.password.loading); | ||
|
||
const openModal = () => { | ||
setModalIsOpen(true); | ||
}; | ||
|
||
const closeModal = () => { | ||
setModalIsOpen(false); | ||
}; | ||
|
||
const onSubmit = async (data: { | ||
oldPassword: string; | ||
newPassword: string; | ||
confirmPassword: string; | ||
}) => { | ||
try { | ||
// @ts-ignore | ||
const result = await dispatch(updatePassword(data)).unwrap(); | ||
const { message } = result; | ||
toast.success(message); | ||
closeModal(); | ||
} catch (error) { | ||
toast.error("Failed to update password."); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="w-full h-screen flex justify-center items-center"> | ||
<ToastContainer /> | ||
<Button | ||
onClick={openModal} | ||
className="bg-[#DB4444] text-white py-3 px-2 my-4 text-normal md:text-lg rounded-sm" | ||
text="Update Password" | ||
/> | ||
<Modal | ||
isOpen={modalIsOpen} | ||
onRequestClose={closeModal} | ||
style={{ | ||
overlay: { | ||
backgroundColor: "rgba(211, 211, 211, 0.5)", // or D0D0D0 | ||
}, | ||
content: { | ||
top: "50%", | ||
left: "50%", | ||
right: "auto", | ||
bottom: "auto", | ||
marginRight: "-50%", | ||
transform: "translate(-50%, -50%)", | ||
width: "50%", | ||
height: "80%", | ||
}, | ||
}} | ||
> | ||
<div className="flex justify-center"> | ||
<h1 className="absolute top-8 font-bold text-[#DB4444]"> | ||
Update Your Password | ||
</h1> | ||
</div> | ||
<div | ||
className="mt-20" | ||
style={{ | ||
width: "100%", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<PasswordUpdateForm | ||
onCancel={closeModal} | ||
onSubmit={onSubmit} | ||
loading={loading} | ||
/> | ||
</div> | ||
<div className="flex justify-center"> | ||
<p className="absolute bottom-6 text-sm flex justify-center items-center"> | ||
For your own Security we recommend you to have a | ||
<span className="font-bold">strong Password</span> | ||
! | ||
</p> | ||
</div> | ||
</Modal> | ||
</div> | ||
); | ||
}; | ||
|
||
export default UpdatePasswordPage; |
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.