Skip to content

Commit

Permalink
change app and env
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelshoham committed Dec 20, 2023
1 parent 364cb38 commit 7992ad5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
6 changes: 1 addition & 5 deletions src/api/posts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import axios from 'axios';

const api = axios.create({
baseURL: 'https://bb-projects-db-api-mego-program1.vercel.app',
});
const api = import.meta.env.VITE_SERVER_URL

export {api} ;

14 changes: 8 additions & 6 deletions src/pages/Porjects/components/listProjects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NavLink, useParams } from "react-router-dom";
import Header from "./header";
import { Grid } from "@mui/material";
import { api } from "../../../api/posts";
import axios from "axios";


const token = localStorage.getItem("authToken");
Expand All @@ -22,22 +23,23 @@ let userID = ''


try {
const response = await api.get(`${import.meta.env.VITE_SERVER_URL}/users/self`,
const response = await axios.get(`${api}/users/self`,
{
headers: {
'Authorization': token,
'Content-Type': 'application/json; charset=utf-8',
}
})
console.log('user id:', response.data.result[0]._id);
userID = response.data.result[0]._id;}
console.log(response)
console.log('user id:', response.data.data.result[0]._id);
userID = response.data.data.result[0]._id;}
catch(error) {
console.error('error: ', error.message);
};



const UrlDataBoard = `${import.meta.env.VITE_SERVER_URL}/board/user/${userID}/read`;
const UrlDataBoard = `${api}/board/user/${userID}/read`;
console.log(UrlDataBoard)

export default function ListProject() {
Expand All @@ -51,7 +53,7 @@ export default function ListProject() {
}, [])

const fetchProjects = () => {
api.get(UrlDataBoard, { headers })
axios.get(UrlDataBoard, { headers })
.then(response => {
setProjectsList(response.data)

Expand All @@ -62,7 +64,7 @@ export default function ListProject() {
}

function handleDeleteItem(id) {
api.delete(`${import.meta.env.VITE_SERVER_URL}/board/${id}/delete`, { headers })
axios.delete(`${api}/board/${id}/delete`, { headers })
.then(() => {
fetchProjects();
})
Expand Down
11 changes: 6 additions & 5 deletions src/pages/create-project/components/createProject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { NavLink, useParams } from "react-router-dom";
import Header from "../../Porjects/components/header";
import {api} from "../../../api/posts";
import { Project } from "../../Porjects/components/Project";
import axios from "axios";

const UrlDataBoard = `${import.meta.env.VITE_SERVER_URL}/board/create`;
const UrlDataBoard = `${api}/board/create`;
const headers = {
'Authorization': 'Happy',
'Content-Type': 'application/json; charset=utf-8'
Expand All @@ -18,15 +19,15 @@ console.log("token: " + token)
let userID = '';

try {
const response = await api.get(`${import.meta.env.VITE_SERVER_URL}/users/self`,
const response = await axios.get(`${api}/users/self`,
{
headers: {
'Authorization': token,
'Content-Type': 'application/json; charset=utf-8',
}
})
// console.log('user id:', response.data.result[0]._id);
userID = response.data.result[0]._id;}
userID = response.data.data.result[0]._id;}
catch(error) {
console.error('error: ', error.message);
};
Expand Down Expand Up @@ -60,7 +61,7 @@ export default function CreateProject() {
event.preventDefault();

if (contect.name.trim().length > 0 && contect.description.trim().length > 0) {
api.post(UrlDataBoard, contect, { headers })
axios.post(UrlDataBoard, contect, { headers })
.then(response => {
setContect(response.data)
setSaved(true)
Expand All @@ -75,7 +76,7 @@ export default function CreateProject() {
}
}
function handleDeleteItem(id) {
api.delete(`${import.meta.env.VITE_SERVER_URL}/board/${id}/delete`, { headers })
axios.delete(`${api}/board/${id}/delete`, { headers })
.then(() => {
alert("the project has been deleted")
setSaved(false)
Expand Down

0 comments on commit 7992ad5

Please sign in to comment.