-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(setting_page): created changePassword as separated component
- Loading branch information
1 parent
4af10fd
commit 5f6256f
Showing
3 changed files
with
97 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from "react"; | ||
import { useDispatch } from "react-redux"; | ||
import { | ||
startProgressBar, | ||
stopProgressBar, | ||
} from "../../services/redux-actions"; | ||
import settingPageApi from "../../services/api/pages/settingPageApi"; | ||
import { useState } from "react"; | ||
import { toastError, toastSuccess } from "../../services/toast"; | ||
|
||
const ChangePassword = () => { | ||
const dispatch = useDispatch(); | ||
const [inputFieldData, setInputFieldData] = useState({ | ||
oldPassword: "", | ||
newPassword: "", | ||
cNewPassword: "", | ||
}); | ||
|
||
const getInputFieldData = (e) => { | ||
const name = e.target.name; | ||
const value = e.target.value; | ||
setInputFieldData({ | ||
...inputFieldData, | ||
[name]: value, | ||
}); | ||
}; | ||
|
||
const changePassword = async (e) => { | ||
try { | ||
e.preventDefault(); | ||
dispatch(startProgressBar()); | ||
const res = await settingPageApi.changePassword(inputFieldData); | ||
const data = await res.data; | ||
if (res.status === 200 && data.success) { | ||
toastSuccess(data.msg); | ||
} else { | ||
toastError(data.msg); | ||
} | ||
dispatch(stopProgressBar()); | ||
setInputFieldData({ | ||
oldPassword: "", | ||
newPassword: "", | ||
cNewPassword: "", | ||
}); | ||
} catch (err) { | ||
if (err.response) { | ||
if (err.response.data.success === false) { | ||
toastError(err.response.data.msg); | ||
} | ||
} else { | ||
toastError("Some Problem Occur, Please Try again later!!!"); | ||
} | ||
dispatch(stopProgressBar()); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="Setting_Container_With_Input_Field"> | ||
<h1>Change Password</h1> | ||
<input | ||
type="password" | ||
placeholder="Old password" | ||
name="oldPassword" | ||
value={inputFieldData.oldPassword} | ||
onChange={getInputFieldData} | ||
/> | ||
<input | ||
type="password" | ||
placeholder="New password" | ||
name="newPassword" | ||
value={inputFieldData.newPassword} | ||
onChange={getInputFieldData} | ||
/> | ||
<form> | ||
<input | ||
type="password" | ||
placeholder="Conform password" | ||
name="cNewPassword" | ||
value={inputFieldData.cNewPassword} | ||
onChange={getInputFieldData} | ||
/> | ||
<button onClick={changePassword}>Change</button> | ||
</form> | ||
<p>Don't Forgot Your Password</p> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default ChangePassword; |
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