Skip to content

Commit

Permalink
chore: add axios and create a .env file
Browse files Browse the repository at this point in the history
closes #81
  • Loading branch information
lfjnascimento committed Jul 10, 2024
1 parent f6f24d5 commit ee04d58
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
1 change: 1 addition & 0 deletions dashboard/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_BASE_URL=http://localhost
1 change: 1 addition & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@tanstack/react-query": "^5.45.1",
"@tanstack/react-table": "^8.17.3",
"@vitejs/plugin-react": "^4.3.1",
"axios": "^1.7.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"flat": "^6.0.1",
Expand Down
54 changes: 52 additions & 2 deletions dashboard/pnpm-lock.yaml

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

11 changes: 5 additions & 6 deletions dashboard/src/api/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { useQuery, UseQueryResult } from '@tanstack/react-query';

import type { Tree } from '../types/tree/Tree';

import http from "./api"

Check failure on line 5 in dashboard/src/api/Tree.tsx

View workflow job for this annotation

GitHub Actions / lint-js

Replace `"./api"` with `'./api';`

Check failure on line 5 in dashboard/src/api/Tree.tsx

View workflow job for this annotation

GitHub Actions / lint-js

Replace `"./api"` with `'./api';`

const fetchTreeCheckoutData = async (): Promise<Tree[]> => {
const res = await fetch('/api/tree');
if (!res.ok) {
throw new Error('Request to /api/tree response was not ok');
}
return res.json();
};
const res = await http.get('/api/tree/');

Check failure on line 8 in dashboard/src/api/Tree.tsx

View workflow job for this annotation

GitHub Actions / lint-js

Delete `··`

Check failure on line 8 in dashboard/src/api/Tree.tsx

View workflow job for this annotation

GitHub Actions / lint-js

Delete `··`
return res.data;

Check failure on line 9 in dashboard/src/api/Tree.tsx

View workflow job for this annotation

GitHub Actions / lint-js

Delete `··`

Check failure on line 9 in dashboard/src/api/Tree.tsx

View workflow job for this annotation

GitHub Actions / lint-js

Delete `··`
}

Check failure on line 10 in dashboard/src/api/Tree.tsx

View workflow job for this annotation

GitHub Actions / lint-js

Insert `;`

Check failure on line 10 in dashboard/src/api/Tree.tsx

View workflow job for this annotation

GitHub Actions / lint-js

Insert `;`

export const useTreeTable = (): UseQueryResult => {
return useQuery({ queryKey: ['treeData'], queryFn: fetchTreeCheckoutData });
Expand Down
7 changes: 7 additions & 0 deletions dashboard/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import axios from "axios"

Check failure on line 1 in dashboard/src/api/api.ts

View workflow job for this annotation

GitHub Actions / lint-js

Replace `"axios"` with `'axios';`

Check failure on line 1 in dashboard/src/api/api.ts

View workflow job for this annotation

GitHub Actions / lint-js

Replace `"axios"` with `'axios';`

const API_BASE_URL = import.meta.env.VITE_API_BASE_URL

Check failure on line 3 in dashboard/src/api/api.ts

View workflow job for this annotation

GitHub Actions / lint-js

Insert `;`

Check failure on line 3 in dashboard/src/api/api.ts

View workflow job for this annotation

GitHub Actions / lint-js

Insert `;`

export default axios.create({
baseURL: API_BASE_URL,
});

0 comments on commit ee04d58

Please sign in to comment.