Skip to content

Commit

Permalink
msotly working, fit and finish pending
Browse files Browse the repository at this point in the history
  • Loading branch information
David Tai committed Mar 6, 2020
1 parent e586335 commit cacadc0
Show file tree
Hide file tree
Showing 16 changed files with 1,299 additions and 65 deletions.
14 changes: 10 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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'>
Expand All @@ -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',
Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"eslint-plugin-react-hooks": "2.5.0",
"jest": "25.1.0",
"live-server": "1.2.1",
"rollup": "1.32.0",
"rollup": "2.0.0",
"rollup-plugin-filesize": "6.2.1",
"rollup-plugin-peer-deps-external": "2.2.2",
"rollup-plugin-typescript2": "0.26.0",
Expand All @@ -93,19 +93,22 @@
},
"browserslist": "> 0.25%, not dead",
"dependencies": {
"@hanzo/middleware": "0.0.15",
"@hanzo/react": "0.0.15",
"@hanzo/utils": "0.0.15",
"@hanzo/middleware": "0.0.16",
"@hanzo/react": "0.0.16",
"@hanzo/utils": "0.0.16",
"@material-ui/core": "4.9.5",
"akasha": "0.1.13",
"classnames": "2.2.6",
"commerce.js": "2.0.3",
"commerce.js": "2.0.12",
"fast-memoize": "2.5.2",
"midstream": "2.0.1",
"midstream": "2.0.2",
"mobx": "5.15.4",
"mobx-react": "6.1.8",
"npm-check-updates": "4.0.3",
"moment": "2.24.0",
"moment-timezone": "0.5.28",
"prop-types": "^15.7.2",
"react-is": "^16.13.0",
"react-payment-inputs": "1.1.2",
"react-virtualized": "9.21.2"
},
"peerDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const plugins = [
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/react-is/index.js': ['isFragment', 'ForwardRef']
'node_modules/react-is/index.js': ['isFragment', 'ForwardRef'],
'node_modules/prop-types/index.js': ['elementType'],
'node_modules/react-virtualized/dist/es/WindowScroller/WindowScroller.js': ['bpfrpt_proptype_WindowScroller'],
}
}),
filesize(),
Expand Down
38 changes: 38 additions & 0 deletions src/bootstrap.tsx
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,
)
}
231 changes: 231 additions & 0 deletions src/components/Cart.tsx
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)
Loading

0 comments on commit cacadc0

Please sign in to comment.