Search code examples
reactjsreact-admin

./src/views/users/UserCreate.js Attempted import error: 'email' is not exported from './../validations'


I Have an react app with the following tree:

src/
--/views
  --validations.js
  --/users
    --UserCreate.js

My validations.js code:

import {
    required,
    minLength,
    maxLength,
    minValue,
    maxValue,
    number,
    regex,
    email,
    choices
} from 'react-admin';

export const required = () => required("Campo obrigatório")
export const minLength = (value) => minLength(value,"Este campo deve ter o minimo de "+value+" caracteres")
export const maxLength = (value) => maxLength("Este campo deve ter o máximo de "+value+" caracteres")
export const email = () => email("Digite um e-mail válido")
export const passwordsMatch = (value, allValues) => value !== allValues.password ? 'As senhas não coincidem' : undefined;

My UserCreate.js code like this:

import React, { Component } from 'react';
import { Create, SimpleForm, TextInput, DisabledInput } from 'react-admin';
import { required, email, minLength,maxLength } from './../validations';


export const UserCreate = props => (
    <Create {...props}>
        <SimpleForm redirect="list">
            <DisabledInput label="#" source="id" />
            <TextInput source="name" validate={[required(),minLength(5),maxLength(20)]} label="Nome"/>
            <TextInput source="email" validate={[required(),minLength(5),maxLength(20),email()]} label="E-mail"/>
            <TextInput source="password" validate={[required(),minLength(8),maxLength(20)]} label="Senha" type="password"/>
            <TextInput name="confirm_password" validate={[passwordsMatch]} label="Confirmar senha" type="password"/>
        </SimpleForm>
    </Create>
)

But, on run i getting the following error:

./src/views/users/UserCreate.js Attempted import error: 'email' is not exported from './../validations'.

what am I doing wrong?


Solution

  • You're importing email and declaring a constant called email as well.

    That's making a conflict in your code and it's taking the first email from the module react-admin which is not exported.

    You should change the name of your const in order to make it work.