import { Form, Input, InputNumber, Skeleton } from "antd"; import { Constants, myFetch } from "../../utils"; import { useRef } from "react"; import { useTranslation } from "react-i18next"; export function MyUsernameFormInput({ propsFormItem, propsInput, showSkeleton, thirdPerson, }) { const { t } = useTranslation(); return ( ); } export function MyAccountNameFormInput({ propsFormItem, propsInput, disableAccountNameCheck, hasFeedback, showSkeleton, thirdPerson, }) { const { t } = useTranslation(); return ( ); } export function MyPasswordFormInput({ propsFormItem, propsInput, formItemName, label, inputPlaceholder, formItemRules, }) { const { t } = useTranslation(); return ( ); } export function MyCalendarMaxFutureBookingDaysFormInput() { const { t } = useTranslation(); return ( ); } export function MyCalendarMinEarliestBookingTimeFormInput() { const { t } = useTranslation(); return ( ); } export function MyCompanyNameFormInput({ showSkeleton }) { const { t } = useTranslation(); return ( ); } export function MyAvailableCheckFormInput({ propsFormItem, propsInput, formItemName, minLength, maxLength, label, ruleMessageValueRequired, ruleMessageValueMinLengthRequired, ruleMessageValueNotAvailable, inputPlaceholder, inputType, disableAvailableCheck = false, fetchUrl, fetchParameter, fetchDelay, hasFeedback, showSkeleton, }) { const delayTimeout = useRef(); const isValid = (value) => { return value.length >= minLength && value.length <= maxLength; }; return ( ({ validator(_, value) { if (!value || !isValid(value)) { return Promise.reject(""); } if (disableAvailableCheck) { return Promise.resolve(); } if (delayTimeout.current) { clearTimeout(delayTimeout.current); } return new Promise((resolve, reject) => { delayTimeout.current = setTimeout(() => { let body = {}; body[fetchParameter] = value; // like accountName: value myFetch({ url: fetchUrl, method: "POST", body: body, }) .then(() => resolve()) .catch(() => reject(ruleMessageValueNotAvailable)); }, fetchDelay); }); }, }), ]} /> ); } export function MyFormInput({ propsFormItem, propsInput, formItemName, formItemRules, minLength, maxLength, label, ruleMessageValueRequired, ruleMessageValueMinLengthRequired, inputPlaceholder, inputType, inputNotRequired, showSkeleton, }) { const commonProps = { ...propsInput, placeholder: inputPlaceholder, }; const myFormItemRules = []; if (!inputNotRequired) { myFormItemRules.push({ required: true, message: ruleMessageValueRequired, }); } if (formItemRules) { // check if formItemRules is an array if (Array.isArray(formItemRules)) { myFormItemRules.push(...formItemRules); } else { myFormItemRules.push(formItemRules); } } if (inputType === "number") { commonProps.min = minLength; commonProps.max = maxLength; } else { commonProps.minLength = minLength; commonProps.maxLength = maxLength; myFormItemRules.push({ min: minLength, message: ruleMessageValueMinLengthRequired, }); } const inputComponents = { textarea: showSkeleton ? ( ) : ( ), number: , password: , default: showSkeleton ? ( ) : ( ), }; return ( {inputComponents[inputType] || inputComponents.default} ); }