* Replace Terms & Conditions with Sign Up Link on Sign In #4502 * terms replaced with signup link * begin fix (incomplete / do not merge) * Revert * Introduce welcome page * Update Twenty website --------- Co-authored-by: Mamatha Yarramaneni <mamathayarramaneni@Mamathas-Macbook.local> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { useForm } from 'react-hook-form';
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import { useRecoilValue } from 'recoil';
|
|
import { z } from 'zod';
|
|
|
|
import { PASSWORD_REGEX } from '@/auth/utils/passwordRegex.ts';
|
|
import { isSignInPrefilledState } from '@/client-config/states/isSignInPrefilledState.ts';
|
|
|
|
const validationSchema = z
|
|
.object({
|
|
exist: z.boolean(),
|
|
email: z.string().trim().email('Email must be a valid email'),
|
|
password: z
|
|
.string()
|
|
.regex(PASSWORD_REGEX, 'Password must contain at least 8 characters'),
|
|
})
|
|
.required();
|
|
|
|
export type Form = z.infer<typeof validationSchema>;
|
|
export const useSignInUpForm = () => {
|
|
const isSignInPrefilled = useRecoilValue(isSignInPrefilledState);
|
|
const form = useForm<Form>({
|
|
mode: 'onChange',
|
|
defaultValues: {
|
|
exist: false,
|
|
},
|
|
resolver: zodResolver(validationSchema),
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (isSignInPrefilled === true) {
|
|
form.setValue('email', 'tim@apple.dev');
|
|
form.setValue('password', 'Applecar2025');
|
|
}
|
|
}, [form, isSignInPrefilled]);
|
|
return { form: form };
|
|
};
|