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 ? (