7bc8e5d214c0756f3c70c158efc1f5ae.json 13.5 KB
Newer Older
Mathias Engelbrecht Pilegård's avatar
Mathias Engelbrecht Pilegård committed
1
{"ast":null,"code":"var _jsxFileName = \"C:\\\\Users\\\\Bruger\\\\Desktop\\\\Web-projects\\\\pipit\\\\client\\\\src\\\\components\\\\updateUserData\\\\updateUserDataModal\\\\UpdateUserDataModal.jsx\",\n    _s = $RefreshSig$();\n\nimport React, { useState, useEffect } from 'react';\nimport \"./UpdateUserDataModal.css\";\nimport { useOktaAuth } from '@okta/okta-react';\nimport config from '../../../config';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\n\nconst UpdateUserDataModal = ({\n  removeModal\n}) => {\n  _s();\n\n  const {\n    authState,\n    oktaAuth\n  } = useOktaAuth();\n  const [userInfo, setUserInfo] = useState(null);\n  const accessToken = oktaAuth.getAccessToken();\n\n  const stopProp = e => {\n    e.stopPropagation();\n  };\n\n  useEffect(() => {\n    if (!authState.isAuthenticated) {\n      // When user isn't authenticated, forget any user info\n      setUserInfo(null);\n    } else {\n      oktaAuth.getUser().then(info => {\n        setUserInfo(info);\n      });\n    }\n  }, [authState, oktaAuth]); // Update if authState changes\n\n  useEffect(() => {\n    userInfo && setFirstname(userInfo.given_name);\n    userInfo && setLastname(userInfo.family_name);\n    userInfo && setUsername(userInfo.email);\n  }, [userInfo]);\n  const [firstname, setFirstname] = useState('');\n  const [lastname, setLastname] = useState('');\n  const [username, setUsername] = useState('');\n\n  const handlefirstnameChange = e => {\n    setFirstname(e.target.value);\n  };\n\n  const handlelastnameChange = e => {\n    setLastname(e.target.value);\n  };\n\n  const handleUsernameChange = e => {\n    setUsername(e.target.value);\n  };\n\n  const userInputData = JSON.stringify({\n    firstname: `${firstname}`,\n    lastname: `${lastname}`,\n    email: `${username}`\n  });\n  const updateUserDataRequestOptions = {\n    method: 'PUT',\n    body: userInputData\n  };\n\n  const handleUpdateUserDataFormSubmit = e => {\n    e.preventDefault();\n    fetch(config.serviceAPI.updateUserDataURL, updateUserDataRequestOptions).then(res => {\n      if (!res.ok) {\n        window.alert(\"Error\");\n        Promise.reject(\"\");\n        return;\n      }\n\n      if (res.ok) {\n        removeModal();\n      }\n    });\n  };\n\n  return /*#__PURE__*/_jsxDEV(\"div\", {\n    className: \"modal-content\",\n    children: /*#__PURE__*/_jsxDEV(\"div\", {\n      className: \"updateUserDataModal\",\n      children: [/*#__PURE__*/_jsxDEV(\"h2\", {\n        children: \"Update information\"\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 86,\n        columnNumber: 9\n      }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n        userDataSubmitForm: true,\n        children: /*#__PURE__*/_jsxDEV(\"form\", {\n          onSubmit: handleUpdateUserDataFormSubmit,\n          children: [/*#__PURE__*/_jsxDEV(\"label\", {\n            children: [\"First name:\", /*#__PURE__*/_jsxDEV(\"input\", {\n              id: \"firstname\",\n              type: \"text\",\n              value: firstname,\n              onChange: handlefirstnameChange\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 91,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 89,\n            columnNumber: 13\n          }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n            children: [\"Last Name:\", /*#__PURE__*/_jsxDEV(\"input\", {\n              id: \"lastname\",\n              type: \"text\",\n              value: lastname,\n              onChange: handlelastnameChange\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 98,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 96,\n            columnNumber: 13\n          }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n            children: [\"Email:\", /*#__PURE__*/_jsxDEV(\"input\", {\n              id: \"email\",\n              type: \"text\",\n              value: username,\n              onChange: handleUsernameChange\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 105,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 103,\n            columnNumber: 13\n          }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n            className: \"buttonContainer\",\n            children: [/*#__PURE__*/_jsxDEV(\"button\", {\n              className: \"noButton\",\n              onClick: e => removeModal(),\n              children: \"Cancel\"\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 111,\n              columnNumber: 15\n            }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n              className: \"yesButton\",\n              type: \"submit\",\n              children: \"Update\"\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 114,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 110,\n            columnNumber: 13\n          }, this)]\n        }, void 0, true, {\n          fileName: _jsxFileName,\n          lineNumber: 88,\n          columnNumber: 11\n        }, this)\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 87,\n        columnNumber: 9\n      }, this)]\n    }, void 0, true, {\n      fileName: _jsxFileName,\n      lineNumber: 85,\n      columnNumber: 7\n    }, this)\n  }, void 0, false, {\n    fileName: _jsxFileName,\n    lineNumber: 84,\n    columnNumber: 5\n  }, this);\n};\n\n_s(UpdateUserDataModal, \"AxzdzHC979Yq9E6/6HJDjeCl4CA=\", false, function () {\n  return [useOktaAuth];\n});\n\n_c = UpdateUserDataModal;\nexport default UpdateUserDataModal;\n\nvar _c;\n\n$RefreshReg$(_c, \"UpdateUserDataModal\");","map":{"version":3,"sources":["C:/Users/Bruger/Desktop/Web-projects/pipit/client/src/components/updateUserData/updateUserDataModal/UpdateUserDataModal.jsx"],"names":["React","useState","useEffect","useOktaAuth","config","UpdateUserDataModal","removeModal","authState","oktaAuth","userInfo","setUserInfo","accessToken","getAccessToken","stopProp","e","stopPropagation","isAuthenticated","getUser","then","info","setFirstname","given_name","setLastname","family_name","setUsername","email","firstname","lastname","username","handlefirstnameChange","target","value","handlelastnameChange","handleUsernameChange","userInputData","JSON","stringify","updateUserDataRequestOptions","method","body","handleUpdateUserDataFormSubmit","preventDefault","fetch","serviceAPI","updateUserDataURL","res","ok","window","alert","Promise","reject"],"mappings":";;;AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,QAA2C,OAA3C;AACA,OAAO,2BAAP;AACA,SAASC,WAAT,QAA4B,kBAA5B;AACA,OAAOC,MAAP,MAAmB,iBAAnB;;;AAEA,MAAMC,mBAAmB,GAAG,CAAC;AAAEC,EAAAA;AAAF,CAAD,KAAqB;AAAA;;AAC/C,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA0BL,WAAW,EAA3C;AACA,QAAM,CAACM,QAAD,EAAWC,WAAX,IAA0BT,QAAQ,CAAC,IAAD,CAAxC;AACA,QAAMU,WAAW,GAAGH,QAAQ,CAACI,cAAT,EAApB;;AAEA,QAAMC,QAAQ,GAAGC,CAAC,IAAI;AACpBA,IAAAA,CAAC,CAACC,eAAF;AACD,GAFD;;AAIAb,EAAAA,SAAS,CAAC,MAAM;AACd,QAAI,CAACK,SAAS,CAACS,eAAf,EAAgC;AAC9B;AACAN,MAAAA,WAAW,CAAC,IAAD,CAAX;AACD,KAHD,MAGO;AACLF,MAAAA,QAAQ,CAACS,OAAT,GAAmBC,IAAnB,CAAwBC,IAAI,IAAI;AAC9BT,QAAAA,WAAW,CAACS,IAAD,CAAX;AACD,OAFD;AAGD;AACF,GATQ,EASN,CAACZ,SAAD,EAAYC,QAAZ,CATM,CAAT,CAT+C,CAkBpB;;AAE3BN,EAAAA,SAAS,CAAC,MAAM;AACdO,IAAAA,QAAQ,IACNW,YAAY,CAACX,QAAQ,CAACY,UAAV,CADd;AAIAZ,IAAAA,QAAQ,IACNa,WAAW,CAACb,QAAQ,CAACc,WAAV,CADb;AAIAd,IAAAA,QAAQ,IACNe,WAAW,CAACf,QAAQ,CAACgB,KAAV,CADb;AAGD,GAZQ,EAYN,CAAChB,QAAD,CAZM,CAAT;AAcA,QAAM,CAACiB,SAA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AAA,kBAtBF;AAAA;AAAA;AAAA;AAAA;AAAA;AADF;AAAA;AAAA;AAAA;AAAA,cAFF;AAAA;AAAA;AAAA;AAAA;AAAA;AADF;AAAA;AAAA;AAAA;AAAA,UADF;AAwCD,CArHD;;GAAMD,mB;UAC4BF,W;;;KAD5BE,mB;AAuHN,eAAeA,mBAAf","sourcesContent":["import React, { useState, useEffect } from 'react'\r\nimport \"./UpdateUserDataModal.css\"\r\nimport { useOktaAuth } from '@okta/okta-react';\r\nimport config from '../../../config';\r\n\r\nconst UpdateUserDataModal = ({ removeModal }) => {\r\n  const { authState, oktaAuth } = useOktaAuth();\r\n  const [userInfo, setUserInfo] = useState(null);\r\n  const accessToken = oktaAuth.getAccessToken();\r\n\r\n  const stopProp = e => {\r\n    e.stopPropagation()\r\n  }\r\n\r\n  useEffect(() => {\r\n    if (!authState.isAuthenticated) {\r\n      // When user isn't authenticated, forget any user info\r\n      setUserInfo(null);\r\n    } else {\r\n      oktaAuth.getUser().then(info => {\r\n        setUserInfo(info);\r\n      });\r\n    }\r\n  }, [authState, oktaAuth]); // Update if authState changes\r\n\r\n  useEffect(() => {\r\n    userInfo && (\r\n      setFirstname(userInfo.given_name)\r\n    )\r\n\r\n    userInfo && (\r\n      setLastname(userInfo.family_name)\r\n    )\r\n\r\n    userInfo && (\r\n      setUsername(userInfo.email)\r\n    )\r\n  }, [userInfo])\r\n\r\n  const [firstname, setFirstname] = useState('')\r\n  const [lastname, setLastname] = useState('')\r\n  const [username, setUsername] = useState('');\r\n\r\n  const handlefirstnameChange = (e) => {\r\n    setFirstname(e.target.value)\r\n  }\r\n\r\n  const handlelastnameChange = (e) => {\r\n    setLastname(e.target.value)\r\n  }\r\n\r\n  const handleUsernameChange = (e) => {\r\n    setUsername(e.target.value);\r\n  };\r\n\r\n  const userInputData = JSON.stringify({\r\n    firstname: `${firstname}`,\r\n    lastname: `${lastname}`,\r\n    email: `${username}`\r\n  })\r\n\r\n  const updateUserDataRequestOptions = {\r\n    method: 'PUT',\r\n    body: userInputData\r\n  };\r\n\r\n  const handleUpdateUserDataFormSubmit = (e) => {\r\n    e.preventDefault();\r\n\r\n    fetch(config.serviceAPI.updateUserDataURL, updateUserDataRequestOptions)\r\n      .then((res) => {\r\n        if (!res.ok) {\r\n          window.alert(\"Error\")\r\n          Promise.reject(\"\")\r\n          return\r\n        }\r\n        if (res.ok) {\r\n          removeModal()\r\n        }\r\n      })\r\n  }\r\n\r\n  return (\r\n    <div className=\"modal-content\">\r\n      <div className=\"updateUserDataModal\">\r\n        <h2>Update information</h2>\r\n        <div userDataSubmitForm>\r\n          <form onSubmit={handleUpdateUserDataFormSubmit}>\r\n            <label>\r\n              First name:\r\n              <input\r\n                id=\"firstname\" type=\"text\"\r\n                value={firstname}\r\n                onChange={handlefirstnameChange} />\r\n            </label>\r\n            <label>\r\n              Last Name:\r\n              <input\r\n                id=\"lastname\" type=\"text\"\r\n                value={lastname}\r\n                onChange={handlelastnameChange} />\r\n            </label>\r\n            <label>\r\n              Email:\r\n              <input\r\n                id=\"email\" type=\"text\"\r\n                value={username}\r\n                onChange={handleUsernameChange} />\r\n            </label>\r\n            <div className=\"buttonContainer\">\r\n              <button className=\"noButton\" onClick={e => removeModal()}>\r\n                Cancel\r\n              </button>\r\n              <button className=\"yesButton\" type=\"submit\">\r\n                Update\r\n              </button>\r\n            </div>\r\n          </form>\r\n        </div>\r\n      </div>\r\n    </div>\r\n  )\r\n}\r\n\r\nexport default UpdateUserDataModal\r\n"]},"metadata":{},"sourceType":"module"}