bugfix: duplicate model created when we click save twice

This commit is contained in:
Michael Shanks 2020-06-25 10:41:00 +01:00
parent 51d9f23aee
commit 4315d25d66
1 changed files with 6 additions and 2 deletions

View File

@ -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 => {