-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
msotly working, fit and finish pending
- Loading branch information
David Tai
committed
Mar 6, 2020
1 parent
e586335
commit cacadc0
Showing
16 changed files
with
1,299 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,16 @@ | |
|
||
<html lang='en'> | ||
<head> | ||
<meta charset='utf-8'> | ||
<meta charSet='utf-8'/> | ||
<meta | ||
name='viewport' | ||
content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' | ||
/> | ||
<meta | ||
name='msapplication-tap-highlight' | ||
content='no' | ||
/> | ||
|
||
|
||
<title>Shop.js Example</title> | ||
<meta name='description' content='Shop.js Example'> | ||
|
@@ -16,10 +25,7 @@ | |
|
||
<script src='https://unpkg.com/react@16/umd/react.development.js' crossorigin></script> | ||
<script src='https://unpkg.com/react-dom@16/umd/react-dom.development.js' crossorigin></script> | ||
<script src='https://unpkg.com/[email protected]/prop-types.js'></script> | ||
<script src='https://unpkg.com/react-is@16/umd/react-is.development.js'></script> | ||
<script type='text/javascript'> | ||
window.reactIs$1 = ReactIs | ||
window.process = { | ||
env: { | ||
NODE_ENV: 'production', | ||
|
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import { useLocalStore, useObserver } from 'mobx-react' | ||
|
||
import { Checkout } from './components' | ||
import { ShopStore, ILibraryClient } from './stores' | ||
|
||
export default function(client: ILibraryClient, el: Element) { | ||
const ShopJS = (): JSX.Element => { | ||
const shopStore = useLocalStore(() => new ShopStore(client, {})) | ||
|
||
shopStore.commerce.set('sad-keanu-shirt', 1) | ||
|
||
return useObserver(() => ( | ||
<Checkout | ||
address={shopStore.address} | ||
setAddress={(k: string, v: any) => shopStore.setAddress(k, v)} | ||
order={shopStore.order} | ||
setOrder={(k: string, v: any) => shopStore.setOrder(k, v)} | ||
payment={shopStore.payment} | ||
setPayment={(k: string, v: any) => shopStore.setPayment(k, v)} | ||
user={shopStore.user} | ||
setUser={(k: string, v: any) => shopStore.setUser(k, v)} | ||
setCoupon={(c: string) => shopStore.setCoupon(c)} | ||
checkout={() => shopStore.checkout() } | ||
setItem={(id: string, quantity: number) => shopStore.setItem(id, quantity)} | ||
countryOptions={ shopStore.countryOptions } | ||
stateOptions={ shopStore.stateOptions } | ||
orderNumber={ shopStore.orderNumber } | ||
/> | ||
)) | ||
} | ||
|
||
ReactDOM.render( | ||
<ShopJS/>, | ||
el, | ||
) | ||
} |
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,231 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
|
||
import { | ||
MUIText, | ||
} from '@hanzo/react' | ||
|
||
import { | ||
renderUICurrencyFromJSON, | ||
} from '@hanzo/utils' | ||
|
||
import { | ||
Button, | ||
Grid, | ||
} from '@material-ui/core' | ||
|
||
import { makeStyles } from '@material-ui/core/styles' | ||
const useStyles = makeStyles((theme) => ({ | ||
right: { | ||
textAlign: 'right', | ||
}, | ||
bold: { | ||
fontWeight: 700, | ||
}, | ||
items: { | ||
paddingTop: theme.spacing(2), | ||
paddingBottom: theme.spacing(2), | ||
}, | ||
coupon: { | ||
paddingBottom: theme.spacing(2), | ||
}, | ||
lineSpacing: { | ||
paddingBottom: theme.spacing(1), | ||
}, | ||
total: { | ||
paddingTop: theme.spacing(2), | ||
paddingBottom: theme.spacing(2), | ||
}, | ||
couponInput: { | ||
'& .MuiInputBase-root': { | ||
borderTopRightRadius: 0, | ||
borderBottomRightRadius: 0, | ||
}, | ||
'& .MuiOutlinedInput-notchedOutline': { | ||
borderRight: 0, | ||
}, | ||
}, | ||
couponButton: { | ||
borderTopLeftRadius: 0, | ||
borderBottomLeftRadius: 0, | ||
border: '1px solid', | ||
borderColor: 'rgba(0, 0, 0, 0.23)', | ||
paddingTop: 7, | ||
paddingBottom: 7, | ||
}, | ||
})) | ||
|
||
import { | ||
Box, | ||
Typography, | ||
} from '@material-ui/core' | ||
|
||
const quantityOpts = {} | ||
|
||
for (let i = 0; i < 10; i++) { | ||
quantityOpts[i] = i | ||
} | ||
|
||
const Cart = ({ | ||
width, | ||
height, | ||
order, | ||
setCoupon, | ||
setItem, | ||
}): JSX.Element => { | ||
const classes = useStyles() | ||
|
||
return ( | ||
<Box p={[2, 3, 4]}> | ||
<Grid container> | ||
<Grid item xs={12}> | ||
<Typography variant='h5'> | ||
Your Items | ||
</Typography> | ||
</Grid> | ||
<Grid item xs={12}> | ||
<div className={classes.items}> | ||
{ | ||
order.items.map((item) => { | ||
return ( | ||
<Grid container alignItems='center' key={item.name}> | ||
<Grid item xs={12} sm={7}> | ||
<Typography variant='body1'> | ||
{ item.name } | ||
</Typography> | ||
<Typography variant='body2'> | ||
{ item.description } | ||
</Typography> | ||
<br/> | ||
</Grid> | ||
<Grid item xs={8} sm={2} className={classes.right}> | ||
<Typography variant='body1'> | ||
{ renderUICurrencyFromJSON(order.currency, item.price) } x | ||
</Typography> | ||
</Grid> | ||
<Grid item xs={4} sm={3} className={classes.right}> | ||
<MUIText | ||
select | ||
disabled={ item.locked } | ||
options={quantityOpts} | ||
value={ item.quantity } | ||
setValue={ (quantity) => { | ||
setItem(item.id, parseInt(quantity, 10)) | ||
}} | ||
/> | ||
</Grid> | ||
</Grid> | ||
) | ||
}) | ||
} | ||
</div> | ||
</Grid> | ||
|
||
<Grid item xs={12} className={classes.coupon}> | ||
<div> | ||
<Grid container> | ||
<Grid item xs={8} sm={10} md={9}> | ||
<MUIText | ||
className={classes.couponInput} | ||
fullWidth | ||
disableAutoChange | ||
variant='outlined' | ||
size='small' | ||
placeholder='Coupon Code' | ||
defaultValue={ order.couponCodes[0] } | ||
setValue={ (code) => setCoupon(code) } | ||
/> | ||
</Grid> | ||
<Grid item xs={4} sm={2} md={3}> | ||
<Button | ||
className={classes.couponButton} | ||
fullWidth | ||
disableElevation | ||
size='medium' | ||
variant='contained' | ||
> | ||
Apply | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
</div> | ||
</Grid> | ||
|
||
<Grid item xs={12}> | ||
<div> | ||
<Grid container className={classes.lineSpacing}> | ||
<Grid item xs={8} sm={9} className={classes.right}> | ||
<Typography variant='body1'> | ||
Subtotal | ||
</Typography> | ||
</Grid> | ||
<Grid item xs className={classes.right}> | ||
<Typography variant='body1'> | ||
{ renderUICurrencyFromJSON(order.currency, order.subtotal) } | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
|
||
{ | ||
order.discount > 0 && ( | ||
<Grid container className={classes.lineSpacing}> | ||
<Grid item xs={8} sm={9} className={classes.right}> | ||
<Typography variant='body1'> | ||
You Saved | ||
</Typography> | ||
</Grid> | ||
<Grid item xs className={classes.right}> | ||
<Typography variant='body1'> | ||
{ renderUICurrencyFromJSON(order.currency, order.discount) } | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
) | ||
} | ||
|
||
<Grid container className={classes.lineSpacing}> | ||
<Grid item xs={8} sm={9} className={classes.right}> | ||
<Typography variant='body1'> | ||
Shipping | ||
</Typography> | ||
</Grid> | ||
<Grid item xs className={classes.right}> | ||
<Typography variant='body1'> | ||
{ order.shipping ? renderUICurrencyFromJSON(order.currency, order.shipping) : 'Free' } | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
|
||
<Grid container> | ||
<Grid item xs={8} sm={9} className={classes.right}> | ||
<Typography variant='body1'> | ||
Tax | ||
</Typography> | ||
</Grid> | ||
<Grid item xs className={classes.right}> | ||
<Typography variant='body1'> | ||
{ renderUICurrencyFromJSON(order.currency, order.tax) } | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
|
||
<Grid container className={classes.total}> | ||
<Grid item xs={8} sm={9} className={classes.right}> | ||
<Typography variant='h6'> | ||
Total | ||
</Typography> | ||
</Grid> | ||
<Grid item xs className={classes.right}> | ||
<Typography variant='h6'> | ||
{ renderUICurrencyFromJSON(order.currency, order.total) } | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
</div> | ||
</Grid> | ||
</Grid> | ||
</Box> | ||
) | ||
} | ||
|
||
export default observer(Cart) |
Oops, something went wrong.