feat: Adds the ability to create a new article (#5255)

This commit is contained in:
Muhsin Keloth
2022-08-18 11:45:08 +05:30
committed by GitHub
parent 45d0d101b1
commit 0cd08065d1
9 changed files with 117 additions and 36 deletions

View File

@@ -32,13 +32,20 @@ export const actions = {
}
},
create: async ({ commit }, params) => {
create: async ({ commit, dispatch }, { portalSlug, ...articleObj }) => {
commit(types.SET_UI_FLAG, { isCreating: true });
try {
const { data } = await articlesAPI.create(params);
const { id: articleId } = data;
commit(types.ADD_ARTICLE, data);
const {
data: { payload },
} = await articlesAPI.createArticle({
portalSlug,
articleObj,
});
const { id: articleId, portal } = payload;
commit(types.ADD_ARTICLE, payload);
commit(types.ADD_ARTICLE_ID, articleId);
commit(types.ADD_ARTICLE_FLAG, articleId);
dispatch('portals/updatePortal', portal, { root: true });
return articleId;
} catch (error) {
return throwErrorMessage(error);
@@ -63,7 +70,7 @@ export const actions = {
}
},
update: async ({ commit }, { portalSlug, articleId, ...articleObj }) => {
commit(types.ADD_ARTICLE_FLAG, {
commit(types.UPDATE_ARTICLE_FLAG, {
uiFlags: {
isUpdating: true,
},
@@ -85,7 +92,7 @@ export const actions = {
} catch (error) {
return throwErrorMessage(error);
} finally {
commit(types.ADD_ARTICLE_FLAG, {
commit(types.UPDATE_ARTICLE_FLAG, {
uiFlags: {
isUpdating: false,
},
@@ -94,7 +101,7 @@ export const actions = {
}
},
delete: async ({ commit }, articleId) => {
commit(types.ADD_ARTICLE_FLAG, {
commit(types.UPDATE_ARTICLE_FLAG, {
uiFlags: {
isDeleting: true,
},
@@ -109,7 +116,7 @@ export const actions = {
} catch (error) {
return throwErrorMessage(error);
} finally {
commit(types.ADD_ARTICLE_FLAG, {
commit(types.UPDATE_ARTICLE_FLAG, {
uiFlags: {
isDeleting: false,
},