Skip to content

Commit

Permalink
v1 admin synapse
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnypaulino committed Jul 17, 2024
1 parent d7b7eb1 commit 23dcdb5
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 118 deletions.
2 changes: 1 addition & 1 deletion src/Components/Layout/TopBar/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Container = styled.div`
padding: 10px;
.iconResponsive {
@media screen and (min-width: 750px) {
@media screen and (min-width: 1080px) {
display: none ;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { Form, Formik } from "formik";
import { Button } from "primereact/button";
import { Dialog } from "primereact/dialog";
import { useContext } from "react";
import { useParams } from "react-router-dom";
import DropdownComponent from "../../../../../Components/Dropdown";
import { Column, Padding, Row } from "../../../../../Styles/styles";
import { RadioButton } from "primereact/radiobutton";
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";
import { useFetchRequestAllRegistration } from "../../../../../Services/Beneficiaries/query";
import { Column, Padding, Row } from "../../../../../Styles/styles";

const ModalAddStudent = ({
onHide,
Expand All @@ -26,16 +23,12 @@ const ModalAddStudent = ({
) as RegistrationClassroomTypes;


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


const { data: registrationsRequests } = useFetchRequestAllRegistration();

const initialValues = {
classroom_id: id,
student_id: ""
}

student_id: "",
};

return (
<Dialog
Expand All @@ -45,72 +38,48 @@ const ModalAddStudent = ({
style={{ width: "30vw" }}
>
<Padding padding="8px" />
<div className="flex justify-content-center">
<div className="flex flex-wrap gap-3">
<div className="flex align-items-center">
<RadioButton
value={false}
onChange={(e) => setIsNew(e.value)}
checked={isNew === false}
/>
<label htmlFor="ingredient1" className="ml-2">
Aluno existente
</label>
</div>
<div className="flex align-items-center">
<RadioButton
value={true}
onChange={(e) => setIsNew(e.value)}
checked={isNew === true}
/>
<label className="ml-2">Novo aluno</label>
</div>
</div>
</div>
{isNew ? (
<UsersProvider>
<CreateUserPage isStudent />
</UsersProvider>
) : (
<Formik
initialValues={initialValues}
onSubmit={(values) => {
props.AddStudentClassroom({ student_id: parseInt(values.student_id), classroom_id: parseInt(id!) })
onHide();
}}
>
{({ values, handleChange, errors, touched }) => {
return (
<Form>
<div className="col-12">
<label>Alunos</label>
<Padding />
<DropdownComponent
value={values.student_id}
placerholder="Selecione o aluno"
name="student_id"
optionsValue="id"
optionsLabel="name"
onChange={handleChange}
options={registrationsRequests}
/>
{errors.student_id && touched.student_id ? (
<div style={{ color: "red", marginTop: "8px" }}>
{errors.student_id}
</div>
) : null}
</div>
<Padding padding="16px" />
<Column style={{ width: "100%" }}>
<Row id="end">
<Button label="Adicionar" type="submit" />
</Row>
</Column>
</Form>
);
}}
</Formik>
)}

<Formik
initialValues={initialValues}
onSubmit={(values) => {
props.AddStudentClassroom({
student_id: parseInt(values.student_id),
classroom_id: parseInt(id!),
});
onHide();
}}
>
{({ values, handleChange, errors, touched }) => {
return (
<Form>
<div className="col-12">
<label>Alunos</label>
<Padding />
<DropdownComponent
value={values.student_id}
placerholder="Selecione o aluno"
name="student_id"
optionsValue="id"
optionsLabel="name"
onChange={handleChange}
options={registrationsRequests}
/>
{errors.student_id && touched.student_id ? (
<div style={{ color: "red", marginTop: "8px" }}>
{errors.student_id}
</div>
) : null}
</div>
<Padding padding="16px" />
<Column style={{ width: "100%" }}>
<Row id="end">
<Button label="Adicionar" type="submit" />
</Row>
</Column>
</Form>
);
}}
</Formik>
</Dialog>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/School/SchoolList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const TecnologySocial = () => {
<div className="grid">
{propsAplication.project?.map((item, index) => {
return (
<div className="col-12 md:col-6 lg:col-4">
<div key={index} className="col-12 md:col-6 lg:col-4">
<CardTs title={item.name} id={item.id} />
</div>
);
Expand Down
1 change: 0 additions & 1 deletion src/Pages/Student/StudentList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const BeneficiariesListPage = () => {
value={props.registrations}
tableStyle={{ minWidth: "50rem" }}
header={renderHeader}
showGridlines
paginator
rows={10}
>
Expand Down
3 changes: 1 addition & 2 deletions src/Pages/Users/CreateUser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const CreateUserPage = ({ isStudent }: { isStudent: boolean }) => {
});

return (
<ContentPage title="Criar professor" description="Crie o professor.">
<ContentPage title={isStudent ? "Criar Aluno" : "Criar Professor"} description={isStudent ? "Crie o Aluno." : "Crie o Professor."}>
<Padding />
<Formik
initialValues={{
Expand All @@ -59,7 +59,6 @@ export const CreateUserPage = ({ isStudent }: { isStudent: boolean }) => {
validationSchema={CreateUserSchema}
>
{({ values, handleChange, errors, touched }) => {
console.log(errors);
return (
<Form>
<InputsUser
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Classroom/controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const ControllerClassroom = () => {
confirmButtonColor: styles.colors.colorsBaseProductNormal,
}).then((result) => {
if (result.isConfirmed) {
queryClient.refetchQueries("")
queryClient.refetchQueries("useRequestsClassroomRegistration")
}
});
},
Expand Down
47 changes: 27 additions & 20 deletions src/Services/#/controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@ import { idUser, login, logout, menuItem } from "../localstorage";
import { LoginRequest, LoginSystemRequest } from "./request";
import { LoginTypes } from "./types";

export const LoginController = ({ setError }: { setError: any, }) => {
export const LoginController = ({ setError }: { setError: any }) => {
const history = useNavigate();

const LoginRequestMutation = useMutation(
(data: LoginTypes) => LoginRequest(data),
{
onError: (error: any) => {
Swal.fire({
icon: 'error',
icon: "error",
title: error.response.data.message,
confirmButtonColor: styles.colors.colorsBaseProductNormal,
})
setError(error.response.data.message)
});
setError(error.response.data.message);
},
onSuccess: (data) => {
idUser(JSON.stringify(data.data));

history("/");
menuItem("1");
window.location.reload();
if (data.data?.student?.id) {
Swal.fire({
icon: "error",
title: "Seu usuário não tem permissão para acessar o sistema.",
confirmButtonColor: styles.colors.colorsBaseProductNormal,
});
} else {
idUser(JSON.stringify(data.data));
history("/");
menuItem("1");
window.location.reload();
}
},

}
);

Expand All @@ -36,25 +42,26 @@ export const LoginController = ({ setError }: { setError: any, }) => {
{
onError: (error: any) => {
Swal.fire({
icon: 'error',
icon: "error",
title: error.response.data.message,
confirmButtonColor: styles.colors.colorsBaseProductNormal,
})
setError(error.response.data.message)
});
setError(error.response.data.message);
},
onSuccess: (data, variables) => {
logout()
logout();
login(data.data.token);

LoginRequestMutation.mutate({user_name: variables.user_name, password: variables.password})

LoginRequestMutation.mutate({
user_name: variables.user_name,
password: variables.password,
});
},

}
);

return {
LoginRequestMutation,
LoginSystemRequestMutation
}
}
LoginSystemRequestMutation,
};
};
6 changes: 2 additions & 4 deletions src/Services/#/request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import http from "../axios";
import { LoginTypes } from "./types";

export const LoginSystemRequest = async (body: LoginTypes) => {

console.log(process.env.REACT_APP_API_PATH_USERNAME)
return await http.post("/user/#-system-auth", {
user_name: "editor",
password: "iptisynpaseeditor2022",
user_name: process.env.REACT_APP_API_PATH_USERNAME,
password: process.env.REACT_APP_API_PATH_PASSWORD,
});
};

Expand Down
20 changes: 10 additions & 10 deletions src/Services/SocialTechnology/request.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import http from "../axios";
import { GetIdUser } from "../localstorage";
import { GetIdUser, logout } from "../localstorage";

export const requestSocialTechnologytList = async () => {
console.log(GetIdUser())
if (false) {
return await http
.get("/user/teacher-school/" + GetIdUser().id)
Expand All @@ -22,10 +21,11 @@ export const requestSocialTechnologytList = async () => {
.get("/school")
.then((response) => response.data)
.catch((err) => {
// if(err.response.status === 401){
// logout()
// window.location.reload()
// }

if(err.response.status === 401){
logout()
window.location.reload()
}

throw err;
});
Expand Down Expand Up @@ -55,10 +55,10 @@ export const requestCreateSocialTechnology = async (body: {name: string, uf: str
.post("/school", body)
.then((response) => response.data)
.catch((err) => {
// if(err.response.status === 401){
// logout()
// window.location.reload()
// }
if(err.response.status === 401){
logout()
window.location.reload()
}

throw err;
});
Expand Down

0 comments on commit 23dcdb5

Please # to comment.