Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, { useContext, useState } from "react";
import { Button } from "react-bootstrap";
import { GlobalContext } from "../../contexts/GlobalContext";
import { BasketContext } from "../../contexts/BasketContext";
import axios from "axios";
export default function SaveBasket({ add }) {
const [info, setInfo] = useState("");
const { api_host } = useContext(GlobalContext);
const basketContext = useContext(BasketContext);
function saveBasket(basketData){
const payload = {shopping_cart: basketData};
console.log(payload);
// basketData.map((basketDatum) => {
// const url = api_host + "accounts/user_profiles/hughdickinson";
// axios
// .patch(url, {item_data: basketData})
// .then((response) => {
// console.log(response);
// })
// .catch((error) => {
// console.log(error);
// });
// });
const profileUrl = api_host + "accounts/user-profiles/hughdickinson/";
console.log(profileUrl);
axios
.patch(profileUrl, payload)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
}
return (
// input field is only here for testing
// this will be replaced by real dataset later.
<Button
type="button"
variant="primary"
onClick={() => saveBasket(basketContext.datasets)}
>Save Basket Contents</Button>
);
}