Skip to content

Commit

Permalink
Merge pull request #38 from ipti/emitCSV
Browse files Browse the repository at this point in the history
emit csv
  • Loading branch information
jonnypaulino authored Jul 30, 2024
2 parents bf29d3b + c655378 commit c5eaddd
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Pages/InitialPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Button } from "primereact/button";
import { useContext, useState } from "react";
import CardQuant from "../../Components/Chart/CardQuant";
import ContentPage from "../../Components/ContentPage";
import DropdownComponent from "../../Components/Dropdown";
import Loading from "../../Components/Loading";
import { AplicationContext } from "../../Context/Aplication/context";
import { useFetchRequestUsersChart } from "../../Services/Users/query";
import { Padding, Row } from "../../Styles/styles";
import { PropsAplicationContext } from "../../Types/types";
import DropdownComponent from "../../Components/Dropdown";
import http from "../../Services/axios";
import { getYear } from "../../Services/localstorage";
import { ROLE } from "../../Controller/controllerGlobal";

export interface Chart {
totalUserSocialTechnologies: number;
Expand Down Expand Up @@ -36,9 +40,33 @@ const State = () => {
const InitialPage = () => {
const propsAplication = useContext(AplicationContext) as PropsAplicationContext
const props = State();

const downloadCSV = async () => {

console.log("Njnsdans")
try {
const response = await http.get('/user-bff/chart-csv?year=' + getYear())

// Criar um link para download
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'meuben.csv'); // Nome do arquivo
document.body.appendChild(link);
link.click();

// Remover o link
} catch (error) {
console.error('Erro ao baixar o arquivo:', error);
}
};

if (props.isLoading) return <Loading />;
return (
<ContentPage title={"Bem vindo, " + propsAplication.user?.name + "!"} description="Visualização dos dados gerais do meuBen.">
{propsAplication.user?.role === ROLE.ADMIN && <Row id="end">
<Button label="Baixar CSV" icon="pi pi-download" iconPos="left" onClick={downloadCSV} />
</Row>}
<Padding padding="8px" />
{propsAplication.project && <Row id="end"><DropdownComponent options={[...propsAplication.project, { id: undefined, name: "Todos" }]} optionsLabel="name" optionsValue="id" value={props.ts} onChange={(e) => props.setTs(e.target.value)} placerholder="Filtrar por Tecnologia" /></Row>
} <Padding padding="16px" />
Expand Down

0 comments on commit c5eaddd

Please sign in to comment.