From cf538cff314defd978e7fec1917b6acbc53b73de Mon Sep 17 00:00:00 2001 From: Ismael Bejarano Date: Thu, 21 Nov 2024 19:54:07 -0300 Subject: [PATCH] Apply PR feedback --- assets/js/api.js | 2 +- assets/js/components/channels/ChannelIndex.jsx | 13 +++++++++++-- assets/js/components/channels/ProviderModal.jsx | 5 ++++- .../vendor/css/materialize/components/_global.scss | 4 ++++ lib/ask_web/controllers/survey_controller.ex | 4 ++-- lib/ask_web/router.ex | 2 +- locales/template/translation.json | 3 ++- test/ask/survey_test.exs | 2 +- test/ask_web/controllers/survey_controller_test.exs | 2 +- 9 files changed, 27 insertions(+), 10 deletions(-) diff --git a/assets/js/api.js b/assets/js/api.js index 3d021ddfe..244fdd01d 100644 --- a/assets/js/api.js +++ b/assets/js/api.js @@ -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)}`, ) } diff --git a/assets/js/components/channels/ChannelIndex.jsx b/assets/js/components/channels/ChannelIndex.jsx index 6ea8597bf..78442c540 100644 --- a/assets/js/components/channels/ChannelIndex.jsx +++ b/assets/js/components/channels/ChannelIndex.jsx @@ -29,6 +29,7 @@ type State = { modalSurveys: Array, modalProvider: ?string, modalIndex: ?number, + modalError: ?Object, } class ChannelIndex extends Component { @@ -41,6 +42,7 @@ class ChannelIndex extends Component { modalSurveys: [], modalProvider: null, modalIndex: null, + modalError: null, } } @@ -62,6 +64,7 @@ class ChannelIndex extends Component { modalSurveys: [], modalProvider: provider, modalIndex: index, + modalError: null, }) const { baseUrl } = config[provider][index] api.fetchActiveSurveys(provider, baseUrl) @@ -72,14 +75,17 @@ class ChannelIndex extends Component { 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 { @@ -138,7 +144,8 @@ class ChannelIndex extends Component { modalSurveys, modalProvider, modalIndex, - } = this.state; + modalError, + } = this.state if (!channels) { return ( @@ -178,6 +185,7 @@ class ChannelIndex extends Component { 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 ( { onConfirm={() => this.deleteProvider(provider, index)} loading={loading} surveys={surveys} + error={error} /> ) } diff --git a/assets/js/components/channels/ProviderModal.jsx b/assets/js/components/channels/ProviderModal.jsx index 9a4409de5..332af657b 100644 --- a/assets/js/components/channels/ProviderModal.jsx +++ b/assets/js/components/channels/ProviderModal.jsx @@ -11,6 +11,7 @@ export const ProviderModal = ({ onConfirm, loading, surveys, + error, }) => { let name = `${provider[0].toUpperCase()}${provider.slice(1)}` if (multiple) name = `${name} (${friendlyName})` @@ -29,6 +30,7 @@ export const ProviderModal = ({
{loading ? {t("Searching active surveys...")} : + error ? {t("Error searching active surveys...")} : surveys.length == 0 ? {t("No active surveys")} :
{t("These surveys are active, using channels from this provider. Deleting the channels will interrupt the surveys.")} @@ -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) diff --git a/assets/vendor/css/materialize/components/_global.scss b/assets/vendor/css/materialize/components/_global.scss index 86b54eb35..b974a78f1 100755 --- a/assets/vendor/css/materialize/components/_global.scss +++ b/assets/vendor/css/materialize/components/_global.scss @@ -801,3 +801,7 @@ td, th{ } } } + +.provider-error { + color: $input-error-color; +} diff --git a/lib/ask_web/controllers/survey_controller.ex b/lib/ask_web/controllers/survey_controller.ex index 71764189e..c5180f29a 100644 --- a/lib/ask_web/controllers/survey_controller.ex +++ b/lib/ask_web/controllers/survey_controller.ex @@ -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 diff --git a/lib/ask_web/router.ex b/lib/ask_web/router.ex index 377adb6e6..e266a660a 100644 --- a/lib/ask_web/router.ex +++ b/lib/ask_web/router.ex @@ -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 diff --git a/locales/template/translation.json b/locales/template/translation.json index 4cff033d8..07f02100a 100644 --- a/locales/template/translation.json +++ b/locales/template/translation.json @@ -16,7 +16,6 @@ "Accepts refusals": "", "Action": "", "Active": "", - "Active surveys": "", "Activity": "", "Actual success rate": "", "Actual success rate value throughout the survey's life": "", @@ -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": "", @@ -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": "", diff --git a/test/ask/survey_test.exs b/test/ask/survey_test.exs index 03799f323..e03b63963 100644 --- a/test/ask/survey_test.exs +++ b/test/ask/survey_test.exs @@ -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() diff --git a/test/ask_web/controllers/survey_controller_test.exs b/test/ask_web/controllers/survey_controller_test.exs index a91f3eb39..0db2a948b 100644 --- a/test/ask_web/controllers/survey_controller_test.exs +++ b/test/ask_web/controllers/survey_controller_test.exs @@ -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"] == [ %{