Skip to content

Commit

Permalink
Apply PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaelbej committed Nov 21, 2024
1 parent cd2ead7 commit cf538cf
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion assets/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export const newWave = (projectId, panelSurveyId) => {

export const fetchActiveSurveys = (provider, baseUrl) => {
return apiFetchJSON(
`surveys/active_channel/${provider}?base_url=${encodeURIComponent(baseUrl)}`,
`surveys/active_channels/${provider}?base_url=${encodeURIComponent(baseUrl)}`,
)
}

Expand Down
13 changes: 11 additions & 2 deletions assets/js/components/channels/ChannelIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type State = {
modalSurveys: Array<Object>,
modalProvider: ?string,
modalIndex: ?number,
modalError: ?Object,
}

class ChannelIndex extends Component<any, State> {
Expand All @@ -41,6 +42,7 @@ class ChannelIndex extends Component<any, State> {
modalSurveys: [],
modalProvider: null,
modalIndex: null,
modalError: null,
}
}

Expand All @@ -62,6 +64,7 @@ class ChannelIndex extends Component<any, State> {
modalSurveys: [],
modalProvider: provider,
modalIndex: index,
modalError: null,
})
const { baseUrl } = config[provider][index]
api.fetchActiveSurveys(provider, baseUrl)
Expand All @@ -72,14 +75,17 @@ class ChannelIndex extends Component<any, State> {
modalSurveys: surveys,
modalProvider: provider,
modalIndex: index,
modalError: null,
})
})
.catch(() => {
.catch((error) => {
console.log(error)
this.setState({
modalLoading: false,
modalSurveys: [],
modalProvider: provider,
modalIndex: index,
modalError: error,
})
})
} else {
Expand Down Expand Up @@ -138,7 +144,8 @@ class ChannelIndex extends Component<any, State> {
modalSurveys,
modalProvider,
modalIndex,
} = this.state;
modalError,
} = this.state

if (!channels) {
return (
Expand Down Expand Up @@ -178,6 +185,7 @@ class ChannelIndex extends Component<any, State> {
const providerModal = (provider, index, friendlyName, multiple) => {
const loading = provider === modalProvider && index === modalIndex ? modalLoading : false
const surveys = provider === modalProvider && index === modalIndex ? modalSurveys : []
const error = provider === modalProvider && index === modalIndex ? modalError : null
return (
<ProviderModal
key={`${provider}-${index}`}
Expand All @@ -188,6 +196,7 @@ class ChannelIndex extends Component<any, State> {
onConfirm={() => this.deleteProvider(provider, index)}
loading={loading}
surveys={surveys}
error={error}
/>
)
}
Expand Down
5 changes: 4 additions & 1 deletion assets/js/components/channels/ProviderModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const ProviderModal = ({
onConfirm,
loading,
surveys,
error,
}) => {
let name = `${provider[0].toUpperCase()}${provider.slice(1)}`
if (multiple) name = `${name} (${friendlyName})`
Expand All @@ -29,6 +30,7 @@ export const ProviderModal = ({

<div className="provider-surveys">
{loading ? <span>{t("Searching active surveys...")}</span> :
error ? <span className="provider-error">{t("Error searching active surveys...")}</span> :
surveys.length == 0 ? <span>{t("No active surveys")}</span> :
<div>
<span>{t("These surveys are active, using channels from this provider. Deleting the channels will interrupt the surveys.")}</span>
Expand All @@ -54,7 +56,8 @@ ProviderModal.propTypes = {
multiple: PropTypes.bool,
onConfirm: PropTypes.func,
loading: PropTypes.bool,
surveys: PropTypes.any
surveys: PropTypes.any,
error: PropTypes.any,
}

export default translate()(ProviderModal)
4 changes: 4 additions & 0 deletions assets/vendor/css/materialize/components/_global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,7 @@ td, th{
}
}
}

.provider-error {
color: $input-error-color;
}
4 changes: 2 additions & 2 deletions lib/ask_web/controllers/survey_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ defmodule AskWeb.SurveyController do
end
end

def active_channel(conn, %{"provider" => provider, "base_url" => base_url}) do
surveys = Survey.with_active_channel(provider, base_url)
def active_channels(conn, %{"provider" => provider, "base_url" => base_url}) do
surveys = Survey.with_active_channels(provider, base_url)

render(conn, "index.json", surveys: surveys)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ask_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ defmodule AskWeb.Router do
get "/settings", UserController, :settings, as: :settings
post "/update_settings", UserController, :update_settings, as: :update_settings

get "/surveys/active_channel/:provider", SurveyController, :active_channel, as: :surveys_active_channel
get "/surveys/active_channels/:provider", SurveyController, :active_channels, as: :surveys_active_channels
end
end

Expand Down
3 changes: 2 additions & 1 deletion locales/template/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"Accepts refusals": "",
"Action": "",
"Active": "",
"Active surveys": "",
"Activity": "",
"Actual success rate": "",
"Actual success rate value throughout the survey's life": "",
Expand Down Expand Up @@ -171,6 +170,7 @@
"Error ID:": "",
"Error details": "",
"Error message": "",
"Error searching active surveys...": "",
"Error: CSV doesn't have a header for the primary language": "",
"Error: CSV is empty": "",
"Error: primary language name not found for code": "",
Expand Down Expand Up @@ -478,6 +478,7 @@
"The schedule of your survey restricts the days and hours during which respondents will be contacted. You can also specify re-contact attempts intervals.": "",
"The selected questionnaire will be sent over the survey channels to every respondent until a cutoff rule is reached. If you wish, you can try an experiment to compare questionnaires performance.": "",
"The system only accepts CSV files": "",
"These surveys are active, using channels from this provider. Deleting the channels will interrupt the surveys.": "",
"This is a wave of a panel survey. The settings from previous waves will be used as a template for this wave. Any changes made to this wave's settings will serve as a template for future waves of this panel survey": "",
"This question is not relevant for partial flag": "",
"This question is relevant for partial flag": "",
Expand Down
2 changes: 1 addition & 1 deletion test/ask/survey_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ defmodule Ask.SurveyTest do
setup_surveys_with_channels(surveys, channels)

active_surveys =
Survey.with_active_channel("sms", "test")
Survey.with_active_channels("sms", "test")
|> Enum.map(fn c -> c.id end)
|> Enum.sort()

Expand Down
2 changes: 1 addition & 1 deletion test/ask_web/controllers/survey_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3295,7 +3295,7 @@ defmodule AskWeb.SurveyControllerTest do
setup_surveys_with_channels(surveys, channels)
survey = Survey |> Repo.get(Enum.at(surveys, 1).id)

result = get(conn, surveys_active_channel_path(conn, :active_channel, "sms", base_url: "test"))
result = get(conn, surveys_active_channels_path(conn, :active_channels, "sms", base_url: "test"))

assert json_response(result, 200)["data"] == [
%{
Expand Down

0 comments on commit cf538cf

Please sign in to comment.