Skip to content

Commit

Permalink
add stiudent classroom
Browse files Browse the repository at this point in the history
  • Loading branch information
TI JONNY committed Jul 16, 2024
1 parent effbff0 commit d7b7eb1
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/Components/Menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const Menu = ({ viewdMenu }: { viewdMenu: boolean }) => {
menuItem("5");
}}
active={active === 5 ? true : false}
path={"/beneficiarios"}
path={"/alunos"}
icon={active === 5 ? beneficiaries_hover : beneficiaries}
/>
<Padding />
Expand All @@ -128,7 +128,7 @@ const Menu = ({ viewdMenu }: { viewdMenu: boolean }) => {

{1 === ROLE.ADMIN || 2 === ROLE.Coordenador ? (
<Item
text={"Usuarios"}
text={"Professores"}
funcActiv={() => {
setActive(6);
menuItem("6");
Expand Down
4 changes: 2 additions & 2 deletions src/Context/Classroom/RegistrationsList/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const RegistartionClassroomProvider = ({
}: {
children: React.ReactNode;
}) => {
const { registrations, DeleteRegistration, isLoading } = RegistrationClassroomState();
const { registrations, DeleteRegistration, isLoading, AddStudentClassroom } = RegistrationClassroomState();

return (
<RegistrationClassroomContext.Provider
value={{ registrations, DeleteRegistration, isLoading }}
value={{ registrations, DeleteRegistration, isLoading, AddStudentClassroom }}
>
{children}
</RegistrationClassroomContext.Provider>
Expand Down
11 changes: 9 additions & 2 deletions src/Context/Classroom/RegistrationsList/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ import { useParams } from "react-router-dom";
import { ControllerUpdateRegistration } from "../../../Services/PreRegistration/controller";
import { useFetchRequestClassroomRegistration } from "../../../Services/PreRegistration/query";
import { Root } from "./type";
import { AddClassroom } from "../type";
import { ControllerClassroom } from "../../../Services/Classroom/controller";
export const RegistrationClassroomState = () => {
const {id} = useParams()
const {data: registrationsRequeset, isLoading} = useFetchRequestClassroomRegistration(parseInt(id!))
const {requestDeleteRegistrationClassroomMutation} = ControllerUpdateRegistration()
const {requestDeleteRegistrationClassroomMutation, } = ControllerUpdateRegistration()
const {requestAddClassroomMutation} = ControllerClassroom()

const DeleteRegistration = (id: number) => {
requestDeleteRegistrationClassroomMutation.mutate(id)
}

const AddStudentClassroom = (data: AddClassroom) => {
requestAddClassroomMutation.mutate({classroom_id: data.classroom_id, student_id: data.student_id})
}

const [registrations, setregistrations] = useState<Root | undefined>();

useEffect(() => {
Expand All @@ -21,5 +28,5 @@ export const RegistrationClassroomState = () => {
}, [registrationsRequeset])


return {registrations, DeleteRegistration, isLoading }
return {registrations, DeleteRegistration, isLoading, AddStudentClassroom }
}
2 changes: 2 additions & 0 deletions src/Context/Classroom/RegistrationsList/type.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { AddClassroom } from "../type";

export interface RegistrationClassroomTypes {
registrations?: RegistrationsList | undefined;
DeleteRegistration: (id: number) => void
isLoading: boolean
AddStudentClassroom: (data: AddClassroom) => void
}

export type RegistrationsList = Root;
Expand Down
9 changes: 7 additions & 2 deletions src/Context/Classroom/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ export interface Classroom {
export interface CreateClassroom {
name: string;
school_id?: number,
teacher_id?: number,
year_id?: number
teacher_id?: number,
year_id?: number
}

export interface AddClassroom {
classroom_id: number,
student_id: number
}

export interface ChangeClassroom {
Expand Down
2 changes: 1 addition & 1 deletion src/Context/Users/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const UsersState = () => {
user_name: data.user_name,
password: data.password,
user_type_id: data.user_type_id,
school_id: 2
school_id: data.school_id
}
props.requestUserMutation.mutate(body);
};
Expand Down
24 changes: 11 additions & 13 deletions src/Pages/Classroom/ClassroomCreate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DropdownComponent from "../../../Components/Dropdown";
import Loading from "../../../Components/Loading";
import TextInput from "../../../Components/TextInput";
import ClassroomProvider, {
ClassroomContext,
ClassroomContext,
} from "../../../Context/Classroom/context";
import { ClassroomTypes } from "../../../Context/Classroom/type";
import { useFetchRequestAllYear } from "../../../Services/Classroom/query";
Expand Down Expand Up @@ -45,18 +45,18 @@ const FormClassroomPage = () => {
const initialValues = {
name: "",
year_id: undefined,
teacher_id: GetIdUser().teacher ? GetIdUser().id : undefined
teacher_id: GetIdUser().teacher ? GetIdUser().teacher.id : undefined
};

const {data: yearRequest} = useFetchRequestAllYear()
const { data: yearRequest } = useFetchRequestAllYear()

const { data: userRequest } = useFetchRequestUsers(undefined);



const year: YearType | undefined = yearRequest
const year: YearType | undefined = yearRequest

const teacher: TeacherType | undefined = userRequest
const teacher: TeacherType | undefined = userRequest

const props = useContext(ClassroomContext) as ClassroomTypes;

Expand All @@ -75,8 +75,6 @@ const teacher: TeacherType | undefined = userRequest
}}
>
{({ values, errors, handleChange, touched }) => {

console.log(values)
return (
<Form>
<div className="grid">
Expand All @@ -97,8 +95,8 @@ const teacher: TeacherType | undefined = userRequest
) : null}
</div>
<div className="col-12 md:col-6">
<label>Ano *</label>
<Padding />
<label>Ano *</label>
<Padding />
<DropdownComponent
name="year_id"
placerholder="Escolha o ano *"
Expand All @@ -107,13 +105,13 @@ const teacher: TeacherType | undefined = userRequest
value={values.year_id}
onChange={handleChange}
options={
year
year
}
/>
</div>
<div className="col-12 md:col-6">
<label>Professor *</label>
<Padding />
<label>Professor *</label>
<Padding />
<DropdownComponent
name="teacher_id"
placerholder="Escolha o professor da turma *"
Expand All @@ -123,7 +121,7 @@ const teacher: TeacherType | undefined = userRequest
disabled={GetIdUser().teacher}
onChange={handleChange}
options={
teacher
teacher
}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { useParams } from "react-router-dom";
import DropdownComponent from "../../../../../Components/Dropdown";
import { Column, Padding, Row } from "../../../../../Styles/styles";
import { RadioButton } from "primereact/radiobutton";
import { useState } from "react";
import { useContext, useState } from "react";
import UsersProvider from "../../../../../Context/Users/context";
import { CreateUserPage } from "../../../../Users/CreateUser";
import { useFetchRequestAllRegistration } from "../../../../../Services/Beneficiaries/query";
import { RegistrationClassroomContext } from "../../../../../Context/Classroom/RegistrationsList/context";
import { RegistrationClassroomTypes } from "../../../../../Context/Classroom/RegistrationsList/type";

const ModalAddStudent = ({
onHide,
Expand All @@ -19,6 +21,11 @@ const ModalAddStudent = ({
}) => {
const { id } = useParams();

const props = useContext(
RegistrationClassroomContext
) as RegistrationClassroomTypes;


const [isNew, setIsNew] = useState(false);


Expand All @@ -29,7 +36,6 @@ const ModalAddStudent = ({
student_id: ""
}

console.log(registrationsRequests)

return (
<Dialog
Expand Down Expand Up @@ -69,6 +75,7 @@ const ModalAddStudent = ({
<Formik
initialValues={initialValues}
onSubmit={(values) => {
props.AddStudentClassroom({ student_id: parseInt(values.student_id), classroom_id: parseInt(id!) })
onHide();
}}
>
Expand All @@ -82,8 +89,8 @@ const ModalAddStudent = ({
value={values.student_id}
placerholder="Selecione o aluno"
name="student_id"
optionsValue="student_id"
optionsLabel="student_name"
optionsValue="id"
optionsLabel="name"
onChange={handleChange}
options={registrationsRequests}
/>
Expand Down
5 changes: 3 additions & 2 deletions src/Pages/#/#.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ const LoginPage = () => {
width: "100%",
position: "relative",
overflowY: "auto",

}}
>
<div>
<div className="col-12 md:col-12">
<div style={{zIndex: 200, position: "absolute"}}>
<div className="col-12 md:col-12" >
{/* <div className={classes.marginMobile20} /> */}
<Row style={{ justifyContent: "center" }}>
<Column>
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/#/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const ContainerLogin = styled.div`
background-repeat: no-repeat;
background-position: right top;
position: fixed;
z-index: 200;
h1 {
font-family: ${styles.typography.types.bold};
text-align: center;
Expand Down
18 changes: 14 additions & 4 deletions src/Pages/Student/StudentList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import BeneficiariesListProvider, {
import { BeneficiariesListType } from "../../../Context/Beneficiaries/BeneficiariesList/type";
import color from "../../../Styles/colors";
import { Padding } from "../../../Styles/styles";
import { formatarData } from "../../../Controller/controllerGlobal";

const BeneficiariesList = () => {
return (
Expand Down Expand Up @@ -70,6 +71,15 @@ const BeneficiariesListPage = () => {
// );
// };

const BodyCreated = (value: any) => {
return(
<p>
{formatarData(value.created_at)}
</p>
)

}

return (
<>
<ContentPage title="Alunos" description="Visualização dos alunos da escolas.">
Expand All @@ -83,12 +93,12 @@ const BeneficiariesListPage = () => {
paginator
rows={10}
>
<Column field="student_name" header="Nome"></Column>
<Column field="id" header=""></Column>
<Column
field="school_name"
header="Escola"
field="name"
header="Nome"
></Column>
<Column field="classroom_name" header="Turma"></Column>
<Column body={BodyCreated} header="Data de criação"></Column>
{/* <Column header="Ações" body={ActionBeneficiariesBody}></Column> */}
</DataTable>
</ContentPage>
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Users/CreateUser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export const CreateUserPage = ({ isStudent }: { isStudent: boolean }) => {
});

return (
<ContentPage title="Criar usuários" description="Criar usuário.">
<ContentPage title="Criar professor" description="Crie o professor.">
<Padding />
<Formik
initialValues={{
name: "",
user_name: "",
user_type_id: isStudent ? ROLE.Student : undefined,
user_type_id: isStudent ? ROLE.Student : ROLE.Teacher,
password: "",
school_id: undefined,
confirmPassword: "",
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Users/Inputs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const InputsUser = ({
optionsValue="id"
value={values.user_type_id}
onChange={handleChange}
disabled={isStudent}
disabled
options={
1 === ROLE.ADMIN
? [
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Users/ListUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ListUsersPage = () => {
className="flex justify-content-between"
// style={{ background: color.colorCard }}
>
<Button label="Criar usuário" onClick={() => history("/users/criar")} />
<Button label="Criar professor" onClick={() => history("/users/criar")} />

{/* <div>
<DropdownComponent optionsLabel="name" value={props.role} onChange={(e) => props.setRole(e.target.value)} optionsValue="id" placerholder="Filtrar tipo de usuário" options={1 === ROLE.ADMIN
Expand Down Expand Up @@ -79,7 +79,7 @@ const ListUsersPage = () => {

return (
<>
<ContentPage title="Usuários" description="Lista usuários do MeuBen.">
<ContentPage title="Professores" description="Lista Professores cadastrados.">
<Padding padding="16px" />
<DataTable value={props.users} header={renderHeader} paginator rows={10} rowsPerPageOptions={[5, 10, 25, 50]} tableStyle={{ minWidth: "50rem" }}>
<Column field="id" header=""></Column>
Expand Down
6 changes: 3 additions & 3 deletions src/Router/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ const RoutesApp = () => {
/>
<Route
element={<PrivateRoute Component={<BeneficiariesList />} />}
path="/beneficiarios"
path="/alunos"
/>
<Route
element={<PrivateRoute Component={<BeneficiariesCreate />} />}
path="/beneficiarios/criar"
path="/alunos/criar"
/>
<Route
element={<PrivateRoute Component={<BeneficiariesEdit />} />}
path="/beneficiarios/:id"
path="/alunos/:id"
/>
<Route
element={<PrivateRoute Component={<ListUsers />} />}
Expand Down
Loading

0 comments on commit d7b7eb1

Please # to comment.