Skip to content
Snippets Groups Projects
Commit 8efed1bc authored by Chris Lawton's avatar Chris Lawton
Browse files

handle 404

parent ba6953c0
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
const lastEdited = '.js-last-edited'; const lastEdited = '.js-last-edited';
const editButton = '.js-edit-comment'; const editButton = '.js-edit-comment';
const feedContent = '.js-feed-content'; const feedContent = '.js-feed-content';
const commentError = '.js-comment-error';
const cancelEditButton = '.js-cancel-edit'; const cancelEditButton = '.js-cancel-edit';
const submitEditButton = '.js-submit-edit'; const submitEditButton = '.js-submit-edit';
...@@ -50,6 +51,9 @@ ...@@ -50,6 +51,9 @@
showComment(this); showComment(this);
showEditButton(this); showEditButton(this);
hidePageDownEditor(this); hidePageDownEditor(this);
if ((commentError).length) {
hideError();
}
}); });
// handle submit // handle submit
...@@ -58,7 +62,6 @@ ...@@ -58,7 +62,6 @@
const id = $(commentContainer).attr('data-id'); const id = $(commentContainer).attr('data-id');
const editedComment = $(this).closest(pageDown).find('.wmd-preview').html(); const editedComment = $(this).closest(pageDown).find('.wmd-preview').html();
const commentMD = $(this).closest(editBlock).find('textarea').val(); const commentMD = $(this).closest(editBlock).find('textarea').val();
$(commentContainer).attr('data-comment', commentMD);
// TODO - get correct URL // TODO - get correct URL
const url = `${window.location.origin}/apply/api/comments/${id}/edit/`; const url = `${window.location.origin}/apply/api/comments/${id}/edit/`;
...@@ -72,8 +75,15 @@ ...@@ -72,8 +75,15 @@
body: JSON.stringify({ body: JSON.stringify({
message: editedComment message: editedComment
}) })
}).then(response => response.json()).then(data => { }).then(response => {
updateComment(commentContainer, data.id, data.message); if (response.status === 404) {
$(this).closest(editBlock).append('<p class="wrapper--error js-comment-error"><b>Update unsuccessful</b>. This comment has been edited elsewhere - please refresh to get the latest updates.</p>');
$(this).attr('disabled', true);
return;
}
return response.json();
}).then(data => {
updateComment(commentContainer, data.id, data.message, commentMD);
updateLastEdited(this, data.edited); updateLastEdited(this, data.edited);
showComment(this); showComment(this);
showEditButton(this); showEditButton(this);
...@@ -106,9 +116,10 @@ ...@@ -106,9 +116,10 @@
$(el).closest(feedContent).find(lastEdited).html(`${parsedDate} ${time}`); $(el).closest(feedContent).find(lastEdited).html(`${parsedDate} ${time}`);
}; };
const updateComment = (el, id, newComment) => { const updateComment = (el, id, newComment, newCommentMD) => {
$(el).attr('data-id', id); $(el).attr('data-id', id);
$(el).html(newComment); $(el).html(newComment);
$(el).attr('data-comment', newCommentMD);
}; };
const closeAllEditors = () => { const closeAllEditors = () => {
...@@ -117,4 +128,6 @@ ...@@ -117,4 +128,6 @@
$(editButton).parent().show(); $(editButton).parent().show();
}; };
const hideError = () => $(commentError).remove();
})(jQuery); })(jQuery);
...@@ -89,6 +89,10 @@ ...@@ -89,6 +89,10 @@
margin: 0 auto 2rem; margin: 0 auto 2rem;
background: $color--light-pink; background: $color--light-pink;
border: 1px solid $color--tomato; border: 1px solid $color--tomato;
.feed & {
margin: 0 0 1rem;
}
} }
&--bottom-space { &--bottom-space {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment