-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from AmanNegi/dev-react
fix: dev react
- Loading branch information
Showing
6 changed files
with
142 additions
and
86 deletions.
There are no files selected for viewing
139 changes: 76 additions & 63 deletions
139
frontend/react/Agro-Millets/src/components/ShopItem.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
frontend/react/Agro-Millets/src/pages/Cart/application/cart.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import axios from "axios"; | ||
import { API_URL } from "../../../constants"; | ||
import { toast } from "react-toastify"; | ||
import appState from "../../../data/AppState"; | ||
|
||
// Gets user cart | ||
export default async function getCart() { | ||
if (!appState.isUserLoggedIn()) { | ||
toast.error("You must be logged in to view your cart"); | ||
return null; | ||
} | ||
|
||
var id = appState.userData._id; | ||
var res = await axios.get(API_URL + `/cart/get/${id}`); | ||
|
||
console.log(res); | ||
return res.data.data.items; | ||
} | ||
|
||
// Gets millet item | ||
export async function getItem(id) { | ||
var res = await axios.get(API_URL + "/list/getItem/" + id); | ||
console.log(res); | ||
return res.data.data; | ||
} | ||
|
||
// Adds item to cart | ||
export async function addToCart(itemId, count) { | ||
if (!appState.isUserLoggedIn()) { | ||
toast.error("You must be logged in to add item to cart"); | ||
return 0; | ||
} | ||
|
||
var res = await axios.post(API_URL + "/cart/add", { | ||
userId: appState.userData._id, | ||
item: itemId, | ||
count: count, | ||
}); | ||
|
||
console.log(res); | ||
return 1; | ||
} |
18 changes: 16 additions & 2 deletions
18
frontend/react/Agro-Millets/src/pages/Cart/presentation/Cart.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters