Skip to content

Commit

Permalink
Merge pull request #23 from ipti/new/registration
Browse files Browse the repository at this point in the history
New/registration
  • Loading branch information
jonnypaulino authored Jun 12, 2024
2 parents 083c8f0 + c211e3a commit 10a3013
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 96 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/
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@types/react": "^18.2.47",
"@types/react-dom": "^18.2.18",
"axios": "^1.6.7",
"buffer": "^6.0.3",
"cross-env": "^7.0.3",
"file-saver": "^2.0.5",
"formik": "^2.4.5",
Expand Down
2 changes: 2 additions & 0 deletions src/Components/TextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ const TextInput = ({
disabled,
onBlur,
name,
type
}: PropsInputText) => {
return (
<div>
<InputText
style={{ width: "100%" }}
onBlur={onBlur}
type={type}
disabled={disabled}
value={value}
name={name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface Project {
export interface Project {
name: string
id: number
ruler_url: string
}


Expand Down
6 changes: 4 additions & 2 deletions src/Context/Project/ProjectOne/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { ProjectOneTypes } from "./type";
export const ProjectOneContext = createContext<ProjectOneTypes | null>(null);

const ProjectOneProvider = ({ children }: { children: React.ReactNode }) => {
const { isLoading, project, updateProject } = ProjectOneState();
const { isLoading, project, updateProject, rulerProject } = ProjectOneState();

return (
<ProjectOneContext.Provider value={{ isLoading, project, updateProject }}>
<ProjectOneContext.Provider
value={{ isLoading, project, updateProject, rulerProject }}
>
{children}
</ProjectOneContext.Provider>
);
Expand Down
12 changes: 10 additions & 2 deletions src/Context/Project/ProjectOne/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const ProjectOneState = () => {
const { id } = useParams();
const { data, isLoading } = useFetchRequestProjectOne(parseInt(id!));
const [project, setProject] = useState();
const { requestUpdateprojectMutation } = ProjectController();
const { requestUpdateprojectMutation, requestRulerprojectMutation } =
ProjectController();

useEffect(() => {
if (data) {
Expand All @@ -17,13 +18,20 @@ export const ProjectOneState = () => {
}, [data]);

const updateProject = (data: UpdateProject, id: number) => {
console.log(id)
requestUpdateprojectMutation.mutate({ data: data, id: id });
};

const rulerProject = (file: File, id: number) => {
const formData = new FormData();

formData.append("file", file);
requestRulerprojectMutation.mutate({ data: formData, id: id });
};

return {
project,
isLoading,
updateProject,
rulerProject
};
};
2 changes: 2 additions & 0 deletions src/Context/Project/ProjectOne/type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface ProjectOneTypes {
project: ApiProject | undefined;
isLoading: boolean;
updateProject: (data: UpdateProject, id: number) => void;
rulerProject: (file: File, id: number) => void
}

export interface ApiProject {
Expand All @@ -17,6 +18,7 @@ export interface Project {
active: boolean
approval_percentage: number
avartar_url: any
ruler_url: string
social_technology_id: number
createdAt: string
updatedAt: string
Expand Down
16 changes: 16 additions & 0 deletions src/Controller/controllerGlobal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import axios from "axios";
import { Buffer } from 'buffer';


export const gerarIdAleatorio = (tamanho: number) => {
const caracteres =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
Expand Down Expand Up @@ -98,4 +102,16 @@ export const loadImageFileAsBase64 = (imagePath: string): Promise<string> => {
})
.catch(reject);
});
};


export const convertImageUrlToBase64 = async (imageUrl: string): Promise<string> => {
try {
const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });
const base64 = Buffer.from(response.data, 'binary').toString('base64');
const mimeType = response.headers['content-type'];
return `data:${mimeType};base64,${base64}`;
} catch (error: any) {
throw new Error(`Failed to convert image to Base64: ${error.message}`);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from "../../../../../../Context/Classroom/Meeting/MeetingListRegistration/type";
import {
Status,
convertImageUrlToBase64,
loadImageFileAsBase64,
} from "../../../../../../Controller/controllerGlobal";
import styles from "../../../../../../Styles";
Expand All @@ -39,6 +40,8 @@ const Beneficiarios = () => {

const [logoBase64, setLogoBase64] = useState<string | null>(null);
const [logoBaseLeft64, setLogoBaseLeft64] = useState<string | null>(null);
const [logoBaseRegua64, setLogoBaseRegua64] = useState<string | null>(null);


const FilterRegistration = (fouls: any) => {
const array = [];
Expand Down Expand Up @@ -78,6 +81,24 @@ const Beneficiarios = () => {
loadLogo();
}, []);


useEffect(() => {
const loadLogo = async () => {
try {
if (props.meeting?.classroom.project.ruler_url) {
const base64 = await convertImageUrlToBase64(props.meeting?.classroom.project.ruler_url);

setLogoBaseRegua64(base64);
}

} catch (error) {
console.error("Error loading logo image:", error);
}
};

loadLogo();
}, [props.meeting]);

const FilterId = (fouls: any) => {
const array = [];
for (const foul of fouls) {
Expand Down Expand Up @@ -247,13 +268,18 @@ const Beneficiarios = () => {
// alignment: 'center'
// };
// },
footer: (currentPage: number, pageCount: number) => {
return {
text: `${currentPage} de ${pageCount}`,
footer: (currentPage, pageCount) => {
return logoBaseRegua64 ? {
image: logoBaseRegua64 || '',
alignment: "center",
margin: [0, 0, 20, 0],
};
},
margin: [0, 0, 20, 20],
fit: [400, 400]
} : {
text: `${currentPage} de ${pageCount}`,
alignment: "center",
margin: [0, 0, 20, 0],
}
},
pageMargins: [40, 100, 40, 60],
background: (currentPage, pageCount) => {
return {
Expand Down
51 changes: 37 additions & 14 deletions src/Pages/Classroom/ClassroomOne/Report/Pdf/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import imgLateral from "../../../../../Assets/images/logoleftpdf.png";
import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
import { TDocumentDefinitions } from "pdfmake/interfaces";
import { loadImageFileAsBase64 } from "../../../../../Controller/controllerGlobal";
import { convertImageUrlToBase64, loadImageFileAsBase64 } from "../../../../../Controller/controllerGlobal";

pdfMake.vfs = pdfFonts.pdfMake.vfs;

Expand All @@ -21,7 +21,7 @@ export const ReportClassroom = () => {

const [logoBase64, setLogoBase64] = useState<string | null>(null);
const [logoBaseLeft64, setLogoBaseLeft64] = useState<string | null>(null);
// const [logoBaseRegua64, setLogoBaseRegua64] = useState<string | null>(null);
const [logoBaseRegua64, setLogoBaseRegua64] = useState<string | null>(null);

const [report, setReport] = useState<ReportClassroomType | undefined>();

Expand Down Expand Up @@ -59,6 +59,24 @@ export const ReportClassroom = () => {
loadLogo();
}, []);

useEffect(() => {
const loadLogo = async () => {
try {
if (report?.project.ruler_url) {
const base64 = await convertImageUrlToBase64(report?.project.ruler_url);

setLogoBaseRegua64(base64);
}

} catch (error) {
console.error("Error loading logo image:", error);
}
};

loadLogo();
}, [report]);


// useEffect(() => {
// const loadLogo = async () => {
// try {
Expand Down Expand Up @@ -232,7 +250,7 @@ export const ReportClassroom = () => {

const generatePDF = () => {
const pageSize = 10; // Define the number of rows per page

// Function to generate the table body for a specific subset of registrations
const createTableBody = (registrationsSubset: any, startIndex: number) => {
// Create the header row
Expand All @@ -243,7 +261,7 @@ export const ReportClassroom = () => {
"FREQUÊNCIA",
"STATUS",
];

// Create the body rows
const bodyRows = registrationsSubset.map((item: any, index: number) => {
return [
Expand All @@ -254,10 +272,10 @@ export const ReportClassroom = () => {
parseInt(bodyTotal(item).percentage) > report?.project?.approval_percentage! ? "Aprovado" : "Reprovado",
];
});

return [headerRow, ...bodyRows];
};

const docDefinition: TDocumentDefinitions = {
pageOrientation: "landscape",
content: [
Expand Down Expand Up @@ -351,13 +369,18 @@ export const ReportClassroom = () => {
},
];
},
footer: (currentPage: number, pageCount: number) => {
return {
text: `${currentPage} de ${pageCount}`,
footer: (currentPage, pageCount) => {
return logoBaseRegua64 ? {
image: logoBaseRegua64 || '',
alignment: "center",
margin: [0, 0, 20, 0],
};
},
margin: [0, 0, 20, 20],
fit: [400, 400]
} : {
text: `${currentPage} de ${pageCount}`,
alignment: "center",
margin: [0, 0, 20, 0],
}
},
pageMargins: [40, 60, 40, 60],
background: (currentPage, pageCount) => {
return {
Expand All @@ -367,10 +390,10 @@ export const ReportClassroom = () => {
};
},
};

pdfMake.createPdf(docDefinition).open();
};


const bodyTotal = (rowData: RegisterClassroom) => {
var count = 0;
Expand Down
Loading

0 comments on commit 10a3013

Please sign in to comment.