diff --git a/json-server/db-1587790522563.json b/json-server/db-1587790522563.json new file mode 100644 index 0000000..4ff6aec --- /dev/null +++ b/json-server/db-1587790522563.json @@ -0,0 +1,268 @@ +{ + "dishes": [ + { + "id": 0, + "name": "Uthappizza", + "image": "images/uthappizza.png", + "category": "mains", + "label": "Hot", + "price": "4.99", + "featured": true, + "description": "A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer." + }, + { + "id": 1, + "name": "Zucchipakoda", + "image": "images/zucchipakoda.png", + "category": "appetizer", + "label": "", + "price": "1.99", + "featured": false, + "description": "Deep fried Zucchini coated with mildly spiced Chickpea flour batter accompanied with a sweet-tangy tamarind sauce" + }, + { + "id": 2, + "name": "Vadonut", + "image": "images/vadonut.png", + "category": "appetizer", + "label": "New", + "price": "1.99", + "featured": false, + "description": "A quintessential ConFusion experience, is it a vada or is it a donut?" + }, + { + "id": 3, + "name": "ElaiCheese Cake", + "image": "images/elaicheesecake.png", + "category": "dessert", + "label": "", + "price": "2.99", + "featured": false, + "description": "A delectable, semi-sweet New York Style Cheese Cake, with Graham cracker crust and spiced with Indian cardamoms" + } + ], + "comments": [ + { + "id": 0, + "dishId": 0, + "rating": 5, + "comment": "Imagine all the eatables, living in conFusion!", + "author": "John Lemon", + "date": "2012-10-16T17:57:28.556094Z" + }, + { + "id": 1, + "dishId": 0, + "rating": 4, + "comment": "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", + "author": "Paul McVites", + "date": "2014-09-05T17:57:28.556094Z" + }, + { + "id": 2, + "dishId": 0, + "rating": 3, + "comment": "Eat it, just eat it!", + "author": "Michael Jaikishan", + "date": "2015-02-13T17:57:28.556094Z" + }, + { + "id": 3, + "dishId": 0, + "rating": 4, + "comment": "Ultimate, Reaching for the stars!", + "author": "Ringo Starry", + "date": "2013-12-02T17:57:28.556094Z" + }, + { + "id": 4, + "dishId": 0, + "rating": 2, + "comment": "It's your birthday, we're gonna party!", + "author": "25 Cent", + "date": "2011-12-02T17:57:28.556094Z" + }, + { + "id": 5, + "dishId": 1, + "rating": 5, + "comment": "Imagine all the eatables, living in conFusion!", + "author": "John Lemon", + "date": "2012-10-16T17:57:28.556094Z" + }, + { + "id": 6, + "dishId": 1, + "rating": 4, + "comment": "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", + "author": "Paul McVites", + "date": "2014-09-05T17:57:28.556094Z" + }, + { + "id": 7, + "dishId": 1, + "rating": 3, + "comment": "Eat it, just eat it!", + "author": "Michael Jaikishan", + "date": "2015-02-13T17:57:28.556094Z" + }, + { + "id": 8, + "dishId": 1, + "rating": 4, + "comment": "Ultimate, Reaching for the stars!", + "author": "Ringo Starry", + "date": "2013-12-02T17:57:28.556094Z" + }, + { + "id": 9, + "dishId": 1, + "rating": 2, + "comment": "It's your birthday, we're gonna party!", + "author": "25 Cent", + "date": "2011-12-02T17:57:28.556094Z" + }, + { + "id": 10, + "dishId": 2, + "rating": 5, + "comment": "Imagine all the eatables, living in conFusion!", + "author": "John Lemon", + "date": "2012-10-16T17:57:28.556094Z" + }, + { + "id": 11, + "dishId": 2, + "rating": 4, + "comment": "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", + "author": "Paul McVites", + "date": "2014-09-05T17:57:28.556094Z" + }, + { + "id": 12, + "dishId": 2, + "rating": 3, + "comment": "Eat it, just eat it!", + "author": "Michael Jaikishan", + "date": "2015-02-13T17:57:28.556094Z" + }, + { + "id": 13, + "dishId": 2, + "rating": 4, + "comment": "Ultimate, Reaching for the stars!", + "author": "Ringo Starry", + "date": "2013-12-02T17:57:28.556094Z" + }, + { + "id": 14, + "dishId": 2, + "rating": 2, + "comment": "It's your birthday, we're gonna party!", + "author": "25 Cent", + "date": "2011-12-02T17:57:28.556094Z" + }, + { + "id": 15, + "dishId": 3, + "rating": 5, + "comment": "Imagine all the eatables, living in conFusion!", + "author": "John Lemon", + "date": "2012-10-16T17:57:28.556094Z" + }, + { + "id": 16, + "dishId": 3, + "rating": 4, + "comment": "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", + "author": "Paul McVites", + "date": "2014-09-05T17:57:28.556094Z" + }, + { + "id": 17, + "dishId": 3, + "rating": 3, + "comment": "Eat it, just eat it!", + "author": "Michael Jaikishan", + "date": "2015-02-13T17:57:28.556094Z" + }, + { + "id": 18, + "dishId": 3, + "rating": 4, + "comment": "Ultimate, Reaching for the stars!", + "author": "Ringo Starry", + "date": "2013-12-02T17:57:28.556094Z" + }, + { + "id": 19, + "dishId": 3, + "rating": 2, + "comment": "It's your birthday, we're gonna party!", + "author": "25 Cent", + "date": "2011-12-02T17:57:28.556094Z" + } + ], + "promotions": [ + { + "id": 0, + "name": "Weekend Grand Buffet", + "image": "images/buffet.png", + "label": "New", + "price": "19.99", + "featured": true, + "description": "Featuring mouthwatering combinations with a choice of five different salads, six enticing appetizers, six main entrees and five choicest desserts. Free flowing bubbly and soft drinks. All for just $19.99 per person " + } + ], + "leaders": [ + { + "id": 0, + "name": "Peter Pan", + "image": "images/alberto.png", + "designation": "Chief Epicurious Officer", + "abbr": "CEO", + "featured": false, + "description": "Our CEO, Peter, credits his hardworking East Asian immigrant parents who undertook the arduous journey to the shores of America with the intention of giving their children the best future. His mother's wizardy in the kitchen whipping up the tastiest dishes with whatever is available inexpensively at the supermarket, was his first inspiration to create the fusion cuisines for which The Frying Pan became well known. He brings his zeal for fusion cuisines to this restaurant, pioneering cross-cultural culinary connections." + }, + { + "id": 1, + "name": "Dhanasekaran Witherspoon", + "image": "images/alberto.png", + "designation": "Chief Food Officer", + "abbr": "CFO", + "featured": false, + "description": "Our CFO, Danny, as he is affectionately referred to by his colleagues, comes from a long established family tradition in farming and produce. His experiences growing up on a farm in the Australian outback gave him great appreciation for varieties of food sources. As he puts it in his own words, Everything that runs, wins, and everything that stays, pays!" + }, + { + "id": 2, + "name": "Agumbe Tang", + "image": "images/alberto.png", + "designation": "Chief Taste Officer", + "abbr": "CTO", + "featured": false, + "description": "Blessed with the most discerning gustatory sense, Agumbe, our CFO, personally ensures that every dish that we serve meets his exacting tastes. Our chefs dread the tongue lashing that ensues if their dish does not meet his exacting standards. He lives by his motto, You click only if you survive my lick." + }, + { + "id": 3, + "name": "Alberto Somayya", + "image": "images/alberto.png", + "designation": "Executive Chef", + "abbr": "EC", + "featured": true, + "description": "Award winning three-star Michelin chef with wide International experience having worked closely with whos-who in the culinary world, he specializes in creating mouthwatering Indo-Italian fusion experiences. He says, Put together the cuisines from the two craziest cultures, and you get a winning hit! Amma Mia!" + } + ], + "feedback": [ + { + "firstname": "fdas", + "lastname": "afds", + "telnum": "134113", + "email": "dafdads@daffas.dfdafd", + "agree": true, + "contactType": "Email", + "message": "afadsfds", + "date": "2017-12-04T09:41:49.890Z", + "id": 1 + } + ] +} \ No newline at end of file diff --git a/json-server/db.json b/json-server/db.json new file mode 100644 index 0000000..2d2ed39 --- /dev/null +++ b/json-server/db.json @@ -0,0 +1,268 @@ +{ + "dishes": [ + { + "id": 0, + "name": "Uthappizza", + "image": "images/uthappizza.png", + "category": "mains", + "label": "Hot", + "price": "4.99", + "featured": true, + "description": "A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer." + }, + { + "id": 1, + "name": "Zucchipakoda", + "image": "images/zucchipakoda.png", + "category": "appetizer", + "label": "", + "price": "1.99", + "featured": false, + "description": "Deep fried Zucchini coated with mildly spiced Chickpea flour batter accompanied with a sweet-tangy tamarind sauce" + }, + { + "id": 2, + "name": "Vadonut", + "image": "images/vadonut.png", + "category": "appetizer", + "label": "New", + "price": "1.99", + "featured": false, + "description": "A quintessential ConFusion experience, is it a vada or is it a donut?" + }, + { + "id": 3, + "name": "ElaiCheese Cake", + "image": "images/elaicheesecake.png", + "category": "dessert", + "label": "", + "price": "2.99", + "featured": false, + "description": "A delectable, semi-sweet New York Style Cheese Cake, with Graham cracker crust and spiced with Indian cardamoms" + } + ], + "comments": [ + { + "id": 0, + "dishId": 0, + "rating": 5, + "comment": "Imagine all the eatables, living in conFusion!", + "author": "John Lemon", + "date": "2012-10-16T17:57:28.556094Z" + }, + { + "id": 1, + "dishId": 0, + "rating": 4, + "comment": "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", + "author": "Paul McVites", + "date": "2014-09-05T17:57:28.556094Z" + }, + { + "id": 2, + "dishId": 0, + "rating": 3, + "comment": "Eat it, just eat it!", + "author": "Michael Jaikishan", + "date": "2015-02-13T17:57:28.556094Z" + }, + { + "id": 3, + "dishId": 0, + "rating": 4, + "comment": "Ultimate, Reaching for the stars!", + "author": "Ringo Starry", + "date": "2013-12-02T17:57:28.556094Z" + }, + { + "id": 4, + "dishId": 0, + "rating": 2, + "comment": "It's your birthday, we're gonna party!", + "author": "25 Cent", + "date": "2011-12-02T17:57:28.556094Z" + }, + { + "id": 5, + "dishId": 1, + "rating": 5, + "comment": "Imagine all the eatables, living in conFusion!", + "author": "John Lemon", + "date": "2012-10-16T17:57:28.556094Z" + }, + { + "id": 6, + "dishId": 1, + "rating": 4, + "comment": "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", + "author": "Paul McVites", + "date": "2014-09-05T17:57:28.556094Z" + }, + { + "id": 7, + "dishId": 1, + "rating": 3, + "comment": "Eat it, just eat it!", + "author": "Michael Jaikishan", + "date": "2015-02-13T17:57:28.556094Z" + }, + { + "id": 8, + "dishId": 1, + "rating": 4, + "comment": "Ultimate, Reaching for the stars!", + "author": "Ringo Starry", + "date": "2013-12-02T17:57:28.556094Z" + }, + { + "id": 9, + "dishId": 1, + "rating": 2, + "comment": "It's your birthday, we're gonna party!", + "author": "25 Cent", + "date": "2011-12-02T17:57:28.556094Z" + }, + { + "id": 10, + "dishId": 2, + "rating": 5, + "comment": "Imagine all the eatables, living in conFusion!", + "author": "John Lemon", + "date": "2012-10-16T17:57:28.556094Z" + }, + { + "id": 11, + "dishId": 2, + "rating": 4, + "comment": "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", + "author": "Paul McVites", + "date": "2014-09-05T17:57:28.556094Z" + }, + { + "id": 12, + "dishId": 2, + "rating": 3, + "comment": "Eat it, just eat it!", + "author": "Michael Jaikishan", + "date": "2015-02-13T17:57:28.556094Z" + }, + { + "id": 13, + "dishId": 2, + "rating": 4, + "comment": "Ultimate, Reaching for the stars!", + "author": "Ringo Starry", + "date": "2013-12-02T17:57:28.556094Z" + }, + { + "id": 14, + "dishId": 2, + "rating": 2, + "comment": "It's your birthday, we're gonna party!", + "author": "25 Cent", + "date": "2011-12-02T17:57:28.556094Z" + }, + { + "id": 15, + "dishId": 3, + "rating": 5, + "comment": "Imagine all the eatables, living in conFusion!", + "author": "John Lemon", + "date": "2012-10-16T17:57:28.556094Z" + }, + { + "id": 16, + "dishId": 3, + "rating": 4, + "comment": "Sends anyone to heaven, I wish I could get my mother-in-law to eat it!", + "author": "Paul McVites", + "date": "2014-09-05T17:57:28.556094Z" + }, + { + "id": 17, + "dishId": 3, + "rating": 3, + "comment": "Eat it, just eat it!", + "author": "Michael Jaikishan", + "date": "2015-02-13T17:57:28.556094Z" + }, + { + "id": 18, + "dishId": 3, + "rating": 4, + "comment": "Ultimate, Reaching for the stars!", + "author": "Ringo Starry", + "date": "2013-12-02T17:57:28.556094Z" + }, + { + "id": 19, + "dishId": 3, + "rating": 2, + "comment": "It's your birthday, we're gonna party!", + "author": "25 Cent", + "date": "2011-12-02T17:57:28.556094Z" + } + ], + "promotions": [ + { + "id": 0, + "name": "Weekend Grand Buffet", + "image": "images/buffet.png", + "label": "New", + "price": "19.99", + "featured": true, + "description": "Featuring mouthwatering combinations with a choice of five different salads, six enticing appetizers, six main entrees and five choicest desserts. Free flowing bubbly and soft drinks. All for just $19.99 per person " + } + ], + "leaders": [ + { + "id": 0, + "name": "Peter Pan", + "image": "images/alberto.png", + "designation": "Chief Epicurious Officer", + "abbr": "CEO", + "featured": false, + "description": "Our CEO, Peter, credits his hardworking East Asian immigrant parents who undertook the arduous journey to the shores of America with the intention of giving their children the best future. His mother's wizardy in the kitchen whipping up the tastiest dishes with whatever is available inexpensively at the supermarket, was his first inspiration to create the fusion cuisines for which The Frying Pan became well known. He brings his zeal for fusion cuisines to this restaurant, pioneering cross-cultural culinary connections." + }, + { + "id": 1, + "name": "Dhanasekaran Witherspoon", + "image": "images/alberto.png", + "designation": "Chief Food Officer", + "abbr": "CFO", + "featured": false, + "description": "Our CFO, Danny, as he is affectionately referred to by his colleagues, comes from a long established family tradition in farming and produce. His experiences growing up on a farm in the Australian outback gave him great appreciation for varieties of food sources. As he puts it in his own words, Everything that runs, wins, and everything that stays, pays!" + }, + { + "id": 2, + "name": "Agumbe Tang", + "image": "images/alberto.png", + "designation": "Chief Taste Officer", + "abbr": "CTO", + "featured": false, + "description": "Blessed with the most discerning gustatory sense, Agumbe, our CFO, personally ensures that every dish that we serve meets his exacting tastes. Our chefs dread the tongue lashing that ensues if their dish does not meet his exacting standards. He lives by his motto, You click only if you survive my lick." + }, + { + "id": 3, + "name": "Alberto Somayya", + "image": "images/alberto.png", + "designation": "Executive Chef", + "abbr": "EC", + "featured": true, + "description": "Award winning three-star Michelin chef with wide International experience having worked closely with whos-who in the culinary world, he specializes in creating mouthwatering Indo-Italian fusion experiences. He says, Put together the cuisines from the two craziest cultures, and you get a winning hit! Amma Mia!" + } + ], + "feedback": [ + { + "firstname": "fdas", + "lastname": "afds", + "telnum": "134113", + "email": "dafdads@daffas.dfdafd", + "agree": true, + "contactType": "Email", + "message": "afadsfds", + "date": "2017-12-04T09:41:49.890Z", + "id": 1 + } + ] + } \ No newline at end of file diff --git a/public/assets/images/alberto.png b/json-server/public/images/alberto.png similarity index 100% rename from public/assets/images/alberto.png rename to json-server/public/images/alberto.png diff --git a/public/assets/images/buffet.png b/json-server/public/images/buffet.png similarity index 100% rename from public/assets/images/buffet.png rename to json-server/public/images/buffet.png diff --git a/public/assets/images/elaicheesecake.png b/json-server/public/images/elaicheesecake.png similarity index 100% rename from public/assets/images/elaicheesecake.png rename to json-server/public/images/elaicheesecake.png diff --git a/json-server/public/images/logo.png b/json-server/public/images/logo.png new file mode 100644 index 0000000..fee0a33 Binary files /dev/null and b/json-server/public/images/logo.png differ diff --git a/public/assets/images/uthappizza.png b/json-server/public/images/uthappizza.png similarity index 100% rename from public/assets/images/uthappizza.png rename to json-server/public/images/uthappizza.png diff --git a/public/assets/images/vadonut.png b/json-server/public/images/vadonut.png similarity index 100% rename from public/assets/images/vadonut.png rename to json-server/public/images/vadonut.png diff --git a/public/assets/images/zucchipakoda.png b/json-server/public/images/zucchipakoda.png similarity index 100% rename from public/assets/images/zucchipakoda.png rename to json-server/public/images/zucchipakoda.png diff --git a/package-lock.json b/package-lock.json index 1c288ef..f94e03a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3810,6 +3810,22 @@ "sha.js": "^2.4.8" } }, + "cross-fetch": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-2.1.0.tgz", + "integrity": "sha512-FTIt2WK44RiafWQ62xIvd+oBoVd392abh1lF872trLlA74JCR1s4oTHlixwoIKy44ehn8WbQ0Ds2P16sw7ZQxg==", + "requires": { + "node-fetch": "2.1.1", + "whatwg-fetch": "2.0.3" + }, + "dependencies": { + "whatwg-fetch": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", + "integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ=" + } + } + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -8803,6 +8819,11 @@ "tslib": "^1.10.0" } }, + "node-fetch": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.1.tgz", + "integrity": "sha1-NpynC4L1DIZJYQSmx3bSdPTkotQ=" + }, "node-forge": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.9.0.tgz", diff --git a/package.json b/package.json index 2f8b171..3c0a7b3 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "@testing-library/user-event": "^7.2.1", "bootstrap": "^4.0.0", "bootstrap-social": "^5.1.1", + "cross-fetch": "^2.1.0", "font-awesome": "^4.7.0", "prismic-reactjs": "^1.3.0", "react": "^16.13.1", diff --git a/src/components/DishdetailComponent.js b/src/components/DishdetailComponent.js index 5287000..9706009 100644 --- a/src/components/DishdetailComponent.js +++ b/src/components/DishdetailComponent.js @@ -5,6 +5,7 @@ import {Date} from 'prismic-reactjs'; import {Link} from 'react-router-dom'; import { Control, LocalForm, Errors } from 'react-redux-form'; import { Loading } from './LoadingComponent'; +import { baseUrl } from '../shared/baseUrl'; const required = (val) => val && val.length; const maxLength = (len) => (val) => !(val) || (val.length <= len); @@ -181,7 +182,7 @@ function RenderDish({dish,isLoading, errMess, comments, addComment}) {
- + {dish.name} {dish.description} diff --git a/src/components/HomeComponent.js b/src/components/HomeComponent.js index b465940..e679025 100644 --- a/src/components/HomeComponent.js +++ b/src/components/HomeComponent.js @@ -1,6 +1,7 @@ import React from 'react'; import { Card, CardImg, CardText, CardBody, CardTitle, CardSubtitle} from 'reactstrap'; import {Loading} from './LoadingComponent'; +import { baseUrl } from '../shared/baseUrl'; function RenderCard({item, isLoading, errMess}) { if (isLoading) { @@ -15,7 +16,7 @@ function RenderCard({item, isLoading, errMess}) { }else{ return( - + {item.name} {item.designation ? {item.designation} : null } @@ -34,7 +35,7 @@ function Home(props) {
- +
diff --git a/src/components/MainComponent.js b/src/components/MainComponent.js index 313bcf0..e7363fd 100644 --- a/src/components/MainComponent.js +++ b/src/components/MainComponent.js @@ -11,7 +11,7 @@ import Footer from './FooterComponent'; import About from './AboutComponent'; import Contact from './ContactComponent'; import DishDetail from './DishdetailComponent'; -import { addComment, fetchDishes } from '../redux/ActionCreators'; +import { addComment, fetchDishes, fetchComments, fetchPromos } from '../redux/ActionCreators'; const mapStateToProps = state => { @@ -27,8 +27,9 @@ const mapDispatchToProps = dispatch => ({ addComment: (dishId, rating, author, comment) => dispatch(addComment(dishId, rating, author, comment)), fetchDishes: () => {dispatch(fetchDishes())}, - resetFeedbackForm: () => { dispatch(actions.reset('feedback'))} - + resetFeedbackForm: () => { dispatch(actions.reset('feedback'))}, + fetchComments: () => dispatch(fetchComments()), + fetchPromos: () => dispatch(fetchPromos()) }); class Main extends Component{ @@ -39,6 +40,8 @@ class Main extends Component{ //Life cycle method componentDidMount(){ this.props.fetchDishes(); + this.props.fetchComments(); + this.props.fetchPromos(); } onDishSelect(dishID) { @@ -51,7 +54,9 @@ class Main extends Component{ dish={this.props.dishes.dishes.filter((dish) => dish.featured)[0]} dishesLoading={this.props.dishes.isLoading} dishesErrMess={this.props.dishes.errMess} - promotion={this.props.promotions.filter((promo) => promo.featured)[0]} + promotion={this.props.promotions.promotions.filter((promo) => promo.featured)[0]} + promoLoading={this.props.promotions.isLoading} + promoErrMess={this.props.promotions.errMess} leader={this.props.leaders.filter((leader) => leader.featured)[0]} /> ); @@ -62,7 +67,8 @@ class Main extends Component{ dish={this.props.dishes.dishes.filter((dish) => dish.id === parseInt(match.params.dishId,10))[0]} isLoading={this.props.dishes.isLoading} errMess={this.props.dishes.errMess} - comments={this.props.comments.filter((comment) => comment.dishId === parseInt(match.params.dishId,10))} + comments={this.props.comments.comments.filter((comment) => comment.dishId === parseInt(match.params.dishId,10))} + commentsErrMess={this.props.comments.errMess} addComment={this.props.addComment} /> ); diff --git a/src/components/MenuComponent.js b/src/components/MenuComponent.js index d3aea7d..735f31d 100644 --- a/src/components/MenuComponent.js +++ b/src/components/MenuComponent.js @@ -2,6 +2,7 @@ import React from 'react'; import { Card, CardImg, CardImgOverlay, CardTitle, Breadcrumb, BreadcrumbItem } from 'reactstrap'; import { Link } from 'react-router-dom'; import {Loading} from './LoadingComponent'; +import { baseUrl } from '../shared/baseUrl'; //functional component---> ////when we are just rendering the props instead of storing the states, we required the function component @@ -9,7 +10,7 @@ function RenderMenuItem({dish}){ return( - + {dish.name} diff --git a/src/redux/ActionCreators.js b/src/redux/ActionCreators.js index f804177..1aeb00a 100644 --- a/src/redux/ActionCreators.js +++ b/src/redux/ActionCreators.js @@ -1,5 +1,6 @@ import * as ActionTypes from './ActionTypes'; import { DISHES } from './../shared/dishes'; +import { baseUrl } from '../shared/baseUrl'; export const addComment = (dishId, rating, author, comment) => ({ type: ActionTypes.ADD_COMMENT, @@ -15,9 +16,9 @@ export const fetchDishes = () => (dispatch) => { dispatch(dishesLoading(true)); - setTimeout(() => { - dispatch(addDishes(DISHES)); - }, 2000); + return fetch(baseUrl + 'dishes') + .then(response => response.json()) + .then(dishes => dispatch(addDishes(dishes))); } export const dishesLoading = () => ({ @@ -32,4 +33,43 @@ export const dishesFailed = (errmess) => ({ export const addDishes = (dishes) => ({ type: ActionTypes.ADD_DISHES, payload: dishes +}); + +export const fetchComments = () => (dispatch) => { + return fetch(baseUrl + 'comments') + .then(response => response.json()) + .then(comments => dispatch(addComments(comments))); +}; + +export const commentsFailed = (errmess) => ({ + type: ActionTypes.COMMENTS_FAILED, + payload: errmess +}); + +export const addComments = (comments) => ({ + type: ActionTypes.ADD_COMMENTS, + payload: comments +}); + +export const fetchPromos = () => (dispatch) => { + + dispatch(promosLoading()); + + return fetch(baseUrl + 'promotions') + .then(response => response.json()) + .then(promos => dispatch(addPromos(promos))); +} + +export const promosLoading = () => ({ + type: ActionTypes.PROMOS_LOADING +}); + +export const promosFailed = (errmess) => ({ + type: ActionTypes.PROMOS_FAILED, + payload: errmess +}); + +export const addPromos = (promos) => ({ + type: ActionTypes.ADD_PROMOS, + payload: promos }); \ No newline at end of file diff --git a/src/redux/ActionTypes.js b/src/redux/ActionTypes.js index 7b5e778..9960c83 100644 --- a/src/redux/ActionTypes.js +++ b/src/redux/ActionTypes.js @@ -1,4 +1,11 @@ export const ADD_COMMENT = 'ADD_COMMENT'; export const DISHES_LOADING = 'DISHES_LOADING'; export const DISHES_FAILED = 'DISHES_FAILED'; -export const ADD_DISHES = 'ADD_DISHES'; \ No newline at end of file +export const ADD_DISHES = 'ADD_DISHES'; + +export const ADD_COMMENTS = 'ADD_COMMENTS'; +export const COMMENTS_FAILED = 'COMMENTS_FAILED'; + +export const PROMOS_LOADING = 'PROMOS_LOADING'; +export const ADD_PROMOS = 'ADD_PROMOS'; +export const PROMOS_FAILED = 'PROMOS_FAILED'; \ No newline at end of file diff --git a/src/redux/comments.js b/src/redux/comments.js index 8cb8547..1712808 100644 --- a/src/redux/comments.js +++ b/src/redux/comments.js @@ -1,16 +1,20 @@ -import { COMMENTS } from '../shared/comments'; import * as ActionTypes from './ActionTypes'; -export const Comments = (state = COMMENTS, action) => { - switch (action.type) { - case ActionTypes.ADD_COMMENT: - var comment = action.payload; - comment.id = state.length; - comment.date = new Date(); - console.log("Comment: ", comment); - return state.concat(comment); +export const Comments = (state = { errMess: null, comments:[]}, action) => { + switch (action.type) { + case ActionTypes.ADD_COMMENTS: + return {...state, errMess: null, comments: action.payload}; - default: - return state; - } + case ActionTypes.COMMENTS_FAILED: + return {...state, errMess: action.payload}; + + case ActionTypes.ADD_COMMENT: + var comment = action.payload; + comment.id = state.comments.length; + comment.date = new Date(); + return { ...state, comments: state.comments.concat(comment)}; + + default: + return state; + } }; \ No newline at end of file diff --git a/src/redux/promotions.js b/src/redux/promotions.js index 44efc6c..2f1a24a 100644 --- a/src/redux/promotions.js +++ b/src/redux/promotions.js @@ -1,7 +1,18 @@ -import { PROMOTIONS } from '../shared/promotions'; +import * as ActionTypes from './ActionTypes'; -export const Promotions = (state = PROMOTIONS, action) => { +export const Promotions = (state = { isLoading: true, + errMess: null, + promotions:[]}, action) => { switch (action.type) { + case ActionTypes.ADD_PROMOS: + return {...state, isLoading: false, errMess: null, promotions: action.payload}; + + case ActionTypes.PROMOS_LOADING: + return {...state, isLoading: true, errMess: null, promotions: []} + + case ActionTypes.PROMOS_FAILED: + return {...state, isLoading: false, errMess: action.payload}; + default: return state; } diff --git a/src/shared/baseUrl.js b/src/shared/baseUrl.js new file mode 100644 index 0000000..a58bcbc --- /dev/null +++ b/src/shared/baseUrl.js @@ -0,0 +1 @@ +export const baseUrl = 'http://localhost:3001/'; \ No newline at end of file