From 02a3080c5bd245012b47756edbf6db0c35a5c2e4 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Fri, 16 Sep 2022 20:30:13 +0530 Subject: [PATCH] fix(ui) - new site - update active site and clear date --- frontend/app/Router.js | 2 +- .../components/Client/Sites/NewSiteForm.js | 21 ++++++++++--------- frontend/app/duck/site.js | 21 +++++++++++++++++-- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/frontend/app/Router.js b/frontend/app/Router.js index 8bd3de882..4d6c9f941 100644 --- a/frontend/app/Router.js +++ b/frontend/app/Router.js @@ -126,7 +126,7 @@ class Router extends React.Component { } fetchInitialData = async () => { - await this.props.fetchUserInfo(), + await this.props.fetchUserInfo() await this.props.fetchSiteList() const { mstore } = this.props; mstore.initClient(); diff --git a/frontend/app/components/Client/Sites/NewSiteForm.js b/frontend/app/components/Client/Sites/NewSiteForm.js index 0a9dc81c7..75776e1f1 100644 --- a/frontend/app/components/Client/Sites/NewSiteForm.js +++ b/frontend/app/components/Client/Sites/NewSiteForm.js @@ -7,6 +7,9 @@ import { setSiteId } from 'Duck/site'; import { withRouter } from 'react-router-dom'; import styles from './siteForm.module.css'; import { confirm } from 'UI'; +import { clearSearch } from 'Duck/search'; +import { clearSearch as clearSearchLive } from 'Duck/liveSearch'; +import { withStore } from 'App/mstore'; @connect( (state) => ({ @@ -23,13 +26,17 @@ import { confirm } from 'UI'; pushNewSite, fetchList, setSiteId, + clearSearch, + clearSearchLive, } ) @withRouter +@withStore export default class NewSiteForm extends React.PureComponent { state = { existsError: false, }; + componentDidMount() { const { @@ -60,16 +67,10 @@ export default class NewSiteForm extends React.PureComponent { }); } else { this.props.save(this.props.site).then(() => { - this.props.fetchList().then(() => { - const { sites } = this.props; - const site = sites.last(); - if (!pathname.includes('/client')) { - this.props.setSiteId(site.get('id')); - } - this.props.onClose(null, site); - }); - - // this.props.pushNewSite(site) + this.props.onClose(null); + this.props.clearSearch(); + this.props.clearSearchLive(); + this.props.mstore.initClient(); }); } }; diff --git a/frontend/app/duck/site.js b/frontend/app/duck/site.js index f8be1a89f..08d04b70e 100644 --- a/frontend/app/duck/site.js +++ b/frontend/app/duck/site.js @@ -4,7 +4,8 @@ import { mergeReducers, createItemInListUpdater, success, - array + array, + createListUpdater, } from './funcTools/tools'; import { createCRUDReducer, @@ -15,6 +16,7 @@ import { createRemove, createUpdate, createSave, + saveType, } from './funcTools/crud'; import { createRequestReducer } from './funcTools/request'; import { Map, List, fromJS } from "immutable"; @@ -25,6 +27,7 @@ const storedSiteId = localStorage.getItem(SITE_ID_STORAGE_KEY); const name = 'project'; const idKey = 'id'; const itemInListUpdater = createItemInListUpdater(idKey) +const updateItemInList = createListUpdater(idKey); const EDIT_GDPR = 'sites/EDIT_GDPR'; const SAVE_GDPR = 'sites/SAVE_GDPR'; @@ -34,6 +37,7 @@ const SET_SITE_ID = 'sites/SET_SITE_ID'; const FETCH_GDPR_SUCCESS = success(FETCH_GDPR); const SAVE_GDPR_SUCCESS = success(SAVE_GDPR); const FETCH_LIST_SUCCESS = success(FETCH_LIST); +const SAVE = saveType('sites/SAVE'); const initialState = Map({ list: List(), @@ -49,6 +53,12 @@ const reducer = (state = initialState, action = {}) => { return state.mergeIn([ 'instance', 'gdpr' ], action.gdpr); case FETCH_GDPR_SUCCESS: return state.mergeIn([ 'instance', 'gdpr' ], action.data); + case success(SAVE): + console.log(action) + const newSite = Site(action.data); + return updateItemInList(state, newSite) + .set('siteId', newSite.get('id')) + .set('active', newSite); case SAVE_GDPR_SUCCESS: const gdpr = GDPR(action.data); return state.setIn([ 'instance', 'gdpr' ], gdpr); @@ -99,10 +109,17 @@ export function fetchList() { }; } +export function save(site) { + return { + types: array(SAVE), + call: client => client.post(`/projects`, site.toData()), + } +} + // export const fetchList = createFetchList(name); export const init = createInit(name); export const edit = createEdit(name); -export const save = createSave(name); +// export const save = createSave(name); export const update = createUpdate(name); export const remove = createRemove(name);