mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-12 10:11:38 -05:00
Refactor: Improve trip sharing UX with Turbo and better controls
Major improvements: 1. Use Turbo for sharing updates - no page reload, modal stays open 2. Add Stimulus copy button controller - clean implementation with 'Copied!' feedback 3. Allow updating notes/photos toggles without disabling sharing 4. Add 'Update Sharing' button to save changes while keeping sharing enabled 5. Use 'true'/'false' strings consistently instead of '1'/'0' 6. Update all request specs to use 'true'/'false' values Technical changes: - Wrap form in turbo_frame_tag for seamless updates - Controller responds with turbo_stream to replace form content - Create copy_button_controller.js for proper copy feedback - Checkboxes now editable when sharing is enabled - Separate 'Update Sharing' and 'Disable Sharing' actions
This commit is contained in:
parent
736aa15a1e
commit
0c538de698
4 changed files with 239 additions and 200 deletions
|
|
@ -42,7 +42,12 @@ class TripsController < ApplicationController
|
|||
# Handle sharing settings update
|
||||
if params[:trip] && params[:trip][:sharing]
|
||||
handle_sharing_update
|
||||
redirect_to @trip, notice: 'Trip was successfully updated.', status: :see_other and return
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream { render turbo_stream: turbo_stream.replace("sharing_form_#{@trip.id}", partial: 'trips/sharing', locals: { trip: @trip }) }
|
||||
format.html { redirect_to @trip, notice: 'Trip was successfully updated.', status: :see_other }
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
# Handle regular trip update
|
||||
|
|
|
|||
31
app/javascript/controllers/copy_button_controller.js
Normal file
31
app/javascript/controllers/copy_button_controller.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["button"]
|
||||
static values = { text: String }
|
||||
|
||||
copy(event) {
|
||||
event.preventDefault()
|
||||
const text = event.currentTarget.dataset.copyText
|
||||
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
const button = event.currentTarget
|
||||
const originalHTML = button.innerHTML
|
||||
|
||||
// Show "Copied!" feedback
|
||||
button.innerHTML = `
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
<span>Copied!</span>
|
||||
`
|
||||
|
||||
// Restore original content after 2 seconds
|
||||
setTimeout(() => {
|
||||
button.innerHTML = originalHTML
|
||||
}, 2000)
|
||||
}).catch(err => {
|
||||
console.error('Failed to copy text: ', err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -11,200 +11,203 @@
|
|||
Trip Sharing Settings
|
||||
</h3>
|
||||
|
||||
<%= form_with model: trip, url: trip_path(trip), method: :patch, data: { turbo: false } do |f| %>
|
||||
<% if trip.sharing_enabled? %>
|
||||
<!-- Sharing is enabled -->
|
||||
<div class="space-y-4">
|
||||
<!-- Sharing Status -->
|
||||
<div class="alert <%= trip.sharing_expired? ? 'alert-warning' : 'alert-success' %>">
|
||||
<% if trip.sharing_expired? %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg>
|
||||
<div>
|
||||
<h3 class="font-bold">Link Expired</h3>
|
||||
<p class="text-sm">This share link has expired and is no longer accessible</p>
|
||||
</div>
|
||||
<% else %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
|
||||
<div>
|
||||
<h3 class="font-bold">Sharing Active</h3>
|
||||
<p class="text-sm">This trip is publicly accessible via the link below</p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<%= turbo_frame_tag "sharing_form_#{trip.id}" do %>
|
||||
<%= form_with model: trip, url: trip_path(trip), method: :patch, id: "sharing_form_#{trip.id}" do |f| %>
|
||||
<% if trip.sharing_enabled? %>
|
||||
<!-- Sharing is enabled -->
|
||||
<div class="space-y-4">
|
||||
<!-- Sharing Status -->
|
||||
<div class="alert <%= trip.sharing_expired? ? 'alert-warning' : 'alert-success' %>">
|
||||
<% if trip.sharing_expired? %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg>
|
||||
<div>
|
||||
<h3 class="font-bold">Link Expired</h3>
|
||||
<p class="text-sm">This share link has expired and is no longer accessible</p>
|
||||
</div>
|
||||
<% else %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
|
||||
<div>
|
||||
<h3 class="font-bold">Sharing Active</h3>
|
||||
<p class="text-sm">This trip is publicly accessible via the link below</p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<!-- Sharing URL -->
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Sharing link</span>
|
||||
</label>
|
||||
<div class="join w-full">
|
||||
<input
|
||||
type="text"
|
||||
value="<%= shared_trip_url(trip.sharing_uuid) %>"
|
||||
readonly
|
||||
class="input input-bordered join-item flex-1"
|
||||
id="sharing-url-<%= trip.id %>">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline join-item"
|
||||
onclick="navigator.clipboard.writeText(document.getElementById('sharing-url-<%= trip.id %>').value).then(() => {
|
||||
const btn = this;
|
||||
const original = btn.innerHTML;
|
||||
btn.innerHTML = '<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"h-5 w-5\" viewBox=\"0 0 20 20\" fill=\"currentColor\"><path fill-rule=\"evenodd\" d=\"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z\" clip-rule=\"evenodd\" /></svg> Copied';
|
||||
setTimeout(() => btn.innerHTML = original, 2000);
|
||||
})">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" /></svg>
|
||||
Copy
|
||||
<!-- Sharing URL -->
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Sharing link</span>
|
||||
</label>
|
||||
<div class="join w-full">
|
||||
<input
|
||||
type="text"
|
||||
value="<%= shared_trip_url(trip.sharing_uuid) %>"
|
||||
readonly
|
||||
class="input input-bordered join-item flex-1"
|
||||
id="sharing-url-<%= trip.id %>">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline join-item gap-2"
|
||||
data-action="click->copy-button#copy"
|
||||
data-copy-button-target="button"
|
||||
data-copy-text="<%= shared_trip_url(trip.sharing_uuid) %>">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" /></svg>
|
||||
<span>Copy</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="label">
|
||||
<span class="label-text-alt">Share this link with others to give them access to your trip</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- View Public Page Button -->
|
||||
<div class="flex justify-center">
|
||||
<%= link_to shared_trip_path(trip.sharing_uuid), target: '_blank', class: 'btn btn-outline btn-primary gap-2' do %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
|
||||
</svg>
|
||||
View Public Page
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<!-- Sharing Options -->
|
||||
<div class="card bg-base-200">
|
||||
<div class="card-body p-4">
|
||||
<h4 class="font-semibold mb-3">What to share:</h4>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="form-control">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<%= check_box_tag 'trip[sharing][share_notes]', 'true', trip.share_notes?, class: 'toggle toggle-primary' %>
|
||||
<div>
|
||||
<span class="label-text font-medium block">Share trip notes</span>
|
||||
<span class="label-text-alt text-xs">Include your description and notes</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<%= check_box_tag 'trip[sharing][share_photos]', 'true', trip.share_photos?, class: 'toggle toggle-primary' %>
|
||||
<div>
|
||||
<span class="label-text font-medium block">Share photos</span>
|
||||
<span class="label-text-alt text-xs">Include photos from this trip</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-xs text-base-content/60 mt-3 p-2 bg-base-100 rounded">
|
||||
<strong>Always included:</strong> Trip name, dates, route map, distance, and countries visited
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Privacy Notice -->
|
||||
<div class="alert alert-info">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
|
||||
<div>
|
||||
<h3 class="font-bold">Privacy Protection</h3>
|
||||
<div class="text-sm">
|
||||
• Only selected information is shared<br>
|
||||
• Personal information and account details are never included<br>
|
||||
• You can disable sharing at any time
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<%= hidden_field_tag 'trip[sharing][enabled]', 'true' %>
|
||||
<div class="modal-action">
|
||||
<%= submit_tag "Update Sharing",
|
||||
class: "btn btn-primary" %>
|
||||
<%= submit_tag "Disable Sharing",
|
||||
name: 'trip[sharing][enabled]',
|
||||
value: 'false',
|
||||
class: "btn btn-error",
|
||||
data: { turbo_confirm: "Are you sure you want to disable sharing for this trip?" } %>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<!-- Sharing is disabled - Enable form -->
|
||||
<div class="space-y-4">
|
||||
<p class="text-base-content/70">
|
||||
Generate a public link to share this trip with friends, family, or on social media.
|
||||
</p>
|
||||
|
||||
<!-- Sharing Options -->
|
||||
<div class="card bg-base-200">
|
||||
<div class="card-body p-4">
|
||||
<h4 class="font-semibold mb-3">Choose what to share:</h4>
|
||||
|
||||
<div class="form-control mb-3">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Link expiration</span>
|
||||
</label>
|
||||
<%= select_tag 'trip[sharing][expiration]',
|
||||
options_for_select([
|
||||
['1 hour', '1h'],
|
||||
['12 hours', '12h'],
|
||||
['24 hours', '24h'],
|
||||
['Never (permanent)', 'permanent']
|
||||
], '24h'),
|
||||
class: 'select select-bordered w-full' %>
|
||||
<div class="label">
|
||||
<span class="label-text-alt">Choose how long the sharing link will remain active</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="divider my-2"></div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="form-control">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<%= check_box_tag 'trip[sharing][share_notes]', 'true', true, class: 'toggle toggle-primary' %>
|
||||
<div>
|
||||
<span class="label-text font-medium block">Share trip notes</span>
|
||||
<span class="label-text-alt text-xs">Include your description and notes</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<%= check_box_tag 'trip[sharing][share_photos]', 'true', true, class: 'toggle toggle-primary' %>
|
||||
<div>
|
||||
<span class="label-text font-medium block">Share photos</span>
|
||||
<span class="label-text-alt text-xs">Include photos from this trip</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-xs text-base-content/60 mt-3 p-2 bg-base-100 rounded">
|
||||
<strong>Always included:</strong> Trip name, dates, route map, distance, and countries visited
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Privacy Notice -->
|
||||
<div class="alert alert-info">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
|
||||
<div>
|
||||
<h3 class="font-bold">Privacy Protection</h3>
|
||||
<div class="text-sm">
|
||||
• Only selected information will be shared<br>
|
||||
• Personal information and account details are never included<br>
|
||||
• You can disable sharing at any time
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<%= hidden_field_tag 'trip[sharing][enabled]', 'true' %>
|
||||
<div class="modal-action">
|
||||
<button type="button" class="btn btn-ghost" onclick="sharing_modal_<%= trip.id %>.close()">
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
<div class="label">
|
||||
<span class="label-text-alt">Share this link with others to give them access to your trip</span>
|
||||
<%= submit_tag "Enable Sharing", class: "btn btn-primary" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- View Public Page Button -->
|
||||
<div class="flex justify-center">
|
||||
<%= link_to shared_trip_path(trip.sharing_uuid), target: '_blank', class: 'btn btn-outline btn-primary gap-2' do %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
|
||||
</svg>
|
||||
View Public Page
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<!-- Current Sharing Options Display -->
|
||||
<div class="card bg-base-200">
|
||||
<div class="card-body p-4">
|
||||
<h4 class="font-semibold mb-2">What's being shared:</h4>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<% if trip.share_notes? %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-success" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" /></svg>
|
||||
<% else %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-base-content/30" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" /></svg>
|
||||
<% end %>
|
||||
<span class="<%= trip.share_notes? ? 'text-base-content' : 'text-base-content/50' %>">Trip notes</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<% if trip.share_photos? %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-success" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" /></svg>
|
||||
<% else %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-base-content/30" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" /></svg>
|
||||
<% end %>
|
||||
<span class="<%= trip.share_photos? ? 'text-base-content' : 'text-base-content/50' %>">Photos</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-xs text-base-content/60 mt-2">
|
||||
Always included: Trip name, dates, route map, distance, and countries visited
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Privacy Notice -->
|
||||
<div class="alert alert-info">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
|
||||
<div>
|
||||
<h3 class="font-bold">Privacy Protection</h3>
|
||||
<div class="text-sm">
|
||||
• Only selected information is shared<br>
|
||||
• Personal information and account details are never included<br>
|
||||
• You can disable sharing at any time
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="modal-action">
|
||||
<%= submit_tag "Disable Sharing",
|
||||
name: 'trip[sharing][enabled]',
|
||||
value: '0',
|
||||
class: "btn btn-error",
|
||||
data: { turbo_confirm: "Are you sure you want to disable sharing for this trip?" } %>
|
||||
<button type="button" class="btn btn-primary" onclick="sharing_modal_<%= trip.id %>.close()">
|
||||
Done
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<!-- Sharing is disabled - Enable form -->
|
||||
<div class="space-y-4">
|
||||
<p class="text-base-content/70">
|
||||
Generate a public link to share this trip with friends, family, or on social media.
|
||||
</p>
|
||||
|
||||
<!-- Sharing Options -->
|
||||
<div class="card bg-base-200">
|
||||
<div class="card-body p-4">
|
||||
<h4 class="font-semibold mb-3">Choose what to share:</h4>
|
||||
|
||||
<div class="form-control mb-3">
|
||||
<label class="label">
|
||||
<span class="label-text font-medium">Link expiration</span>
|
||||
</label>
|
||||
<%= select_tag 'trip[sharing][expiration]',
|
||||
options_for_select([
|
||||
['1 hour', '1h'],
|
||||
['12 hours', '12h'],
|
||||
['24 hours', '24h'],
|
||||
['Never (permanent)', 'permanent']
|
||||
], '24h'),
|
||||
class: 'select select-bordered w-full' %>
|
||||
<div class="label">
|
||||
<span class="label-text-alt">Choose how long the sharing link will remain active</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="divider my-2"></div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="form-control">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<%= check_box_tag 'trip[sharing][share_notes]', '1', true, class: 'toggle toggle-primary' %>
|
||||
<div>
|
||||
<span class="label-text font-medium block">Share trip notes</span>
|
||||
<span class="label-text-alt text-xs">Include your description and notes</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<%= check_box_tag 'trip[sharing][share_photos]', '1', true, class: 'toggle toggle-primary' %>
|
||||
<div>
|
||||
<span class="label-text font-medium block">Share photos</span>
|
||||
<span class="label-text-alt text-xs">Include photos from this trip</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-xs text-base-content/60 mt-3 p-2 bg-base-100 rounded">
|
||||
<strong>Always included:</strong> Trip name, dates, route map, distance, and countries visited
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Privacy Notice -->
|
||||
<div class="alert alert-info">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
|
||||
<div>
|
||||
<h3 class="font-bold">Privacy Protection</h3>
|
||||
<div class="text-sm">
|
||||
• Only selected information will be shared<br>
|
||||
• Personal information and account details are never included<br>
|
||||
• You can disable sharing at any time
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<%= hidden_field_tag 'trip[sharing][enabled]', '1' %>
|
||||
<div class="modal-action">
|
||||
<button type="button" class="btn btn-ghost" onclick="sharing_modal_<%= trip.id %>.close()">
|
||||
Cancel
|
||||
</button>
|
||||
<%= submit_tag "Enable Sharing", class: "btn btn-primary" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ RSpec.describe 'Shared::Trips', type: :request do
|
|||
context 'enabling sharing' do
|
||||
it 'enables sharing and redirects to trip' do
|
||||
patch trip_path(trip),
|
||||
params: { trip: { sharing: { enabled: '1', expiration: '24h' } } }
|
||||
params: { trip: { sharing: { enabled: 'true', expiration: '24h' } } }
|
||||
|
||||
expect(response).to redirect_to(trip_path(trip))
|
||||
expect(flash[:notice]).to eq('Trip was successfully updated.')
|
||||
|
|
@ -131,7 +131,7 @@ RSpec.describe 'Shared::Trips', type: :request do
|
|||
|
||||
it 'enables sharing with notes option' do
|
||||
patch trip_path(trip),
|
||||
params: { trip: { sharing: { enabled: '1', expiration: '24h', share_notes: '1' } } }
|
||||
params: { trip: { sharing: { enabled: 'true', expiration: '24h', share_notes: 'true' } } }
|
||||
|
||||
expect(response).to redirect_to(trip_path(trip))
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ RSpec.describe 'Shared::Trips', type: :request do
|
|||
|
||||
it 'enables sharing with photos option' do
|
||||
patch trip_path(trip),
|
||||
params: { trip: { sharing: { enabled: '1', expiration: '24h', share_photos: '1' } } }
|
||||
params: { trip: { sharing: { enabled: 'true', expiration: '24h', share_photos: 'true' } } }
|
||||
|
||||
expect(response).to redirect_to(trip_path(trip))
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ RSpec.describe 'Shared::Trips', type: :request do
|
|||
|
||||
it 'sets custom expiration when provided' do
|
||||
patch trip_path(trip),
|
||||
params: { trip: { sharing: { enabled: '1', expiration: '1h' } } }
|
||||
params: { trip: { sharing: { enabled: 'true', expiration: '1h' } } }
|
||||
|
||||
expect(response).to redirect_to(trip_path(trip))
|
||||
trip.reload
|
||||
|
|
@ -163,7 +163,7 @@ RSpec.describe 'Shared::Trips', type: :request do
|
|||
|
||||
it 'enables permanent sharing' do
|
||||
patch trip_path(trip),
|
||||
params: { trip: { sharing: { enabled: '1', expiration: 'permanent' } } }
|
||||
params: { trip: { sharing: { enabled: 'true', expiration: 'permanent' } } }
|
||||
|
||||
expect(response).to redirect_to(trip_path(trip))
|
||||
trip.reload
|
||||
|
|
@ -179,7 +179,7 @@ RSpec.describe 'Shared::Trips', type: :request do
|
|||
|
||||
it 'disables sharing and redirects to trip' do
|
||||
patch trip_path(trip),
|
||||
params: { trip: { sharing: { enabled: '0' } } }
|
||||
params: { trip: { sharing: { enabled: 'false' } } }
|
||||
|
||||
expect(response).to redirect_to(trip_path(trip))
|
||||
expect(flash[:notice]).to eq('Trip was successfully updated.')
|
||||
|
|
@ -192,7 +192,7 @@ RSpec.describe 'Shared::Trips', type: :request do
|
|||
context 'when trip does not exist' do
|
||||
it 'returns not found' do
|
||||
patch trip_path(id: 999999),
|
||||
params: { trip: { sharing: { enabled: '1' } } }
|
||||
params: { trip: { sharing: { enabled: 'true' } } }
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
|
|
@ -204,7 +204,7 @@ RSpec.describe 'Shared::Trips', type: :request do
|
|||
|
||||
it 'returns not found' do
|
||||
patch trip_path(other_trip),
|
||||
params: { trip: { sharing: { enabled: '1' } } }
|
||||
params: { trip: { sharing: { enabled: 'true' } } }
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
|
|
@ -214,7 +214,7 @@ RSpec.describe 'Shared::Trips', type: :request do
|
|||
context 'when user is not signed in' do
|
||||
it 'returns unauthorized' do
|
||||
patch trip_path(trip),
|
||||
params: { trip: { sharing: { enabled: '1' } } }
|
||||
params: { trip: { sharing: { enabled: 'true' } } }
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue