You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
984 B
38 lines
984 B
import type { FormEvent } from 'react'
|
|
|
|
import trim from 'lodash/trim'
|
|
|
|
import { formIds } from 'config/form'
|
|
|
|
import { useAuthStore } from 'features/AuthStore'
|
|
import { useForm } from 'features/FormStore'
|
|
|
|
import { useValidateForm } from './useValidateForm'
|
|
|
|
export const useSubmitHandler = () => {
|
|
const { register } = useAuthStore()
|
|
const { readFormValue } = useForm()
|
|
const validateForm = useValidateForm()
|
|
|
|
const readTrimmedValue = (fieldName: string) => trim(readFormValue(fieldName))
|
|
|
|
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
|
event.preventDefault()
|
|
|
|
if (validateForm()) {
|
|
const firstname = readTrimmedValue(formIds.firstname)
|
|
const lastname = readTrimmedValue(formIds.lastname)
|
|
const email = readTrimmedValue(formIds.email)
|
|
const password = readTrimmedValue(formIds.password)
|
|
|
|
register({
|
|
email,
|
|
firstname,
|
|
lastname,
|
|
password,
|
|
})
|
|
}
|
|
}
|
|
|
|
return handleSubmit
|
|
}
|
|
|