From 84b9840cb57e99bc6960b70feb7f90d779a21288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Garc=C3=ADa=20Isa=C3=ADa?= Date: Wed, 13 Nov 2024 18:17:30 -0300 Subject: [PATCH] Move API routes concerns back to api.js Those URLs in the RespondentIndex.jsx smelled. See #2350 --- assets/js/api.js | 11 +++++++++++ .../components/respondents/RespondentIndex.jsx | 16 +++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/assets/js/api.js b/assets/js/api.js index 85777fd84..49fc92c22 100644 --- a/assets/js/api.js +++ b/assets/js/api.js @@ -683,6 +683,17 @@ export const refreshDispositionHistoryLink = (projectId, surveyId) => { ) } +export const resultsFileUrl = (projectId, surveyId, q) => + `/api/v1/projects/${projectId}/surveys/${surveyId}/respondents/results_csv${ + (q && `?q=${encodeURIComponent(q)}`) || "" + }` +export const dispositionHistoryFileUrl = (projectId, surveyId) => + `/api/v1/projects/${projectId}/surveys/${surveyId}/respondents/disposition_history` +export const incentivesFileUrl = (projectId, surveyId) => + `/api/v1/projects/${projectId}/surveys/${surveyId}/respondents/incentives` +export const interactionsFileUrl = (projectId, surveyId) => + `/api/v1/projects/${projectId}/surveys/${surveyId}/respondents/interactions` + export const generateResults = (projectId, surveyId, filter) => apiPostJSON(`projects/${projectId}/surveys/${surveyId}/respondents/results`, null, { q: filter }) export const generateDispositionHistory = (projectId, surveyId) => diff --git a/assets/js/components/respondents/RespondentIndex.jsx b/assets/js/components/respondents/RespondentIndex.jsx index 039f15273..572834edc 100644 --- a/assets/js/components/respondents/RespondentIndex.jsx +++ b/assets/js/components/respondents/RespondentIndex.jsx @@ -164,24 +164,22 @@ class RespondentIndex extends Component { resultsFileUrl(applyUserFilter = false) { const { projectId, surveyId, filter } = this.props const q = (applyUserFilter && filter) || null - return `/api/v1/projects/${projectId}/surveys/${surveyId}/respondents/results_csv${ - (q && `?q=${encodeURIComponent(q)}`) || "" - }` + return api.resultsFileUrl(projectId, surveyId, q) } - + dispositionHistoryFileUrl() { const { projectId, surveyId } = this.props - return `/api/v1/projects/${projectId}/surveys/${surveyId}/respondents/disposition_history` + return api.dispositionHistoryFileUrl(projectId, surveyId) } - + incentivesFileUrl() { const { projectId, surveyId } = this.props - return `/api/v1/projects/${projectId}/surveys/${surveyId}/respondents/incentives` + return api.incentivesFileUrl(projectId, surveyId) } - + interactionsFileUrl() { const { projectId, surveyId } = this.props - return `/api/v1/projects/${projectId}/surveys/${surveyId}/respondents/interactions` + return api.interactionsFileUrl(projectId, surveyId) } sortBy(name) {