From 5146f2e4846a86445cc851e5389ffb8092f1fefd Mon Sep 17 00:00:00 2001 From: TI JONNY Date: Tue, 17 Dec 2024 17:09:00 -0300 Subject: [PATCH] add file the register term --- .env | 4 +- .../Beneficiaries/BeneficiaresEdit/state.tsx | 4 +- .../Beneficiaries/BeneficiaresEdit/type.ts | 72 ++++++++++++--- src/Controller/controllerGlobal.tsx | 2 +- .../BeneficiariesEdit/ModalAddTerm/index.tsx | 87 ++++++++++++++----- .../Beneficiaries/BeneficiariesEdit/index.tsx | 9 +- .../RegistrationList/Registration/index.tsx | 31 ++++--- src/Services/PreRegistration/controller.tsx | 5 +- src/Services/PreRegistration/types.tsx | 3 +- 9 files changed, 155 insertions(+), 62 deletions(-) diff --git a/.env b/.env index 7c3a28b..77602a0 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -# REACT_APP_API_PATH=http://localhost:3000/ -REACT_APP_API_PATH=https://br-ipti-beneficiarios.azurewebsites.net/ \ No newline at end of file +REACT_APP_API_PATH=http://localhost:3000/ +# REACT_APP_API_PATH=https://br-ipti-beneficiarios.azurewebsites.net/ \ No newline at end of file diff --git a/src/Context/Beneficiaries/BeneficiaresEdit/state.tsx b/src/Context/Beneficiaries/BeneficiaresEdit/state.tsx index 0cda69f..f7f986d 100644 --- a/src/Context/Beneficiaries/BeneficiaresEdit/state.tsx +++ b/src/Context/Beneficiaries/BeneficiaresEdit/state.tsx @@ -13,7 +13,7 @@ import { useFetchRequestProjectList, useFetchRequestRegistrationOne, } from "../../../Services/PreRegistration/query"; -import { CreateRegistrationClassroomType, CreateRegistrationTermType } from "../../../Services/PreRegistration/types"; +import { CreateRegistrationClassroomType } from "../../../Services/PreRegistration/types"; import { UpdateRegister } from "../../Classroom/Registration/type"; import { Registration } from "./type"; @@ -81,7 +81,7 @@ export const BeneficiariesEditState = () => { requestRegistrationClassroomMutation.mutate(data); }; - const CreateRegisterTerm = (data: CreateRegistrationTermType) => { + const CreateRegisterTerm = (data: FormData) => { requestRegisterTermMutation.mutate({data: data}); }; diff --git a/src/Context/Beneficiaries/BeneficiaresEdit/type.ts b/src/Context/Beneficiaries/BeneficiaresEdit/type.ts index 0f7fc02..e06abba 100644 --- a/src/Context/Beneficiaries/BeneficiaresEdit/type.ts +++ b/src/Context/Beneficiaries/BeneficiaresEdit/type.ts @@ -15,12 +15,12 @@ export interface BeneficiariesEditType { classrooms: any file: any | undefined setFile: Dispatch> - CreateRegisterTerm: (data: CreateRegistrationTermType) => void + CreateRegisterTerm: (data: FormData) => void } export interface Registration { id: number - avatar_url: string + avatar_url: any name: string birthday: string cpf: string @@ -37,22 +37,66 @@ export interface Registration { status: string createdAt: string updatedAt: string - cep: string + cep: any address: any number: any - complement: string - neighborhood: string - city_fk: number - state_fk: number + complement: any + neighborhood: any + city_fk: any + state_fk: any + register_term: RegisterTerm[] register_classroom: RegisterClassroom[] - register_term: any +} + +export interface RegisterTerm { + id: number + dateTerm: string + dateValid: any + createdAt: string + updatedAt: string + registration_fk: number + blob_file_fk: number + blob_file: BlobFile +} + +export interface BlobFile { + id: number + blob_url: string + key: string + createdAt: string + updatedAt: string } export interface RegisterClassroom { - id: number; - registration_fk: number; - classroom_fk: number; - status: string; - createdAt: string; - updatedAt: string; + id: number + registration_fk: number + classroom_fk: number + status: string + createdAt: string + updatedAt: string + classroom: Classroom +} + +export interface Classroom { + id: number + project_fk: number + name: string + year: number + active: boolean + status: string + createdAt: string + updatedAt: string + project: Project +} + +export interface Project { + id: number + name: string + active: boolean + approval_percentage: number + ruler_url: any + avartar_url: any + social_technology_id: number + createdAt: string + updatedAt: string } diff --git a/src/Controller/controllerGlobal.tsx b/src/Controller/controllerGlobal.tsx index 55e93db..23a05ab 100644 --- a/src/Controller/controllerGlobal.tsx +++ b/src/Controller/controllerGlobal.tsx @@ -39,7 +39,7 @@ export function formatarData(data: string): string { return dataEdit; } -export function isWithinOneYear(date1: any, date2: any) { +export function isWithinOneYear(date1: any, date2: any, dateValid?: any) { const oneYearInMilliseconds = 365 * 24 * 60 * 60 * 1000; // Um ano em milissegundos const timeDifference = Math.abs(new Date(date1).getUTCMilliseconds() - new Date(date2).getUTCMilliseconds()); // Diferença absoluta em ms diff --git a/src/Pages/Beneficiaries/BeneficiariesEdit/ModalAddTerm/index.tsx b/src/Pages/Beneficiaries/BeneficiariesEdit/ModalAddTerm/index.tsx index c52cfe6..0ca5a8c 100644 --- a/src/Pages/Beneficiaries/BeneficiariesEdit/ModalAddTerm/index.tsx +++ b/src/Pages/Beneficiaries/BeneficiariesEdit/ModalAddTerm/index.tsx @@ -1,11 +1,13 @@ import { Form, Formik } from "formik"; import { Button } from "primereact/button"; import { Dialog } from "primereact/dialog"; +import * as Yup from "yup"; import CalendarComponent from "../../../../Components/Calendar"; +import TextInput from "../../../../Components/TextInput"; import { ControllerUpdateRegistration } from "../../../../Services/PreRegistration/controller"; -import { CreateRegistrationTermType } from "../../../../Services/PreRegistration/types"; import { Column, Padding, Row } from "../../../../Styles/styles"; + const ModalAddTerm = ({ onHide, visible, @@ -16,32 +18,46 @@ const ModalAddTerm = ({ id: number }) => { - const { - - requestRegisterTermMutation - } = ControllerUpdateRegistration(); - const CreateRegisterTerm = (data: CreateRegistrationTermType) => { - requestRegisterTermMutation.mutate({data: data}); - }; + const { + requestRegisterTermMutation + } = ControllerUpdateRegistration(); + const CreateRegisterTerm = (data: FormData) => { + requestRegisterTermMutation.mutate({ data: data }); + }; + + const schema = Yup.object().shape({ + dateTerm: Yup.string().required("Data de assinatura é obrigatório"), + dateValid: Yup.string().required("Data de validade é obrigatório"), + file: Yup.string().required("Arquivo com termo é obrigatório"), + + + }); return ( - 800 ? "30vw" : "50vw" }}> + 800 ? "50vw" : "70vw" }}> { - CreateRegisterTerm({ - data_term: values.dateTerm, - registration: id!, - }); + if (values.file) { + + const formData = new FormData(); + formData.append("dateTerm",values.dateTerm.toString() ) + formData.append("dateValid",values.dateValid?.toString() ) + formData.append("registration", id?.toString()) + formData.append("file", values.file[0]) + + CreateRegisterTerm(formData); + } onHide(); }} > - {({ values, handleChange, errors, touched }) => { + {({ values, handleChange, errors, touched, setFieldValue }) => { return (
-
+
- {/* {errors.dateTerm && touched.dateTerm ? ( + {errors.dateTerm && touched.dateTerm ? (
- {errors.dateTerm.toString()} + {String(errors.dateTerm)}
- ) : null} */} + ) : null} +
+
+ + + + {errors.dateValid && touched.dateValid ? ( +
+ {String(errors.dateValid)} +
+ ) : null} +
+
+ + + setFieldValue("file", e.target.files)} + name="file" + /> + {errors.file && touched.file ? ( +
+ {String(errors.file)} +
+ ) : null}
-
{" "} diff --git a/src/Pages/Beneficiaries/BeneficiariesEdit/index.tsx b/src/Pages/Beneficiaries/BeneficiariesEdit/index.tsx index 141bfc7..b567180 100644 --- a/src/Pages/Beneficiaries/BeneficiariesEdit/index.tsx +++ b/src/Pages/Beneficiaries/BeneficiariesEdit/index.tsx @@ -31,6 +31,7 @@ import { Container, Padding, Row } from "../../../Styles/styles"; import ModalCreateRegisterClassroom from "./ModalCreateRegisterClassroom"; import { validaCPF } from "../../../Controller/controllerValidCPF"; import ModalAddTerm from "./ModalAddTerm"; +import Icon from "../../../Components/Icon"; const BeneficiariesEdit = () => { @@ -113,10 +114,9 @@ const BeneficiariesEditPage = () => { style={{ background: color.colorCard }} >
@@ -406,7 +406,10 @@ const BeneficiariesEditPage = () => { header={renderHeaderTerm} > { return (<>{formatarData(row?.dateTerm!)}) }} header="Data de assinatura"> - { return (<>{isWithinOneYear(new Date(Date.now()), row?.dateTerm!) ? "Termo ativo" : "Termo vencido" }) }} header="Status"> + { return (<>{formatarData(row?.dateValid ?? "")}) }} header="Data de validade"> + + { return (<>{isWithinOneYear(new Date(Date.now()), row?.dateTerm!, row?.dateValid!) ? "Termo ativo" : "Termo vencido"}) }} header="Status"> + { return ( {window.open(row.blob_file.blob_url)}} style={{cursor: "pointer"}}>) }} header="Ações"> diff --git a/src/Pages/Classroom/ClassroomOne/RegistrationList/Registration/index.tsx b/src/Pages/Classroom/ClassroomOne/RegistrationList/Registration/index.tsx index 4286c50..9513d62 100644 --- a/src/Pages/Classroom/ClassroomOne/RegistrationList/Registration/index.tsx +++ b/src/Pages/Classroom/ClassroomOne/RegistrationList/Registration/index.tsx @@ -40,8 +40,8 @@ const RegistrationPage = () => { const props = useContext( RegistrationDetailsContext ) as RegistrationDetailsTypes; - const [visibleTerm, setVisibleTerm] = useState(); - + const [visibleTerm, setVisibleTerm] = useState(); + const { id } = useParams(); const { data: classroom } = useFetchRequestClassroomOne(parseInt(id!)); @@ -53,10 +53,9 @@ const RegistrationPage = () => { style={{ background: color.colorCard }} >