From 6ac63c94d1beec5acf80924cc8947f9a3a843340 Mon Sep 17 00:00:00 2001 From: jonny paulino Date: Mon, 18 Mar 2024 12:03:22 -0300 Subject: [PATCH] create users --- src/assets/css/styles.css | 4 +- src/controller/login/auth.js | 2 +- src/controller/user/createUser.js | 47 ++-- src/routes.js | 2 + .../RegistrationConfirmed/FormPerson/index.js | 209 ++++++++++-------- .../RegistrationConfirmed.js | 1 - src/screens/Users/CreateUser/index.js | 94 ++++++++ src/screens/Users/CreateUser/style.js | 0 src/screens/Users/EditUser/index.js | 0 src/screens/Users/ListUsers/index.js | 13 ++ 10 files changed, 245 insertions(+), 127 deletions(-) create mode 100644 src/screens/Users/CreateUser/index.js create mode 100644 src/screens/Users/CreateUser/style.js create mode 100644 src/screens/Users/EditUser/index.js create mode 100644 src/screens/Users/ListUsers/index.js diff --git a/src/assets/css/styles.css b/src/assets/css/styles.css index 78bd58f..e4d0253 100644 --- a/src/assets/css/styles.css +++ b/src/assets/css/styles.css @@ -84,7 +84,7 @@ root { } -/* input[type="text"], +input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], @@ -109,4 +109,4 @@ root { -moz-transition: border linear .2s, box-shadow linear .2s; -o-transition: border linear .2s, box-shadow linear .2s; transition: border linear .2s, box-shadow linear .2s; - } */ \ No newline at end of file + } \ No newline at end of file diff --git a/src/controller/login/auth.js b/src/controller/login/auth.js index d15b2e9..19b7f76 100644 --- a/src/controller/login/auth.js +++ b/src/controller/login/auth.js @@ -8,7 +8,7 @@ const handleLogin = async (email, password, history) => { signInWithEmailAndPassword(auth, email, password) .then((userCredential) => { const user = userCredential.user; - login(user); + login(user.accessToken); history.push("/"); }) .catch((error) => { diff --git a/src/controller/user/createUser.js b/src/controller/user/createUser.js index 8abbfbe..fe1c5ef 100644 --- a/src/controller/user/createUser.js +++ b/src/controller/user/createUser.js @@ -1,30 +1,27 @@ import { createUserWithEmailAndPassword } from "firebase/auth"; import { auth, firestore } from "../../config/firebase"; -import { collection } from "@firebase/firestore" -import { addDoc } from "@firebase/firestore" +import { collection } from "@firebase/firestore"; +import { addDoc } from "@firebase/firestore"; +export function createUser(data) { + // Create the user with email and password + createUserWithEmailAndPassword(auth, data.email, data.password) + .then((userCredential) => { + // User created successfully + const user = userCredential.user; + const userData = { + name: data.name, + role: data.role, + email: user.email, + uid: user.uid, + }; - -export function createUser(email, password) { - // Create the user with email and password - createUserWithEmailAndPassword(auth, email, password) - .then((userCredential) => { - // User created successfully - const user = userCredential.user; - - const userData = { - nome: user.displayName, - email: user.email, - uid: user.uid, - }; - - const ref = collection(firestore, "userData"); - addDoc(ref, userData) - - }) - .catch((error) => { - // Handle errors - console.error('Error creating user:', error.message); - }); - } \ No newline at end of file + const ref = collection(firestore, "userData"); + addDoc(ref, userData); + }) + .catch((error) => { + // Handle errors + console.error("Error creating user:", error.message); + }); +} diff --git a/src/routes.js b/src/routes.js index 8348f2f..99d3910 100644 --- a/src/routes.js +++ b/src/routes.js @@ -12,6 +12,7 @@ import Register from "./containers/Register"; import FormRegistration from "./containers/Registration/FormRegistration/FormRegistration"; import { isAuthenticated } from "./services/auth"; import PdfTodasReceita from "./Pdf/PdfTodasReceitas"; +import CreateUserScreen from "./screens/Users/CreateUser"; //const Home = lazy(() => import("./containers/Home")); @@ -55,6 +56,7 @@ const Routes = () => ( + diff --git a/src/screens/Classroom/RegistrationConfirmed/FormPerson/index.js b/src/screens/Classroom/RegistrationConfirmed/FormPerson/index.js index d9f5e08..6c38953 100644 --- a/src/screens/Classroom/RegistrationConfirmed/FormPerson/index.js +++ b/src/screens/Classroom/RegistrationConfirmed/FormPerson/index.js @@ -2,7 +2,13 @@ import { makeStyles, withStyles } from "@material-ui/core/styles"; import React from "react"; import { Grid } from "@material-ui/core"; -import { FormControl, FormControlLabel, Radio, RadioGroup, TextField } from "@mui/material"; +import { + FormControl, + FormControlLabel, + Radio, + RadioGroup, + TextField, +} from "@mui/material"; import { useRef } from "react"; import MaskCpf from "../../../../components/Mask/maskcpf"; import styles from "../../../../styles"; @@ -11,110 +17,117 @@ import styleBase from "../../../../styles"; import { Column, Padding } from "../../../../styles/style"; import MaskDate from "../../../../components/Mask/maskdate"; - const useStyles = makeStyles(styles); const PurpleRadio = withStyles({ - root: { - "&$checked": { - color: styleBase.colors.colorsBaseProductNormal - } + root: { + "&$checked": { + color: styleBase.colors.colorsBaseProductNormal, }, - checked: {} -})(props => ); + }, + checked: {}, +})((props) => ); const FormPerson = ({ values, handleChange }) => { + const classes = useStyles(); - const classes = useStyles(); - - const inputRef = useRef(null); - - return ( - <> + const inputRef = useRef(null); -

Dados básicos

- - -

Name

- - - -
-
- +

Dados básicos

+ + +

Name

+ + + +
+
+ + + + +

Sexo *

+ - - - -

Sexo *

- - } - label="Feminino" - /> - } - label="Masculino" - /> - -
-
-
- - -

Data de Nascimento

- - - -
-
- - - -

CPF

- - - -
- -
- - ) -} + } + label="Feminino" + /> + } + label="Masculino" + /> + + +
+
+ + +

Data de Nascimento

+ + + +
+
+ + +

CPF

+ + + +
+
+ + ); +}; -export default FormPerson; \ No newline at end of file +export default FormPerson; diff --git a/src/screens/Classroom/RegistrationConfirmed/RegistrationConfirmed.js b/src/screens/Classroom/RegistrationConfirmed/RegistrationConfirmed.js index b8634d1..0094184 100644 --- a/src/screens/Classroom/RegistrationConfirmed/RegistrationConfirmed.js +++ b/src/screens/Classroom/RegistrationConfirmed/RegistrationConfirmed.js @@ -28,7 +28,6 @@ const Home = props => { const history = useHistory() const { oneRegistration, handleUpdate, initialValues, points } = useContext(FormRegistrationContext) -console.log(oneRegistration) return ( <> { history.goBack() }} style={{ cursor: "pointer" }} /> diff --git a/src/screens/Users/CreateUser/index.js b/src/screens/Users/CreateUser/index.js new file mode 100644 index 0000000..50c9e8d --- /dev/null +++ b/src/screens/Users/CreateUser/index.js @@ -0,0 +1,94 @@ +import { Grid } from "@material-ui/core"; +import { makeStyles } from "@material-ui/core/styles"; +import React from "react"; +import styles from "../../../styles"; +import { Column, Padding } from "../../../styles/style"; + + +import { TextField } from "@mui/material"; +import { Form, Formik } from "formik"; + +import { ButtonPurple } from "../../../components/Buttons"; +import SelectUi from "../../../ui/Select"; +import { createUser } from "../../../controller/user/createUser"; + +const useStyles = makeStyles(styles); + +const CreateUserScreen = () => { + const classes = useStyles(); + + return ( +
+

Criar usuário

+ + createUser(values)}> + {({ values, handleChange, setFieldValue }) => { + return ( +
+ + + + + +

Nome

+ + + +
+
+ + +

Email

+ + + +
+
+ + +

Tipo de Usuário

+ + setFieldValue("role", values.id)} name={"role"} value={values.role} getOptionLabel={props => props.name} getOptionValue={props => props.id} label={"Tipo de usuário"}/> + +
+
+ + +

Senha

+ + + +
+
+
+ ); + }} +
+
+ ); +}; + +export default CreateUserScreen; diff --git a/src/screens/Users/CreateUser/style.js b/src/screens/Users/CreateUser/style.js new file mode 100644 index 0000000..e69de29 diff --git a/src/screens/Users/EditUser/index.js b/src/screens/Users/EditUser/index.js new file mode 100644 index 0000000..e69de29 diff --git a/src/screens/Users/ListUsers/index.js b/src/screens/Users/ListUsers/index.js new file mode 100644 index 0000000..5535592 --- /dev/null +++ b/src/screens/Users/ListUsers/index.js @@ -0,0 +1,13 @@ +import React from "react"; + +const ListUserScreen = () => { + + + return ( +
+ +
+ ) +} + +export default ListUserScreen; \ No newline at end of file