import { Form, Input, InputNumber } from "antd";
import { Constants, myFetch } from "../../utils";
import { useRef } from "react";
import { useTranslation } from "react-i18next";
export function MyUsernameFormInput({ propsFormItem, propsInput }) {
const { t } = useTranslation();
return (
);
}
export function MyAccountNameFormInput({
propsFormItem,
propsInput,
disableAccountNameCheck,
hasFeedback,
}) {
const { t } = useTranslation();
return (
);
}
export function MyPasswordFormInput({ propsFormItem, propsInput }) {
const { t } = useTranslation();
return (
);
}
export function MyCalendarMaxFutureBookingDaysFormInput() {
const { t } = useTranslation();
return (
);
}
export function MyCalendarMinEarliestBookingTimeFormInput() {
const { t } = useTranslation();
return (
);
}
export function MyAvailableCheckFormInput({
propsFormItem,
propsInput,
formItemName,
minLength,
maxLength,
label,
ruleMessageValueRequired,
ruleMessageValueMinLengthRequired,
ruleMessageValueNotAvailable,
inputPlaceholder,
inputType,
disableAvailableCheck = false,
fetchUrl,
fetchParameter,
fetchDelay,
hasFeedback,
}) {
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((errStatus) => {
console.log(errStatus);
reject(ruleMessageValueNotAvailable);
});
}, fetchDelay);
});
},
}),
]}
/>
);
}
export function MyFormInput({
propsFormItem,
propsInput,
formItemName,
formItemRules,
minLength,
maxLength,
label,
ruleMessageValueRequired,
ruleMessageValueMinLengthRequired,
inputPlaceholder,
inputType,
}) {
const commonProps = {
...propsInput,
placeholder: inputPlaceholder,
};
const myFormItemRules = [
{
required: true,
message: ruleMessageValueRequired,
},
];
if (formItemRules) {
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: (
),
number: ,
password: ,
default: ,
};
return (
{inputComponents[inputType] || inputComponents.default}
);
}