Skip to content

Commit

Permalink
Move API routes concerns back to api.js
Browse files Browse the repository at this point in the history
Those URLs in the RespondentIndex.jsx smelled.

See #2350
  • Loading branch information
matiasgarciaisaia committed Nov 13, 2024
1 parent b633f1a commit 84b9840
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
11 changes: 11 additions & 0 deletions assets/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
16 changes: 7 additions & 9 deletions assets/js/components/respondents/RespondentIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,22 @@ class RespondentIndex extends Component<Props, State> {
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) {
Expand Down

0 comments on commit 84b9840

Please sign in to comment.