Skip to content

Commit

Permalink
fix: conversão de requisição ao back utilizando Api.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
artursanntos committed Oct 1, 2023
1 parent a07bb0e commit bd4906c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
15 changes: 7 additions & 8 deletions src/contexts/IndicatorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { collaboratorType, indicatorType } from '../types';
import { useContext } from 'react';
import { VfoodsContext } from './VfoodsContext';
import axios from 'axios';
import Api from '../Api';

interface IndicatorContextType {
collaborator: collaboratorType[];
Expand All @@ -24,22 +25,20 @@ export function IndicatorProvider({ children }: IndicatorProviderProps) {
const { manager } = useContext(VfoodsContext);

const createIndicator = async () => {
console.log("Chegou aqui");
//console.log("Chegou aqui");

try {
const url = 'http://localhost:3000/indicador'
const url = 'indicador/'

const headers = {
'Content-Type': 'application/json'
}

console.log(manager.id);

// setIndicator({...indicator, gestor: manager.id})
// console.log(manager.id);

const response = await axios.post(url, {...indicator, idGestor: manager.id}, { headers })

console.log(response)
Api.post(url, {...indicator, idGestor: manager.id}, { headers }).then(response => {
console.log(response)
});
} catch (error) {
console.log(error)
}
Expand Down
54 changes: 32 additions & 22 deletions src/contexts/VfoodsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, SetStateAction, useState, Dispatch, ReactNode, useEffect } from 'react';
import { collaboratorType, indicatorType, managerType, metasMesIndicadorType } from '../types';
import axios from 'axios';
import Api from '../Api';

interface VfoodsContextType {
allCollaborators: collaboratorType[];
Expand Down Expand Up @@ -33,16 +34,21 @@ export function VfoodsProvider({ children }: VfoodsProviderProps) {
// TODO: get manager id from backend
const tempId = '[email protected]'
try {
const url = 'http://localhost:3000/gestor/' + tempId

const response = axios.get(url)

const man = (await response).data

setManager(man)
getCollaborators(man)
getIndicators(man)

const url = 'gestor/' + tempId

// const response = axios.get(url)

Api.get(url).then(response => {
const man = response.data
setManager(man)
getCollaborators(man)
getIndicators(man)
})
/*
console.log(manager);
console.log(allCollaborators);
console.log(allIndicators);
*/
} catch (error) {
console.log(error)
}
Expand All @@ -51,12 +57,13 @@ export function VfoodsProvider({ children }: VfoodsProviderProps) {
const getCollaborators = async (manager: managerType) => {
const urlEmail = manager.email
try {
const url = 'http://localhost:3000/gestor/colaboradores/' + urlEmail
const response = axios.get(url)

const collab = (await response).data
setAllCollab(collab)
console.log(allCollaborators)
const url = 'gestor/colaboradores/' + urlEmail
//const response = axios.get(url)
Api.get(url).then(response => {
const collab = response.data
setAllCollab(collab)
console.log(allCollaborators);
})

} catch (error) {
console.log(error)
Expand All @@ -66,12 +73,15 @@ export function VfoodsProvider({ children }: VfoodsProviderProps) {
const getIndicators = async (manager: managerType) => {
const urlID = manager.id
try {
const url = 'http://localhost:3000/indicador/' + urlID
const response = axios.get(url)

const ind = (await response).data
setAllIndicators(ind)
console.log(allIndicators)
const url = 'indicador/' + urlID

Api.get(url).then(response => {
// console.log(response)
const ind = response.data
setAllIndicators(ind)
// console.log(allIndicators);

})

} catch (error) {
console.log(error)
Expand Down

0 comments on commit bd4906c

Please sign in to comment.