Skip to content

Commit

Permalink
feat: fix issue with redirect when message fails to create
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsey committed Jan 5, 2022
1 parent 727a831 commit 75cd5e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const usersApi = {
}

export const messagesApi = {
create: data => $http('/api/messages', { method: 'POST', data }),
create: data => $http('/api/messages', { method: 'POST', data }, true),
page: params => $http('/api/messages', { params }),
pageIgnored: params => $http('/api/messages/ignored', { params }),
ignore: data => $http('/api/messages/ignore', { method: 'POST', data }),
Expand All @@ -180,7 +180,7 @@ export const messagesApi = {
updateMessageDraft: draft => $http('/api/messages/draft', { method: 'PUT', data: { draft } }),
convos: {
page: (id, params) => $http(`/api/conversations/${id}`, { params }),
create: data => $http('/api/conversations', { method: 'POST', data }),
create: data => $http('/api/conversations', { method: 'POST', data }, true),
delete: id => $http(`/api/conversations/${id}`, { method: 'DELETE' })
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/layout/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@
<button class="inverted-button cancel" @click="cancel()">
Cancel
</button>
<button class="no-animate send" v-if="editorConvoMode" @click.prevent="createAction(newMessage).then(closeEditor)" :disabled="!canCreate() || !newMessage?.content?.body?.length || !newMessage?.content?.subject?.length || !newMessage?.receiver_ids?.length">
<button class="no-animate send" v-if="editorConvoMode" @click.prevent="createAction(newMessage).then(() => true).catch(() => false).then(c => c ? closeEditor() : null)" :disabled="!canCreate() || !newMessage?.content?.body?.length || !newMessage?.content?.subject?.length || !newMessage?.receiver_ids?.length">
<i class="fa fa-paper-plane" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Send
</button>
<button class="no-animate send" v-if="!editorConvoMode" @click.prevent="updateAction(newMessage).then(closeEditor)" :disabled="!canUpdate() || !newMessage?.content?.body?.length">
<button class="no-animate send" v-if="!editorConvoMode" @click.prevent="updateAction(newMessage).then(() => true).catch(() => false).then(c => c ? closeEditor() : null)" :disabled="!canUpdate() || !newMessage?.content?.body?.length">
<i class="fa fa-paper-plane" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Send Reply
</button>

Expand All @@ -207,7 +207,7 @@
<button class="inverted-button cancel" @click="cancel()">
Cancel
</button>
<button class="send" @click.prevent="post?.id ? updateAction(posting.post).then(closeEditor) : createAction(posting.post).then(closeEditor)" :disabled="post?.id ? !canUpdate(post) : !canCreate()">
<button class="send" @click.prevent="post?.id ? updateAction(posting.post).then(() => true).catch(() => false).then(c => c ? closeEditor() : null) : createAction(posting.post).then(() => true).catch(() => false).then(c => c ? closeEditor() : null)" :disabled="post?.id ? !canUpdate(post) : !canCreate()">
<i class="fa fa-paper-plane" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;{{ posting?.post?.id ? 'Edit Post' : 'Create Reply' }}
</button>

Expand All @@ -219,7 +219,7 @@
<button class="inverted-button cancel" @click="cancel()">
Cancel
</button>
<button class="send" @click.prevent="createAction(threadCopy).then(closeEditor);" :disabled="!threadCopy?.title.length || !canCreate() || (threadCopy?.addPoll && !threadCopy.pollValid)">
<button class="send" @click.prevent="createAction(threadCopy).then(() => true).catch(() => false).then(c => c ? closeEditor() : null);" :disabled="!threadCopy?.title.length || !canCreate() || (threadCopy?.addPoll && !threadCopy.pollValid)">
<i class="fa fa-paper-plane" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Start Thread
</button>

Expand Down
3 changes: 2 additions & 1 deletion src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const routes = [
path: '/messages',
name: 'Messages',
component: Messages,
meta: { requiresAuth: true, bodyClass: 'messages' }
meta: { requiresAuth: true, ignoreAxiosInterceptor: true, bodyClass: 'messages' }
},
{
path: '/mentions',
Expand Down Expand Up @@ -228,6 +228,7 @@ $axios.interceptors.response.use(res => res, err => {
if (router.currentRoute._value.meta.requiresAuth) router.push({ name: 'Login'})
break
case 403:
if (router.currentRoute._value.meta.ignoreAxiosInterceptor) break
if (err.response.statusText === 'Forbidden' || err.response.data.error === 'Forbidden') {
router.push({ name: 'Forbidden'})
}
Expand Down

0 comments on commit 75cd5e5

Please sign in to comment.