Skip to content

Commit

Permalink
add file the register term
Browse files Browse the repository at this point in the history
  • Loading branch information
TI JONNY committed Dec 17, 2024
1 parent 3769744 commit 5146f2e
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# REACT_APP_API_PATH=http://localhost:3000/
REACT_APP_API_PATH=https://br-ipti-beneficiarios.azurewebsites.net/
REACT_APP_API_PATH=http://localhost:3000/
# REACT_APP_API_PATH=https://br-ipti-beneficiarios.azurewebsites.net/
4 changes: 2 additions & 2 deletions src/Context/Beneficiaries/BeneficiaresEdit/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -81,7 +81,7 @@ export const BeneficiariesEditState = () => {
requestRegistrationClassroomMutation.mutate(data);
};

const CreateRegisterTerm = (data: CreateRegistrationTermType) => {
const CreateRegisterTerm = (data: FormData) => {
requestRegisterTermMutation.mutate({data: data});
};

Expand Down
72 changes: 58 additions & 14 deletions src/Context/Beneficiaries/BeneficiaresEdit/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export interface BeneficiariesEditType {
classrooms: any
file: any | undefined
setFile: Dispatch<SetStateAction<any | undefined>>
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
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion src/Controller/controllerGlobal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
87 changes: 67 additions & 20 deletions src/Pages/Beneficiaries/BeneficiariesEdit/ModalAddTerm/index.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 (
<Dialog onHide={onHide} header="Novo termo" visible={visible} style={{ width: window.innerWidth > 800 ? "30vw" : "50vw" }}>
<Dialog onHide={onHide} header="Novo termo" visible={visible} style={{ width: window.innerWidth > 800 ? "50vw" : "70vw" }}>
<Formik
initialValues={{ dateTerm: new Date(Date.now()) }}
initialValues={{ dateTerm: new Date(Date.now()), dateValid: "", file: undefined}}
validationSchema={schema}
onSubmit={(values) => {
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 (
<Form>
<div className="grid">
<div className="col-12">
<div className="col-12 md:col-6">
<label>Data de assinatura</label>
<Padding />
<CalendarComponent
Expand All @@ -50,13 +66,44 @@ const ModalAddTerm = ({
dateFormat="dd/mm/yy"
onChange={handleChange}
/>
{/* {errors.dateTerm && touched.dateTerm ? (
{errors.dateTerm && touched.dateTerm ? (
<div style={{ color: "red", marginTop: "8px" }}>
{errors.dateTerm.toString()}
{String(errors.dateTerm)}
</div>
) : null} */}
) : null}
</div>
<div className="col-12 md:col-6">
<label>Data de validade</label>
<Padding />
<CalendarComponent
value={values.dateValid}
name="dateValid"
dateFormat="dd/mm/yy"
placeholder="Data de validade"
onChange={handleChange}
/>
{errors.dateValid && touched.dateValid ? (
<div style={{ color: "red", marginTop: "8px" }}>
{String(errors.dateValid)}
</div>
) : null}
</div>
<div className="col-12 md:col-6">
<label>Termo </label>
<Padding />
<TextInput
// value={file}
type="file"
placeholder="Termo"
onChange={(e) => setFieldValue("file", e.target.files)}
name="file"
/>
{errors.file && touched.file ? (
<div style={{ color: "red", marginTop: "8px" }}>
{String(errors.file)}
</div>
) : null}
</div>

</div>{" "}
<Padding padding="16px" />
<Column style={{ width: "100%" }}>
Expand Down
9 changes: 6 additions & 3 deletions src/Pages/Beneficiaries/BeneficiariesEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -113,10 +114,9 @@ const BeneficiariesEditPage = () => {
style={{ background: color.colorCard }}
>
<Button
label={isWithinOneYear(new Date(Date.now()), props.registrations?.register_term[props.registrations?.register_term.length - 1]?.dateTerm!) ? "Termo ativo" : "Novo termo" }
label={"Novo termo"}
icon="pi pi-plus"
type="button"
disabled={isWithinOneYear(new Date(Date.now()), props.registrations?.register_term[props.registrations?.register_term.length - 1]?.dateTerm!)}
onClick={() => setVisibleTerm(true)}
/>
</div>
Expand Down Expand Up @@ -406,7 +406,10 @@ const BeneficiariesEditPage = () => {
header={renderHeaderTerm}
>
<Column body={(row) => { return (<>{formatarData(row?.dateTerm!)}</>) }} header="Data de assinatura"></Column>
<Column body={(row) => { return (<>{isWithinOneYear(new Date(Date.now()), row?.dateTerm!) ? "Termo ativo" : "Termo vencido" }</>) }} header="Status"></Column>
<Column body={(row) => { return (<>{formatarData(row?.dateValid ?? "")}</>) }} header="Data de validade"></Column>

<Column body={(row) => { return (<>{isWithinOneYear(new Date(Date.now()), row?.dateTerm!, row?.dateValid!) ? "Termo ativo" : "Termo vencido"}</>) }} header="Status"></Column>
<Column align={"center"} body={(row) => { return (<Row id="center" onClick={() => {window.open(row.blob_file.blob_url)}} style={{cursor: "pointer"}}><Icon icon="pi pi-download" /></Row>) }} header="Ações"></Column>

</DataTable>
<Padding padding="8px" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const RegistrationPage = () => {
const props = useContext(
RegistrationDetailsContext
) as RegistrationDetailsTypes;
const [visibleTerm, setVisibleTerm] = useState<any>();
const [visibleTerm, setVisibleTerm] = useState<any>();


const { id } = useParams();
const { data: classroom } = useFetchRequestClassroomOne(parseInt(id!));
Expand All @@ -53,10 +53,9 @@ const RegistrationPage = () => {
style={{ background: color.colorCard }}
>
<Button
label={isWithinOneYear(new Date(Date.now()), props.registration?.registration?.register_term[props.registration?.registration?.register_term.length - 1]?.dateTerm!) ? "Termo ativo" : "Novo termo" }
label={"Novo termo"}
icon="pi pi-plus"
type="button"
disabled={isWithinOneYear(new Date(Date.now()), props.registration?.registration?.register_term[props.registration?.registration?.register_term.length - 1]?.dateTerm!)}
onClick={() => setVisibleTerm(true)}
/>
</div>
Expand Down Expand Up @@ -232,18 +231,18 @@ const RegistrationPage = () => {
</div>
</div>{" "}
<Padding padding="8px" />
<h3>Termo</h3>
<Padding padding="8px" />
<DataTable
value={props.registration?.registration?.register_term}
tableStyle={{ minWidth: "50rem" }}
header={renderHeaderTerm}
>
<Column body={(row) => { return (<>{formatarData(row?.dateTerm!)}</>) }} header="Data de assinatura"></Column>
<Column body={(row) => { return (<>{isWithinOneYear(new Date(Date.now()), row?.dateTerm!) ? "Termo ativo" : "Termo vencido" }</>) }} header="Status"></Column>
</DataTable>
<h3>Termo</h3>
<Padding padding="8px" />

<DataTable
value={props.registration?.registration?.register_term}
tableStyle={{ minWidth: "50rem" }}
header={renderHeaderTerm}
>
<Column body={(row) => { return (<>{formatarData(row?.dateTerm!)}</>) }} header="Data de assinatura"></Column>
<Column body={(row) => { return (<>{isWithinOneYear(new Date(Date.now()), row?.dateTerm!) ? "Termo ativo" : "Termo vencido"}</>) }} header="Status"></Column>

</DataTable>
{/* <h3>Endereço</h3>
<Padding />
<div className="grid">
Expand Down
5 changes: 2 additions & 3 deletions src/Services/PreRegistration/controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
} from "./request";
import {
CreatePreRegistration,
CreateRegistrationClassroomType,
CreateRegistrationTermType,
CreateRegistrationClassroomType
} from "./types";

export const ControllerPreRegistration = () => {
Expand Down Expand Up @@ -100,7 +99,7 @@ export const ControllerUpdateRegistration = () => {
);

const requestRegisterTermMutation = useMutation(
({ data}: { data: CreateRegistrationTermType}) =>
({ data}: { data: FormData}) =>
requestCreateRegistrationTerm(data),
{
onError: (error: any) => {
Expand Down
3 changes: 2 additions & 1 deletion src/Services/PreRegistration/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface CreatePreRegistration {

export interface CreateRegistrationTermType {
registration: number;
data_term: string | Date;
dataValid: string | Date;
dataTerm: string | Date;
}

0 comments on commit 5146f2e

Please sign in to comment.