import { Button, Table, Text } from '@chakra-ui/react'; import { z as zod } from 'zod'; import { UserCreateWrite, ZodUserCreateWrite } from '@/back-api'; import { PageLayout } from '@/components/Layout/PageLayout'; import { ParameterLayout } from '@/components/ParameterLayout'; import { TopBar } from '@/components/TopBar/TopBar'; import { FormInput } from '@/components/form/FormInput'; import { FormPassword } from '@/components/form/FormPassword'; import { Formidable, zodResolver } from '@/components/formidable'; import { useFormidable } from '@/components/formidable/FormidableConfig'; import { UserService } from '@/service/user.service'; const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', //timeZoneName: "short", }; export const ManageAccountPage = () => { const { data: users } = UserService.useGets(); return ( <> id Login e-mail blocked avatar Last connection {users?.map((data) => ( {data.id} {data.login} {data.email} {data.blocked ? 'true' : 'false'} {data.avatar ? 'yes' : 'no'} {data.lastConnection ? new Date(data.lastConnection).toLocaleDateString( 'fr-FR', options ) : ''} ))} ); }; const passwordSchema = zod .string() .min(8, 'The password must be at least 8 characters long.') .max(128, 'The password must not exceed 128 characters.') .refine((value) => /[a-z]/.test(value), { message: 'The password must contain at least one lowercase letter.', }) .refine((value) => /[A-Z]/.test(value), { message: 'The password must contain at least one uppercase letter.', }) .refine((value) => /\d/.test(value), { message: 'The password must contain at least one number.', }) .refine( //(value) => /[]/.test(value), (value) => /[-_@()\{\}\[\]=+\*\/\<\>!$=\'\|`&~"#²\:\/;\.,\?]/.test(value), { message: 'The password must contain at least one special character in: -_@(){}[]=+*/<>!$=\'|`&~"#²:/;.,?', } ) .refine((value) => !/\s/.test(value), { message: 'The password must not contain spaces.', }); export const ZodUserCreateWithNewPassword = ZodUserCreateWrite.omit({ password: true, }).extend({ password: passwordSchema, }); export const CreateUserComponent = () => { const form = useFormidable({ initialValues: { login: '', email: '', password: '', }, configuration: { enableModifyNotification: false, enableReset: false, singleLineForm: true, }, resolver: zodResolver(ZodUserCreateWithNewPassword), }); //const { connect, lastError, isConnectionLoading } = useLogin(); const userCreate = UserService.useCreate({}); const onSubmit = () => { userCreate.call(form.values); }; return ( {userCreate.error && ( {userCreate.error.message} )} ); };