-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] add reset password API support (#119)
Also make sure to verify permission on reload
- Loading branch information
1 parent
40755d9
commit aebbd16
Showing
9 changed files
with
170 additions
and
40 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
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
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,76 @@ | ||
import { StatusCodes } from 'http-status-codes'; | ||
import useMountedState from './useMountedState'; | ||
import { postUserResetPassword } from '@/api/users'; | ||
import { notifications } from '@mantine/notifications'; | ||
import { IconCheck, IconFileAlert } from '@tabler/icons-react'; | ||
|
||
export const usePostUserResetPassword = () => { | ||
const [data, setData] = useMountedState<any | null>(null); | ||
const [error, setError] = useMountedState<string | null>(null); | ||
const [loading, setLoading] = useMountedState<boolean>(false); | ||
|
||
const resetPasswordUser = async (userName:string) => { | ||
try { | ||
setLoading(true); | ||
notifications.show({ | ||
id: 'load-data', | ||
loading: true, | ||
color: '#545BEB', | ||
title: 'Changing Password', | ||
message: 'Password will be Changed.', | ||
autoClose: false, | ||
withCloseButton: false, | ||
}); | ||
setError(null); | ||
const res = await postUserResetPassword(userName); | ||
|
||
switch (res.status) { | ||
case StatusCodes.OK: { | ||
setData(res.data); | ||
notifications.update({ | ||
id: 'load-data', | ||
color: 'green', | ||
title: 'Password was Changed', | ||
message: 'Successfully Changed!!', | ||
icon: <IconCheck size="1rem" />, | ||
autoClose: 3000, | ||
}); | ||
break; | ||
|
||
} | ||
default: { | ||
setError(res.data); | ||
console.error(res); | ||
notifications.update({ | ||
id: 'load-data', | ||
color: 'red', | ||
title: 'Error Occured', | ||
message: res.data, | ||
icon: <IconFileAlert size="1rem" />, | ||
autoClose: 2000, | ||
}); | ||
} | ||
} | ||
} catch(error) { | ||
setError('Failed to get Create User'); | ||
notifications.update({ | ||
id: 'load-data', | ||
color: 'red', | ||
title: 'Error Occured', | ||
message: 'Error Occured while Creating User', | ||
icon: <IconFileAlert size="1rem" />, | ||
autoClose: 2000, | ||
}); | ||
console.error(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const resetData = () => { | ||
setData(null); | ||
}; | ||
|
||
return { data, error, loading, resetPasswordUser, resetData }; | ||
}; | ||
|
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
Oops, something went wrong.