import useSWR from "swr";
import { Field, reduxForm } from "redux-form";
import { useRouter } from "next/router";
import DatePicker, { registerLocale, setDefaultLocale } from "react-datepicker";
import cy from "date-fns/locale/cy";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import "react-datepicker/dist/react-datepicker.css";
import moment from "moment";
import jsonpath from "jsonpath";
import fieldLookup from "../../data/crmfieldlookuptranslations.json";
import pickListLookup from "../../data/picklistLookups.json";
import useTranslation from "next-translate/useTranslation";
import FileUpload from "../newappeal/fileupload";
import { useDropzone } from "react-dropzone";
const RenderTextfield = ({
id,
className,
rows,
datafieldname,
name,
label,
input,
errorMsg,
meta: { touched, error },
...custom
}) => {
return (
<>
{touched && error && (
Error:{" "}
{errorMsg}
)}
>
);
};
export function Textfield(props) {
const { name, label, validate, ticketnumber } = props;
const required = (value) => (value ? undefined : "Required");
if (name == "pinswg_name") {
return (
);
} else {
return (
);
}
}
const RenderMultiline = ({
className,
rows,
datafieldname,
name,
label,
input,
meta: { touched, error },
...custom
}) => {
return (
<>
>
);
};
export function MultiLinefield(props) {
const { name, label } = props;
return (
Do not include personal or financial information, like your
National Insurance number or credit card details.
);
}
const RenderDatePicker = ({
datafieldname,
name,
label,
id,
errorMsg,
input: { onChange, value },
meta: { touched, error },
...custom
}) => {
const router = useRouter();
registerLocale("cy", cy);
return (
<>
>
);
};
export function DateFieldPicker(props) {
const { name, label } = props;
const required = (value) => (value ? undefined : "Required");
return (
);
}
export function DateField(props) {
const { name, label } = props;
return (
);
}
const RenderYesNo = ({
datafieldname,
name,
label,
id,
errorMsg,
options,
input: { onChange, value },
meta: { touched, error },
...custom
}) => {
return (
<>
>
);
};
export function YesNofield(props) {
const router = useRouter();
const { name, label } = props;
const yesNo = router.locale == "cy" ? ["Ydw", "Na"] : ["Yes", "No"];
const required = (value) => (value ? undefined : "Required");
return (
);
}
const RenderPickList = ({
datafieldname,
picklistData,
name,
label,
input,
meta: { touched, errorStr },
}) => {
let { t } = useTranslation();
var dropdownObj = jsonpath.query(
picklistData,
"$..value[?(@.LogicalName=='" + datafieldname + "')]..Options"
);
dropdownObj = dropdownObj[0];
return (
{touched && errorStr && {errorStr}}
);
};
export function PickList(props) {
const { name, label, datafieldname } = props;
return (
);
}
export function NumericField(props) {
const { name, label } = props;
return (
);
}
export function DecimalField(props) {
const { name, label } = props;
return (
);
}
const RenderCaseID = {};
export function ReadOnlyfield(props) {
const { name, label, value } = props;
//console.log(props.value.refno);
return (
);
}
const FieldsTranslations = (label) => {
const router = useRouter();
const { locale } = router;
const { appealtypes } = router.query;
let formObj = jsonpath.query(fieldLookup, "$['" + appealtypes + "']");
let labelTrans =
router.locale == "cy"
? jsonpath.query(
formObj,
"$..[?(@.value=='" + label + "')].value_cy"
)
: label;
return labelTrans;
};
const PickListTranslations = (optionValue) => {
const router = useRouter();
const { locale } = router;
const { appealtypes } = router.query;
//console.log(optionValue);
let optionTrans =
router.locale == "cy"
? jsonpath.query(
pickListLookup,
'$..[?(@.value=="' + optionValue + '")].value_cy'
)
: optionValue;
//console.log(optionTrans, optionValue);
return optionTrans;
};
export function FileUploadField(props) {
return (
helllo
);
}
const baseStyle = {
display: "flex",
flexDirection: "column",
alignItems: "center",
padding: "20px",
borderWidth: 2,
borderRadius: 2,
borderColor: "#eeeeee",
borderStyle: "dashed",
backgroundColor: "#fafafa",
color: "#bdbdbd",
transition: "border .3s ease-in-out",
};
const activeStyle = {
borderColor: "#2196f3",
};
const acceptStyle = {
borderColor: "#00e676",
};
const rejectStyle = {
borderColor: "#ff1744",
};
const RenderFileUpload = ({
id,
className,
rows,
datafieldname,
name,
label,
input,
errorMsg,
meta: { touched, error },
...custom
}) => {
const [files, setFiles] = useState([]);
const onDrop = useCallback((acceptedFiles) => {
setFiles(
acceptedFiles.map((file) =>
Object.assign(file, {
preview: URL.createObjectURL(file),
})
)
);
}, []);
const {
getRootProps,
getInputProps,
isDragActive,
isDragAccept,
isDragReject,
} = useDropzone({
onDrop,
});
const style = useMemo(
() => ({
...baseStyle,
...(isDragActive ? activeStyle : {}),
...(isDragAccept ? acceptStyle : {}),
...(isDragReject ? rejectStyle : {}),
}),
[isDragActive, isDragReject, isDragAccept]
);
const thumbs = files.map((file) => (

-{" "}
{file.name} ({file.size / 1024}kb)
));
// clean up
useEffect(
() => () => {
files.forEach((file) => URL.revokeObjectURL(file.preview));
},
[files]
);
return (
{" "}
{touched && errorStr &&
{errorStr}}
);
};