Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
68b5e83
Add CommunityFridge data model
neal-bpm Aug 25, 2026
be328c4
Fix parameter name in changeset function for CommunityFridge module
neal-bpm Aug 26, 2026
e841246
Community Fridge CRUD operation added
neal-bpm Aug 26, 2026
32365d6
Addressed the review comments
neal-bpm Aug 26, 2026
f38a1bc
Refactor CommunityFridgeTest to use alias for Location and update tes…
neal-bpm Aug 27, 2026
d7c2e06
Merge branch 'main' into vn/community-fridges-data-model-v1
neal-bpm Aug 27, 2026
3c70e80
Defer community fridge location fixture improvement to separate PR
neal-bpm Aug 28, 2026
6226e42
Enforce one community fridge per location via unique_constraint
neal-bpm Aug 31, 2026
702a77b
Merge branch 'vn/community-fridges-data-model-v1' into vn/community-f…
neal-bpm Aug 31, 2026
be26bd2
Add community fridge fixtures and comprehensive test coverage
neal-bpm Aug 31, 2026
0a046ab
Merge branch 'main' into vn/community-fridge-crud-v1
neal-bpm Sep 3, 2026
55476d1
Merge branch 'main' into vn/community-fridge-ui-v1
neal-bpm Sep 10, 2026
a4f815f
Add Community Fridge dispatcher UI to dispatchers only.
neal-bpm Sep 14, 2026
c3c5d45
Merge branch 'main' into vn/community-fridges-data-model-v1
neal-bpm Sep 14, 2026
ea5e3ce
Add Cancel button to community fridge form actions
neal-bpm Sep 14, 2026
14d55d9
Add cancel button to community fridge form
neal-bpm Sep 14, 2026
d3a2509
Add CommunityFridge data model
neal-bpm Aug 25, 2026
25b84a3
Fix parameter name in changeset function for CommunityFridge module
neal-bpm Aug 26, 2026
727cb30
Community Fridge CRUD operation added
neal-bpm Aug 26, 2026
e3f3813
Addressed the review comments
neal-bpm Aug 26, 2026
58ee025
Refactor CommunityFridgeTest to use alias for Location and update tes…
neal-bpm Aug 27, 2026
36eeb07
Defer community fridge location fixture improvement to separate PR
neal-bpm Aug 28, 2026
34cd1c7
Enforce one community fridge per location via unique_constraint
neal-bpm Aug 31, 2026
8849b2b
Add community fridge fixtures and comprehensive test coverage
neal-bpm Aug 31, 2026
dd8e389
Merge branch 'vn/community-fridges-data-model-v1' into vn/community-f…
mveytsman Sep 28, 2026
281eb5e
Merge branch 'main' into vn/community-fridge-crud-v1
neal-bpm Sep 30, 2026
b9eadc7
Merge remote-tracking branch 'origin/vn/community-fridge-crud-v1' int…
neal-bpm Sep 30, 2026
b77e307
Fix redundant DB query and register :community_fridges page in layout…
neal-bpm Oct 7, 2026
0c8390d
Merge branch 'main' into vn/community-fridge-ui-v1
mveytsman Oct 8, 2026
c4e8ee5
Remove unused alias for Locations in CommunityFridgeLiveTest
neal-bpm Oct 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bike_brigade/locations/community_fridge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule BikeBrigade.Locations.CommunityFridge do
def changeset(community_fridge, params) do
community_fridge
|> cast(params, @fields ++ [:location_id])
|> validate_required([:name, :location_id])
|> validate_required([:name])
|> unique_constraint(:location_id)
|> assoc_constraint(:location)
end
Expand Down
10 changes: 10 additions & 0 deletions lib/bike_brigade_web/components/layouts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ defmodule BikeBrigadeWeb.Layouts do
:campaigns,
:opportunities,
:riders,
:community_fridges,
:stats,
:users,
:messages,
Expand Down Expand Up @@ -69,6 +70,15 @@ defmodule BikeBrigadeWeb.Layouts do
</:icon>
Riders
</.sidebar_link>
<.sidebar_link
selected={@current_page == :community_fridges}
navigate={~p"/community_fridges"}
>
<:icon>
<Heroicons.archive_box />
</:icon>
Community Fridges
</.sidebar_link>
<.sidebar_link selected={@current_page == :stats} navigate={~p"/stats"}>
<:icon>
<Heroicons.chart_bar />
Expand Down
55 changes: 55 additions & 0 deletions lib/bike_brigade_web/live/community_fridge_live/form_component.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
defmodule BikeBrigadeWeb.CommunityFridgeLive.FormComponent do
use BikeBrigadeWeb, :live_component

