Skip to content

Commit

Permalink
Fix automatic camel casing of subscriber attribs on the UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Sep 18, 2021
1 parent 8733b20 commit f1fbcd4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion frontend/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ http.interceptors.response.use((resp) => {
// Transform field case.
data = humps.camelizeKeys(resp.data.data);
}

if (resp.config.preserveCase && resp.config.preserveResultsCase) {
resp.data.data.results.forEach((r, n) => {
// Only preserve case for certain keys under the 'results' key.
const save = {};
resp.config.preserveResultsCase.forEach((key) => {
save[key] = JSON.stringify(r[key]);
});

const item = humps.camelizeKeys(r);
Object.keys(save).forEach((key) => {
item[key] = JSON.parse(save[key]);
});

data.results[n] = item;
});
}
} else {
data = resp.data.data;
}
Expand Down Expand Up @@ -111,7 +128,13 @@ export const deleteList = (id) => http.delete(`/api/lists/${id}`,

// Subscribers.
export const getSubscribers = async (params) => http.get('/api/subscribers',
{ params, loading: models.subscribers, store: models.subscribers });
{
params,
loading: models.subscribers,
store: models.subscribers,
preserveCase: true,
preserveResultsCase: ['attribs'],
});

export const getSubscriber = async (id) => http.get(`/api/subscribers/${id}`,
{ loading: models.subscribers });
Expand Down

0 comments on commit f1fbcd4

Please sign in to comment.