From f6f7a9fa0bd18b8f5052903cb39932104ae55505 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Thu, 30 Mar 2023 19:31:02 +0300 Subject: [PATCH] moved token decodint to @flare/tuitio-client-react --- package-lock.json | 76 +++++++++---------- package.json | 2 +- .../components/UserProfileComponent.js | 43 +++++++++++ .../components/UserProfileContainer.js | 45 ++--------- src/utils/camelizeKeys.js | 31 -------- 5 files changed, 87 insertions(+), 110 deletions(-) create mode 100644 src/features/user/profile/components/UserProfileComponent.js delete mode 100644 src/utils/camelizeKeys.js diff --git a/package-lock.json b/package-lock.json index 19df8ce..fc9761b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1311,25 +1311,25 @@ } }, "@flare/js-utils": { - "version": "1.0.3", - "resolved": "https://lab.code-rove.com/public-node-registry/@flare/js-utils/-/js-utils-1.0.3.tgz", - "integrity": "sha512-VgXQHoQEVZ/71B6YQHQP8/Yd/w1smGD+kCCiNvJKZ1xMD3nkN9mjoHxIqbOJMZ2q5PZlV6gXYT7eVol8Wm+D0A==" + "version": "1.0.4", + "resolved": "https://lab.code-rove.com/public-node-registry/@flare/js-utils/-/js-utils-1.0.4.tgz", + "integrity": "sha512-U55xP+4E9DYWWaq4YnlNoi/MeAw3dDvhWSPN2hqQiO08dBBGIdKFZDYSLOMSzc5ccqErbiAc+dCuJ+ZSjfkptA==" }, "@flare/tuitio-client": { - "version": "1.2.0", - "resolved": "https://lab.code-rove.com/public-node-registry/@flare/tuitio-client/-/tuitio-client-1.2.0.tgz", - "integrity": "sha512-5h2hLH1kJXhSiQxsrj3lnXz45h3p/Z+liN0XCVEbkOEFU4NXhgxegeODo0X9P/++nPQOOmGbwDTUObkCkO2yJA==", + "version": "1.2.1", + "resolved": "https://lab.code-rove.com/public-node-registry/@flare/tuitio-client/-/tuitio-client-1.2.1.tgz", + "integrity": "sha512-74gnrw/AQDUObgUMy3DqGD4AdputIyRkk2EToi3cVIWVRSaoa2I9HmPi+qyfJkv4akrEH42rRSL3naN6vpnbIA==", "requires": { - "@flare/js-utils": "^1.0.3", + "@flare/js-utils": "^1.0.4", "axios": "^1.3.2" } }, "@flare/tuitio-client-react": { - "version": "1.2.0", - "resolved": "https://lab.code-rove.com/public-node-registry/@flare/tuitio-client-react/-/tuitio-client-react-1.2.0.tgz", - "integrity": "sha512-0ioFR9FLBtgzSxahVn/4bBB+8r2uRwWICYlCausSImgONwBPXkgNtfj6eubYPEZ8jjqVMRnMCbD59qvBB1clfg==", + "version": "1.2.1", + "resolved": "https://lab.code-rove.com/public-node-registry/@flare/tuitio-client-react/-/tuitio-client-react-1.2.1.tgz", + "integrity": "sha512-Z5fv+1tH4QX7xOV+so9KoeJZwSdVbmSQA6GjsUYYZF2Yp7TEB2OwYYbw+xse4+fPCvsJMs5tgknCZvzvekWCpQ==", "requires": { - "@flare/tuitio-client": "^1.2.0" + "@flare/tuitio-client": "^1.2.1" } }, "@gar/promisify": { @@ -2621,9 +2621,9 @@ } }, "@types/yargs": { - "version": "17.0.22", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.22.tgz", - "integrity": "sha512-pet5WJ9U8yPVRhkwuEIp5ktAeAqRZOq4UdAyWLWzxbtpyXnzbtLdKiXAjJzi/KLmPGS9wk86lUFWZFN6sISo4g==", + "version": "17.0.24", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", + "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", "dev": true, "requires": { "@types/yargs-parser": "*" @@ -2807,9 +2807,9 @@ "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==" }, "@types/node": { - "version": "18.15.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.3.tgz", - "integrity": "sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw==" + "version": "18.15.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz", + "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==" }, "@types/normalize-package-data": { "version": "2.4.1", @@ -2837,9 +2837,9 @@ "integrity": "sha512-L28j2FcJfSZOnL1WBjDYp2vUHCeIFlyYI/53EwD/rKUBQ7MtUUfbQWiyKJGpcnv4/WgrhWsFKrcPstcAt/J0tQ==" }, "@types/react": { - "version": "18.0.28", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.28.tgz", - "integrity": "sha512-RD0ivG1kEztNBdoAK7lekI9M+azSnitIn85h4iOiaLjaTrMjzslhaqCGaI4IyCJ1RljWiLCEu4jyrLLgqxBTew==", + "version": "18.0.31", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.31.tgz", + "integrity": "sha512-EEG67of7DsvRDU6BLLI0p+k1GojDLz9+lZsnCpCRTa/lOokvyPBvp8S5x+A24hME3yyQuIipcP70KJ6H7Qupww==", "requires": { "@types/prop-types": "*", "@types/scheduler": "*", @@ -2870,9 +2870,9 @@ } }, "@types/scheduler": { - "version": "0.16.2", - "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", - "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" + "version": "0.16.3", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.3.tgz", + "integrity": "sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==" }, "@types/source-list-map": { "version": "0.1.2", @@ -4482,9 +4482,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001467", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001467.tgz", - "integrity": "sha512-cEdN/5e+RPikvl9AHm4uuLXxeCNq8rFsQ+lPHTfe/OtypP3WwnVVbjn+6uBV7PaFL6xUFzTh+sSCOz1rKhcO+Q==" + "version": "1.0.30001473", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001473.tgz", + "integrity": "sha512-ewDad7+D2vlyy+E4UJuVfiBsU69IL+8oVmTuZnH5Q6CIUbxNfI50uVpRHbUPDD6SUaN2o0Lh4DhTrvLG/Tn1yg==" }, "capture-exit": { "version": "2.0.0", @@ -5813,9 +5813,9 @@ "integrity": "sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==" }, "electron-to-chromium": { - "version": "1.4.333", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.333.tgz", - "integrity": "sha512-YyE8+GKyGtPEP1/kpvqsdhD6rA/TP1DUFDN4uiU/YI52NzDxmwHkEb3qjId8hLBa5siJvG0sfC3O66501jMruQ==" + "version": "1.4.345", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.345.tgz", + "integrity": "sha512-znGhOQK2TUYLICgS25uaM0a7pHy66rSxbre7l762vg9AUoCcJK+Bu+HCPWpjL/U/kK8/Hf+6E0szAUJSyVYb3Q==" }, "elliptic": { "version": "6.5.4", @@ -10841,9 +10841,9 @@ "integrity": "sha512-cnAsSVxIDsYt0v7HmC0hWZFwwXSh+E6PgCrREDuN/EsjgLwA5XRmlMHhSiDPrt6HxY1gTivEa/Zh7GtODoLevQ==" }, "nanoid": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", - "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==" + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==" }, "nanomatch": { "version": "1.2.13", @@ -12627,9 +12627,9 @@ "integrity": "sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg==" }, "prettier": { - "version": "2.8.4", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.4.tgz", - "integrity": "sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==", + "version": "2.8.7", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz", + "integrity": "sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==", "dev": true }, "pretty-bytes": { @@ -15191,9 +15191,9 @@ "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" }, "terser": { - "version": "5.16.6", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.16.6.tgz", - "integrity": "sha512-IBZ+ZQIA9sMaXmRZCUMDjNH0D5AQQfdn4WUjHL0+1lF4TP1IHRJbrhb6fNaXWikrYQTSkb7SLxkeXAiy1p7mbg==", + "version": "5.16.8", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.16.8.tgz", + "integrity": "sha512-QI5g1E/ef7d+PsDifb+a6nnVgC4F22Bg6T0xrBrz6iloVB4PUkkunp6V8nzoOOZJIzjWVdAGqCdlKlhLq/TbIA==", "requires": { "@jridgewell/source-map": "^0.3.2", "acorn": "^8.5.0", diff --git a/package.json b/package.json index 512eee7..685670c 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "private": true, "dependencies": { "@flare/js-utils": "^1.0.3", - "@flare/tuitio-client-react": "^1.2.0", + "@flare/tuitio-client-react": "^1.2.1", "@material-ui/core": "^4.11.2", "@material-ui/icons": "^4.11.2", "@material-ui/lab": "^4.0.0-alpha.61", diff --git a/src/features/user/profile/components/UserProfileComponent.js b/src/features/user/profile/components/UserProfileComponent.js new file mode 100644 index 0000000..1caaf51 --- /dev/null +++ b/src/features/user/profile/components/UserProfileComponent.js @@ -0,0 +1,43 @@ +import React, { useMemo } from "react"; +import PropTypes from "prop-types"; +import { useTranslation } from "react-i18next"; +import { Card, CardHeader, CardContent } from "@material-ui/core"; +import PageTitle from "../../../../components/common/PageTitle"; +import UserProfileCardContent from "./UserProfileCardContent"; + +const UserProfileComponent = ({ userData }) => { + const { t } = useTranslation(); + + const userLoginDate = useMemo( + () => + t("DATE_FORMAT", { + date: { value: userData.createdAt, format: "DD-MM-YYYY HH:mm:ss" } + }), + [t, userData.createdAt] + ); + + const userDescription = t("User.Profile.Description", { + userName: `${userData.firstName} ${userData.lastName}`, + loginDate: userLoginDate + }); + + return ( + <> + + + + + + + + + ); +}; + +UserProfileComponent.propTypes = { + userData: PropTypes.object.isRequired +}; + +export default UserProfileComponent; diff --git a/src/features/user/profile/components/UserProfileContainer.js b/src/features/user/profile/components/UserProfileContainer.js index 4d02b09..0fa469a 100644 --- a/src/features/user/profile/components/UserProfileContainer.js +++ b/src/features/user/profile/components/UserProfileContainer.js @@ -1,46 +1,11 @@ -import React, { useMemo } from "react"; -import { useTranslation } from "react-i18next"; -import { Card, CardHeader, CardContent } from "@material-ui/core"; -import { useTuitioToken } from "@flare/tuitio-client-react"; -import { camelizeKeys } from "../../../../utils/camelizeKeys"; -import PageTitle from "../../../../components/common/PageTitle"; -import UserProfileCardContent from "./UserProfileCardContent"; +import React from "react"; +import { useTuitioDecodedToken } from "@flare/tuitio-client-react"; +import UserProfileComponent from "./UserProfileComponent"; const UserProfileContainer = () => { - const { t } = useTranslation(); - const { token } = useTuitioToken(); - - const decodedToken = useMemo(() => atob(token), [token]); - const userData = useMemo( - () => camelizeKeys(JSON.parse(decodedToken)), - [decodedToken] - ); - - const userLoginDate = useMemo( - () => - t("DATE_FORMAT", { - date: { value: userData.createdAt, format: "DD-MM-YYYY HH:mm:ss" } - }), - [t, userData.createdAt] - ); - - const userDescription = t("User.Profile.Description", { - userName: `${userData.firstName} ${userData.lastName}`, - loginDate: userLoginDate - }); - + const { decodedToken } = useTuitioDecodedToken(); return ( - <> - - - - - - - - + <>{decodedToken && } ); }; diff --git a/src/utils/camelizeKeys.js b/src/utils/camelizeKeys.js deleted file mode 100644 index 5691b1f..0000000 --- a/src/utils/camelizeKeys.js +++ /dev/null @@ -1,31 +0,0 @@ -function camelizeKeys(o) { - var newO, origKey, newKey, value; - if (o instanceof Array) { - return o.map(function (value) { - if (typeof value === "object") { - value = camelizeKeys(value); - } - return value; - }); - } else { - newO = {}; - for (origKey in o) { - if (Object.prototype.hasOwnProperty.call(o, origKey)) { - newKey = ( - origKey.charAt(0).toLowerCase() + origKey.slice(1) || origKey - ).toString(); - value = o[origKey]; - if ( - value instanceof Array || - (value !== null && value.constructor === Object) - ) { - value = camelizeKeys(value); - } - newO[newKey] = value; - } - } - } - return newO; -} - -export { camelizeKeys };