diff --git a/src/components/Appointment/Appointment.js b/src/components/Appointment/Appointment.js index 1729a23..7b8e7b0 100644 --- a/src/components/Appointment/Appointment.js +++ b/src/components/Appointment/Appointment.js @@ -2,7 +2,7 @@ import React from "react"; import Button from "react-bootstrap/Button"; import Badge from "react-bootstrap/Badge"; import useModal from "../../hooks/useModal"; -import { setStatus } from "../../util/helpers"; +import { setStatus } from "../../utils/helpers"; import { Card } from "antd"; import "./Appointment.css"; diff --git a/src/components/Booking/Booking.js b/src/components/Booking/Booking.js index 38ed7cb..1fac3c3 100644 --- a/src/components/Booking/Booking.js +++ b/src/components/Booking/Booking.js @@ -2,7 +2,7 @@ import React from "react"; import Button from "react-bootstrap/esm/Button"; import Badge from "react-bootstrap/Badge"; import "./Booking.css"; -import { setStatus } from "../../util/helpers"; +import { setStatus } from "../../utils/helpers"; const Booking = ({ booking, onView }) => { // console.log("booking", booking); diff --git a/src/components/BookingForm/BookingForm.js b/src/components/BookingForm/BookingForm.js index c845318..bdcb229 100644 --- a/src/components/BookingForm/BookingForm.js +++ b/src/components/BookingForm/BookingForm.js @@ -41,7 +41,7 @@ const BookingForm = ({ onCancel, onConfirm, oldData, slots, onGetSlots, slotStat authCtx.handleCustomerLogin(); return; } - onConfirm({ ...values, userId: authCtx.userId, googleAccountName: authCtx.user.displayName, email: authCtx.user.email, photoURL: authCtx.user.photoURL }); + onConfirm({ ...values, userId: authCtx.userId, googleAccountName: authCtx.user.displayName, email: authCtx.user.email, photoURL: authCtx.user.photoURL, createdTime: new Date() }); resetForm(); }} initialValues={{ diff --git a/src/components/Settings/GeneralSettings.js b/src/components/Settings/GeneralSettings.js index 23c8854..4c3b122 100644 --- a/src/components/Settings/GeneralSettings.js +++ b/src/components/Settings/GeneralSettings.js @@ -1,17 +1,17 @@ -import React, { useState } from "react" -import { Button } from "react-bootstrap" -import ClockPicker from "../ClockPicker/ClockPicker" -import { useFormik } from "formik" +import React, { useState } from "react"; +import { Button } from "react-bootstrap"; +import ClockPicker from "../ClockPicker/ClockPicker"; +import { useFormik } from "formik"; -import * as yup from "yup" -import { compareTimes } from "../../util/helpers" -import "./GeneralSettings.css" +import * as yup from "yup"; +import { compareTimes } from "../../utils/helpers"; +import "./GeneralSettings.css"; const GeneralSettings = ({ onConfirm, onBack, initialValues: defaults }) => { - const [pickerTime, setPickerTime] = useState(null) - const [showPicker, setShowPicker] = useState(false) - const [pickerFunction, setPickerFunction] = useState(() => () => {}) - const [editMode, setEditMode] = useState(false) + const [pickerTime, setPickerTime] = useState(null); + const [showPicker, setShowPicker] = useState(false); + const [pickerFunction, setPickerFunction] = useState(() => () => {}); + const [editMode, setEditMode] = useState(false); const formik = useFormik({ initialValues: { @@ -21,75 +21,62 @@ const GeneralSettings = ({ onConfirm, onBack, initialValues: defaults }) => { validationSchema: yup.object().shape({ startTime: yup.string().required("Starting time is required!"), endTime: yup.string().required("Ending time is required!"), - slotSize: yup - .number() - .min(0, "Minutes must be positive numbers") - .max(120, "Max slot size is 120 minutes") - .required("*Slot size is required!"), - address: yup - .string() - .min(8, "address is Too Short!") - .max(50, "address is Too Long!") - .required("*Address is required!"), + slotSize: yup.number().min(0, "Minutes must be positive numbers").max(120, "Max slot size is 120 minutes").required("*Slot size is required!"), + address: yup.string().min(8, "address is Too Short!").max(50, "address is Too Long!").required("*Address is required!"), }), onSubmit: (values) => { if (validateTime()) { // console.log("time is valid") // alert(JSON.stringify(values, null, 2)) - setEditMode(false) - onConfirm({ ...values }) + setEditMode(false); + onConfirm({ ...values }); } }, - }) + }); const validateTime = () => { - const isValid = compareTimes(formik.values.startTime, formik.values.endTime) + const isValid = compareTimes(formik.values.startTime, formik.values.endTime); if (!isValid) { - formik.setFieldError("startTime", "Start time must be before end time") - formik.setFieldError("endTime", "Start time must be before end time") + formik.setFieldError("startTime", "Start time must be before end time"); + formik.setFieldError("endTime", "Start time must be before end time"); } else { - formik.setFieldError("startTime", "") - formik.setFieldError("endTime", "") + formik.setFieldError("startTime", ""); + formik.setFieldError("endTime", ""); } - return isValid - } + return isValid; + }; const handleChangeStartTime = (value) => { - formik.setFieldValue("startTime", value) - formik.setFieldTouched("startTime") - } + formik.setFieldValue("startTime", value); + formik.setFieldTouched("startTime"); + }; const handleChangeEndTime = (value) => { - formik.setFieldValue("endTime", value) - formik.setFieldTouched("endTime") - } + formik.setFieldValue("endTime", value); + formik.setFieldTouched("endTime"); + }; const handleUsePicker = (setValueFunction, initalValue = null) => { - setPickerTime(initalValue) - setPickerFunction(() => setValueFunction) - setShowPicker(true) - } + setPickerTime(initalValue); + setPickerFunction(() => setValueFunction); + setShowPicker(true); + }; const handleClosePicker = () => { - setPickerFunction(() => () => {}) - setPickerTime(null) - setShowPicker(false) - } + setPickerFunction(() => () => {}); + setPickerTime(null); + setShowPicker(false); + }; const handleGoBack = () => { //TODO: findout why this needs to be called twice // onBack() - onBack() - } + onBack(); + }; return ( <> - +

General Shop Settings

@@ -97,28 +84,16 @@ const GeneralSettings = ({ onConfirm, onBack, initialValues: defaults }) => {
{editMode ? ( <> - - ) : ( <> -
- {formik.touched.startTime && formik.errors.startTime && ( - - {formik.errors.startTime} - - )} + {formik.touched.startTime && formik.errors.startTime && {formik.errors.startTime}}
@@ -165,21 +128,12 @@ const GeneralSettings = ({ onConfirm, onBack, initialValues: defaults }) => {
{formik.values.endTime} {editMode && ( - - handleUsePicker(handleChangeEndTime, formik.values.endTime) - } - > + handleUsePicker(handleChangeEndTime, formik.values.endTime)}> Change )}
- {formik.touched.endTime && formik.errors.endTime && ( - - {formik.errors.endTime} - - )} + {formik.touched.endTime && formik.errors.endTime && {formik.errors.endTime}}
@@ -188,56 +142,31 @@ const GeneralSettings = ({ onConfirm, onBack, initialValues: defaults }) => {
{editMode ? ( - + ) : ( {formik.values.slotSize} )} Minutes
- {formik.touched.slotSize && formik.errors.slotSize && ( - - {formik.errors.slotSize} - - )} + {formik.touched.slotSize && formik.errors.slotSize && {formik.errors.slotSize}}
-