Skip to content

Commit

Permalink
Merge pull request #800 from ecomplus/v2-option
Browse files Browse the repository at this point in the history
chore: persist across tabs with local storage autentication v2
  • Loading branch information
matheusgnreis authored May 7, 2024
2 parents 69b4cb6 + da4b633 commit e0be51d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/controllers/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export default function () {

const id = Tab.selectedItems[done]
if (id) {
const isApiv2 = Number(window.sessionStorage.getItem('api_version')) === 2
const isApiv2 = Number(window.localStorage.getItem('api_version')) === 2 || window.ECOMCLIENT_API_STORE.indexOf('v2') > -1
const apiBaseUri = isApiv2 ? 'https://ecomplus.io/v2' : 'https://api.e-com.plus/v1'
askConfirmation(
`${apiBaseUri}/${slug}/${id}.json`,
Expand Down
8 changes: 3 additions & 5 deletions src/controllers/resources/form/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ export default function () {
$emptyGrid.focus()
return
}

// add li element
var $li = $('<li />', {
html: liGrid
Expand Down Expand Up @@ -551,7 +550,6 @@ export default function () {
if (options.length) {
$inputOption.attr('placeholder', options[0])
}

if (gridsOptions.hasOwnProperty(gridId)) {
// grid already in use
var idAux = 2
Expand Down Expand Up @@ -922,8 +920,9 @@ export default function () {
// single new option
newOption = handleNewOption()
} else {
// multiple options should be separated with points
var options = option.split(/[,;/\\|.]+/g)
// multiple options should be separated with some char

var options = option.split(/[;/\\|]+/g)

// handle all new options
for (var i = 0; i < options.length; i++) {
Expand Down Expand Up @@ -2078,7 +2077,6 @@ export default function () {
if (dateStrs.length === 2) {
dateStrs.forEach((dateStr, i) => {
const { day, month, year, hour, min, sec } = parseHourDate(dateStr)
console.log(day, month, year, hour, min, sec)
if (day && month && year) {
const date = new Date(year, month - 1, day)
if (hour >= 0 && min >= 0 && sec >= 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<link href="https://fonts.googleapis.com/css2?family=Fira+Sans:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">
<link href="/assets/css/core.min.css" rel="stylesheet">
<script>
if (sessionStorage.getItem('api_version') === '2') {
const isApiVersion2 = sessionStorage.getItem('api_version') === '2' || localStorage.getItem('api_version') === '2'
if (isApiVersion2) {
ECOMCLIENT_API_STORE = 'https://ecomplus.io/v2/'
}
if (sessionStorage.getItem('cloudcomm_pid')) {
Expand Down
8 changes: 5 additions & 3 deletions src/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const getAuthState = (name, storeId, myId) => {
return fromStorage
}
const isApiv2 = Number(getAuthState('api_version')) === 2

const apiBaseUri = isApiv2 ? 'https://ecomplus.io/v2' : 'https://api.e-com.plus/v1'
if (isApiv2) {
localStorage.setItem('api_version', '2')
Expand Down Expand Up @@ -205,7 +206,7 @@ const handleSso = (storeId, username, session) => {
if (domain) {
window.location = `https://${domain}/admin/?token=${gotrueToken}`
} else {
initDashboard(storeId, username, json)
initDashboard(storeId, username, json, isApiv2)
}
})
.fail(authFail)
Expand All @@ -218,7 +219,7 @@ const handleSso = (storeId, username, session) => {
if (urlParams.get('sso_url')) {
window.location = `https://admin.e-com.plus${urlParams.get('sso_url')}`
} else {
initDashboard(storeId, username, session)
initDashboard(storeId, username, session, isApiv2)
}
}
})
Expand Down Expand Up @@ -250,10 +251,11 @@ const handleSso = (storeId, username, session) => {
proceedToSession()
}

const initDashboard = (storeId, username, session) => {
const initDashboard = (storeId, username, session, isApiv2) => {
if (window.history.pushState) {
window.history.pushState({}, document.title, window.location.pathname)
}

if (isApiv2) {
window.ECOMCLIENT_API_STORE = 'https://ecomplus.io/v2/'
sessionStorage.setItem('api_version', '2')
Expand Down
7 changes: 4 additions & 3 deletions src/script/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import EventEmitter from 'eventemitter3'

const { sessionStorage, localStorage, Image, $, app } = window

const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2
const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2 || window.ECOMCLIENT_API_STORE.indexOf('v2') > -1
console.log('which api', isApiv2)

;(function () {
const dictionary = {
Expand Down Expand Up @@ -225,7 +226,7 @@ const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2
hideToast()
// E-Com Plus Store API
// https://ecomstore.docs.apiary.io/#
const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2
const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2 || window.ECOMCLIENT_API_STORE.indexOf('v2') > -1
const apiBaseUri = isApiv2 ? 'https://ecomplus.io/v2' : 'https://api.e-com.plus/v1'
// API endpoint full URL
var uri = apiBaseUri + '/' + endpoint
Expand Down Expand Up @@ -323,7 +324,7 @@ const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2
var callSearchApi = function (endpoint, method, callback, bodyObject) {
// E-Com Plus Search API
// https://ecomsearch.docs.apiary.io/#
const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2
const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2 || window.ECOMCLIENT_API_STORE.indexOf('v2') > -1
const apiBaseUri = isApiv2 ? 'https://ecomplus.io/v2/search/_els' : 'https://apx-search.e-com.plus/api/v1'
// API endpoint full URL
let uri
Expand Down

0 comments on commit e0be51d

Please sign in to comment.