Skip to content

Commit 13eaa92

Browse files
committed
initial commit
1 parent a3f79c2 commit 13eaa92

11 files changed

+17035
-0
lines changed

Diff for: package-lock.json

+16,583
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "cupcake-configurator",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"bootstrap": "^4.3.1",
7+
"jquery": "^3.3.1",
8+
"popper.js": "^1.15.0",
9+
"react": "^16.8.6",
10+
"react-dom": "^16.8.6",
11+
"react-scripts": "2.1.8",
12+
"typescript": "^3.4.2"
13+
},
14+
"scripts": {
15+
"start": "react-scripts start",
16+
"build": "react-scripts build",
17+
"test": "react-scripts test",
18+
"eject": "react-scripts eject"
19+
},
20+
"eslintConfig": {
21+
"extends": "react-app"
22+
},
23+
"browserslist": [
24+
">0.2%",
25+
"not dead",
26+
"not ie <= 11",
27+
"not op_mini all"
28+
]
29+
}

Diff for: public/favicon.ico

3.78 KB
Binary file not shown.

Diff for: public/index.html

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
9+
/>
10+
<meta name="theme-color" content="#000000" />
11+
<!--
12+
manifest.json provides metadata used when your web app is installed on a
13+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
14+
-->
15+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
16+
<!--
17+
Notice the use of %PUBLIC_URL% in the tags above.
18+
It will be replaced with the URL of the `public` folder during the build.
19+
Only files inside the `public` folder can be referenced from the HTML.
20+
21+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
22+
work correctly both with client-side routing and a non-root public URL.
23+
Learn how to configure a non-root public URL by running `npm run build`.
24+
-->
25+
<title>Emoticakes Cupcake Configurator</title>
26+
</head>
27+
<body>
28+
<noscript>You need to enable JavaScript to run this app.</noscript>
29+
<div id="root"></div>
30+
<!--
31+
This HTML file is a template.
32+
If you open it directly in the browser, you will see an empty page.
33+
34+
You can add webfonts, meta tags, or analytics to this file.
35+
The build step will place the bundled scripts into the <body> tag.
36+
37+
To begin the development, run `npm start` or `yarn start`.
38+
To create a production bundle, use `npm run build` or `yarn build`.
39+
-->
40+
</body>
41+
</html>

Diff for: public/manifest.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "Emoticakes Cupcake Configurator",
3+
"name": "Emoticakes Cupcake Configurator",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

Diff for: src/App.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import React, { Component } from "react";
2+
import * as Constants from "./Constants";
3+
import { generateUniqueKey } from "./Helpers";
4+
5+
class App extends Component {
6+
constructor(props) {
7+
super(props);
8+
this.state = Constants.initialState;
9+
this.addToOrder = this.addToOrder.bind(this);
10+
this.removeFromOrder = this.removeFromOrder.bind(this);
11+
}
12+
13+
onStartOver = () => {
14+
this.setState({ ...Constants.initialState });
15+
};
16+
17+
getCurrentOrder() {
18+
return JSON.parse(JSON.stringify(this.state.orderDetails));
19+
}
20+
21+
updateOrderDetails(orderDetails) {
22+
this.setState({
23+
orderTotal: this.calculateTotal(orderDetails),
24+
orderDetails: orderDetails
25+
});
26+
}
27+
28+
addToOrder(newItem) {
29+
let currentOrder = this.getCurrentOrder();
30+
currentOrder.push({
31+
key: generateUniqueKey("CC"), // key is unique
32+
name: newItem.name,
33+
price: newItem.price
34+
});
35+
this.updateOrderDetails(currentOrder);
36+
}
37+
38+
removeFromOrder(itemToRemove) {
39+
let currentOrder = this.getCurrentOrder();
40+
let currentOrderItemRemoved = currentOrder.filter(function(item) {
41+
return item.key !== itemToRemove;
42+
});
43+
this.updateOrderDetails(currentOrderItemRemoved);
44+
}
45+
46+
calculateTotal(orderDetails) {
47+
var totalPrice = orderDetails.reduce(function(accumulator, order) {
48+
return accumulator + order.price;
49+
}, 0);
50+
return totalPrice;
51+
}
52+
53+
render() {
54+
return (
55+
<div>
56+
<h1>Cupcake Configurator</h1>
57+
<p>lorem ipsum instructions</p>
58+
<h4>Add to Order</h4>
59+
<ul>
60+
{Object.keys(Constants.boxSizes).map((item, i) => (
61+
<li
62+
onClick={e => this.addToOrder(Constants.boxSizes[item], e)}
63+
key={i}
64+
>
65+
{Constants.boxSizes[item].name} ({Constants.boxSizes[item].count})
66+
</li>
67+
))}
68+
</ul>
69+
<h4>Your Order</h4>
70+
<h5>Order Total: ${this.state.orderTotal}</h5>
71+
<ul>
72+
{this.state.orderDetails.map(item => (
73+
<li key={item.key}>
74+
<button
75+
type="button"
76+
onClick={e => this.removeFromOrder(item.key, e)}
77+
>
78+
remove
79+
</button>
80+
{item.name}
81+
</li>
82+
))}
83+
</ul>
84+
<button type="button" onClick={this.onStartOver}>
85+
Start Over
86+
</button>
87+
</div>
88+
);
89+
}
90+
}
91+
92+
// todo:
93+
//
94+
// 1. select cake flavor (1 per dozen)
95+
// 2. select frosting flavors (up to 2 per dozen)
96+
// 3. provide a message on cupcakes (custom disc color, letter color)
97+
// 4. delivery (extra charge) or pick-up
98+
// 5. send email on order quote submission, cc: to submitter
99+
// https://sheelahb.com/blog/how-to-send-email-from-react-without-a-backend/
100+
//
101+
102+
export default App;

