|
|
|
|
@ -4,10 +4,17 @@ import { |
|
|
|
|
useState, |
|
|
|
|
} from 'react' |
|
|
|
|
|
|
|
|
|
import { useLocation, useHistory } from 'react-router' |
|
|
|
|
|
|
|
|
|
import { ClientIds } from 'config/clients/types' |
|
|
|
|
|
|
|
|
|
import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields' |
|
|
|
|
import { changePassword } from 'features/AuthServiceApp/requests/changePassword' |
|
|
|
|
import { getClientSettings } from 'features/AuthStore/helpers' |
|
|
|
|
|
|
|
|
|
export const useChangePasswordForm = () => { |
|
|
|
|
const location = useLocation() |
|
|
|
|
const history = useHistory() |
|
|
|
|
const [error, setError] = useState('') |
|
|
|
|
const [isFetching, setIsFetching] = useState(false) |
|
|
|
|
const [password, setPassword] = useState('') |
|
|
|
|
@ -18,16 +25,18 @@ export const useChangePasswordForm = () => { |
|
|
|
|
checkPassword, |
|
|
|
|
} = useAuthFields('login') |
|
|
|
|
|
|
|
|
|
const { client_id } = getClientSettings() |
|
|
|
|
|
|
|
|
|
const currentClientId = new URLSearchParams(location.search).get('client_id') ?? client_id |
|
|
|
|
|
|
|
|
|
const handleSubmit = async (event: SyntheticEvent) => { |
|
|
|
|
event?.preventDefault() |
|
|
|
|
setIsFetching(true) |
|
|
|
|
try { |
|
|
|
|
const redirectUrl = await changePassword(password) |
|
|
|
|
await changePassword(currentClientId as ClientIds, password) |
|
|
|
|
setError('') |
|
|
|
|
setIsFetching(false) |
|
|
|
|
if (redirectUrl) { |
|
|
|
|
await window.location.assign(redirectUrl) |
|
|
|
|
} |
|
|
|
|
history.push(`/autorize?client_id=${currentClientId}`) |
|
|
|
|
} catch (err) { |
|
|
|
|
setError(String(err)) |
|
|
|
|
setIsFetching(false) |
|
|
|
|
|