generated from CMU-17-356/dronut-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added merchant order page, and updated theme * just need to stash changes * can show order information * Removed usused code * removed prices * removed prices * debug * debugging * loads data * before pulling * able to see the prices and quantity * fix merge conflict * remove unused var * bug --------- Co-authored-by: Philip Kaufholz <[email protected]> Co-authored-by: hachiyuki8 <[email protected]>
- Loading branch information
1 parent
ad3f5d7
commit 106d92f
Showing
16 changed files
with
1,392 additions
and
39 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,49 @@ | ||
import axios from "axios"; | ||
import CustomerOrder from "../components/CustomerOrder"; | ||
import Product from "../components/Order"; | ||
|
||
interface OrderResponse { | ||
username: string, | ||
items: [{ | ||
title: string; | ||
quantity: number; | ||
}], | ||
totals: number, | ||
address: string, | ||
transaction_id: string, | ||
status: string, | ||
username : String, | ||
items: [{ | ||
title: String, | ||
quantity: Number, | ||
}], | ||
transaction_id: String | ||
totals : Number, | ||
address : String // Delivery address | ||
status: String // unpaid -> paid -> sent -> delivered | ||
_id: string; | ||
} | ||
|
||
|
||
function convertToOrder(json: OrderResponse): CustomerOrder { | ||
function convertToOrder(json: OrderResponse): Product { | ||
return { | ||
name: json.username, | ||
id: json.transaction_id, | ||
items: json.items, | ||
address: json.address, | ||
price: json.totals, | ||
username : json.username, | ||
items: json.items, | ||
transaction_id: json.transaction_id, | ||
totals : json.totals, | ||
address : json.address, // Delivery address | ||
status: json.status, | ||
|
||
id: json._id | ||
}; | ||
} | ||
|
||
async function getOrders() { | ||
const products = await axios.get(`${process.env.REACT_APP_BACKEND_URL}/api/orders`) | ||
const data_array = products.data.map(convertToOrder); | ||
// https://dronuts-backend.fly.dev/api/orders | ||
const orders = await axios.get(`${process.env.REACT_APP_BACKEND_URL}/api/orders`) | ||
const data_array = orders.data.map(convertToOrder); | ||
console.log("jedwp") | ||
console.log(data_array) | ||
return data_array | ||
} | ||
|
||
export default getOrders | ||
async function getSpecificOrders(id: string) { | ||
// https://dronuts-backend.fly.dev/api/orders | ||
const orders = await axios.get(`${process.env.REACT_APP_BACKEND_URL}/api/orders/${id}`) | ||
console.log("orders", orders) | ||
//@ts-ignore | ||
const data_array = convertToOrder(orders.data); | ||
return data_array | ||
} | ||
|
||
export {getOrders, getSpecificOrders} |
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,31 @@ | ||
import axios from "axios"; | ||
import Product from "../components/Product"; | ||
|
||
interface ProductResponse { | ||
image: string; | ||
title: string; | ||
display_name: string; | ||
price: number; | ||
_id: string; | ||
} | ||
|
||
|
||
function convertToProduct(json: any): Product { | ||
return { | ||
name: json.display_name, | ||
title : json.title, | ||
image: json.image, | ||
price: json.price, | ||
id: json._id | ||
}; | ||
} | ||
|
||
async function getSpecificProducts(name:string) { | ||
const products = await axios.get(`${process.env.REACT_APP_BACKEND_URL}/api/products/`+name) | ||
console.log(products.data) | ||
return products.data | ||
// returns {image: '', _id: '63fe706e9886852807f775c9', title: 'plain', display_name: 'Plain donut', price: 0.99} | ||
} | ||
|
||
|
||
export default getSpecificProducts |
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
interface CustomerOrder { | ||
name: string, | ||
username: string, | ||
id: string, | ||
items: [{ | ||
title: string; | ||
quantity: number; | ||
}], | ||
address: string, | ||
price: number, | ||
totals: number, | ||
} | ||
|
||
export default CustomerOrder |
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,16 @@ | ||
|
||
interface Order { | ||
username : String, | ||
items: [{ | ||
title: String, | ||
quantity: Number, | ||
}], | ||
transaction_id: String | ||
totals : Number, | ||
address : String // Delivery address | ||
status: String // unpaid -> paid -> sent -> delivered | ||
id: string; | ||
|
||
} | ||
|
||
export default Order |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import useLocalStorageState, { LocalStorageState } from 'use-local-storage-state' | ||
import Order from './Order'; | ||
|
||
const useOrderArray = (key: string, initialArray? : Order[]) => { | ||
|
||
const [orders, setOrders] = initialArray ? useLocalStorageState(key, {defaultValue: initialArray}) // eslint-disable-line react-hooks/rules-of-hooks | ||
: useLocalStorageState(key) as LocalStorageState<Order[]> // eslint-disable-line react-hooks/rules-of-hooks | ||
|
||
const handleAddOrder= (order : Order) => { | ||
setOrders(orders.concat([order])) | ||
}; | ||
|
||
// const handleRemoveProduct = (id: string) => { | ||
// const removedItem = products.find((product) => product.id === id); | ||
// if (removedItem !== undefined) { | ||
// const removeIndex = products.indexOf(removedItem) | ||
// setProducts(products.slice(0, removeIndex).concat(products.slice(removeIndex+1))); | ||
// } | ||
// }; | ||
|
||
// const getTotalPrice = () => { | ||
// return orders.reduce((total, item) => total + item.price , 0); | ||
// }; | ||
|
||
const numInArray = (thisID : string) => { | ||
const notThisProduct = orders.filter((order) => order.id === thisID) | ||
return notThisProduct.length | ||
} | ||
|
||
return { | ||
orders, | ||
pushOrder: handleAddOrder, | ||
// removeProduct: (id: string) => handleRemoveProduct(id), | ||
// totalPrice: getTotalPrice, | ||
setOrders: setOrders, | ||
numInArray : numInArray | ||
}; | ||
}; | ||
|
||
export default useOrderArray; |
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 |
---|---|---|
|
@@ -66,4 +66,3 @@ function CustomerPage (props : CustomerPageProps) { | |
}; | ||
|
||
export default CustomerPage; | ||
|
Oops, something went wrong.