diff --git a/app/helpers/podcasts_helper.rb b/app/helpers/podcasts_helper.rb index ef3024ddf..f34ce0d25 100644 --- a/app/helpers/podcasts_helper.rb +++ b/app/helpers/podcasts_helper.rb @@ -101,4 +101,20 @@ def disable_non_compliant_language(language) language end end + + def subscribe_link_platform_label(link) + I18n.t("helpers.label.podcast.subscribe_link.#{link.platform}") + end + + def subscribe_link_id_label(link) + if link.uses_apple_id? + I18n.t("helpers.label.podcast.subscribe_link.id.apple") + elsif link.uses_unique_id? + I18n.t("helpers.label.podcast.subscribe_link.id.unique", platform: subscribe_link_platform_label(link)) + end + end + + def subscribe_link_enabled_label(link) + I18n.t("helpers.label.podcast.subscribe_link.enabled", platform: subscribe_link_platform_label(link)) + end end diff --git a/app/javascript/controllers/subscribe_links_controller.js b/app/javascript/controllers/subscribe_links_controller.js index 96cd4ee0e..571752142 100644 --- a/app/javascript/controllers/subscribe_links_controller.js +++ b/app/javascript/controllers/subscribe_links_controller.js @@ -5,9 +5,12 @@ export default class extends Controller { addLink(event) { const now = new Date().getTime() - console.log(event.target.value) const platform = event.target.value - const html = this.templateTarget.innerHTML.replaceAll("NEW_RECORD", now).replaceAll("NEW_PLATFORM", platform) + + const template = this.templateTargets.filter((target) => { + return target.dataset.platform === platform + }) + const html = template[0].innerHTML.replaceAll("NEW_RECORD", now).replaceAll("NEW_PLATFORM", platform) this.templateTarget.insertAdjacentHTML("beforeBegin", html) } } diff --git a/app/models/podcast.rb b/app/models/podcast.rb index 95f7afbd4..d1ff04d37 100644 --- a/app/models/podcast.rb +++ b/app/models/podcast.rb @@ -291,7 +291,7 @@ def only_one_of_each_link_platform if dupes.any? dupes.each do |p| - errors.add(:podcast, "cannot have more than one #{p} link") + errors.add(:podcast, "cannot have more than one #{I18n.t("helpers.label.podcast.subscribe_link.#{p}")} link") end end end diff --git a/app/models/subscribe_link.rb b/app/models/subscribe_link.rb index 043599074..9eeee47aa 100644 --- a/app/models/subscribe_link.rb +++ b/app/models/subscribe_link.rb @@ -19,4 +19,12 @@ class SubscribeLink < ApplicationRecord scope :with_platform_id, -> { where(platform: UNIQUE_PLATFORMS) } validates :external_id, presence: true + + def uses_apple_id? + APPLE_PLATFORMS.include?(platform) + end + + def uses_unique_id? + UNIQUE_PLATFORMS.include?(platform) + end end diff --git a/app/views/podcast_engagement/_form_subscribe_link.html.erb b/app/views/podcast_engagement/_form_subscribe_link.html.erb index fabab91c2..6325c015e 100644 --- a/app/views/podcast_engagement/_form_subscribe_link.html.erb +++ b/app/views/podcast_engagement/_form_subscribe_link.html.erb @@ -1,20 +1,20 @@ -