diff --git a/app/javascript/retrospring/controllers/inbox_sharing_controller.ts b/app/javascript/retrospring/controllers/inbox_sharing_controller.ts new file mode 100644 index 00000000..bec8dd0e --- /dev/null +++ b/app/javascript/retrospring/controllers/inbox_sharing_controller.ts @@ -0,0 +1,48 @@ +import { Controller } from '@hotwired/stimulus'; + +export default class extends Controller { + static targets = ['twitter', 'tumblr', 'custom']; + + declare readonly twitterTarget: HTMLAnchorElement; + declare readonly tumblrTarget: HTMLAnchorElement; + declare readonly customTarget: HTMLAnchorElement; + declare readonly hasCustomTarget: boolean; + + static values = { + config: Object, + autoClose: Boolean + }; + + declare readonly configValue: Record; + declare readonly autoCloseValue: boolean; + + connect() { + if (this.autoCloseValue) { + this.twitterTarget.addEventListener('click', () => this.close()); + this.tumblrTarget.addEventListener('click', () => this.close()); + + if (this.hasCustomTarget) { + this.customTarget.addEventListener('click', () => this.close()); + } + } + } + + configValueChanged(value): void { + if (Object.keys(value).length === 0) { + return; + } + + this.element.classList.remove('d-none'); + + this.twitterTarget.href = this.configValue['twitter']; + this.tumblrTarget.href = this.configValue['tumblr']; + + if (this.hasCustomTarget) { + this.customTarget.href = `${this.customTarget.href}${this.configValue['custom']}`; + } + } + + close(): void { + (this.element.closest(".inbox-entry")).remove(); + } +} diff --git a/app/models/user/sharing_methods.rb b/app/models/user/sharing_methods.rb new file mode 100644 index 00000000..2c4e38b4 --- /dev/null +++ b/app/models/user/sharing_methods.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module User::SharingMethods + def display_sharing_custom_url + URI(sharing_custom_url).host + end +end diff --git a/db/migrate/20230205162103_enable_sharing_for_service_owners.rb b/db/migrate/20230205162103_enable_sharing_for_service_owners.rb new file mode 100644 index 00000000..f194722c --- /dev/null +++ b/db/migrate/20230205162103_enable_sharing_for_service_owners.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class EnableSharingForServiceOwners < ActiveRecord::Migration[6.1] + def up + execute <<~SQUIRREL + UPDATE users + SET sharing_enabled = true + WHERE id IN (SELECT user_id FROM services); + SQUIRREL + end + + def down; end +end