Compare commits

..

6 Commits

Author SHA1 Message Date
John Huang@tthqws02
ada0bb5bd7 ADD: product selection draft on top of the PayPal button 2021-11-15 19:01:10 -05:00
John Huang@tthqws02
536783da6f UPD: apollo wrapper wraps <App /> 2021-11-15 19:00:27 -05:00
John Huang@tthqws02
dfd1a2918f UPD: add @apollo/client to this project 2021-11-15 18:59:07 -05:00
John Huang@tthqws02
9cb7678c6c UPD: init product section 2021-11-15 17:20:32 -05:00
John Huang@tthqws02
8e6666ba35 ADD: empty project folders for expansion 2021-11-15 03:28:51 -05:00
John Huang@tthqws02
c58f27ba99 UPD: make invoiceDetail as a self-contained compoient 2021-11-15 03:27:55 -05:00
13 changed files with 169 additions and 22 deletions

View File

@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@apollo/client": "^3.4.17",
"@mrmlnc/readdir-enhanced": "^2.2.1",
"@paypal/react-paypal-js": "^7.4.2",
"@testing-library/jest-dom": "^5.15.0",

View File

@ -0,0 +1 @@
export {default as something} from './something';

View File

@ -0,0 +1 @@
export {default as something} from './something';

View File

@ -0,0 +1 @@
export { useGetProd } from "./products/useGetProd";

View File

@ -0,0 +1,30 @@
// By JCH, 20211115
// Using the ApolloClient Hook to create our own custom Hook
import { gql, useQuery } from "@apollo/client";
const getProductListAPI = () => gql`
query getProductList {
getProductList {
ID
productName
productDesc
picHiURL
picMeURL
picLoURL
price
discountedPrice
notes
}
}
`;
// custom hook for query
const useGetProd = () => {
// I omitted the error in the return
const { loading, data } = useQuery(getProductListAPI());
return loading ? null : data.getProductList;
};
export { useGetProd };

View File

@ -1,18 +1,22 @@
import React from "react";
const Invoice = (props) => {
// re-arrange to make invoice detail a self-contained element
const Invoice = ( {invoiceDetails} ) => {
let addressInfo = invoiceDetails.purchase_units[0].shipping.address;
let address = `${addressInfo.address_line_1} ${addressInfo.admin_area_2}, ${addressInfo.admin_area_1} ${addressInfo.postal_code}`;
return (
<div className="container">
Date Purchased: {props.date}
Date Purchased: {invoiceDetails.create_time}
<br />
Item: {props.itemName}
Item: {invoiceDetails.purchase_units[0].description}
<br />
Amount Paid: ${props.itemValue}
Amount Paid: ${invoiceDetails.purchase_units[0].amount.value}
<br />
Ship to: {props.buyerName}
Ship to: {invoiceDetails.purchase_units[0].shipping.name.full_name}
<br />
Shipping address: {props.streetAddr} {props.city}, {props.state} {props.postalCode}
{/* Shipping address: {streetAddr} {city}, {state} {postalCode} */}
Shpping address: {address}
</div>
);
}

View File

@ -1,22 +1,26 @@
import React, { useState } from "react";
import "./home.css";
import { PayPal, Purchase, ShowCase, Home } from '.';
import { AllProducts} from "../products"
const details = () => {
// component
const Details = () => {
return (
<>
<ShowCase />
<AllProducts />
<Purchase />
<PayPal />
</>
);
};
const Landing = () => {
const [showDetails, setShowDetails] = useState(false);
return (
<>
{showDetails ? details() : <Home goNext={() => setShowDetails(true)} />}
{showDetails ? <Details /> : <Home goNext={() => setShowDetails(true)} />}
</>
);
};

View File

@ -48,18 +48,8 @@ const PayPal = () => {
</div>
</PayPalScriptProvider>
</div>
{showInvoice &&
<Invoice
date={invoiceDetails.create_time}
itemName={invoiceDetails.purchase_units[0].description}
itemValue={invoiceDetails.purchase_units[0].amount.value}
buyerName={invoiceDetails.purchase_units[0].shipping.name.full_name}
streetAddr={invoiceDetails.purchase_units[0].shipping.address.address_line_1}
city={invoiceDetails.purchase_units[0].shipping.address.admin_area_2}
state={invoiceDetails.purchase_units[0].shipping.address.admin_area_1}
postalCode={invoiceDetails.purchase_units[0].shipping.address.postal_code}
/>
}
{/* This is a nice touch */}
{showInvoice && <Invoice invoiceDetails={invoiceDetails} />}
</>
);
};

View File

@ -0,0 +1,24 @@
thead {
color: rgb(19, 58, 19);
}
tbody {
color: blue;
}
tfoot {
color: red;
}
table,
thead th,
tbody td {
border: 1px solid white;
border-collapse:collapse;
}
thead th,
tbody td {
background-color: rgb(220, 224, 228);
padding: 0.25rem 0.5rem;
}

View File

@ -0,0 +1,61 @@
import React from 'react';
import { useGetProd } from '../api';
import './allProducts.css';
const AllProducts = ( ) => {
const allProducts = useGetProd();
let ProductList = () => {
if (allProducts) {
return (
<table>
<thead>
<tr>
<th></th>
<th>ID</th>
<th>Model #</th>
<th>Description</th>
<th>Price</th>
</tr>
</thead>
<tbody>
{ allProducts.map(product => {
return (
<tr key={product.ID}>
<td>[ ]</td>
<td>{product.ID}</td>
<td>{product.productName}</td>
<td>{product.productDesc}</td>
<td>${product.price}</td>
</tr>
);
})
}
</tbody>
<tfoot></tfoot>
</table>
);
} else {
return (
<>
<p> Loading... </p>
</>
)
}
};
return (
<div className="container">
<hr />
<span className="danger">Fetch product list from https://api.oemautomation.com:3001 </span>
<hr />
<ProductList />
<hr />
</div>
);
}
export default AllProducts;

View File

@ -0,0 +1 @@
export {default as AllProducts} from './allProducts';

View File

@ -0,0 +1 @@
export {default as something} from './something';

View File

@ -4,9 +4,37 @@ import './index.css';
import App from './App';
import 'bootstrap/dist/css/bootstrap.min.css';
import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client";
import { ApolloProvider } from "@apollo/client/react";
import { setContext } from "@apollo/client/link/context";
const httpLink = createHttpLink({
uri: "https://api.oemautomation.com:3001",
});
const authLink = setContext((_, { headers }) => {
// get the authentication token from local storage if it exists
const token = localStorage.getItem("token");
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
authtoken: "to do here",
authorization: token ? `Bearer ${token}` : "",
},
};
});
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
});
ReactDOM.render(
<React.StrictMode>
<App />
<ApolloProvider client={client}>
<App />
</ApolloProvider>
</React.StrictMode>,
document.getElementById('root')
);
);