Skip to content

Commit 0e6e86b

Browse files
Merge branch 'inputvalidation' of https://github.com/prajwalkulkarni/user-story into inputvalidation
2 parents 3572068 + 04c5948 commit 0e6e86b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/pages/MyProfile.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ const MyProfile = () => {
1616

1717
const [, setUpdated] = useState(false)
1818

19+
const [updatingField, setUpdatingField] = useState('')
20+
1921
const handleInputChange = (event) => {
22+
setUpdatingField(event.target.value)
2023
setUser({
2124
...user,
2225
[event.target.name]: event.target.value
@@ -25,6 +28,10 @@ const MyProfile = () => {
2528

2629
const updateProfile = async () => {
2730
try {
31+
if (!updatingField) {
32+
toast.error('Input cannot be empty')
33+
return
34+
}
2835
const response = await userStory.updateUser({ id: userId, ...user })
2936
if (response) {
3037
toast.success('Profile updated successfully')

0 commit comments

Comments
 (0)