save: fixed dialog

backend: fixed provider storing
This commit is contained in:
muerwre 2018-12-11 15:30:22 +07:00
parent 17baf8ac15
commit 7cdc1f4f95
5 changed files with 17 additions and 12 deletions

View file

@ -13,8 +13,11 @@ module.exports = async (req, res) => {
const route = parseRoute(body.route); const route = parseRoute(body.route);
const stickers = parseStickers(body.stickers); const stickers = parseStickers(body.stickers);
const logo = parseString(body.logo, 16); const logo = parseString(body.logo, 16);
const provider = parseString(body.provider, 16) || 'DEFAULT';
const distance = parseNumber(body.distance, 0, 1000); const distance = parseNumber(body.distance, 0, 1000);
console.log('SAVING PROVIDER?', provider, body.provider);
if ((!route || route.length <= 0) && (!stickers || stickers.length <= 0)) { if ((!route || route.length <= 0) && (!stickers || stickers.length <= 0)) {
return res.send({ success: false, mode: 'empty' }); return res.send({ success: false, mode: 'empty' });
} }
@ -26,7 +29,7 @@ module.exports = async (req, res) => {
if (exists) { if (exists) {
exists.set({ exists.set({
title, route, stickers, logo, distance, updated_at: Date.now(), title, route, stickers, logo, distance, updated_at: Date.now(), provider,
}).save(); }).save();
return res.send({ return res.send({
@ -35,14 +38,14 @@ module.exports = async (req, res) => {
} }
const created = await Route.create({ const created = await Route.create({
_id: address, title, route, stickers, owner, logo, distance, _id: address, title, route, stickers, owner, logo, distance, provider,
}); });
await owner.routes.push(created); await owner.routes.push(created);
await owner.save(); await owner.save();
return res.send({ return res.send({
success: true, title, address, route, stickers success: true, title, address, route, stickers, provider,
}); });
}; };

View file

@ -46,6 +46,7 @@ export function configureStore() {
} }
export const history = createBrowserHistory(); export const history = createBrowserHistory();
export const historyListener = history.listen(location => { export const historyListener = history.listen((location, action) => {
if (action === 'REPLACE') return;
store.dispatch(locationChanged(location.pathname)); store.dispatch(locationChanged(location.pathname));
}); });

View file

@ -18,7 +18,7 @@ import {
setSaveOverwrite, setSaveSuccess, setTitle, setSaveOverwrite, setSaveSuccess, setTitle,
setUser setUser
} from '$redux/user/actions'; } from '$redux/user/actions';
import { getUrlData, parseQuery, pushLoaderState, pushNetworkInitError, pushPath } from '$utils/history'; import { getUrlData, parseQuery, pushLoaderState, pushNetworkInitError, pushPath, replacePath } from '$utils/history';
import { editor } from '$modules/Editor'; import { editor } from '$modules/Editor';
import { ACTIONS } from '$redux/user/constants'; import { ACTIONS } from '$redux/user/constants';
import { MODES } from '$constants/modes'; import { MODES } from '$constants/modes';
@ -265,13 +265,13 @@ function* clearSaga({ type }) {
function* sendSaveRequestSaga({ title, address, force }) { function* sendSaveRequestSaga({ title, address, force }) {
if (editor.isEmpty) return yield put(setSaveError(TIPS.SAVE_EMPTY)); if (editor.isEmpty) return yield put(setSaveError(TIPS.SAVE_EMPTY));
const { route, stickers } = editor.dumpData(); const { route, stickers, provider } = editor.dumpData();
const { logo, distance } = yield select(getState); const { logo, distance } = yield select(getState);
const { id, token } = yield select(getUser); const { id, token } = yield select(getUser);
const { result, timeout, cancel } = yield race({ const { result, timeout, cancel } = yield race({
result: postMap({ result: postMap({
id, token, route, stickers, title, force, address, logo, distance, id, token, route, stickers, title, force, address, logo, distance, provider,
}), }),
timeout: delay(10000), timeout: delay(10000),
cancel: take(ACTIONS.RESET_SAVE_DIALOG), cancel: take(ACTIONS.RESET_SAVE_DIALOG),
@ -295,7 +295,8 @@ function* refreshUserData() {
function* setSaveSuccessSaga({ address, title }) { function* setSaveSuccessSaga({ address, title }) {
const { id } = yield select(getUser); const { id } = yield select(getUser);
pushPath(`/${address}/edit`); replacePath(`/${address}/edit`);
yield put(setTitle(title)); yield put(setTitle(title));
yield put(setAddress(address)); yield put(setAddress(address));

View file

@ -20,7 +20,7 @@ export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, {
}).then(result => (result && result.data && result.data.success && result.data)); }).then(result => (result && result.data && result.data.success && result.data));
export const postMap = ({ export const postMap = ({
title, address, route, stickers, id, token, force, logo, distance, title, address, route, stickers, id, token, force, logo, distance, provider,
}) => axios.post(API.POST_MAP, { }) => axios.post(API.POST_MAP, {
title, title,
address, address,
@ -31,6 +31,7 @@ export const postMap = ({
force, force,
logo, logo,
distance, distance,
provider,
}).then(result => (result && result.data && result.data)); }).then(result => (result && result.data && result.data));
export const checkIframeToken = ({ viewer_id, auth_key }) => axios.get(API.IFRAME_LOGIN_VK, { export const checkIframeToken = ({ viewer_id, auth_key }) => axios.get(API.IFRAME_LOGIN_VK, {

View file

@ -1,9 +1,8 @@
import { history } from '$redux/store'; import { history } from '$redux/store';
export const getPath = () => (window.location && window.location.pathname); export const getPath = () => (window.location && window.location.pathname);
export const pushPath = url => { export const pushPath = url => history.push(url);
return history.push(url); export const replacePath = url => history.replace(url);
};
export const getUrlData = (url = getPath()) => { export const getUrlData = (url = getPath()) => {
const [, path, mode] = url.split('/'); const [, path, mode] = url.split('/');