Skip to content

Commit 910619b

Browse files
authored
Merge pull request #48 from untilhamza/release/v1.8.0
Release/v1.8.0
2 parents aee34e4 + 0a5fbd0 commit 910619b

File tree

4 files changed

+22
-176
lines changed

4 files changed

+22
-176
lines changed

src/components/BookingForm/BookingForm.js

+5-173
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import { useEffect, useState } from "react";
21
import { Formik, ErrorMessage } from "formik";
3-
import { useHistory } from "react-router-dom";
42
import * as yup from "yup";
5-
import Swal from "sweetalert2";
63
import moment from "moment";
74
import { Form, Button } from "react-bootstrap";
85
import { DatePicker } from "antd";
96
import TimeSelector from "../TimeSelector/TimeSelector";
10-
import { RecaptchaVerifier, signInWithPhoneNumber } from "firebase/auth";
11-
import { auth } from "../../database/firebase-config";
127

138
import "./BookingForm.css";
149

@@ -17,89 +12,12 @@ const koreanPhoneRegex = /^((\+82))((10\d{7,8})|(2\d{8}))$/;
1712
const schema = yup.object().shape({
1813
name: yup.string().required("Name is required!"),
1914
phone: yup.string().min(8, "*Enter a valid phone number").matches(koreanPhoneRegex, "*Enter a valid phone number!").required("*Phone number is required!"),
20-
email: yup.string().email("Must be a valid email").max(255).required("*Email is required!"),
15+
email: yup.string(),
2116
date: yup.string().required("*Booking date is required!"),
2217
time: yup.string().required("*Booking time is required!"),
2318
});
2419

