From 6d46efa61062b1d472c291a740077034f1f9bdbe Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 4 Mar 2022 11:53:27 +0100 Subject: [PATCH] accompanying course: fix posting of pinned comment --- .../vuejs/AccompanyingCourse/store/index.js | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index f7fd59b32..849a77289 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -203,9 +203,11 @@ let initPromise = (root) => Promise.all([getScopesPromise(root), accompanyingCou //console.log('### mutation: toggleConfidential'); state.accompanyingCourse.confidential = value; }, - postFirstComment(state, comment) { - //console.log('### mutation: postFirstComment', comment); - state.accompanyingCourse.pinnedComment = comment; + addPinnedComment(state, value) { + state.accompanyingCourse.pinnedComment = value; + }, + removePinnedComment(state, value) { + state.accompanyingCourse.pinnedComment = null; }, updateSocialIssues(state, value) { console.log('updateSocialIssues', value); @@ -337,6 +339,35 @@ let initPromise = (root) => Promise.all([getScopesPromise(root), accompanyingCou throw error; }) }, + /** + * Add/remove pinnedComment + */ + removePinnedComment({ commit, dispatch }) { + const body = {}; + const url = `/api/1.0/person/accompanying-course/${id}/comment.json`; + + return makeFetch('DELETE', url, body) + .then((response) => { + commit('removePinnedComment'); + }) + .catch((error) => { + commit('catchError', error); + throw error; + }) + }, + addPinnedComment({ commit, dispatch }, payload) { + const body = payload ? { type: payload.type, content: payload.content } : {}; + const url = `/api/1.0/person/accompanying-course/${id}/comment.json`; + + return makeFetch('POST', url, body) + .then((response) => { + dispatch('patchFirstComment', response); + }) + .catch((error) => { + commit('catchError', error); + throw error; + }) + }, /** * Add/remove/display anonymous requestor */ @@ -606,18 +637,23 @@ let initPromise = (root) => Promise.all([getScopesPromise(root), accompanyingCou return Promise.all(promises); }, - postFirstComment({ commit }, payload) { - const url = `/api/1.0/person/accompanying-course/${id}.json` - const body = { type: "accompanying_period", pinnedComment: payload } - + patchFirstComment({ commit }, payload) { + const url = `/api/1.0/person/accompanying-course/${id}.json`; + const body = { + type: "accompanying_period", + pinnedComment: { + type: "accompanying_period_comment", + id: payload.id + } + }; return makeFetch('PATCH', url, body) .then((response) => { - commit('postFirstComment', response.pinnedComment); + commit('addPinnedComment', response.pinnedComment); }) .catch((error) => { commit('catchError', error); throw error; - }) + }); }, updateSocialIssues({ state, commit, dispatch }, { payload, body, method }) { const url = `/api/1.0/person/accompanying-course/${id}/socialissue.json`;