From 7bbb5a9f71b1d753eee3af413d6805da47d428e5 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 15 Nov 2026 11:00:21 +0100 Subject: [PATCH] fix(packing): anyone on the trip can be put down as the bringer of a shared item, and taken off again (#3098) A common item only let you pledge yourself. Nobody else could be named, and a bringer could never be removed, so an item that went personal and back kept its owner's avatar for good. The item menu now lists every member to tick on or off, a click on the avatar opens it there, and the add route takes an optional user_id limited to the trip's members. Taking the owner off clears the owner. The remove route now checks visibility for the caller, not for the user named in the path. --- client/src/api/client.ts | 2 +- .../Packing/PackingListPanelCategoryGroup.tsx | 2 +- .../Packing/PackingListPanelItemRow.test.tsx | 53 +++++++++++++++- .../Packing/PackingListPanelItemRow.tsx | 50 ++++++++++++--- .../components/Packing/usePackingListPanel.ts | 2 +- client/src/store/slices/packingSlice.ts | 7 ++- .../repositories/PackingItems.repository.ts | 6 ++ server/src/nest/packing/packing.controller.ts | 7 ++- server/src/nest/packing/packing.dto.ts | 2 + server/src/nest/packing/packing.service.ts | 13 ++-- server/tests/integration/packing.test.ts | 43 +++++++++++++ .../PackingItems.repository.test.ts | 19 ++++++ .../unit/nest/packing.controller.test.ts | 12 +++- .../tests/unit/nest/packing.service.test.ts | 62 ++++++++++++------- shared/src/packing/packing.schema.ts | 7 +++ 15 files changed, 238 insertions(+), 49 deletions(-) diff --git a/client/src/api/client.ts b/client/src/api/client.ts index 91aac58fa..056b13662 100644 --- a/client/src/api/client.ts +++ b/client/src/api/client.ts @@ -520,7 +520,7 @@ export const packingApi = { reorder: (tripId: number | string, orderedIds: number[]) => apiClient.put(`/trips/${tripId}/packing/reorder`, { orderedIds } satisfies PackingReorderRequest).then(r => r.data), setSharing: (tripId: number | string, id: number, data: PackingSetSharingRequest) => apiClient.put(`/trips/${tripId}/packing/${id}/sharing`, data).then(r => r.data), clone: (tripId: number | string, id: number) => apiClient.post(`/trips/${tripId}/packing/${id}/clone`).then(r => r.data), - addContributor: (tripId: number | string, id: number) => apiClient.post(`/trips/${tripId}/packing/${id}/contributors`).then(r => r.data), + addContributor: (tripId: number | string, id: number, userId?: number) => apiClient.post(`/trips/${tripId}/packing/${id}/contributors`, userId == null ? undefined : { user_id: userId }).then(r => r.data), removeContributor: (tripId: number | string, id: number, userId: number) => apiClient.delete(`/trips/${tripId}/packing/${id}/contributors/${userId}`).then(r => r.data), getCategoryAssignees: (tripId: number | string) => apiClient.get(`/trips/${tripId}/packing/category-assignees`).then(r => r.data), setCategoryAssignees: (tripId: number | string, categoryName: string, userIds: number[]) => apiClient.put(`/trips/${tripId}/packing/category-assignees/${encodeURIComponent(categoryName)}`, { user_ids: userIds } satisfies PackingCategoryAssigneesRequest).then(r => r.data), diff --git a/client/src/components/Packing/PackingListPanelCategoryGroup.tsx b/client/src/components/Packing/PackingListPanelCategoryGroup.tsx index 9776fd419..d8f87996a 100644 --- a/client/src/components/Packing/PackingListPanelCategoryGroup.tsx +++ b/client/src/components/Packing/PackingListPanelCategoryGroup.tsx @@ -52,7 +52,7 @@ interface KategorieGruppeProps { currentUserId?: number onSetSharing?: (id: number, visibility: 'common' | 'personal' | 'shared', recipientIds: number[]) => void onClone?: (id: number) => void - onJoin?: (id: number) => void + onJoin?: (id: number, userId?: number) => void onLeave?: (id: number, userId: number) => void // Opens the choice of one sharing tier for the whole list (#2961). onShareCategory?: () => void diff --git a/client/src/components/Packing/PackingListPanelItemRow.test.tsx b/client/src/components/Packing/PackingListPanelItemRow.test.tsx index d231cc5a0..fb9730ba1 100644 --- a/client/src/components/Packing/PackingListPanelItemRow.test.tsx +++ b/client/src/components/Packing/PackingListPanelItemRow.test.tsx @@ -1,4 +1,4 @@ -// FE-W5ROW-001 to FE-W5ROW-056 +// FE-W5ROW-001 to FE-W5ROW-059 import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' import type { ComponentProps } from 'react' import { http, HttpResponse } from 'msw' @@ -1084,3 +1084,54 @@ describe('ArtikelZeile — overflow menu', () => { expect(danger.style.background).toBe('rgba(239, 68, 68, 0.1)') }) }) + +describe('ArtikelZeile — who brings a common item (#3098)', () => { + const handlers = () => ({ onSetSharing: vi.fn(), onClone: vi.fn(), onJoin: vi.fn(), onLeave: vi.fn() }) + + it('FE-W5ROW-057: the item menu lists every member and ticks one on as a bringer', () => { + const h = handlers() + const { container } = setup({ currentUserId: 1, tripMembers: MEMBERS, ...h }) + + fireEvent.click(overflowTrigger(container)) + fireEvent.click(menuButton(container, 'Brought by')) + fireEvent.click(menuButton(container, 'alice')) + + expect(h.onJoin).toHaveBeenCalledWith(1, 2) + expect(h.onLeave).not.toHaveBeenCalled() + }) + + it('FE-W5ROW-058: a ticked bringer, the owner included, comes off again', () => { + const h = handlers() + const { container } = setup({ + item: buildPackingItem({ + id: 1, name: 'Stove', is_private: 0, owner_id: 1, owner_username: 'owner', + contributors: [{ user_id: 2, username: 'alice' }], + } as unknown as Partial), + currentUserId: 1, tripMembers: MEMBERS, ...h, + }) + + fireEvent.click(overflowTrigger(container)) + fireEvent.click(menuButton(container, 'Brought by')) + fireEvent.click(menuButton(container, 'owner')) + fireEvent.click(menuButton(container, 'alice')) + + expect(h.onLeave).toHaveBeenNthCalledWith(1, 1, 1) + expect(h.onLeave).toHaveBeenNthCalledWith(2, 1, 2) + expect(h.onJoin).not.toHaveBeenCalled() + }) + + it('FE-W5ROW-059: a click on the faces opens the menu at the bringers, also when only co-bringers are left', () => { + const { container } = setup({ + item: buildPackingItem({ + id: 1, name: 'Stove', is_private: 0, owner_id: null, owner_username: null, + contributors: [{ user_id: 2, username: 'alice' }], + } as unknown as Partial), + currentUserId: 1, tripMembers: MEMBERS, ...handlers(), + }) + + fireEvent.click(screen.getByRole('button', { name: 'brought by alice' })) + + expect(menuButton(container, 'alice')).toBeInTheDocument() + expect(menuButton(container, 'owner')).toBeInTheDocument() + }) +}) diff --git a/client/src/components/Packing/PackingListPanelItemRow.tsx b/client/src/components/Packing/PackingListPanelItemRow.tsx index bba12331b..06ac9cc09 100644 --- a/client/src/components/Packing/PackingListPanelItemRow.tsx +++ b/client/src/components/Packing/PackingListPanelItemRow.tsx @@ -39,7 +39,7 @@ interface ArtikelZeileProps { currentUserId?: number onSetSharing?: (id: number, visibility: 'common' | 'personal' | 'shared', recipientIds: number[]) => void onClone?: (id: number) => void - onJoin?: (id: number) => void + onJoin?: (id: number, userId?: number) => void onLeave?: (id: number, userId: number) => void /** Draws the hairline above the row; the category group leaves it off its first row. */ divider?: boolean @@ -68,6 +68,7 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCa const bagBox = useAnchoredPosition(bagBtnRef, showBagPicker, { estimatedHeight: 260, offset: 6 }) const [showItemMenu, setShowItemMenu] = useState(false) const [showMenuCategories, setShowMenuCategories] = useState(false) + const [showMenuBringers, setShowMenuBringers] = useState(false) const [bagInlineCreate, setBagInlineCreate] = useState(false) const [bagInlineName, setBagInlineName] = useState('') const itemMenuBtnRef = useRef(null) @@ -79,8 +80,13 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCa const sharedToMe = !!item.is_private && item.owner_id != null && item.owner_id !== currentUserId const recipients = item.recipients || [] const sharedByMe = !!item.is_private && item.owner_id === currentUserId && recipients.length > 0 - const broughtBy = !item.is_private && item.owner_username ? item.owner_username : null const canShare = canEdit && !isPlaceholder && !!onSetSharing + // Who brings a Common item is anyone's call on the trip, not just a pledge for + // yourself: the menu lists every member to tick on or off (#3098). + const canPickBringers = canEdit && !isPlaceholder && !item.is_private && tripMembers.length > 0 && !!onJoin && !!onLeave + const isBringer = (userId: number) => item.owner_id === userId || (item.contributors || []).some(c => c.user_id === userId) + const toggleBringer = (userId: number) => (isBringer(userId) ? onLeave!(item.id, userId) : onJoin!(item.id, userId)) + const closeItemMenu = () => { setShowItemMenu(false); setShowMenuCategories(false); setShowMenuBringers(false) } const handleToggle = () => togglePackingItem(tripId, item.id, !item.checked) @@ -234,13 +240,23 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCa )} - {!isPlaceholder && broughtBy && ( + {!isPlaceholder && !item.is_private && bringers.length > 0 && ( }> - - - {bringers.length > 1 && } - + {/* A click on the faces opens the menu right at the bringers (#3098). */} + {canPickBringers ? ( + + ) : ( + + + {bringers.length > 1 && } + + )} )} @@ -340,7 +356,7 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCa