import * as React from 'react'; import { SubmitHandler, useForm } from 'react-hook-form'; import Box from '../common/Box'; import Button from '../common/Button'; import Spinner from '../common/Spinner'; import { DangerText } from '../common/CustomTexts'; import { ITenantSignUpTenantForm } from './TenantSignUpP'; import HttpStatus from '../../constants/http_status'; import { getLabel, getValidationMessage } from '../../helpers/formUtils'; interface Props { isSubmitting: boolean; error: string; handleSignUpSubmit(siteName: string, subdomain: string): void; } const TenantSignUpForm = ({ isSubmitting, error, handleSignUpSubmit, }: Props) => { const { register, handleSubmit, formState: { errors } } = useForm(); const onSubmit: SubmitHandler = data => { handleSignUpSubmit(data.siteName, data.subdomain); } return (

Create feedback space

{errors.siteName?.type === 'required' && getValidationMessage('required', 'tenant', 'site_name')}
!/\s/.test(value), notAlreadyTaken: async (newSubdomain) => { const res = await fetch(`/is_available?new_subdomain=${newSubdomain}`); return res.status === HttpStatus.OK; }, }, })} placeholder={getLabel('tenant', 'subdomain')} id="tenantSubdomain" className="formControl" />
.astuto.io
{errors.subdomain?.type === 'required' && getValidationMessage('required', 'tenant', 'subdomain')} {errors.subdomain?.type === 'pattern' && 'Subdomain can only contain alphanumeric characters and hyphens'} {errors.subdomain?.type === 'notAlreadyTaken' && 'Sorry, this subdomain is not available'}
{ error !== '' && { error } }
); } export default TenantSignUpForm;