From e0dc0a8fdb33c9c93776bbbcc9b56ef6928a7c41 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 17 May 2021 15:56:58 +0200 Subject: [PATCH] add Comment component, make POST comment request --- .../Resources/public/vuejs/_js/i18n.js | 3 +- .../public/vuejs/AccompanyingCourse/App.vue | 3 + .../public/vuejs/AccompanyingCourse/api.js | 21 +++-- .../AccompanyingCourse/components/Comment.vue | 76 +++++++++++++++++++ .../vuejs/AccompanyingCourse/js/i18n.js | 4 + .../vuejs/AccompanyingCourse/store/index.js | 13 +++- 6 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.js index e36cbda79..dee070804 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.js @@ -14,9 +14,8 @@ const datetimeFormats = { }, long: { year: "numeric", - month: "short", + month: "numeric", day: "numeric", - weekday: "short", hour: "numeric", minute: "numeric", hour12: false diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue index abc4df337..7a2427b5a 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue @@ -3,6 +3,7 @@ + @@ -13,6 +14,7 @@ import AccompanyingCourse from './components/AccompanyingCourse.vue'; import PersonsAssociated from './components/PersonsAssociated.vue'; import Requestor from './components/Requestor.vue'; import Resources from './components/Resources.vue'; +import Comment from './components/Comment.vue'; //import Test from './components/Test.vue'; export default { @@ -22,6 +24,7 @@ export default { PersonsAssociated, Requestor, Resources, + Comment, //Test }, computed: mapState([ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js index 34eee3f8f..40e883968 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js @@ -121,18 +121,27 @@ const postResource = (id, payload, method) => { /* * Endpoint v.2 chill_api_single_accompanying_course_comment, -* method POST/DELETE, add/remove a comment to the accompanyingCourse +* method POST/DELETE/PATCH, add/remove a comment to the accompanyingCourse * * @id integer - id of accompanyingCourse * @payload -* @method string - POST or DELETE +* @method string - POST, DELETE or PATCH */ -const postComment = (id, payload, method) => { +const postComment = (id, payload) => { console.log('payload', payload); + const body = { type: "accompanying_period_comment" }; + switch (payload.method) { + case 'POST': + body['content'] = payload.content; + break; + case 'DELETE': + body['id'] = 42; + break; + } console.log('body', body); - const url = `/1.0/person/accompanying-course/${id}/comment.json`; + const url = `/api/1.0/person/accompanying-course/${id}/comment.json`; return fetch(url, { - method: method, + method: payload.method, headers: { 'Content-Type': 'application/json;charset=utf-8' }, @@ -142,7 +151,7 @@ const postComment = (id, payload, method) => { if (response.ok) { return response.json(); } throw Error('Error with request resource response'); }); -} +}; export { getAccompanyingCourse, diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue new file mode 100644 index 000000000..b34b0d701 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue @@ -0,0 +1,76 @@ + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js index c4d3d1df1..fd83eaf3f 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/js/i18n.js @@ -54,6 +54,10 @@ const appMessages = { text: "Dénomination", description: "Description", add_resources: "Ajouter des interlocuteurs", + }, + comment: { + title: "Ajout d'une note", + content: "Rédigez une première note..." } } }; 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 20305336c..950fba9f1 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -4,7 +4,8 @@ import { getAccompanyingCourse, patchAccompanyingCourse, postParticipation, postRequestor, - postResource } from '../api'; + postResource, + postComment } from '../api'; const debug = process.env.NODE_ENV !== 'production'; const id = window.accompanyingCourseId; @@ -68,6 +69,9 @@ let initPromise = getAccompanyingCourse(id) toggleConfidential(state, value) { //console.log('### mutation: toggleConfidential'); state.accompanyingCourse.confidential = value; + }, + postFirstComment(state, comment) { + state.accompanyingCourse.comments.push(comment); } }, actions: { @@ -145,6 +149,13 @@ let initPromise = getAccompanyingCourse(id) commit('toggleConfidential', course.confidential); resolve(); })).catch((error) => { commit('catchError', error) }); + }, + postFirstComment({ commit }, payload) { + postComment(id, payload) + .then(comment => new Promise((resolve, reject) => { + commit('postFirstComment', comment); + resolve(); + })).catch((error) => { commit('catchError', error) }); } } });