forked from Archives/Athou_commafeed
reuse validation rule
This commit is contained in:
@@ -6,15 +6,16 @@ import { useForm } from "@mantine/form"
|
||||
import { useAsyncCallback } from "react-async-hook"
|
||||
import { client, errorToStrings } from "@/app/client"
|
||||
import { redirectToRootCategory } from "@/app/redirect/thunks"
|
||||
import { useAppDispatch, useAppSelector } from "@/app/store"
|
||||
import { useAppDispatch } from "@/app/store"
|
||||
import type { InitialSetupRequest } from "@/app/types"
|
||||
import { Alert } from "@/components/Alert"
|
||||
import { useValidationRules } from "@/hooks/useValidationRules"
|
||||
import { PageTitle } from "@/pages/PageTitle"
|
||||
|
||||
export function InitialSetupPage() {
|
||||
const serverInfos = useAppSelector(state => state.server.serverInfos)
|
||||
const dispatch = useAppDispatch()
|
||||
const { _ } = useLingui()
|
||||
const validationRules = useValidationRules()
|
||||
|
||||
const form = useForm<InitialSetupRequest>({
|
||||
initialValues: {
|
||||
@@ -23,10 +24,7 @@ export function InitialSetupPage() {
|
||||
email: "",
|
||||
},
|
||||
validate: {
|
||||
password: value =>
|
||||
serverInfos && value.length < serverInfos.minimumPasswordLength
|
||||
? _(msg`Password must be at least ${serverInfos.minimumPasswordLength} characters`)
|
||||
: null,
|
||||
password: validationRules.password,
|
||||
},
|
||||
validateInputOnChange: true,
|
||||
})
|
||||
|
||||
@@ -10,12 +10,14 @@ import { redirectToRootCategory } from "@/app/redirect/thunks"
|
||||
import { useAppDispatch, useAppSelector } from "@/app/store"
|
||||
import type { RegistrationRequest } from "@/app/types"
|
||||
import { Alert } from "@/components/Alert"
|
||||
import { useValidationRules } from "@/hooks/useValidationRules"
|
||||
import { PageTitle } from "@/pages/PageTitle"
|
||||
|
||||
export function RegistrationPage() {
|
||||
const serverInfos = useAppSelector(state => state.server.serverInfos)
|
||||
const dispatch = useAppDispatch()
|
||||
const { _ } = useLingui()
|
||||
const validationRules = useValidationRules()
|
||||
|
||||
const form = useForm<RegistrationRequest>({
|
||||
initialValues: {
|
||||
@@ -24,10 +26,7 @@ export function RegistrationPage() {
|
||||
email: "",
|
||||
},
|
||||
validate: {
|
||||
password: value =>
|
||||
serverInfos && value.length < serverInfos.minimumPasswordLength
|
||||
? _(msg`Password must be at least ${serverInfos.minimumPasswordLength} characters`)
|
||||
: null,
|
||||
password: validationRules.password,
|
||||
},
|
||||
validateInputOnChange: true,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user