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 Dropzone, { 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 ( <>
{touched && error && ( Error: {" "} {errorMsg} )}
); }; 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 ( <>
{touched && error && ( Error: {" "} {errorMsg} )}
{Object.keys(options).map((key, index) => (
))}
); }; 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 (
); } 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 RenderFileUpload2 = ({ // id, // className, // rows, // datafieldname, // name, // label, // input, // errorMsg, // meta: { touched, errorStr }, // ...custom // }) => { // const [files, setFiles] = useState([]); // const onDrop = useCallback((acceptedFiles, fileRejections, event) => { // setFiles( // acceptedFiles.map((file) => // Object.assign(file, { // preview: URL.createObjectURL(file), // }) // ) // ); // console.log(acceptedFiles); // event.target[acceptedFiles]; // console.log(event.target.files); // }, []); // const onChange = useCallback((acceptedFiles, fileRejections, event) => { // setFiles( // acceptedFiles.map((file) => // Object.assign(file, { // preview: URL.createObjectURL(file), // }) // ) // ); // event.target.files[acceptedFiles]; // console.log(event.target.files); // }, []); // const { // getRootProps, // getInputProps, // isDragActive, // isDragAccept, // isDragReject, // } = useDropzone({ // onDrop, // onChange, // }); // const style = useMemo( // () => ({ // ...baseStyle, // ...(isDragActive ? activeStyle : {}), // ...(isDragAccept ? acceptStyle : {}), // ...(isDragReject ? rejectStyle : {}), // }), // [isDragActive, isDragReject, isDragAccept] // ); // const thumbs = files.map((file) => ( //
// {file.name} -{" "} // // {file.name} ({file.size / 1024}kb) // //
// )); // // clean up // useEffect( // () => () => { // files.forEach((file) => URL.revokeObjectURL(file.preview)); // }, // [files] // ); // const onChangeFile = (e) => { // const { // input: { onChange }, // } = props; // onChange(e.target.files[0]); // }; // return ( //
//
//
//
// //
Drag and drop your images here.
//
//
{" "} // // {touched && errorStr && {errorStr}} //
// ); // }; const RenderFileUpload = (field) => { const files = field.input.value; const style = useMemo( () => ({ ...baseStyle, // ...(isDragActive ? activeStyle : {}), // ...(isDragAccept ? acceptStyle : {}), // ...(isDragReject ? rejectStyle : {}), }), [] // [isDragActive, isDragReject, isDragAccept] ); const [filesList, setFilesList] = useState([]); const thumbs = filesList.map((file) => (
{file.name} -{" "} {file.name} ({file.size / 1024}kb)
)); function bytesToSize(bytes) { var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; if (bytes == 0) return "0 Byte"; var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; } const getThumbnailIcon = (fileObj, fileType) => { switch (fileType) { case "text/html": return "/assets/images/documentTypes/html.png"; break; case "text/plain": return "/assets/images/documentTypes/txt.png"; break; case "application/msword": return "/assets/images/documentTypes/doc.png"; break; case "application/pdf": return "/assets/images/documentTypes/pdf.png"; break; case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": return "/assets/images/documentTypes/docx.png"; break; case "text/csv": return "/assets/images/documentTypes/csv.png"; break; case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": return "/assets/images/documentTypes/xlsx.png"; break; case "application/zip": return "/assets/images/documentTypes/zip.png"; break; case "image/jpeg": case "image/png": return URL.createObjectURL(fileObj); break; } }; return (
field.input.onChange(filesToUpload) } > {({ getRootProps, getInputProps }) => (
{" "}
Drag and drop your files here.
)}
{field.meta.touched && field.meta.error && ( {field.meta.error} )} {files && Array.isArray(files) && (
    {files.map((file, i) => (
    {file.name}{" "} {" "} {file.name} ({bytesToSize(file.size)})
    ))}
)}
); };