alias BikeBrigade.Locations

@impl true
def update(%{community_fridge: community_fridge} = assigns, socket) do
changeset = Locations.change_community_fridge(community_fridge)

{:ok,
socket
|> assign(assigns)
|> assign(:changeset, changeset)}
end

@impl true
def handle_event("validate", %{"community_fridge" => params}, socket) do
changeset =
socket.assigns.community_fridge
|> Locations.change_community_fridge(params)
|> Map.put(:action, :validate)

{:noreply, assign(socket, :changeset, changeset)}
end

def handle_event("save", %{"community_fridge" => params}, socket) do
save_community_fridge(socket, socket.assigns.action, params)
end

defp save_community_fridge(socket, :edit, params) do
case Locations.update_community_fridge(socket.assigns.community_fridge, params) do
{:ok, _community_fridge} ->
{:noreply,
socket
|> put_flash(:info, "Community fridge updated successfully")
|> push_navigate(to: socket.assigns.navigate)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)}
end
end

defp save_community_fridge(socket, :new, params) do
case Locations.create_community_fridge(params) do
{:ok, _community_fridge} ->
{:noreply,
socket
|> put_flash(:info, "Community fridge created successfully")
|> push_navigate(to: socket.assigns.navigate)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div>
<.header>{@title}</.header>
<.simple_form
:let={f}
for={@changeset}
id="community-fridge-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
>
<.input type="text" field={f[:name]} label="Name" />

<.input type="textarea" field={f[:description]} label="Description" />

<.input type="text" field={f[:photo]} label="Photo URL" />

<.input
type="checkbox"
field={f[:active]}
label="Active"
/>

<.input
type="checkbox"
field={f[:pair_preferred]}
label="Pair Preferred"
help_text="Deliveries to this fridge prefer a rider pair"
/>

<:actions>
<.button navigate={~p"/community_fridges"} color={:white}>
Cancel
</.button>
<.button type="submit" phx-disable-with="Saving...">Save</.button>
</:actions>
</.simple_form>
</div>
39 changes: 39 additions & 0 deletions lib/bike_brigade_web/live/community_fridge_live/index.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
defmodule BikeBrigadeWeb.CommunityFridgeLive.Index do
use BikeBrigadeWeb, :live_view

alias BikeBrigade.Locations
alias BikeBrigade.Locations.CommunityFridge

@impl Phoenix.LiveView
def mount(_params, _session, socket) do
{:ok,
socket
|> assign(:page, :community_fridges)
|> assign(:page_title, "Community Fridges")
|> assign(:community_fridge, nil)
|> assign(:community_fridges, Locations.list_community_fridges())}
end

@impl Phoenix.LiveView
def handle_params(params, _url, socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
end

defp apply_action(socket, :index, _params) do
socket
|> assign(:page_title, "Community Fridges")
|> assign(:community_fridge, nil)
end

defp apply_action(socket, :new, _params) do
socket
|> assign(:page_title, "New Fridge")
|> assign(:community_fridge, %CommunityFridge{})
end

defp apply_action(socket, :edit, %{"id" => id}) do
socket
|> assign(:page_title, "Edit Fridge")
|> assign(:community_fridge, Locations.get_community_fridge!(id))
end
end
47 changes: 47 additions & 0 deletions lib/bike_brigade_web/live/community_fridge_live/index.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<.header>
Community Fridges
<:subtitle>
Community fridges are neighbourhood food-sharing locations. Dispatchers can manage fridge details here.
</:subtitle>
</.header>
<div class="flex justify-end">
<.button patch={~p"/community_fridges/new"}>
New Community Fridge
</.button>
</div>
<.table id="community_fridges" rows={@community_fridges}>
<:col :let={community_fridge} label="Name">
{community_fridge.name}
</:col>
<:col :let={community_fridge} label="Description">
{community_fridge.description}
</:col>
<:col :let={community_fridge} label="Pair Preferred">
{if community_fridge.pair_preferred, do: "Yes", else: "No"}
</:col>
<:col :let={community_fridge} label="Active">
{if community_fridge.active, do: "Yes", else: "No"}
</:col>

<:action :let={community_fridge}>
<.link patch={~p"/community_fridges/#{community_fridge.id}/edit"} class="link">
Edit
</.link>
</:action>
</.table>

<.modal
:if={@live_action in [:new, :edit]}
id="community-fridge-modal"
show
on_cancel={JS.navigate(~p"/community_fridges")}
>
<.live_component
module={BikeBrigadeWeb.CommunityFridgeLive.FormComponent}
id={@community_fridge.id || :new}
action={@live_action}
title={@page_title}
community_fridge={@community_fridge}
navigate={~p"/community_fridges"}
/>
</.modal>
4 changes: 4 additions & 0 deletions lib/bike_brigade_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ defmodule BikeBrigadeWeb.Router do
live "/tags/:id/edit", TagLive.Index, :edit

live "/delivery_notes", DeliveryNoteLive.Index, :index

live "/community_fridges", CommunityFridgeLive.Index, :index
live "/community_fridges/new", CommunityFridgeLive.Index, :new
live "/community_fridges/:id/edit", CommunityFridgeLive.Index, :edit
end

get "/stats/leaderboard/download", ExportStatsController, :leaderboard
Expand Down
91 changes: 91 additions & 0 deletions test/bike_brigade_web/live/community_fridge_live_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
defmodule BikeBrigadeWeb.CommunityFridgeLiveTest do
use BikeBrigadeWeb.ConnCase
import Phoenix.LiveViewTest

describe "Community Fridges index (dispatcher)" do
setup [:login]

test "lists all community fridges", ctx do
fridge = fixture(:community_fridge, %{name: "Test Fridge"})
{:ok, _view, html} = live(ctx.conn, ~p"/community_fridges")

assert html =~ "Community Fridges"
assert html =~ fridge.name
end

test "can create a new community fridge", ctx do
{:ok, view, _html} = live(ctx.conn, ~p"/community_fridges")

view |> element("a", "New Community Fridge") |> render_click()
assert_patched(view, ~p"/community_fridges/new")

{:ok, _view, html} =
view
|> form("#community-fridge-form", community_fridge: %{name: "Brand New Fridge"})
|> render_submit()
|> follow_redirect(ctx.conn)

assert html =~ "Community fridge created successfully"
assert html =~ "Brand New Fridge"
end

test "validates name is required", ctx do
{:ok, view, _html} = live(ctx.conn, ~p"/community_fridges/new")

html =
view
|> form("#community-fridge-form", community_fridge: %{name: ""})
|> render_submit()

assert html =~ "can&#39;t be blank"
end

test "can edit a community fridge", ctx do
fridge = fixture(:community_fridge, %{name: "Original Fridge"})
{:ok, view, _html} = live(ctx.conn, ~p"/community_fridges")

view |> element("a", "Edit") |> render_click()
assert_patched(view, ~p"/community_fridges/#{fridge.id}/edit")

{:ok, _view, html} =
view
|> form("#community-fridge-form", community_fridge: %{name: "Updated Fridge"})
|> render_submit()
|> follow_redirect(ctx.conn)

assert html =~ "Community fridge updated successfully"
assert html =~ "Updated Fridge"
refute html =~ "Original Fridge"
end

test "can navigate directly to edit page", ctx do
fridge = fixture(:community_fridge, %{name: "Edit Me"})
{:ok, _view, html} = live(ctx.conn, ~p"/community_fridges/#{fridge.id}/edit")

assert html =~ "Edit Fridge"
end

test "edit preserves existing values", ctx do
fridge =
fixture(:community_fridge, %{
name: "Preserve Me",
description: "Some description",
active: true,
pair_preferred: true
})

{:ok, _view, html} = live(ctx.conn, ~p"/community_fridges/#{fridge.id}/edit")

assert html =~ "Preserve Me"
assert html =~ "Some description"
end
end

describe "Community Fridges access control" do
setup [:login_as_rider]

test "non-dispatchers cannot access community fridges page", ctx do
assert {:error, {:redirect, %{to: "/login"}}} = live(ctx.conn, ~p"/community_fridges")
end
end
end
Loading