Skip to content

Commit

Permalink
fix: initial home select ts
Browse files Browse the repository at this point in the history
  • Loading branch information
TI JONNY committed Jul 3, 2024
1 parent f58601b commit b8a6caa
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/Context/Aplication/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { User } from "../Users/type";

const AplicationState = () => {
const [form, setform] = useState<PropsForm>({ title: "Formulário Sem título", description: "", question: [] })
const { data: projects } = useFetchRequestSocialTechnologyLists()
const { data: projects } = useFetchRequestSocialTechnologyLists();

const [project, setproject] = useState<Array<Projects> | undefined>()
const [user, setuser] = useState<User | undefined>()
const [project, setproject] = useState<Array<Projects> | undefined>();
const [user, setuser] = useState<User | undefined>();


const { data: userRequest } = useFetchRequestUsersOne(parseInt(GetIdUser()!))
const { data: userRequest } = useFetchRequestUsersOne(parseInt(GetIdUser()!));



Expand Down
20 changes: 12 additions & 8 deletions src/Pages/InitialPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useContext } from "react";
import { useContext, useState } from "react";
import CardQuant from "../../Components/Chart/CardQuant";
import ContentPage from "../../Components/ContentPage";
import Loading from "../../Components/Loading";
import { AplicationContext } from "../../Context/Aplication/context";
import { useFetchRequestUsersChart } from "../../Services/Users/query";
import { Padding } from "../../Styles/styles";
import { Padding, Row } from "../../Styles/styles";
import { PropsAplicationContext } from "../../Types/types";
import DropdownComponent from "../../Components/Dropdown";

export interface Chart {
totalUserSocialTechnologies: number;
Expand All @@ -17,27 +18,30 @@ export interface Chart {
}

const State = () => {
const { data, isLoading, isError } = useFetchRequestUsersChart();

const [ts, setTs] = useState<number | undefined>()
const { data, isLoading, isError } = useFetchRequestUsersChart(ts?.toString());

console.log(ts)

var chart: Chart | undefined = data;

return {
chart,
isLoading,
isError,
isError, ts, setTs
};
};

const InitialPage = () => {
const propsAplication = useContext(AplicationContext) as PropsAplicationContext
const props = State();

if (props.isLoading) return <Loading />;
return (
<ContentPage title={"Bem vindo, " + propsAplication.user?.name + "!"} description="Visualização dos dados gerais do meuBen.">
<Padding />
<h1> </h1>
<Padding padding="16px" />
<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" />
<div className="grid">
<div className="col-12 md:col-4 lg:col-4">
<CardQuant title="Total de Ts" quant={props.chart?.totalUserSocialTechnologies!} color="navy_blue" />
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Users/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const useFetchRequestUsers = (role: string | undefined) => {
return useQuery(["useRequestsUsers", role], () => requestUsers(role));
};

export const useFetchRequestUsersChart = () => {
return useQuery(["useRequestsUsersChart"], () => requestUsersChart());
export const useFetchRequestUsersChart = (id?: string) => {
return useQuery(["useRequestsUsersChart", id], () => requestUsersChart(id));
};

export const useFetchRequestUsersOne = (id: number) => {
Expand Down
45 changes: 31 additions & 14 deletions src/Services/Users/request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { getYear, logout } from "../localstorage";
export const requestUsers = (role: string | undefined) => {
let path = "/user-bff";

if(role && role !== "TODOS"){
path = path + "?role="+role
if (role && role !== "TODOS") {
path = path + "?role=" + role
}

return http
Expand All @@ -21,19 +21,36 @@ export const requestUsers = (role: string | undefined) => {
});
};

export const requestUsersChart = () => {
let path = "/user-bff/chart?year="+ getYear() ?? 2024;
export const requestUsersChart = (id?: string) => {

return http
.get(path)
.then((response) => response.data)
.catch((err) => {
if (err.response.status === 401) {
logout();
window.location.reload();
}
throw err;
});

let path = "/user-bff/chart?year=" + getYear() ?? 2024;

console.log(id)

if (id) {
return http.get("/user-bff/chart-ts?year=" + (getYear() ?? 2024) + "&tsId=" + id).then((response) => response.data)
.catch((err) => {
if (err.response.status === 401) {
logout();
window.location.reload();
}
throw err;
});
} else {


return http
.get(path)
.then((response) => response.data)
.catch((err) => {
if (err.response.status === 401) {
logout();
window.location.reload();
}
throw err;
});
}
};

export const requestCreateUsers = (data: CreateUser) => {
Expand Down

0 comments on commit b8a6caa

Please sign in to comment.