diff --git a/package.json b/package.json index b867eb8d..642978ef 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "axios": "^0.25.0", "boomform": "^3.6.7", "classnames": "^2.3.1", + "dayjs": "^1.11.13", "react-google-recaptcha": "^2.1.0", "react-grid-layout": "^1.4.2", "react-quill": "^2.0.0", diff --git a/src/Body/Fields/Date/Date.js b/src/Body/Fields/Date/Date.js index 9c5c2cab..7279373e 100644 --- a/src/Body/Fields/Date/Date.js +++ b/src/Body/Fields/Date/Date.js @@ -1,16 +1,26 @@ import React from 'react' import { Input } from 'boomform' import { iphoneCheck } from '../../../Helpers/global' +import dayjs from 'dayjs' const Date = ({ validation = {}, payment, ...props }) => { - const { min, max } = validation - if (min || max) { + const { min, max, hideDays, disableDates, hiddenCustomDays, isCustom } = + validation + if (min || max || disableDates) { validation = { ...validation, - custom: (value) => { + custom: value => { if (value) { + const dayName = dayjs(value).format('dddd') + const customDay = dayjs(value).format('MMM D, YYYY') if (min?.value > value) return min?.msg if (max?.value < value) return max?.msg + if (disableDates && hideDays[dayName] && !isCustom) { + return `${dayName}s are disabled. Please pick another date. ` + } + if (disableDates && hiddenCustomDays.includes(value) && isCustom) { + return `${customDay} is disabled. Please pick another date.` + } } return false }