Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Show notes panel on crm page (#2320)
* Feat: Show notes panel on CRM page Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
- Loading branch information
1 parent
75d05e5
commit fe2af37
Showing
17 changed files
with
352 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import ApiClient from './ApiClient'; | ||
|
||
class ContactNotes extends ApiClient { | ||
constructor() { | ||
super('contact_notes', { accountScoped: true }); | ||
} | ||
} | ||
|
||
export default new ContactNotes(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
} | ||
|
||
.card { | ||
margin-bottom: var(--space-small); | ||
padding: var(--space-small); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/javascript/dashboard/modules/notes/NotesOnContactPage.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<template> | ||
<note-list :notes="notes" @add="onAdd" @delete="onDelete" /> | ||
</template> | ||
|
||
<script> | ||
import NoteList from './components/NoteList'; | ||
export default { | ||
components: { | ||
NoteList, | ||
}, | ||
props: { | ||
contactId: { | ||
type: Number, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
notes() { | ||
return this.$store.getters['contactNotes/getAllNotesByContact']( | ||
this.contactId | ||
); | ||
}, | ||
}, | ||
mounted() { | ||
this.fetchContactNotes(); | ||
}, | ||
methods: { | ||
fetchContactNotes() { | ||
const { contactId } = this; | ||
if (contactId) this.$store.dispatch('contactNotes/get', { contactId }); | ||
}, | ||
onAdd(content) { | ||
const { contactId } = this; | ||
this.$store.dispatch('contactNotes/create', { content, contactId }); | ||
}, | ||
onDelete(noteId) { | ||
const { contactId } = this; | ||
this.$store.dispatch('contactNotes/delete', { noteId, contactId }); | ||
}, | ||
}, | ||
}; | ||
</script> |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rd/contacts/components/AddNote.stories.js → .../modules/notes/stories/AddNote.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ontacts/components/ContactNote.stories.js → ...ules/notes/stories/ContactNote.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...d/contacts/components/NoteList.stories.js → ...modules/notes/stories/NoteList.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import * as types from '../mutation-types'; | ||
import Vue from 'vue'; | ||
import ContactNotesAPI from '../../api/contactNotes'; | ||
|
||
export const state = { | ||
records: {}, | ||
uiFlags: { | ||
isFetching: false, | ||
isCreating: false, | ||
isDeleting: false, | ||
}, | ||
}; | ||
|
||
export const getters = { | ||
getAllNotesByContact: _state => contactId => { | ||
return _state.records[contactId] || []; | ||
}, | ||
getUIFlags(_state) { | ||
return _state.uiFlags; | ||
}, | ||
}; | ||
|
||
export const actions = { | ||
async get({ commit }, { contactId }) { | ||
commit(types.default.SET_CONTACT_NOTES_UI_FLAG, { | ||
isFetching: true, | ||
}); | ||
try { | ||
const { data } = await ContactNotesAPI.get(contactId); | ||
commit(types.default.SET_CONTACT_NOTES, { contactId, data }); | ||
} catch (error) { | ||
throw new Error(error); | ||
} finally { | ||
commit(types.default.SET_CONTACT_NOTES_UI_FLAG, { | ||
isFetching: false, | ||
}); | ||
} | ||
}, | ||
|
||
async create({ commit }, { contactId, content }) { | ||
commit(types.default.SET_CONTACT_NOTES_UI_FLAG, { | ||
isCreating: true, | ||
}); | ||
try { | ||
const { data } = await ContactNotesAPI.create({ | ||
content, | ||
contactId, | ||
}); | ||
commit(types.default.ADD_CONTACT_NOTE, { | ||
contactId, | ||
data, | ||
}); | ||
} catch (error) { | ||
throw new Error(error); | ||
} finally { | ||
commit(types.default.SET_CONTACT_NOTES_UI_FLAG, { | ||
isCreating: false, | ||
}); | ||
} | ||
}, | ||
|
||
async delete({ commit }, { noteId, contactId }) { | ||
commit(types.default.SET_CONTACT_NOTES_UI_FLAG, { | ||
isDeleting: true, | ||
}); | ||
try { | ||
await ContactNotesAPI.delete(contactId, noteId); | ||
commit(types.default.DELETE_CONTACT_NOTE, { contactId, noteId }); | ||
} catch (error) { | ||
throw new Error(error); | ||
} finally { | ||
commit(types.default.SET_CONTACT_NOTES_UI_FLAG, { | ||
isDeleting: false, | ||
}); | ||
} | ||
}, | ||
}; | ||
|
||
export const mutations = { | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG](_state, data) { | ||
_state.uiFlags = { | ||
..._state.uiFlags, | ||
...data, | ||
}; | ||
}, | ||
|
||
[types.default.SET_CONTACT_NOTES]($state, { data, contactId }) { | ||
Vue.set($state.records, contactId, data); | ||
}, | ||
[types.default.ADD_CONTACT_NOTE]($state, { data, contactId }) { | ||
const contactNotes = $state.records[contactId] || []; | ||
$state.records[contactId] = [...contactNotes, data]; | ||
}, | ||
[types.default.DELETE_CONTACT_NOTE]($state, { noteId, contactId }) { | ||
const contactNotes = $state.records[contactId]; | ||
const withoutDeletedNote = contactNotes.filter(note => note.id !== noteId); | ||
$state.records[contactId] = [...withoutDeletedNote]; | ||
}, | ||
}; | ||
|
||
export default { | ||
namespaced: true, | ||
state, | ||
getters, | ||
actions, | ||
mutations, | ||
}; |
78 changes: 78 additions & 0 deletions
78
app/javascript/dashboard/store/modules/specs/contactNotes/actions.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import axios from 'axios'; | ||
import { actions } from '../../contactNotes'; | ||
import * as types from '../../../mutation-types'; | ||
import notesData from './fixtures'; | ||
|
||
const commit = jest.fn(); | ||
global.axios = axios; | ||
jest.mock('axios'); | ||
|
||
describe('#actions', () => { | ||
describe('#get', () => { | ||
it('sends correct actions if API is success', async () => { | ||
axios.get.mockResolvedValue({ data: notesData }); | ||
await actions.get({ commit }, { contactId: 23 }); | ||
expect(commit.mock.calls).toEqual([ | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isFetching: true }], | ||
[types.default.SET_CONTACT_NOTES, { contactId: 23, data: notesData }], | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isFetching: false }], | ||
]); | ||
}); | ||
it('sends correct actions if API is error', async () => { | ||
axios.get.mockRejectedValue({ message: 'Incorrect header' }); | ||
await expect(actions.get({ commit }, { contactId: 23 })).rejects.toThrow( | ||
Error | ||
); | ||
expect(commit.mock.calls).toEqual([ | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isFetching: true }], | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isFetching: false }], | ||
]); | ||
}); | ||
}); | ||
describe('#create', () => { | ||
it('sends correct actions if API is success', async () => { | ||
axios.post.mockResolvedValue({ data: { id: 2, content: 'hi' } }); | ||
await actions.create({ commit }, { contactId: 1, content: 'hi' }); | ||
expect(commit.mock.calls).toEqual([ | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isCreating: true }], | ||
[ | ||
types.default.ADD_CONTACT_NOTE, | ||
{ contactId: 1, data: { id: 2, content: 'hi' } }, | ||
], | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isCreating: false }], | ||
]); | ||
}); | ||
it('sends correct actions if API is error', async () => { | ||
axios.post.mockRejectedValue({ message: 'Incorrect header' }); | ||
await expect( | ||
actions.create({ commit }, { contactId: 1, content: 'hi' }) | ||
).rejects.toThrow(Error); | ||
expect(commit.mock.calls).toEqual([ | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isCreating: true }], | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isCreating: false }], | ||
]); | ||
}); | ||
}); | ||
|
||
describe('#delete', () => { | ||
it('sends correct actions if API is success', async () => { | ||
axios.delete.mockResolvedValue({ data: notesData[0] }); | ||
await actions.delete({ commit }, { contactId: 1, noteId: 2 }); | ||
expect(commit.mock.calls).toEqual([ | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isDeleting: true }], | ||
[types.default.DELETE_CONTACT_NOTE, { contactId: 1, noteId: 2 }], | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isDeleting: false }], | ||
]); | ||
}); | ||
it('sends correct actions if API is error', async () => { | ||
axios.delete.mockRejectedValue({ message: 'Incorrect header' }); | ||
await expect( | ||
actions.delete({ commit }, { contactId: 1, noteId: 2 }) | ||
).rejects.toThrow(Error); | ||
expect(commit.mock.calls).toEqual([ | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isDeleting: true }], | ||
[types.default.SET_CONTACT_NOTES_UI_FLAG, { isDeleting: false }], | ||
]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.