import { Form, Formik, Field } from 'formik' import * as R from 'ramda' import React from 'react' import ErrorMessage from 'src/components/ErrorMessage' import Modal from 'src/components/Modal' import { HelpTooltip } from 'src/components/Tooltip' import { H1, H3, P } from 'src/components/typography' import * as Yup from 'yup' import { Button } from 'src/components/buttons' import { NumberInput, Autocomplete } from 'src/components/inputs/formik' const initialValues = { customer: '', discount: '', } const validationSchema = Yup.object().shape({ customer: Yup.string().required('A customer is required!'), discount: Yup.number() .required('A discount rate is required!') .min(0, 'Discount rate should be a positive number!') .max(100, 'Discount rate should have a maximum value of 100%!'), }) const getErrorMsg = (formikErrors, formikTouched, mutationError) => { if (!formikErrors || !formikTouched) return null if (mutationError) return 'Internal server error' if (formikErrors.customer && formikTouched.customer) return formikErrors.customer if (formikErrors.discount && formikTouched.discount) return formikErrors.discount return null } const IndividualDiscountModal = ({ showModal, setShowModal, onClose, creationError, addDiscount, customers, }) => { const handleAddDiscount = (customer, discount) => { addDiscount({ variables: { customerId: customer, discount: parseInt(discount), }, }) setShowModal(false) } return ( <> {showModal && ( { handleAddDiscount(customer, discount) }}> {({ errors, touched }) => (
({ code: it.id, display: `${it?.idCardData?.firstName ?? ``}${ it?.idCardData?.firstName && it?.idCardData?.lastName ? ` ` : `` }${it?.idCardData?.lastName ?? ``} (${it.phone})`, }))(customers)} labelProp="display" valueProp="code" />

Define discount rate

This is a percentage discount off of your existing commission rates for a customer entering this code at the machine.

For instance, if you charge 8% commissions, and this code is set for 50%, then you'll instead be charging 4% on transactions using the code.

%

{getErrorMsg(errors, touched, creationError) && ( {getErrorMsg(errors, touched, creationError)} )}
)}
)} ) } export default IndividualDiscountModal