import _ from "lodash"; import useTranslation from "next-translate/useTranslation"; import { useRouter } from "next/router"; import React, { useEffect } from "react"; import "react-datepicker/dist/react-datepicker.css"; import { Field } from "redux-form"; import fieldLookup from "../../data/crmfieldlookuptranslations.json"; import "react-quill-new/dist/quill.snow.css"; import { validateField } from "./validationUtils"; // Import the validation function import { getFieldTranslation } from "./helpers/translationHelpers"; import { RenderRichMultiline } from "./fields/renderRichMultiline"; import { RenderTextfield } from "./fields/renderTextfield"; import { RenderMultiline } from "./fields/renderMultiline"; import { PickList } from "./fields/pickListField"; import { CheckBoxfield } from "./fields/checkBoxField"; import { DateFieldPicker } from "./fields/dateFieldPicker"; import { YesNofield } from "./fields/yesNoField"; import { Radiofield } from "./fields/radioField"; import { NumericField } from "./fields/numericField"; import { DecimalField } from "./fields/decimalField"; import { RenderFileUpload } from "./fields/renderFileUpload"; export { RenderSubFields } from "./fields/renderSubFields"; export { FieldArrayForm } from "./fields/fieldArrayForm"; export { PickList }; export { CheckBoxfield }; export { DateFieldPicker }; export { YesNofield }; export { Radiofield }; export { NumericField }; export { DecimalField }; const getValidationMessages = (t) => ({ requiredMessage: t("newappeal:is-required-label"), emojiNotAllowedMessage: t("newappeal:emojis-not-allowed-label"), invalidPostcodeMessage: t("newappeal:invalid-postcode-label") }); const hasParentFieldValue = ({ parentField, form, formProps }) => parentField != false && !_.isEmpty(formProps[form]) && _.has(formProps[form].values, parentField); const isVisibleByEquality = ({ parentField, form, formProps, parentFieldShowOnValue }) => (hasParentFieldValue({ parentField, form, formProps }) && formProps[form].values[parentField]) == parentFieldShowOnValue; const isVisibleByInclusion = ({ parentField, form, formProps, parentFieldShowOnValue }) => hasParentFieldValue({ parentField, form, formProps }) && parentFieldShowOnValue.indexOf( formProps[form].values[parentField].toString() ) > -1; export function Textfield(props) { const { name, label, validation, ticketnumber, form, formProps, parentField, parentFieldShowOnValue, maxFieldLength, hint } = props; let { t } = useTranslation(); if (name == "pinswg_name") { return ( <>

{t("newappeal:new-appeal-introduction-paragraph")}

{t("newappeal:new-appeal-introduction-paragraph-two")}

{t( "newappeal:new-appeal-introduction-warning-paragraph" )}

); } else { var showIfHasParentShowValue = isVisibleByEquality({ parentField, form, formProps, parentFieldShowOnValue }); // console.log(parentField, showIfHasParentShowValue); // console.log(parentField, formProps, form); //console.log("validation props:", validation); const { requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage } = getValidationMessages(t); return (
{parentField != false ? ( showIfHasParentShowValue && ( validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function label={props.label} maxFieldLength={props.maxFieldLength} /> ) ) : ( validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function label={props.label} errorMsg={t("newappeal:is-required-label")} maxFieldLength={props.maxFieldLength} /> )}
); } } export function MultiLinefield(props) { const { name, label, form, formProps, parentField, parentFieldShowOnValue, validation, maxFieldLength, hint } = props; var showIfHasParentShowValue = isVisibleByInclusion({ parentField, form, formProps, parentFieldShowOnValue }); (showIfHasParentShowValue == parentField) != false && showIfHasParentShowValue; //console.log(showIfHasParentShowValue, formProps[form].values[parentField]); let { t } = useTranslation(); const translatedLabel = FieldsTranslations(props.label); const { requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage } = getValidationMessages(t); return ( <> {parentField != false ? ( showIfHasParentShowValue && (
{props.hasOwnProperty("hint") && props.hint != false && t(props.hint)}{" "}
{t("newappeal:new-appeal-multiline-pid")}
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function maxFieldLength={props.maxFieldLength} />
) ) : (
{props.hasOwnProperty("hint") && props.hint != false && t(props.hint)}{" "}
{t("newappeal:new-appeal-multiline-pid")}
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function maxFieldLength={props.maxFieldLength} />
)} ); } export function RichMultiLinefield(props) { const { name, label, form, formProps, parentField, parentFieldShowOnValue, validation, maxFieldLength } = props; var showIfHasParentShowValue = isVisibleByInclusion({ parentField, form, formProps, parentFieldShowOnValue }); (showIfHasParentShowValue == parentField) != false && showIfHasParentShowValue; //console.log(showIfHasParentShowValue, formProps[form].values[parentField]); let { t } = useTranslation(); const { requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage } = getValidationMessages(t); return ( <> {parentField != false ? ( showIfHasParentShowValue && (
{props.hasOwnProperty("hint") && props.hint != false && t(props.hint)}{" "}
{t("newappeal:new-appeal-multiline-pid")}
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function maxFieldLength={props.maxFieldLength} />
) ) : (
{props.hasOwnProperty("hint") && props.hint != false && t(props.hint)}{" "}
{t("newappeal:new-appeal-multiline-pid")}
validateField( value, validation, requiredMessage, emojiNotAllowedMessage, invalidPostcodeMessage ) } // Use the external validate function maxFieldLength={props.maxFieldLength} />
)} ); } export function DateField(props) { const { name, label } = props; return (
); } export function ReadOnlyfield(props) { const { name, label, value } = props; //console.log(props.value.refno); return ( <>
); } export const FieldsTranslations = (label) => { const router = useRouter(); const { locale } = router; const { appealtypes } = router.query; return getFieldTranslation({ label, locale, appealtypes, fieldLookup }); }; export function FileUploadField(props) { return ( <>

{FieldsTranslations(props.label)}{" "}

); }