-
Notifications
You must be signed in to change notification settings - Fork 1
/
react.cjs.development.js.map
1 lines (1 loc) · 7.19 KB
/
react.cjs.development.js.map
1
{"version":3,"file":"react.cjs.development.js","sources":["../src/lib/handler.ts","../src/index.ts"],"sourcesContent":["import { FormcarryResponse } from './types'\n\nconst backgroundColor = '#262335'\nconst backgroundProperty = `background-color: ${backgroundColor}`\nconst yellow = '#FEDE5D'\nconst pink = '#D86FD4'\nconst orange = '#F88839'\nconst gray = '#E2E1E5'\nconst grayDarker = '#B3AEAE'\nconst turquoise = '#36F5F3'\nconst lightBlue = '#84C9F4'\n\nexport function errorHandler(err: FormcarryResponse) {\n\tconsole.group('%c 🚨 Formcarry Error 🚨', 'background: #E44141; color: #fff')\n\tconsole.table(err)\n\tconsole.log(\n\t\t`%cif you want to disable debugging, just set debug to false like:`,\n\t\t'color: #11C759',\n\t)\n\tconsole.log(\n\t\t'%cconst %c{state, submit} %c= %cuseForm%c(%c{ %cdebug%c: %cfalse %c}%c);',\n\t\t`${backgroundProperty}; color: ${yellow}`,\n\t\t`${backgroundProperty}; color: ${pink}`,\n\t\t`${backgroundProperty}; color: ${gray}`,\n\t\t`${backgroundProperty}; color: ${turquoise}`,\n\t\t`${backgroundProperty}; color: ${pink}`,\n\t\t`${backgroundProperty}; color: ${turquoise}`,\n\t\t`${backgroundProperty}; color: ${yellow}`,\n\t\t`${backgroundProperty}; color: ${grayDarker}`,\n\t\t`${backgroundProperty}; color: ${orange}`,\n\t\t`${backgroundProperty}; color: ${lightBlue}`,\n\t\t`${backgroundProperty}; color: ${pink}`,\n\t)\n\tconsole.groupEnd()\n}\n\nexport function noIdHandler() {\n\tconsole.log(\n\t\t'%c💥 Please set your form ID, you can get it from your dashboard: https://formcarry.com/profile/my-forms',\n\t\t'background-color: #FCB56D; color: #000',\n\t)\n\tconsole.log(\n\t\t'%cconst %c{state, submit} %c= %cuseForm%c(%c{ %cid%c: %c\"Your Form ID\" %c}%c);',\n\t\t`${backgroundProperty}; color: ${yellow}`,\n\t\t`${backgroundProperty}; color: ${pink}`,\n\t\t`${backgroundProperty}; color: ${gray}`,\n\t\t`${backgroundProperty}; color: ${turquoise}`,\n\t\t`${backgroundProperty}; color: ${pink}`,\n\t\t`${backgroundProperty}; color: ${turquoise}`,\n\t\t`${backgroundProperty}; color: ${yellow}`,\n\t\t`${backgroundProperty}; color: ${grayDarker}`,\n\t\t`${backgroundProperty}; color: ${orange}`,\n\t\t`${backgroundProperty}; color: ${lightBlue}`,\n\t\t`${backgroundProperty}; color: ${pink}`,\n\t)\n}\n","import React, { useState, useEffect } from 'react'\nimport { Props, FormcarryResponse } from './lib/types'\nimport { errorHandler, noIdHandler } from './lib/handler'\n\nfunction useForm(props: Props) {\n\tconst { id, debug = true, extraData } = props\n\tconst [submitted, setSubmitted] = useState<boolean>(false)\n\tconst [submitting, setSubmitting] = useState<boolean>(false)\n\tconst [error, setError] = useState<any>(undefined)\n\tconst [response, setResponse] = useState<FormcarryResponse>()\n\n\tuseEffect(() => {\n\t\tif (error && debug) {\n\t\t\terrorHandler(error)\n\t\t}\n\t}, [debug, error])\n\n\tfunction submit(event: React.FormEvent<HTMLFormElement>) {\n\t\t// prevent redirection\n\t\tevent.preventDefault()\n\n\t\tif (!id) {\n\t\t\tnoIdHandler()\n\t\t\treturn\n\t\t}\n\n\t\tconst data = new FormData(event.currentTarget)\n\n\t\tif (typeof extraData === 'object') {\n\t\t\tfor (const item in extraData) {\n\t\t\t\tif (extraData.hasOwnProperty(item)) {\n\t\t\t\t\tdata.append(item, extraData[item])\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// reset states.\n\t\tsetSubmitted(false)\n\t\tsetError(undefined)\n\t\tsetResponse(undefined)\n\n\t\tsetSubmitting(true)\n\n\t\tfetch(`https://formcarry.com/s/${id}`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { Accept: 'application/json' },\n\t\t\tbody: data,\n\t\t})\n\t\t\t.then(res => res.json())\n\t\t\t.then((res: FormcarryResponse) => {\n\t\t\t\tif (res.code === 200) {\n\t\t\t\t\tsetSubmitted(true)\n\t\t\t\t\tsetResponse(res)\n\t\t\t\t} else {\n\t\t\t\t\tsetError(res)\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch(err => {\n\t\t\t\tsetError(err)\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tsetSubmitting(false)\n\t\t\t})\n\t}\n\n\treturn { state: { error, response, submitting, submitted }, submit }\n}\n\nexport { useForm }\n"],"names":["backgroundColor","backgroundProperty","yellow","pink","orange","gray","grayDarker","turquoise","lightBlue","errorHandler","err","console","group","table","log","groupEnd","noIdHandler","useForm","props","id","debug","extraData","useState","submitted","setSubmitted","submitting","setSubmitting","undefined","error","setError","response","setResponse","useEffect","submit","event","preventDefault","data","FormData","currentTarget","item","hasOwnProperty","append","fetch","method","headers","Accept","body","then","res","json","code","state"],"mappings":";;;;;;AAEA,IAAMA,eAAe,GAAG,SAAS;AACjC,IAAMC,kBAAkB,0BAAwBD,eAAiB;AACjE,IAAME,MAAM,GAAG,SAAS;AACxB,IAAMC,IAAI,GAAG,SAAS;AACtB,IAAMC,MAAM,GAAG,SAAS;AACxB,IAAMC,IAAI,GAAG,SAAS;AACtB,IAAMC,UAAU,GAAG,SAAS;AAC5B,IAAMC,SAAS,GAAG,SAAS;AAC3B,IAAMC,SAAS,GAAG,SAAS;SAEXC,YAAY,CAACC,GAAsB;EAClDC,OAAO,CAACC,KAAK,CAAC,0BAA0B,EAAE,kCAAkC,CAAC;EAC7ED,OAAO,CAACE,KAAK,CAACH,GAAG,CAAC;EAClBC,OAAO,CAACG,GAAG,sEAEV,gBAAgB,CAChB;EACDH,OAAO,CAACG,GAAG,CACV,0EAA0E,EACvEb,kBAAkB,iBAAYC,MAAM,EACpCD,kBAAkB,iBAAYE,IAAI,EAClCF,kBAAkB,iBAAYI,IAAI,EAClCJ,kBAAkB,iBAAYM,SAAS,EACvCN,kBAAkB,iBAAYE,IAAI,EAClCF,kBAAkB,iBAAY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