From 509897e582b1cc18ab680ec804656d76b72a1bd0 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Fri, 15 Apr 2022 15:42:59 +0200 Subject: [PATCH] change(ui) - siteId --- .../components/Client/Sites/NewSiteForm.js | 47 +++++++++---------- frontend/app/duck/site.js | 6 +-- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/frontend/app/components/Client/Sites/NewSiteForm.js b/frontend/app/components/Client/Sites/NewSiteForm.js index b98a77a38..407da1021 100644 --- a/frontend/app/components/Client/Sites/NewSiteForm.js +++ b/frontend/app/components/Client/Sites/NewSiteForm.js @@ -39,12 +39,11 @@ export default class NewSiteForm extends React.PureComponent { } else { this.props.save(this.props.site).then(() => { const { sites } = this.props; - const site = sites.last(); - - this.props.pushNewSite(site) - if (!pathname.includes('/client')) { - this.props.setSiteId(site.id) - } + const site = sites.last(); + this.props.pushNewSite(site) + if (!pathname.includes('/client')) { + this.props.setSiteId(site.id) + } this.props.onClose(null, site) }); } @@ -59,17 +58,17 @@ export default class NewSiteForm extends React.PureComponent { const { site, loading } = this.props; return (
-
+
- - -
+ + +
- { this.state.existsError && -
- { "Site exists already. Please choose another one." } -
- } -
-
- ); + { this.state.existsError && +
+ { "Site exists already. Please choose another one." } +
+ } + + + ); } } \ No newline at end of file diff --git a/frontend/app/duck/site.js b/frontend/app/duck/site.js index 5530773f0..ff5142804 100644 --- a/frontend/app/duck/site.js +++ b/frontend/app/duck/site.js @@ -53,12 +53,12 @@ const reducer = (state = initialState, action = {}) => { return state.setIn([ 'instance', 'gdpr' ], gdpr); case FETCH_LIST_SUCCESS: let siteId = state.get("siteId"); - if (!siteId) { - siteId = !!action.data.find(s => s.projectId === storedSiteId) + const siteExists = action.data.map(s => s.projectId).includes(siteId); + if (!siteId || !siteExists) { + siteId = !!action.data.find(s => s.projectId === parseInt(storedSiteId)) ? storedSiteId : action.data[0].projectId; } - console.log('siteId asd', siteId) return state.set('list', List(action.data.map(Site))).set('siteId', siteId); case SET_SITE_ID: localStorage.setItem(SITE_ID_STORAGE_KEY, action.siteId)