Diff for: src/App.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
4+
5+
it('renders without crashing', () => {
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App />, div);
8+
ReactDOM.unmountComponentAtNode(div);
9+
});

Diff for: src/Constants.js

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
export const initialState = {
2+
orderTotal: 0,
3+
orderDetails: []
4+
};
5+
6+
export const boxSizes = {
7+
MINI: {
8+
name: "Mini",
9+
count: 24,
10+
price: 12
11+
},
12+
REG: {
13+
name: "Regular",
14+
count: 12,
15+
price: 34
16+
},
17+
REG_4: {
18+
name: "Regular 4-pack",
19+
count: 12,
20+
price: 12
21+
}
22+
};
23+
24+
export const cakeFlavors = {
25+
chocolate: {
26+
name: "chocolate",
27+
color: "#333"
28+
},
29+
vanilla: {
30+
name: "vanilla",
31+
color: "#333"
32+
},
33+
mocha: {
34+
name: "mocha",
35+
color: "#333"
36+
},
37+
coffee: {
38+
name: "coffee",
39+
color: "#333"
40+
},
41+
spice: {
42+
name: "spice",
43+
color: "#333"
44+
},
45+
carrot: {
46+
name: "carrot",
47+
color: "#333"
48+
},
49+
redVelvet: {
50+
name: "red velvet",
51+
color: "#333"
52+
},
53+
coconut: {
54+
name: "coconut",
55+
color: "#333"
56+
},
57+
lemon: {
58+
name: "lemon",
59+
color: "#333"
60+
}
61+
};
62+
63+
export const frostingFlavors = {
64+
creamCheese: {
65+
name: "cream cheese",
66+
color: "#333"
67+
},
68+
vanillaButtercream: {
69+
name: "vanilla buttercream",
70+
color: "#333"
71+
},
72+
chocolateButtercream: {
73+
name: "chocolate buttercream",
74+
color: "#333"
75+
},
76+
cookiesAndCream: {
77+
name: "cookies and cream",
78+
color: "#333"
79+
},
80+
mintChocolateCookie: {
81+
name: "mint chocolate cookie",
82+
color: "#333"
83+
},
84+
peanutButter: {
85+
name: "peanut butter",
86+
color: "#333"
87+
},
88+
hazelnut: {
89+
name: "hazelnut",
90+
color: "#333"
91+
},
92+
coconut: {
93+
name: "coconut",
94+
color: "#333"
95+
},
96+
lemon: {
97+
name: "lemon",
98+
color: "#333"
99+
},
100+
raspberry: {
101+
name: "raspberry",
102+
color: "#333"
103+
},
104+
strawberry: {
105+
name: "strawberry",
106+
color: "#333"
107+
}
108+
};

Diff for: src/Helpers.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function generateUniqueKey(pre) {
2+
return `${pre}_${new Date().getTime()}`;
3+
}

Diff for: src/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
4+
import * as serviceWorker from './serviceWorker';
5+
6+
ReactDOM.render(<App />, document.getElementById('root'));
7+
8+
// If you want your app to work offline and load faster, you can change
9+
// unregister() to register() below. Note this comes with some pitfalls.
10+
serviceWorker.unregister();

0 commit comments

Comments
 (0)