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