-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d00054a
commit 3011932
Showing
37 changed files
with
569 additions
and
212 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
class SocialProfilesController < ApplicationController | ||
skip_before_action :authenticate_user!, only: [:edit, :update] | ||
before_action :check_ownership, only: [:new, :create] | ||
before_action :check_provider, only: [:new] | ||
before_action :set_social_profile, only: [:edit, :update] | ||
|
||
def new | ||
@social_profile = @sociable.social_profiles.new(provider: params[:provider]) | ||
end | ||
|
||
def create | ||
@social_profile = @sociable.social_profiles.new(social_profile_params) | ||
|
||
begin | ||
ActiveRecord::Base.transaction do | ||
@social_profile.save! | ||
@suggestion = @social_profile.create_suggestion_from( | ||
params: @social_profile.attributes.slice("provider", "value"), | ||
new_record: true | ||
) | ||
end | ||
rescue ActiveRecord::RecordInvalid | ||
end | ||
|
||
respond_to do |format| | ||
if @suggestion&.persisted? | ||
flash[:notice] = "Saved" | ||
format.turbo_stream | ||
else | ||
format.turbo_stream { render :create, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
begin | ||
@suggestion = @social_profile.create_suggestion_from(params: social_profile_params, user: Current.user) | ||
rescue ActiveRecord::RecordInvalid | ||
end | ||
|
||
respond_to do |format| | ||
if @suggestion&.persisted? | ||
flash[:notice] = "Saved" | ||
format.turbo_stream | ||
else | ||
format.turbo_stream { render :update, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def social_profile_params | ||
params.require(:social_profile).permit( | ||
:provider, | ||
:value | ||
) | ||
end | ||
|
||
def set_social_profile | ||
@social_profile ||= SocialProfile.find(params[:id]) | ||
end | ||
|
||
def check_provider | ||
raise StandardError, "Invalid Social Provider" unless SocialProfile::PROVIDERS.include?(params[:provider]) | ||
end | ||
|
||
def check_ownership | ||
head :forbidden unless @sociable.managed_by?(Current.user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Speakers::SocialProfilesController < ::SocialProfilesController | ||
prepend_before_action :set_sociable | ||
|
||
private | ||
|
||
def set_sociable | ||
@sociable ||= Speaker.find_by!(slug: params[:speaker_slug]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%= turbo_frame_tag social_profile do %> | ||
<div class="flex items-center gap-x-2"> | ||
<span class="font-semibold">Add</span> | ||
<% SocialProfile::PROVIDERS.each do |provider| %> | ||
<%= ui_button url: new_polymorphic_path([sociable, social_profile], provider:), kind: :circle, size: :sm, class: "hover:bg-#{provider} hover:fill-white border-base-200" do %> | ||
<%= fab(provider, size: :md) %> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<%= turbo_frame_tag social_profile do %> | ||
<%= form_with(model: social_profile, url: url, class: "flex flex-col") do |form| %> | ||
<%= form.label :value, "#{form.object.provider.humanize} (URL/Handle/Username)" %> | ||
<div class="flex flex-col gap-x-1"> | ||
<span class="text-red-500"><%= social_profile.errors["value"] ? social_profile.errors["value"].first : "" %></span> | ||
<div class="flex items-center gap-x-2"> | ||
<%= form.hidden_field :provider, class: "input input-bordered w-full" %> | ||
<%= form.text_field :value, class: "input input-bordered w-full" %> | ||
<%= ui_button "Save", type: :submit %> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<%= turbo_stream.update "flashes" do %> | ||
<%= render "shared/flashes" %> | ||
<% end %> | ||
|
||
<% if @social_profile.persisted? %> | ||
<%= turbo_stream.update "socials" do %> | ||
<%= render "speakers/socials", speaker: @social_profile.sociable %> | ||
<% end %> | ||
|
||
<%= turbo_stream.append "social-profiles" do %> | ||
<%= render "social_profiles/form", social_profile: @social_profile, url: social_profile_path(@social_profile) %> | ||
<%= render "shared/new_profile", sociable: @social_profile.sociable, social_profile: SocialProfile.new %> | ||
<% end %> | ||
<% else %> | ||
<%= turbo_stream.replace @social_profile do %> | ||
<%= render "social_profiles/form", social_profile: @social_profile, url: speaker_social_profiles_path(@social_profile.sociable, @social_profile) %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= turbo_frame_tag @social_profile do %> | ||
<%= render "form", social_profile: @social_profile, url: social_profile_path(@social_profile) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= turbo_frame_tag @social_profile do %> | ||
<%= render "form", social_profile: @social_profile, url: speaker_social_profiles_path(@social_profile.sociable, @social_profile) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= turbo_stream.update "flashes" do %> | ||
<%= render "shared/flashes" %> | ||
<% end %> | ||
|
||
<%= turbo_stream.update "socials" do %> | ||
<%= render "speakers/socials", speaker: @social_profile.sociable %> | ||
<% end %> | ||
|
||
<%= turbo_stream.replace @social_profile do %> | ||
<%= render "social_profiles/form", social_profile: @social_profile, url: social_profile_path(@social_profile) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.