fix(ui) - new site - update active site and clear date

This commit is contained in:
Shekar Siri 2022-09-16 20:30:13 +05:30
parent b909e16313
commit 02a3080c5b
3 changed files with 31 additions and 13 deletions

View file

@ -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();

View file

@ -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();
});
}
};

View file

@ -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);