import { h, type FunctionComponent } from 'preact' import { useCallback } from 'preact/hooks' import rek, { type FetchError } from 'rek' import useRequestState from '../../shared/hooks/use_request_state.ts' import Button from './button.tsx' import Input from './input.tsx' import Message from './message.tsx' const ForgotPasswordForm: FunctionComponent = () => { const [{ error, pending, success }, actions] = useRequestState() const forgotPassword = useCallback(async (e: SubmitEvent & { currentTarget: HTMLFormElement }) => { e.preventDefault() actions.pending() try { await rek.post('/auth/reset-password', { email: e.currentTarget.email.value, }) actions.success() } catch (err) { actions.error(err as FetchError) } }, []) return success ? ( Success! Check your inbox to choose a new password. ) : (
{error && ( {error.status}: {error.body?.message || error.message} )}
) } export default ForgotPasswordForm