diff --git a/package-lock.json b/package-lock.json index 0424dab..512c9f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1328,9 +1328,9 @@ } }, "@flare/js-utils": { - "version": "1.0.1", - "resolved": "https://lab.code-rove.com/public-node-registry/@flare%2fjs-utils/-/js-utils-1.0.1.tgz", - "integrity": "sha512-54zfXBeof4ns9wEGvUeORd6SiAvCcUNEIiamnLtbASVMY6TxrpGp7UL+Dm7iGdC5jmDb5stla6I8aHroQuvvqg==" + "version": "1.0.2", + "resolved": "https://lab.code-rove.com/public-node-registry/@flare%2fjs-utils/-/js-utils-1.0.2.tgz", + "integrity": "sha512-49KjpcRUD6fXPC60bmCsPa8frU6wlQyI5RsjMD70zsuvk8BZFdopsETsjsCembbmzTScIhfMACU4RnimOEwg9Q==" }, "@gar/promisify": { "version": "1.1.3", diff --git a/package.json b/package.json index ca6b828..bd8632a 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "private": true, "dependencies": { - "@flare/js-utils": "^1.0.0", + "@flare/js-utils": "^1.0.2", "@material-ui/core": "^4.11.2", "@material-ui/icons": "^4.11.2", "@testing-library/jest-dom": "^5.11.6", diff --git a/src/state/initialState.js b/src/state/initialState.js index 2fca86b..00b98d2 100644 --- a/src/state/initialState.js +++ b/src/state/initialState.js @@ -1,6 +1,7 @@ -import { getItem } from "../utils/localStorage"; +import { localStorage } from "@flare/js-utils"; import { storageKeys } from "../utils/identity"; +const { getItem } = localStorage; const token = getItem(storageKeys.TOKEN); const userName = getItem(storageKeys.USER); diff --git a/src/utils/axios.js b/src/utils/axios.js index 0f17e8d..20c75ee 100644 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -1,8 +1,10 @@ import axios from "axios"; import i18next from "i18next"; -import { getItem } from "./localStorage"; +import { localStorage } from "@flare/js-utils"; import { storageKeys } from "./identity"; +const { getItem } = localStorage; + function getHeaders() { const token = getItem(storageKeys.TOKEN); const language = i18next.language; diff --git a/src/utils/identity.js b/src/utils/identity.js index ba79528..66d1fcd 100644 --- a/src/utils/identity.js +++ b/src/utils/identity.js @@ -1,5 +1,7 @@ import { request } from "./axios"; -import { setItem, getItem, removeItem } from "./localStorage"; +import { localStorage } from "@flare/js-utils"; + +const { setItem, getItem, removeItem } = localStorage; const storageKeys = { TOKEN: "AUTHORIZATION_TOKEN", diff --git a/src/utils/localStorage.js b/src/utils/localStorage.js deleted file mode 100644 index 61bd1f9..0000000 --- a/src/utils/localStorage.js +++ /dev/null @@ -1,38 +0,0 @@ -import { typeValidator } from "@flare/js-utils"; - -const setItem = (key, value) => { - const { isArray, isObject } = typeValidator; - let valueToStore = value; - if (isArray(value) || isObject(value)) { - valueToStore = JSON.stringify(value); - } - - window.localStorage.setItem(key, valueToStore); -}; - -const getItem = key => { - var value = window.localStorage.getItem(key); - const { isJson } = typeValidator; - var { data, success } = isJson(value); - - if (success) { - return data; - } else { - return value; - } -}; - -const removeItem = key => { - window.localStorage.removeItem(key); -}; - -const clear = () => { - window.localStorage.clear(); -}; - -const key = index => { - var keyName = window.localStorage.key(index); - return keyName; -}; - -export { setItem, getItem, removeItem, clear, key };