Skip to content

Commit

Permalink
delete classroom
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnypaulino committed Apr 18, 2024
1 parent 26a2a6a commit 6a858b8
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 86 deletions.
3 changes: 2 additions & 1 deletion src/containers/Classroom/Classroom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from "react";
import fetchClassroom from "../../controller/classroom/fetchClassroom";
import Classroom from "../../screens/Classroom/Classroom";
import { getIdSchool } from "../../services/auth";

const Home = props => {

Expand All @@ -11,7 +12,7 @@ const Home = props => {
useEffect(() => {
fetchClassroom()
.then((testDataList) => {
const classroomSchool = testDataList.filter(props => props.object.school_fk === idSchool)
const classroomSchool = testDataList.filter(props => props.object.school_fk === getIdSchool())
setClassroom(classroomSchool)
})
.catch((err) => {
Expand Down
17 changes: 17 additions & 0 deletions src/controller/classroom/deleteClassroom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { collection, deleteDoc, doc } from "@firebase/firestore";
import { firestore } from "../../config/firebase";



export const deleteItem = async (id, history) => {
const itemRef = doc(collection(firestore, "classroom"), id);

try {
await deleteDoc(itemRef);
history.push("/turmas")
console.log("Item deleted successfully");
} catch (err) {
console.error("Error deleting item:", err);
throw err;
}
}
108 changes: 63 additions & 45 deletions src/screens/Classroom/Classroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React, { useContext, useEffect, useState } from "react";

// Material UI
import Grid from "@material-ui/core/Grid";
import { createTheme, makeStyles, ThemeProvider } from "@material-ui/core/styles";
import {
createTheme,
makeStyles,
ThemeProvider,
} from "@material-ui/core/styles";
import Alert from "@material-ui/lab/Alert";

import Select from "react-select";
Expand All @@ -15,65 +19,76 @@ import { Fab, useMediaQuery } from "@material-ui/core";
import AddIcon from "@material-ui/icons/Add";
import { Link } from "react-router-dom";
import { PrivateRouterContext } from "../../context/PrivateRouter/context";
import fetchOneSchool from "../../controller/School/fetchOneSchool";
import fetchSchool from "../../controller/School/fetchSchools";
import { idSchoolLocal } from "../../services/auth";
import { getIdSchool, idSchoolLocal } from "../../services/auth";
import styleBase from "../../styles";
import { Padding } from "../../styles/style";
import styles from "./styles";

const theme = createTheme({
palette: {
primary: {
main: styleBase.colors.colorsBaseProductNormal
}
}
main: styleBase.colors.colorsBaseProductNormal,
},
},
});

const useStyles = makeStyles(theme => styles);

const useStyles = makeStyles((theme) => styles);

const Classroom = ({ classroom, setIdSchool, idSchool }) => {
const [school, setSchool] = useState([])

const {user} = useContext(PrivateRouterContext)

const [school, setSchool] = useState([]);
const [schoolOne, setSchoolOne] = useState();

const matches = useMediaQuery('(max-width:600px)')
const { user } = useContext(PrivateRouterContext);

const matches = useMediaQuery("(max-width:600px)");

const classes = useStyles();

useEffect(() => {
fetchSchool()
.then((testDataList) => {
setSchool(testDataList)
setSchool(testDataList);
if (testDataList[0]) {
setIdSchool(testDataList[0].id)
idSchoolLocal(testDataList[0].id)
if (!getIdSchool()) {
idSchoolLocal(testDataList[0].id);
}
}
})
.catch((err) => {
console.error(err)
})
}, [setIdSchool])
console.error(err);
});
}, [setIdSchool, idSchool]);

useEffect(() => {
if (getIdSchool()) {
fetchOneSchool(getIdSchool())
.then((testDataList) => {
setSchoolOne(testDataList);
})
.catch((err) => {});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [getIdSchool()]);


const stage = () => {
return classroom?.map((item, index) => {
return (
<Grid key={index} item md={4} sm={3} xs={12}>
{item ? <BoxBig
link={`turmas/${item.id}`}
title={item.object.name}
addCursor={true}
textRight="Turma"
>
<p title={item.object.name} className={classes.name}>
{item.object.name}
</p>
</BoxBig>
: null}
{item ? (
<BoxBig
link={`turmas/${item.id}`}
title={item.object.name}
addCursor={true}
textRight="Turma"
>
<p title={item.object.name} className={classes.name}>
{item.object.name}
</p>
</BoxBig>
) : null}
</Grid>
);
});
Expand All @@ -83,27 +98,29 @@ const Classroom = ({ classroom, setIdSchool, idSchool }) => {
<div style={{ position: "relative" }}>
<Grid container direction="row">
<Grid className={classes.boxTitlePagination} item xs={12}>
<div style={{ display: 'flex', flexDirection: "row" }}>
<div style={{ display: "flex", flexDirection: "row" }}>
<h1 className={`${classes.title} ${classes.floatLeft}`}>Turmas </h1>
{/* <p style={{marginLeft: 'auto'}}> Será valido o último ano escolar para cada estagio</p> */}
</div>


<h2>{schoolOne?.object?.name}</h2>
<div className={`${classes.spaceBetween}`}>
<div style={{ width: matches ? "80%" : '50%' }}>
<div style={{ width: matches ? "80%" : "50%" }}>
<label>Escolha uma escola</label>
<Padding />
<Select
className="basic-single"
classNamePrefix="select"
placeholder="Digite uma escola"
options={school}
value={idSchool}
defaultValue={idSchool}
onChange={selectedOption => {
setIdSchool(selectedOption.id)
idSchoolLocal(selectedOption.id)
onChange={(selectedOption) => {
setIdSchool(selectedOption.id);
idSchoolLocal(selectedOption.id);
}}
getOptionValue={opt => opt.id}
getOptionLabel={opt => opt.object.name}
getOptionValue={(opt) => opt.id}
getOptionLabel={(opt) => opt.object.name}
/>
</div>
</div>
Expand All @@ -118,14 +135,15 @@ const Classroom = ({ classroom, setIdSchool, idSchool }) => {
</Grid>
</List>
</Grid>
{user?.role === 1 ? <Link to="/turma/adicionar" className={`${classes.addStage}`}>
<ThemeProvider theme={theme}>
<Fab color="primary" aria-label="add">
<AddIcon />
</Fab>
</ThemeProvider>
</Link> : null}

{user?.role === 1 ? (
<Link to="/turma/adicionar" className={`${classes.addStage}`}>
<ThemeProvider theme={theme}>
<Fab color="primary" aria-label="add">
<AddIcon />
</Fab>
</ThemeProvider>
</Link>
) : null}
</div>
);
};
Expand Down
113 changes: 73 additions & 40 deletions src/screens/Classroom/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,73 @@ import { BoxRegistration } from "../../components/Boxes";
import List from "../../components/List";

// Styles
import { ArrowBack } from "@material-ui/icons";
import { ArrowBack, Delete } from "@material-ui/icons";
import { useHistory } from "react-router";
import { ButtonPurple } from "../../components/Buttons";
import { Padding } from "../../styles/style";

const Create = props => {

const history = useHistory()

const {
data,
baseLink,
classroom
} = props;

const { id } = useParams()
import { Column, Padding, Row } from "../../styles/style";
import { deleteItem } from "../../controller/classroom/deleteClassroom";
import Swal from "sweetalert2";
import styles from "../../styles";
import image from "../../assets/images/Atenção-img.png";


const Create = (props) => {
const history = useHistory();

const { data, baseLink, classroom } = props;

const { id } = useParams();

const deletePreRegistration = (e, id) => {
e.stopPropagation()
if (id) {


return Swal.fire({
title: "Excluir pré matricula?",
text: "Essa ação é irreversível não pode ser desfeita",
imageUrl: image,
imageHeight: 250,
showCancelButton: true,
confirmButtonColor: styles.colors.colorsBaseProductNormal,
cancelButtonColor: styles.colors.colorsBaseCloudNormal,
confirmButtonText: 'Aceitar',
reverseButtons: true,
cancelButtonText: `<div style="color:black" >Cancelar</div>`
}).then((result) => {
if (result.isConfirmed) {
deleteItem(id, history)
}
})
}
}

const registrations = () => {
const registrationList = data ?? [];

return registrationList.map((registration, index) => {

const points = () => {
var count = 0;

if (registration) {
if (registration.object.filhoOculos === "1") {
count++;
}
if ((registration.object.filhossintomas.dificuldadeQuadro && registration.object.filhossintomas.olhoTortoMomentos) ||
(registration.object.filhossintomas.dificuldadeLivro && registration.object.filhossintomas.olhoTortoMomentos) ||
(registration.object.filhossintomas.dificuldadeQuadro && registration.object.filhossintomas.rostoApertaOlhos) ||
(registration.object.filhossintomas.dificuldadeLivro && registration.object.filhossintomas.rostoApertaOlhos) ||
if (
(registration.object.filhossintomas.dificuldadeQuadro &&
registration.object.filhossintomas.olhoTortoMomentos) ||
(registration.object.filhossintomas.dificuldadeLivro &&
registration.object.filhossintomas.olhoTortoMomentos) ||
(registration.object.filhossintomas.dificuldadeQuadro &&
registration.object.filhossintomas.rostoApertaOlhos) ||
(registration.object.filhossintomas.dificuldadeLivro &&
registration.object.filhossintomas.rostoApertaOlhos) ||
registration.object.filhossintomas.olhoTortoConstante ||
(registration.object.filhossintomas.olhoTortoMomentos && registration.object.filhossintomas.rostoApertaOlhos) ||
(registration.object.filhossintomas.olhoTortoMomentos &&
registration.object.filhossintomas.rostoApertaOlhos) ||
registration.object.filhossintomas.tremorOlhos ||
registration.object.filhossintomas.manchaBrancaPupila) {
registration.object.filhossintomas.manchaBrancaPupila
) {
count++;
}
if (
Expand Down Expand Up @@ -90,7 +120,10 @@ const Create = props => {
) {
count++;
}
if (registration.object.horasAtividadesAoArLivre === 1 || registration.object.horasAtividadesAoArLivre === 2) {
if (
registration.object.horasAtividadesAoArLivre === 1 ||
registration.object.horasAtividadesAoArLivre === 2
) {
count++;
}
if (registration.object.testCover === "1") {
Expand All @@ -113,14 +146,10 @@ const Create = props => {
) {
count = count + 5;
}
if (
registration.object.acuidadeTriagemEsquerdo === "8"
) {
if (registration.object.acuidadeTriagemEsquerdo === "8") {
count = count + 2;
}
if (
registration.object.acuidadeTriagemEsquerdo === "nenhum"
) {
if (registration.object.acuidadeTriagemEsquerdo === "nenhum") {
count = count + 2;
}
if (
Expand All @@ -134,20 +163,16 @@ const Create = props => {
) {
count = count + 5;
}
if (
registration.object.acuidadeTriagemDireito === "8"
) {
if (registration.object.acuidadeTriagemDireito === "8") {
count = count + 2;
}
if (
registration.object.acuidadeTriagemDireito === "nenhum"
) {
if (registration.object.acuidadeTriagemDireito === "nenhum") {
count = count + 2;
}
}

return count;
}
};

return (
<BoxRegistration
Expand All @@ -165,18 +190,26 @@ const Create = props => {
});
};

console.log(classroom)

return (
<>
<ArrowBack onClick={() => { history.goBack() }} style={{ cursor: "pointer" }} />
<h1>{classroom && classroom?.object?.name}</h1>
<ArrowBack
onClick={() => {
history.goBack();
}}
style={{ cursor: "pointer" }}
/>
<Row id="space-between" style={{width: "100%", justifyContent: "space-between"}}>
<h1>{classroom && classroom?.object?.name}</h1>
<Column id="center">
<Delete style={{cursor: "pointer"}} onClick={e => deletePreRegistration(e, classroom.id)} />

</Column>
</Row>
<h2>Alunos</h2>
<Padding padding="16px" />
<Grid
// className={classes.marginButtom}
container

direction="row"
style={{ marginBottom: "16px" }}
>
Expand Down

0 comments on commit 6a858b8

Please sign in to comment.