diff --git a/client/src/components/_test/test.component.jsx b/client/src/components/_test/test.component.jsx index 26d6df86a..ab74456b6 100644 --- a/client/src/components/_test/test.component.jsx +++ b/client/src/components/_test/test.component.jsx @@ -1,6 +1,6 @@ import { PaymentRequestButtonElement, - useStripe + useStripe, } from "@stripe/react-stripe-js"; import React, { useEffect, useState } from "react"; import { connect } from "react-redux"; @@ -9,6 +9,8 @@ import { logImEXEvent } from "../../firebase/firebase.utils"; import { setEmailOptions } from "../../redux/email/email.actions"; import { selectBodyshop } from "../../redux/user/user.selectors"; import { TemplateList } from "../../utils/TemplateConstants"; +import { Input, InputNumber, Popover } from "antd"; +import { isInteger } from "lodash"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -18,13 +20,14 @@ const mapDispatchToProps = (dispatch) => ({ setEmailOptions: (e) => dispatch(setEmailOptions(e)), }); + + function Test({ bodyshop, setEmailOptions }) { const stripe = useStripe(); const [paymentRequest, setPaymentRequest] = useState(null); useEffect(() => { if (stripe) { - console.log("in useeff"); const pr = stripe.paymentRequest({ country: "CA", displayItems: [{ label: "Deductible", amount: 1099 }], @@ -37,10 +40,8 @@ function Test({ bodyshop, setEmailOptions }) { requestPayerEmail: true, }); - console.log("pr", pr); // Check the availability of the Payment Request API. pr.canMakePayment().then((result) => { - console.log("result", result); if (result) { setPaymentRequest(pr); } else { diff --git a/client/src/components/contract-status-select/contract-status-select.component.jsx b/client/src/components/contract-status-select/contract-status-select.component.jsx index a248a1220..885b1556a 100644 --- a/client/src/components/contract-status-select/contract-status-select.component.jsx +++ b/client/src/components/contract-status-select/contract-status-select.component.jsx @@ -11,7 +11,7 @@ const ContractStatusComponent = ( const { t } = useTranslation(); useEffect(() => { - if (onChange) { + if (value !== option && onChange) { onChange(option); } }, [option, onChange]); diff --git a/client/src/components/courtesy-car-fuel-select/courtesy-car-fuel-select.component.jsx b/client/src/components/courtesy-car-fuel-select/courtesy-car-fuel-select.component.jsx index d4ff3db4f..07aa8df49 100644 --- a/client/src/components/courtesy-car-fuel-select/courtesy-car-fuel-select.component.jsx +++ b/client/src/components/courtesy-car-fuel-select/courtesy-car-fuel-select.component.jsx @@ -7,7 +7,7 @@ const CourtesyCarFuelComponent = ({ value = 100, onChange }, ref) => { const { t } = useTranslation(); useEffect(() => { - if (onChange) { + if (value !== option && onChange) { onChange(option); } }, [option, onChange]); diff --git a/client/src/components/courtesy-car-status-select/courtesy-car-status-select.component.jsx b/client/src/components/courtesy-car-status-select/courtesy-car-status-select.component.jsx index 7f101590a..0c686c744 100644 --- a/client/src/components/courtesy-car-status-select/courtesy-car-status-select.component.jsx +++ b/client/src/components/courtesy-car-status-select/courtesy-car-status-select.component.jsx @@ -11,7 +11,7 @@ const CourtesyCarStatusComponent = ( const { t } = useTranslation(); useEffect(() => { - if (onChange) { + if (value !== option && onChange) { onChange(option); } }, [option, onChange]); diff --git a/client/src/components/employee-search-select/employee-search-select.component.jsx b/client/src/components/employee-search-select/employee-search-select.component.jsx index 1e158f652..e16880bd5 100644 --- a/client/src/components/employee-search-select/employee-search-select.component.jsx +++ b/client/src/components/employee-search-select/employee-search-select.component.jsx @@ -12,7 +12,7 @@ const EmployeeSearchSelect = ( const [option, setOption] = useState(value); const { t } = useTranslation(); useEffect(() => { - if (onChange) { + if (value !== option && onChange) { onChange(option); } }, [option, onChange]); diff --git a/client/src/components/field-input-number-calculator/field-input-number-calculator.component.jsx b/client/src/components/field-input-number-calculator/field-input-number-calculator.component.jsx new file mode 100644 index 000000000..c8a03f4ce --- /dev/null +++ b/client/src/components/field-input-number-calculator/field-input-number-calculator.component.jsx @@ -0,0 +1,117 @@ +import { Input, Popover } from "antd"; +import React, { useEffect, useState, forwardRef } from "react"; + +const FieldInputNUmberCalculator = ( + { value: formValue, onChange: formOnChange }, + ref +) => { + const [value, setValue] = useState(formValue); + const [total, setTotal] = useState(0); + const [history, setHistory] = useState([]); + + const handleChange = (e) => { + const key = e.target.value; + switch (key) { + case "/": + case "*": + case "+": + case "-": + return; + default: + setValue(key); + return; + } + }; + + const handleKeyDown = (e) => { + const { key } = e; + + let action; + switch (key) { + case "/": + case "*": + case "+": + case "-": + action = key; + break; + case "Enter": + action = "="; + break; + default: + return; + } + + const val = parseFloat(value); + setValue(null); + if (!isNaN(val)) { + setHistory([...history, val, action]); + } + }; + + useEffect(() => { + if (value !== formValue && formOnChange) formOnChange(value); + }, [formOnChange, value]); + + useEffect(() => { + if (history.length > 2) { + const subTotal = history.reduce((acc, val, idx) => { + if (idx === 0) { + return val; + } + switch (val) { + case "/": + case "*": + case "+": + case "-": + return acc; + + default: + //Weve got math on our hands. Find the last operator, and apply it accordingly. + switch (history[idx - 1]) { + case "/": + return acc / val; + case "*": + return acc * val; + case "+": + return acc + val; + case "-": + return acc - val; + default: + return acc; + } + } + }, 0); + setTotal(subTotal); + if (history[history.length - 1] === "=") setValue(subTotal); + } + }, [history]); + + const popContent = ( +