From 8bc33a6790522c907cc599a03a04f6147a5884e1 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Thu, 25 Jun 2020 10:41:00 +0100 Subject: [PATCH] bugfix: duplicate model created when we click save twice --- packages/builder/src/builderStore/store/backend.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index e5e5413111..b7fbd04f4b 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -60,6 +60,10 @@ export const getBackendUiStore = () => { }, select: model => store.update(state => { + model = + typeof model === "string" + ? state.models.find(m => m._id === model) + : model state.selectedModel = model state.draftModel = cloneDeep(model) state.selectedField = "" @@ -69,10 +73,10 @@ export const getBackendUiStore = () => { }), save: async ({ model }) => { const updatedModel = cloneDeep(model) - const SAVE_MODEL_URL = `/api/models` - await api.post(SAVE_MODEL_URL, updatedModel) + const response = await api.post(SAVE_MODEL_URL, updatedModel) await store.actions.models.fetch() + store.actions.models.select((await response.json())._id) }, addField: field => { store.update(state => {