mirror of
https://codeberg.org/JasterV/spazio-solazzo.git
synced 2026-04-26 18:20:03 +00:00
make credo happy
This commit is contained in:
parent
f507d94f87
commit
78de759d96
2 changed files with 28 additions and 26 deletions
|
|
@ -65,7 +65,7 @@ defmodule SpazioSolazzo.CalendarExt do
|
|||
@doc """
|
||||
Checks if a booking spans multiple days
|
||||
"""
|
||||
def is_multi_day?(%DateTime{} = start_datetime, %DateTime{} = end_datetime) do
|
||||
def multi_day?(%DateTime{} = start_datetime, %DateTime{} = end_datetime) do
|
||||
start_date = DateTime.to_date(start_datetime)
|
||||
end_date = DateTime.to_date(end_datetime)
|
||||
Date.compare(start_date, end_date) != :eq
|
||||
|
|
@ -78,7 +78,7 @@ defmodule SpazioSolazzo.CalendarExt do
|
|||
Multi-day: "Feb 10, 2026 9:00 AM - Feb 15, 2026 5:00 PM"
|
||||
"""
|
||||
def format_datetime_range(%DateTime{} = start_datetime, %DateTime{} = end_datetime) do
|
||||
if is_multi_day?(start_datetime, end_datetime) do
|
||||
if multi_day?(start_datetime, end_datetime) do
|
||||
"#{format_datetime_date(start_datetime)} #{format_time(start_datetime)} - #{format_datetime_date(end_datetime)} #{format_time(end_datetime)}"
|
||||
else
|
||||
"#{format_datetime_date(start_datetime)} #{format_time_range(start_datetime, end_datetime)}"
|
||||
|
|
@ -102,7 +102,7 @@ defmodule SpazioSolazzo.CalendarExt do
|
|||
Multi-day: "Feb 15, 2026 5:00 PM"
|
||||
"""
|
||||
def format_datetime_range_end(%DateTime{} = start_datetime, %DateTime{} = end_datetime) do
|
||||
if is_multi_day?(start_datetime, end_datetime) do
|
||||
if multi_day?(start_datetime, end_datetime) do
|
||||
"#{format_datetime_date(end_datetime)} #{format_time(end_datetime)}"
|
||||
else
|
||||
format_time(end_datetime)
|
||||
|
|
|
|||
|
|
@ -7,29 +7,7 @@ defmodule SpazioSolazzoWeb.BookingCancellationLive do
|
|||
def mount(%{"token" => token}, _session, socket) do
|
||||
case Token.verify(token) do
|
||||
{:ok, %{booking_id: booking_id, action: :cancel}} ->
|
||||
case Ash.get(SpazioSolazzo.BookingSystem.Booking, booking_id, load: [:space]) do
|
||||
{:ok, booking} ->
|
||||
if booking.state in [:requested, :accepted] do
|
||||
{:ok,
|
||||
assign(socket,
|
||||
booking: booking,
|
||||
token: token,
|
||||
cancellation_reason: "",
|
||||
show_success: false
|
||||
)}
|
||||
else
|
||||
{:ok,
|
||||
socket
|
||||
|> put_flash(:error, "This booking has already been cancelled or completed")
|
||||
|> push_navigate(to: "/")}
|
||||
end
|
||||
|
||||
{:error, _} ->
|
||||
{:ok,
|
||||
socket
|
||||
|> put_flash(:error, "Booking not found")
|
||||
|> push_navigate(to: "/")}
|
||||
end
|
||||
handle_booking(booking_id, socket)
|
||||
|
||||
{:error, _} ->
|
||||
{:ok,
|
||||
|
|
@ -39,6 +17,30 @@ defmodule SpazioSolazzoWeb.BookingCancellationLive do
|
|||
end
|
||||
end
|
||||
|
||||
defp handle_booking(booking_id, socket) do
|
||||
case Ash.get(SpazioSolazzo.BookingSystem.Booking, booking_id, load: [:space]) do
|
||||
{:ok, %{state: state} = booking} when state in [:requested, :accepted] ->
|
||||
{:ok,
|
||||
assign(socket,
|
||||
booking: booking,
|
||||
cancellation_reason: "",
|
||||
show_success: false
|
||||
)}
|
||||
|
||||
{:ok, _} ->
|
||||
{:ok,
|
||||
socket
|
||||
|> put_flash(:error, "This booking has already been cancelled or completed")
|
||||
|> push_navigate(to: "/")}
|
||||
|
||||
{:error, _} ->
|
||||
{:ok,
|
||||
socket
|
||||
|> put_flash(:error, "Booking not found")
|
||||
|> push_navigate(to: "/")}
|
||||
end
|
||||
end
|
||||
|
||||
def handle_event("validate", %{"reason" => reason}, socket) do
|
||||
{:noreply, assign(socket, cancellation_reason: reason)}
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue