Skip to content

Commit

Permalink
create users
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnypaulino committed Mar 18, 2024
1 parent 4ab10c4 commit 6ac63c9
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 127 deletions.
4 changes: 2 additions & 2 deletions src/assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ root {
}


/* input[type="text"],
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
Expand All @@ -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;
} */
}
2 changes: 1 addition & 1 deletion src/controller/login/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
47 changes: 22 additions & 25 deletions src/controller/user/createUser.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
const ref = collection(firestore, "userData");
addDoc(ref, userData);
})
.catch((error) => {
// Handle errors
console.error("Error creating user:", error.message);
});
}
2 changes: 2 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down Expand Up @@ -55,6 +56,7 @@ const Routes = () => (
<Route path="/register" exact component={Register} />
<Route path="/matricula" exact component={FormRegistration} />
<PrivateRoute exact path="/" component={School} />
<PrivateRoute exact path="/users/criar" component={CreateUserScreen} />
<PrivateRoute exact path="/escolas" component={School} />
<PrivateRoute exact path="/escolas/:id" component={SchoolClassrooms} />
<PrivateRoute exact path="/criar/escolas" component={SchoolCreate} />
Expand Down
209 changes: 111 additions & 98 deletions src/screens/Classroom/RegistrationConfirmed/FormPerson/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 => <Radio color="default" {...props} />);
},
checked: {},
})((props) => <Radio color="default" {...props} />);

const FormPerson = ({ values, handleChange }) => {
const classes = useStyles();

const classes = useStyles();

const inputRef = useRef(null);

return (
<>
const inputRef = useRef(null);

<h2> Dados básicos </h2>
<Grid container>
<Grid item md={6}>
<p className={classes.label}>Name</p>
<Column>
<TextField
className={classes.inputStudent}
value={values.name}
name="name" onChange={handleChange} variant="outlined" />
</Column>
</Grid>
</Grid>
<Grid
className={`${classes.contentMain}`}
container
direction="row"
justifyContent="center"
alignItems="center"
return (
<>
<h2> Dados básicos </h2>
<Grid container>
<Grid item md={6}>
<p className={classes.label}>Name</p>
<Column>
<TextField
className={classes.inputStudent}
value={values.name}
name="name"
onChange={handleChange}
variant="outlined"
/>
</Column>
</Grid>
</Grid>
<Grid
className={`${classes.contentMain}`}
container
direction="row"
justifyContent="center"
alignItems="center"
>
<Grid item xs={12}>
<Padding padding="8px" />
<FormControl
component="fieldset"
className={classes.formControl}
// error={errorList.sex}
>
<p className={classes.label}>Sexo *</p>
<RadioGroup
value={values.sex}
name="sex"
onChange={handleChange}
row
>
<Grid item xs={12}>
<Padding padding="8px" />
<FormControl
component="fieldset"
className={classes.formControl}
// error={errorList.sex}
>
<p className={classes.label}>Sexo *</p>
<RadioGroup
value={values.sex}
name="sex"
onChange={handleChange}
row
>
<FormControlLabel
value={'2'}
name="sex"
control={<PurpleRadio />}
label="Feminino"
/>
<FormControlLabel
value={'1'}
name="sex"
control={<PurpleRadio />}
label="Masculino"
/>
</RadioGroup>
</FormControl>
</Grid>
</Grid>
<Grid container>
<Grid item style={{ width: "100%" }} md={6}>
<p className={classes.label}>Data de Nascimento</p>
<Column>
<TextField className={classes.inputStudent} name="birthday" onChange={handleChange}
value={values.birthday}
InputProps={{
inputComponent: MaskDate,
value: values.birthday,
onChange: handleChange
}}
variant="outlined" />
</Column>
</Grid>
</Grid>
<Grid container>

<Grid item style={{ width: "100%" }} md={6}>
<p className={classes.label}>CPF</p>
<Column>
<TextField className={classes.inputStudent} InputProps={{
inputComponent: MaskCpf,
value: values.cpf,
inputRef: inputRef,
onChange: handleChange,
}} name="cpf" onChange={handleChange}
value={values.cpf}
variant="outlined" />
</Column>
</Grid>

</Grid>
</>
)
}
<FormControlLabel
value={"2"}
name="sex"
control={<PurpleRadio />}
label="Feminino"
/>
<FormControlLabel
value={"1"}
name="sex"
control={<PurpleRadio />}
label="Masculino"
/>
</RadioGroup>
</FormControl>
</Grid>
</Grid>
<Grid container>
<Grid item style={{ width: "100%" }} md={6}>
<p className={classes.label}>Data de Nascimento</p>
<Column>
<TextField
className={classes.inputStudent}
name="birthday"
onChange={handleChange}
value={values.birthday}
InputProps={{
inputComponent: MaskDate,
value: values.birthday,
onChange: handleChange,
}}
variant="outlined"
/>
</Column>
</Grid>
</Grid>
<Grid container>
<Grid item style={{ width: "100%" }} md={6}>
<p className={classes.label}>CPF</p>
<Column>
<TextField
className={classes.inputStudent}
InputProps={{
inputComponent: MaskCpf,
value: values.cpf,
inputRef: inputRef,
onChange: handleChange,
}}
name="cpf"
onChange={handleChange}
value={values.cpf}
variant="outlined"
/>
</Column>
</Grid>
</Grid>
</>
);
};

export default FormPerson;
export default FormPerson;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const Home = props => {
const history = useHistory()

const { oneRegistration, handleUpdate, initialValues, points } = useContext(FormRegistrationContext)
console.log(oneRegistration)
return (
<>
<ArrowBack onClick={() => { history.goBack() }} style={{ cursor: "pointer" }} />
Expand Down
Loading

0 comments on commit 6ac63c9

Please sign in to comment.