2520
const BookingForm = ({ onCancel, onConfirm, oldData, slots, onGetSlots, slotStatus, settings }) => {
26-
const [phoneIsVerified, setPhoneIsVerified] = useState(true);
27-
const [isVerifyingPhone, setIsVerifyingPhone] = useState(true);
28-
const [phoneVerificationCode, setPhoneVerificationCode] = useState("");
29-
const [isRecaptchaVerified, setIsRecaptchaVerified] = useState(null);
30-
const [phoneVerificationError, setPhoneVerificationError] = useState("");
31-
const [phoneConfirmationObject, setPhoneConfirmationObject] = useState(null);
32-
const history = useHistory();
33-
34-
const handleConfirmButtonClick = () => {
35-
if (!phoneIsVerified) {
36-
Swal.fire({
37-
icon: "info",
38-
title: "Phone not verified!",
39-
text: "Please verify your phone number before confirming your booking.",
40-
});
41-
return;
42-
}
43-
};
44-
45-
const handlePhoneVerification = async (phoneNumber) => {
46-
if (!koreanPhoneRegex.test(phoneNumber)) {
47-
setPhoneVerificationError("Please enter a valid Korean phone number.");
48-
Swal.fire({
49-
icon: "info",
50-
title: "Invalid phone number!",
51-
text: "Please enter a valid Korean phone number starting with +82.",
52-
});
53-
return;
54-
}
55-
setIsVerifyingPhone(true);
56-
try {
57-
const appVerifier = window.recaptchaVerifier;
58-
const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, appVerifier);
59-
// SMS sent. Prompt user to type the code from the message, then sign the
60-
// user in with confirmationResult.confirm(code).
61-
setPhoneConfirmationObject(confirmationResult);
62-
} catch (err) {
63-
// history.go(0);
64-
Swal.fire({
65-
icon: "error",
66-
title: "An error occurred!",
67-
text: "Please refresh the page and try again.",
68-
});
69-
}
70-
};
71-
72-
function handlePhoneCode(e) {
73-
e.preventDefault();
74-
if (!phoneConfirmationObject) {
75-
//history.go(0);
76-
Swal.fire({
77-
icon: "error",
78-
title: "An error occurred!",
79-
text: "Please refresh the page and try again.",
80-
});
81-
return;
82-
}
83-
phoneConfirmationObject
84-
.confirm(phoneVerificationCode)
85-
.then((result) => {
86-
// User signed in successfully with their phone.
87-
const user = result.user; //not an admin user
88-
setPhoneIsVerified(true);
89-
setIsVerifyingPhone(false);
90-
})
91-
.catch((error) => {
92-
// User couldn't sign in (bad verification code?)
93-
setPhoneIsVerified(false);
94-
setIsVerifyingPhone(false);
95-
Swal.fire({
96-
icon: "info",
97-
title: "Invalid verification code!",
98-
text: "Please enter a valid verification code sent to your phone.",
99-
});
100-
});
101-
}
102-
10321
function handleGetSlots(date) {
10422
onGetSlots(date);
10523
}
@@ -111,51 +29,6 @@ const BookingForm = ({ onCancel, onConfirm, oldData, slots, onGetSlots, slotStat
11129
return submittedValue.valueOf() < moment().add(-1, "day") || submittedValue.valueOf() >= moment().add(31, "day");
11230
};
11331

114-
// useEffect(() => {
115-
// if (isRecaptchaVerified !== null && !isRecaptchaVerified) {
116-
// history.push("/");
117-
// return;
118-
// }
119-
// }, [isRecaptchaVerified]);
120-
121-
// useEffect(() => {
122-
// try {
123-
// window.recaptchaVerifier = new RecaptchaVerifier(
124-
// "sign-in-button",
125-
// {
126-
// size: "invisible",
127-
// callback: (response) => {
128-
// setIsRecaptchaVerified(true);
129-
// // reCAPTCHA solved, allow signInWithPhoneNumber.
130-
// console.log("reCAPTCHA solved, allow signInWithPhoneNumber.");
131-
// //Now handlePhoneVerification(phoneNumber);
132-
// },
133-
// "expired-callback": () => {
134-
// setIsRecaptchaVerified(false);
135-
// console.log("reCAPTCHA expired");
136-
// // history.go(0);
137-
// Swal.fire({
138-
// icon: "error",
139-
// title: "An error occurred!",
140-
// text: "Please refresh the page and try again.",
141-
// });
142-
// },
143-
// },
144-
// auth
145-
// );
146-
147-
// window.recaptchaVerifier.render().then(function (widgetId) {
148-
// window.recaptchaWidgetId = widgetId;
149-
// });
150-
// } catch (e) {
151-
// console.log("recapture error", e);
152-
// }
153-
154-
// return () => {
155-
// window.recaptchaVerifier.clear();
156-
// };
157-
// }, []);
158-
15932
return (
16033
<Formik
16134
validationSchema={schema}
@@ -178,10 +51,7 @@ const BookingForm = ({ onCancel, onConfirm, oldData, slots, onGetSlots, slotStat
17851
// validated={!errors}
17952
onSubmit={(e) => {
18053
e.preventDefault();
181-
if (phoneIsVerified) {
182-
handleSubmit();
183-
} else {
184-
}
54+
handleSubmit();
18555
}}
18656
className="appointmentForm mx-auto p-3 "
18757
>
@@ -201,44 +71,14 @@ const BookingForm = ({ onCancel, onConfirm, oldData, slots, onGetSlots, slotStat
20171
placeholder="Phone number"
20272
value={values.phone}
20373
onChange={(e) => {
204-
// setPhoneNumber("01098999793");
205-
handleChange(e);
74+
const value = e.target.value;
75+
setFieldValue("phone", value.replace(/[^0-9+]/g, ""));
20676
}}
20777
isValid={touched.phone && !errors.phone}
20878
/>
20979
<div className="text-danger font-italic">
21080
<ErrorMessage name="phone" />
21181
</div>
212-
{/* {!phoneIsVerified && !isVerifyingPhone && (
213-
<Button
214-
id="sign-in-button"
215-
onClick={() => {
216-
handlePhoneVerification(values.phone);
217-
}}
218-
variant="outline-primary"
219-
className="mt-2 btn-sm"
220-
>
221-
Verify phone number!
222-
</Button>
223-
)}
224-
{isVerifyingPhone && !phoneIsVerified && <p className="mb-0">Enter verification code on your phone</p>}
225-
{phoneIsVerified && !isVerifyingPhone && <p className="text-success ">Your phone was verified successfully! </p>}
226-
{isVerifyingPhone && (
227-
<div className="d-flex justify-content-between">
228-
<input className="form-control form-control-sm w-50" type="text" value={phoneVerificationCode} onChange={(e) => setPhoneVerificationCode(e.target.value)} />
229-
<button className="btn btn-outline-primary btn-sm w-50 ms-2" onClick={(e) => handlePhoneCode(e)}>
230-
Verify code
231-
</button>
232-
</div>
233-
)} */}
234-
</Form.Group>
235-
236-
<Form.Group className="mb-3">
237-
<Form.Label className="fw-bold">Email</Form.Label>
238-
<Form.Control type="email" name="email" placeholder="Email" value={values.email} onChange={handleChange} isValid={touched.email && !errors.email} />
239-
<div className="text-danger font-italic">
240-
<ErrorMessage name="email" />
241-
</div>
24282
</Form.Group>
24383

24484
<Form.Group>
@@ -285,15 +125,7 @@ const BookingForm = ({ onCancel, onConfirm, oldData, slots, onGetSlots, slotStat
285125
</Form.Group>
286126

287127
<div className="d-flex justify-content-around p-2">
288-
<Button
289-
variant="success"
290-
type="submit"
291-
className="w-100 me-1"
292-
// onClick={() => {
293-
// handleConfirmButtonClick();
294-
// }}
295-
// disabled={!phoneIsVerified}
296-
>
128+
<Button variant="success" type="submit" className="w-100 me-1">
297129
Confirm Booking
298130
</Button>
299131

src/components/CheckingForm/CheckingForm.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,21 @@ const CheckingForm = ({ onConfirm, onCancel, initialPhoneNumber }) => {
3030
<h5 className="card-title">Enter Phone Number used to make appointment</h5>
3131
<form onSubmit={formik.handleSubmit}>
3232
<div className="form-group mb-3">
33-
<input type="tel" name="phoneNumber" className={"form-control"} placeholder="Phone number" onChange={formik.handleChange} value={formik.values.phoneNumber} />
33+
<input
34+
type="tel"
35+
name="phoneNumber"
36+
className={"form-control"}
37+
placeholder="Phone number"
38+
onChange={(e) => {
39+
const value = e.target.value;
40+
if (value.length > 0) {
41+
formik.setFieldValue("phoneNumber", value.replace(/[^0-9+]/g, ""));
42+
} else {
43+
formik.setFieldValue("phoneNumber", value);
44+
}
45+
}}
46+
value={formik.values.phoneNumber}
47+
/>
3448
{formik.touched.phoneNumber && formik.errors.phoneNumber && <span className="help-block text-danger">{formik.errors.phoneNumber}</span>}
3549
</div>
3650
<div className="d-flex justify-content-around ">

src/env.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"current-env": "development",
2+
"current-env": "production",
33
"production": {
44
"apiKey": "AIzaSyDyl-tV8qgWpgTMISb3M9ybaVxNPoGKuGA",
55
"authDomain": "appointments-9fa9d.firebaseapp.com",

version.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "1.6.0"
2+
"version": "1.8.0"
33
}

0 commit comments

Comments
 (0)