feat: add media view for contacts (#14393)
This commit is contained in:
@@ -2,12 +2,12 @@ import {
|
||||
DuplicateContactException,
|
||||
ExceptionWithMessage,
|
||||
} from 'shared/helpers/CustomErrors';
|
||||
import types from '../../mutation-types';
|
||||
import ContactAPI from '../../../api/contacts';
|
||||
import snakecaseKeys from 'snakecase-keys';
|
||||
import AccountActionsAPI from '../../../api/accountActions';
|
||||
import ContactAPI from '../../../api/contacts';
|
||||
import AnalyticsHelper from '../../../helper/AnalyticsHelper';
|
||||
import { CONTACTS_EVENTS } from '../../../helper/AnalyticsHelper/events';
|
||||
import types from '../../mutation-types';
|
||||
|
||||
const buildContactFormData = contactParams => {
|
||||
const formData = new FormData();
|
||||
@@ -114,6 +114,19 @@ export const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
fetchAttachments: async ({ commit }, id) => {
|
||||
commit(types.SET_CONTACT_UI_FLAG, { isFetchingAttachments: true });
|
||||
try {
|
||||
const response = await ContactAPI.getAttachments(id);
|
||||
commit(types.SET_CONTACT_ATTACHMENTS, {
|
||||
id,
|
||||
data: response.data.payload,
|
||||
});
|
||||
} finally {
|
||||
commit(types.SET_CONTACT_UI_FLAG, { isFetchingAttachments: false });
|
||||
}
|
||||
},
|
||||
|
||||
update: async ({ commit }, { id, isFormData = false, ...contactParams }) => {
|
||||
const { avatar, customAttributes, ...paramsToDecamelize } = contactParams;
|
||||
const decamelizedContactParams = {
|
||||
|
||||
@@ -24,6 +24,7 @@ export const getters = {
|
||||
stopPaths: ['custom_attributes'],
|
||||
});
|
||||
},
|
||||
getContactAttachments: $state => id => $state.records[id]?.attachments || [],
|
||||
getMeta: $state => {
|
||||
return $state.meta;
|
||||
},
|
||||
|
||||
@@ -58,7 +58,15 @@ export const mutations = {
|
||||
},
|
||||
|
||||
[types.EDIT_CONTACT]: ($state, data) => {
|
||||
$state.records[data.id] = data;
|
||||
const existingAttachments = $state.records[data.id]?.attachments;
|
||||
$state.records[data.id] = existingAttachments
|
||||
? { ...data, attachments: existingAttachments }
|
||||
: data;
|
||||
},
|
||||
|
||||
[types.SET_CONTACT_ATTACHMENTS]: ($state, { id, data }) => {
|
||||
if (!$state.records[id]) $state.records[id] = {};
|
||||
$state.records[id].attachments = data;
|
||||
},
|
||||
|
||||
[types.DELETE_CONTACT]: ($state, id) => {
|
||||
|
||||
Reference in New Issue
Block a user