diff --git a/src/Components/Info.js b/src/Components/Info.js index a7f12305..7366f838 100644 --- a/src/Components/Info.js +++ b/src/Components/Info.js @@ -31,6 +31,8 @@ import delivery_title from "../assets/info_delivery.png"; import gradient from "../assets/gradient.png"; import revieworder from "../assets/info_review_order.png"; import firebase from "./Firestore"; +import DatePicker from "react-date-picker"; +import TimePicker from "react-time-picker"; import { FacebookShareButton, FacebookIcon, @@ -49,6 +51,8 @@ import { BitlyClient } from "bitly"; const REACT_APP_BITLY_KEY = `${process.env.REACT_APP_BITLY_KEY}`; const bitly = new BitlyClient(REACT_APP_BITLY_KEY, {}); const analytics = firebase.analytics(); +const time_now = new Date(); +time_now.setMinutes(time_now.getMinutes()); function onLoad(name, item) { analytics.logEvent(name, { name: item }); } @@ -101,6 +105,42 @@ const popover = ( ); +const dayName = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", +]; + +const monthNames = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", +]; + +function formatAMPM(date) { + var hours = date.getHours(); + var minutes = date.getMinutes(); + var ampm = hours >= 12 ? "pm" : "am"; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? "0" + minutes : minutes; + var strTime = hours + ":" + minutes + " " + ampm; + return strTime; +} + export class Info extends React.Component { constructor(props) { super(props); @@ -117,7 +157,9 @@ export class Info extends React.Component { postal: "", notes: "", customerNumber: "", - deliveryTime: "", + time: time_now.getHours() + ":" + time_now.getMinutes(), + date: time_now, + datetime: time_now, id: this.props.id || queryString.parse(this.props.location.search).id, galleryOpened: false, retrieved: false, @@ -212,10 +254,6 @@ export class Info extends React.Component { this.setState({ customerNumber: inputValue, }); - } else if (inputField === "deliveryTime") { - this.setState({ - deliveryTime: inputValue, - }); } else if (inputField === "unit") { this.setState({ unit: inputValue, @@ -253,8 +291,8 @@ export class Info extends React.Component { callPostal = (postal) => { return fetch( "https://developers.onemap.sg/commonapi/search?searchVal=" + - postal + - "&returnGeom=Y&getAddrDetails=Y" + postal + + "&returnGeom=Y&getAddrDetails=Y" ) .then(function (response) { return response.json(); @@ -345,7 +383,14 @@ export class Info extends React.Component { " " + this.state.postal + "*"; - text = text + "\nDelivery Date/Time: *" + this.state.deliveryTime + "*"; + let time_text = dayName[this.state.datetime.getDay()] + + " " + + this.state.datetime.getDate() + + " " + + monthNames[this.state.datetime.getMonth()] + + " " + + formatAMPM(this.state.datetime); + text = text + "\nDelivery Date/Time: *" + time_text + "*"; if (this.state.notes !== "") { // only display notes if customer added text = text + "\nAdditional notes: _" + this.state.notes + "_"; @@ -407,11 +452,11 @@ export class Info extends React.Component { this.state.orderData[idx] === 0.0 ? this.state.totalPrice : parseFloat(this.state.totalPrice) - - parseFloat( - this.state.data.menu_combined[idx].price - ? this.state.data.menu_combined[idx].price - : 0 - ), + parseFloat( + this.state.data.menu_combined[idx].price + ? this.state.data.menu_combined[idx].price + : 0 + ), orderData: update(this.state.orderData, { [idx]: { $set: @@ -436,8 +481,8 @@ export class Info extends React.Component { ? (toPush = true) : (toPush = false) : element.name && element.price - ? (toPush = true) - : (toPush = false); + ? (toPush = true) + : (toPush = false); if (toPush) { data.push(
@@ -533,8 +578,8 @@ export class Info extends React.Component { {this.state.orderData[i] !== undefined ? this.state.orderData[ - JSON.parse(JSON.stringify(i)) - ] + JSON.parse(JSON.stringify(i)) + ] : 0} @@ -583,7 +628,7 @@ export class Info extends React.Component { value="click" className={`image-gallery-fullscreen-button${ isFullscreen ? " active" : "" - }`} + }`} onClick={onClick} /> ); @@ -645,9 +690,47 @@ export class Info extends React.Component { handleSubmit = async (event) => { event.preventDefault(); console.log("submit"); - var text = await this.setOrderText(); - var url = "https://wa.me/65" + this.state.data.contact + "?text=" + text; - window.location = url; + if (time_now > this.state.datetime) { + alert( + "Time cannot be earlier than now" + ); + } else { + var text = await this.setOrderText(); + var url = "https://wa.me/65" + this.state.data.contact + "?text=" + text; + window.location = url; + } + }; + + handleTime = async (time) => { + this.setState({ + time: time, + datetime: new Date( + this.state.date.getMonth() + + 1 + + "/" + + this.state.date.getDate() + + "/" + + this.state.date.getFullYear() + + " " + + time + ), + }); + }; + + handleDate = async (date) => { + this.setState({ + date: date, + datetime: new Date( + date.getMonth() + + 1 + + "/" + + date.getDate() + + "/" + + date.getFullYear() + + " " + + this.state.time + ), + }); }; render() { @@ -721,60 +804,60 @@ export class Info extends React.Component { return this.state.retrieved ? (
{this.state.hasReviewEditMessage || - this.state.hasReviewDeleteMessage ? ( -
+ this.state.hasReviewDeleteMessage ? (
- -
- {this.state.hasReviewEditMessage ? ( -

- Your edit(s) will be reflected once they have been - reviewed. Thank you for your patience! -

- ) : ( -

- This listing will be deleted once your request has - been reviewed. Thank you for your patience! -

- )} -
-
+
+ +
+ {this.state.hasReviewEditMessage ? ( +

+ Your edit(s) will be reflected once they have been + reviewed. Thank you for your patience! +

+ ) : ( +

+ This listing will be deleted once your request has + been reviewed. Thank you for your patience! +

+ )} +
+
+
-
- ) : null} + ) : null} { this.state.hero ? (
) : null} {this.state.data.pickup_option || - this.state.data.delivery_option ? ( -
- - - - {" "} - {this.state.data.pickup_option ? ( - Da Bao - ) : null} - {this.state.data.delivery_option ? ( - Delivery - ) : null}{" "} -
-
- ) : null} + this.state.data.delivery_option ? ( +
+ + + + {" "} + {this.state.data.pickup_option ? ( + Da Bao + ) : null} + {this.state.data.delivery_option ? ( + Delivery + ) : null}{" "} +
+
+ ) : null} {regions.length > 0 ? (
{this.state.data.menu && - this.state.data.whatsapp && - this.state.data.menu_combined.length > 0 && - this.state.data.menu_combined[0].name !== "" ? ( - - - - ) : null} + this.state.data.whatsapp && + this.state.data.menu_combined.length > 0 && + this.state.data.menu_combined[0].name !== "" ? ( + + + + ) : null} {this.state.data.website ? ( 0 && - this.state.data.menu_combined[0].name !== "" ? ( -
-
-
- - - -
- ) : this.state.data.menu && + this.state.data.whatsapp && this.state.data.menu_combined.length > 0 && this.state.data.menu_combined[0].name !== "" ? ( -
-
-
+
+
+
+ + + +
+ ) : this.state.data.menu && + this.state.data.menu_combined.length > 0 && + this.state.data.menu_combined[0].name !== "" ? ( +
+
+
- - - -
- ) : null} + + + +
+ ) : null} {/* Display the first item of the menu with a see more button - TODO: boilerplate code */} {this.state.data.menu && - this.state.data.menu_combined.length > 0 && - this.state.data.menu_combined[0].name !== "" ? ( -
-
- {/* gradient overlay shows if only 1 item OR >1 item && customer hasn't clicked Menu / see more */} - {(!this.state.wantToOrder && + this.state.data.menu_combined.length > 0 && + this.state.data.menu_combined[0].name !== "" ? ( +
+
+ {/* gradient overlay shows if only 1 item OR >1 item && customer hasn't clicked Menu / see more */} + {(!this.state.wantToOrder && this.state.data.menu && this.state.data.menu_combined.length > 1 && this.state.data.menu_combined[1] && - this.state.data.menu_combined[1].name !== "") + this.state.data.menu_combined[1].name !== "") // addresses case where >1 item and customer hasnt clicked || (!this.state.wantToOrder && this.state.data.menu_combined[1] && this.state.data.menu_combined[1].name === - "") - // addresses case where there are multiple items in menu_combined but only 1 non-empty item - || + "") + // addresses case where there are multiple items in menu_combined but only 1 non-empty item + || (!this.state.wantToOrder && this.state.data.menu_combined.length === 1) - // addresses case where there is only 1 item in menu_combined -? ( - - + + + ) : null} +
+ - - ) : null} -
- - - {this.state.data.menu_combined[0] ? ( - - {this.state.data.menu_combined[0].name} - {this.state.data.menu_combined[0] && - this.state.data.menu_combined[0] - .description ? ( - - {" "} + > + + {this.state.data.menu_combined[0] ? ( + + {this.state.data.menu_combined[0].name} + {this.state.data.menu_combined[0] && + this.state.data.menu_combined[0] + .description ? ( + + {" "} ( - { - this.state.data.menu_combined[0] - .description - } + { + this.state.data.menu_combined[0] + .description + } ) - - ) : null} - - ) : null} - - -
-
-
- + ) : null} + + ) : null} + + +
+
+
- $ + + $ {this.state.data.menu_combined[0].price - ? this.state.data.menu_combined[0].price - : "TBD"} - -
-
+ ? this.state.data.menu_combined[0].price + : "TBD"} + +
-
- {this.state.data.whatsapp ? ( -
- - - - {this.state.orderData[0] !== - undefined - ? this.state.orderData[0] // hardcode 0 to display first menu item - : 0} - - - -
- ) : null} +
+ ) : null} +
-
-
-
-
- ) : null} +
+ +
+ ) : null} {/* See more button shows if only 1 item OR >1 item && customer hasn't clicked Menu / see more */} {(!this.state.wantToOrder && this.state.data.menu && this.state.data.menu_combined.length > 1 && this.state.data.menu_combined[1] && this.state.data.menu_combined[1].name !== "") || - (!this.state.wantToOrder && - this.state.data.menu && - this.state.data.menu_combined[0] && - this.state.data.menu_combined[0].name !== "" && - this.state.data.menu_combined[1] && - this.state.data.menu_combined[1].name === "") + (!this.state.wantToOrder && + this.state.data.menu && + this.state.data.menu_combined[0] && + this.state.data.menu_combined[0].name !== "" && + this.state.data.menu_combined[1] && + this.state.data.menu_combined[1].name === "") || - (!this.state.wantToOrder && - this.state.data.menu && - this.state.data.menu_combined.length === 1 && - this.state.data.menu_combined[0] && - this.state.data.menu_combined[0].name !== "") + (!this.state.wantToOrder && + this.state.data.menu && + this.state.data.menu_combined.length === 1 && + this.state.data.menu_combined[0] && + this.state.data.menu_combined[0].name !== "") ? ( -
-
-
- see more ↓ +
+
+
+ see more ↓ +
-
- ) : null} + ) : null} {/* Display the rest of the menu if customer clicks Menu / see more */} {this.state.wantToOrder ? ( @@ -1382,10 +1465,10 @@ export class Info extends React.Component { i ] !== undefined ? this.state.orderData[ - JSON.parse( - JSON.stringify(i) - ) - ] + JSON.parse( + JSON.stringify(i) + ) + ] : 0} @@ -1518,20 +1601,51 @@ export class Info extends React.Component { >
+
-
- - +
+
+ + +
+
+
+
+ + + {time_now > this.state.datetime ? ( + + Time cannot be earlier than now + + ) : null} +
+
-
{" "} @@ -1691,9 +1805,9 @@ export class Info extends React.Component { "whatsapp://send?text=" + encodeURIComponent( "Hungry? Try out " + - this.state.data.name + - " now! Order form / more information at www.foodleh.app/info?id=" + - this.state.id + this.state.data.name + + " now! Order form / more information at www.foodleh.app/info?id=" + + this.state.id ) } > @@ -1750,7 +1864,7 @@ export class Info extends React.Component { > {this.state.data.promo}:{" "} {this.state.data.condition && - this.state.data.condition.length > 40 + this.state.data.condition.length > 40 ? this.state.data.condition.slice(0, 40) + "..." : this.state.data.condition}
@@ -1778,22 +1892,22 @@ export class Info extends React.Component {

) : null} {this.state.data.description_detail && - this.state.data.description_detail !== "" && - this.state.data.description_detail !== undefined ? ( -
-
- Detailed Description -
-

- {this.state.data.description_detail} -

-
- ) : null} + this.state.data.description_detail !== "" && + this.state.data.description_detail !== undefined ? ( +
+
+ Detailed Description +
+

+ {this.state.data.description_detail} +

+
+ ) : null} {/* {Menu appears if menu data is present and whatsapp is not present} */} {this.state.data.menu && !this.state.data.whatsapp ? ( @@ -1883,13 +1997,13 @@ export class Info extends React.Component {
) : ( -
-
-

Loading

- +
+
+

Loading

+ +
-
- ); + ); } }