{"version":3,"file":"TwofaInput-DNUubHmE.js","sources":["../../../app/javascript/components/FormBuilder/Tooltip.jsx","../../../app/javascript/components/FormBuilder/FormLabel.jsx","../../../app/javascript/components/FormBuilder/InputField/index.jsx","../../../app/javascript/components/TwofaInput.jsx"],"sourcesContent":["import React from 'react';\n\nconst Tooltip = ({ tip, onHover }) => (\n \n \n \n {tip}\n \n \n);\n\nexport default Tooltip;\n","import React from 'react';\n\nimport Tooltip from './Tooltip';\nimport { notEmpty } from '@javascript/util.js';\n\nconst FormLabel = ({\n label,\n klass,\n spanKlass,\n htmlFor,\n children,\n required,\n tooltip,\n mobileSubLabel,\n}) => (\n \n);\n\nexport default FormLabel;\n","import React from 'react';\n\nimport FormLabel from '../FormLabel';\nimport ErrorNotice from '../ErrorNotice';\nimport { generateClassName, generateErrors } from '@javascript/util';\n\nconst InputField = (props) => {\n const {\n charLimit = null,\n disabled = false,\n error = [],\n idPrefix = null,\n inputClass = null,\n labelKlass = null,\n maxLength = null,\n min = null,\n mobileSubLabel = null,\n onBlur = null,\n onKeyDown = () => {},\n placeholder = null,\n required = false,\n subtext = null,\n textMask = null,\n spanKlass = '',\n tooltip = null,\n type = 'text',\n value = '',\n handleChange,\n id,\n klass,\n label,\n pattern,\n subTextClassName,\n } = props;\n\n const fieldId = ['fb'];\n if (idPrefix) {\n fieldId.push(idPrefix);\n }\n fieldId.push(id);\n\n const charlimitError = charLimit && value.length > charLimit;\n const className = generateClassName(klass);\n const { errorMessage, errorBool } = generateErrors(error);\n const charLimitClass = ['char-limit'];\n if (charlimitError) {\n charLimitClass.push('error');\n }\n\n const charLimitText = `${value.length}/${charLimit}`;\n\n return (\n
\n \n \n {subtext && (\n {subtext}\n )}\n \n \n {charLimit && (\n {charLimitText}\n )}\n \n
\n );\n};\n\nexport default InputField;\n","import PropTypes from \"prop-types\";\nimport { useEffect, useRef, useState } from \"react\";\n\nconst TwofaInput = (props) => {\n const {\n pinLength = 6,\n className = '',\n helpText = '',\n value = '',\n onChange,\n error = '',\n setError,\n confirmTwofa,\n } = props;\n\n const inputElms = useRef(new Array(pinLength));\n const [valids, setValids] = useState(new Array(pinLength).fill(false));\n const [hasBeenFocused, setHasBeenFocused] = useState(\n new Array(pinLength).fill(false)\n );\n const [errors, setErrors] = useState([]);\n\n const [internalValue, setInternalValue] = useState(\"\");\n\n useEffect(() => {\n if (error) {\n setErrors([{ message: \"Please enter a valid verification code.\" }]);\n setHasBeenFocused(new Array(pinLength).fill(false));\n } else {\n setErrors([]);\n }\n }, [error]);\n\n const navKeys = [\n \"ArrowLeft\",\n \"ArrowRight\",\n \"ArrowUp\",\n \"ArrowDown\",\n \"Tab\",\n \"Shift\",\n \"Backspace\",\n ];\n\n const handleChange = (e, i) => {\n let newValue = \"\";\n let newHasBeenFocused = hasBeenFocused;\n inputElms.current.map((e, i) => {\n const inputValue = e.value\n .trim()\n .charAt()\n .replace(/[^0-9]/g, \"\");\n e.value = inputValue;\n newValue = newValue + inputValue;\n if (e.value.length > 0) {\n newHasBeenFocused[i] = true;\n }\n });\n\n let newValids = valids;\n newValids[i] = e.target.validity.valid;\n setValids(newValids);\n setHasBeenFocused(newHasBeenFocused);\n\n setInternalValue(newValue);\n\n if (i < inputElms.current.length - 1 && e.target.value != \"\") {\n inputElms.current[i + 1].focus();\n }\n\n onChange(e, newValue);\n setError(false);\n };\n\n const handleKeyDown = (e, i) => {\n if (e.key == \"Backspace\" && e.target.value == \"\" && i > 0) {\n inputElms.current[i - 1].focus();\n }\n if (e.key == \"ArrowLeft\" && i > 0) {\n inputElms.current[i - 1].focus();\n }\n\n if (e.key == \"ArrowRight\" && i < inputElms.current.length - 1) {\n inputElms.current[i + 1].focus();\n }\n\n if (e.key === \"Enter\") {\n confirmTwofa(e);\n }\n };\n\n const handleFocus = (e, i) => {\n if (e.target.value != \"\") {\n e.target.select();\n }\n\n if (error) {\n setError(false);\n }\n };\n\n const handleBlur = (e, i) => {\n let newHasBeenFocused = hasBeenFocused;\n newHasBeenFocused[i] = true;\n setHasBeenFocused(newHasBeenFocused);\n };\n\n const handlePaste = (e) => {\n const data = e.clipboardData\n .getData(\"text/plain\")\n .trim()\n .slice(0, pinLength);\n let newValue = \"\";\n let newValids = valids;\n let newHasBeenFocused = hasBeenFocused;\n\n inputElms.current.map((e, i) => {\n if (data[i] != undefined) {\n newValue = newValue + data[i];\n e.value = data[i];\n } else {\n e.value = \"\";\n }\n if (e.value.length > 0) {\n newHasBeenFocused[i] = true;\n }\n newValids[i] = e.validity.valid;\n });\n setValids(newValids);\n setHasBeenFocused(newHasBeenFocused);\n setInternalValue(newValue);\n onChange(e, newValue);\n inputElms.current[pinLength - 1].focus();\n };\n\n const classList = ['TwoFA'];\n\n if (className) {\n classList.push(className);\n }\n\n if (error) {\n classList.push('twofa-error')\n }\n\n return (\n
\n
\n
\n {Array.apply(null, { length: pinLength }).map((e, i) => (\n
\n (inputElms.current[i] = element)}\n maxLength={1}\n onChange={(e) => {\n handleChange(e, i);\n }}\n onKeyDown={(e) => {\n handleKeyDown(e, i);\n }}\n onFocus={(e) => {\n handleFocus(e, i);\n }}\n onBlur={(e) => {\n handleBlur(e, i);\n }}\n required={true}\n value={value.split(\"\")[i]}\n onPaste={handlePaste}\n type={\"number\"}\n inputMode={\"numeric\"}\n pattern=\"\\d*\"\n min={0}\n max={9}\n />\n
\n ))}\n
\n {helpText != \"\" &&
{helpText}
}\n {errors && (\n
    \n {errors.map((error, index) => (\n
  • {error.message}
  • \n ))}\n
\n )}\n
\n
\n );\n};\n\nTwofaInput.propTypes = {\n className: PropTypes.string,\n pinLength: PropTypes.number,\n helpText: PropTypes.string,\n value: PropTypes.string,\n onChange: PropTypes.func,\n error: PropTypes.bool,\n setError: PropTypes.func,\n};\n\nexport default TwofaInput;\n"],"names":["Tooltip","tip","onHover","jsxs","jsx","FormLabel","label","klass","spanKlass","htmlFor","children","required","tooltip","mobileSubLabel","notEmpty","InputField","props","charLimit","disabled","error","idPrefix","inputClass","labelKlass","maxLength","min","onBlur","onKeyDown","placeholder","subtext","textMask","type","value","handleChange","id","pattern","subTextClassName","fieldId","charlimitError","className","generateClassName","errorMessage","errorBool","generateErrors","charLimitClass","charLimitText","ErrorNotice","TwofaInput","pinLength","helpText","onChange","setError","confirmTwofa","inputElms","useRef","valids","setValids","useState","hasBeenFocused","setHasBeenFocused","errors","setErrors","internalValue","setInternalValue","useEffect","e","i","newValue","newHasBeenFocused","inputValue","newValids","handleKeyDown","handleFocus","handleBlur","handlePaste","data","classList","element","index","PropTypes"],"mappings":"0FAEA,MAAMA,EAAU,CAAC,CAAE,IAAAC,EAAK,QAAAC,CACtB,IAAAC,EAAA,KAAC,MAAA,CACC,UAAU,UACV,aAAcD,EACd,QAASA,EAET,SAAA,CAACE,EAAAA,IAAA,OAAA,CAAK,UAAU,eAAgB,CAAA,EAC/BA,EAAA,IAAA,OAAA,CAAK,UAAU,eACb,SACHH,EAAA,CAAA,CAAA,CACF,ECPII,EAAY,CAAC,CACjB,MAAAC,EACA,MAAAC,EACA,UAAAC,EACA,QAAAC,EACA,SAAAC,EACA,SAAAC,EACA,QAAAC,EACA,eAAAC,CACF,IACGV,EAAAA,KAAA,QAAA,CAAM,QAAAM,EAAkB,UAAWF,EAEhC,SAAA,CAAMD,EAAA,OAAS,GACZH,EAAA,KAAA,OAAA,CAAK,UAAWK,EAAY,cAAcA,CAAS,GAAK,aACtD,SAAA,CAAAF,EACAK,GAAYP,EAAA,IAAC,OAAK,CAAA,UAAU,WAAW,SAAC,IAAA,EACxCQ,GAAWR,EAAAA,IAACJ,EAAQ,CAAA,IAAKY,CAAS,CAAA,EAClCE,EAASD,CAAc,SAAM,MAAI,CAAA,UAAU,YAAa,SAAeA,EAAA,CAAA,EAC1E,EAGHH,CAAA,CACH,CAAA,ECrBIK,EAAcC,GAAU,CACtB,KAAA,CACJ,UAAAC,EAAY,KACZ,SAAAC,EAAW,GACX,MAAAC,EAAQ,CAAC,EACT,SAAAC,EAAW,KACX,WAAAC,EAAa,KACb,WAAAC,EAAa,KAC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