feat(members): implement /members page — Kachel-Ansicht (E2, issue #48)
Backend: - Rename V006 migration to V026 (avoid conflict with existing V006) - Migration adds invalidated_at + partial unique index on household_invite Frontend: - Toast.svelte — new system component (message + dismiss) - SegmentedControl.svelte — new system component (options, value, onchange) - members/+page.server.ts — loads members + active invite - members/[userId]/+server.ts — DELETE/PATCH proxy - members/invites/+server.ts — POST (regenerate) proxy - MemberCard.svelte — tile with avatar, kebab, inline role edit - RemoveDialog.svelte — confirmation dialog (desktop modal + BottomSheet mobile) - InviteCard.svelte + InvitePanel.svelte — invite management UI - MemberGrid.svelte — responsive 4/2-col grid with sorted members - members/+page.svelte — page composing all components with optimistic updates Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
50
frontend/src/lib/components/SegmentedControl.svelte
Normal file
50
frontend/src/lib/components/SegmentedControl.svelte
Normal file
@@ -0,0 +1,50 @@
|
||||
<script lang="ts">
|
||||
let {
|
||||
options,
|
||||
value,
|
||||
onchange
|
||||
}: {
|
||||
options: { value: string; label: string }[];
|
||||
value: string;
|
||||
onchange: (value: string) => void;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<div role="group" class="segmented-control">
|
||||
{#each options as option (option.value)}
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={option.value === value ? 'true' : 'false'}
|
||||
class="segment"
|
||||
class:active={option.value === value}
|
||||
onclick={() => onchange(option.value)}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.segmented-control {
|
||||
display: flex;
|
||||
background: var(--color-surface-raised);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.segment {
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 4px 12px;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.04em;
|
||||
background: transparent;
|
||||
border-radius: var(--radius-sm);
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.segment.active {
|
||||
background: var(--color-page);
|
||||
}
|
||||
</style>
|
||||
30
frontend/src/lib/components/SegmentedControl.test.ts
Normal file
30
frontend/src/lib/components/SegmentedControl.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/svelte';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import SegmentedControl from './SegmentedControl.svelte';
|
||||
|
||||
const options = [
|
||||
{ value: 'planner', label: 'Planer' },
|
||||
{ value: 'member', label: 'Mitglied' }
|
||||
];
|
||||
|
||||
describe('SegmentedControl', () => {
|
||||
it('renders all option labels', () => {
|
||||
render(SegmentedControl, { props: { options, value: 'planner', onchange: vi.fn() } });
|
||||
expect(screen.getByRole('button', { name: 'Planer' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Mitglied' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('marks the active option with aria-pressed', () => {
|
||||
render(SegmentedControl, { props: { options, value: 'planner', onchange: vi.fn() } });
|
||||
expect(screen.getByRole('button', { name: 'Planer' })).toHaveAttribute('aria-pressed', 'true');
|
||||
expect(screen.getByRole('button', { name: 'Mitglied' })).toHaveAttribute('aria-pressed', 'false');
|
||||
});
|
||||
|
||||
it('calls onchange with the new value when an option is clicked', async () => {
|
||||
const onchange = vi.fn();
|
||||
render(SegmentedControl, { props: { options, value: 'planner', onchange } });
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Mitglied' }));
|
||||
expect(onchange).toHaveBeenCalledWith('member');
|
||||
});
|
||||
});
|
||||
31
frontend/src/lib/components/Toast.svelte
Normal file
31
frontend/src/lib/components/Toast.svelte
Normal file
@@ -0,0 +1,31 @@
|
||||
<script lang="ts">
|
||||
const { message, visible, ondismiss }: {
|
||||
message: string;
|
||||
visible: boolean;
|
||||
ondismiss?: () => void;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
{#if visible}
|
||||
<div
|
||||
role="status"
|
||||
style="
|
||||
position: fixed;
|
||||
bottom: 24px;
|
||||
right: 24px;
|
||||
z-index: 200;
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
box-shadow: var(--shadow-overlay);
|
||||
border-radius: var(--radius-lg);
|
||||
color: var(--color-text);
|
||||
padding: 12px 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
"
|
||||
>
|
||||
<span>{message}</span>
|
||||
<button aria-label="Schließen" onclick={ondismiss}>✕</button>
|
||||
</div>
|
||||
{/if}
|
||||
23
frontend/src/lib/components/Toast.test.ts
Normal file
23
frontend/src/lib/components/Toast.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/svelte';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import Toast from './Toast.svelte';
|
||||
|
||||
describe('Toast', () => {
|
||||
it('is not mounted when visible is false', () => {
|
||||
render(Toast, { props: { message: 'Hallo', visible: false } });
|
||||
expect(screen.queryByRole('status')).toBeNull();
|
||||
});
|
||||
|
||||
it('shows the message when visible is true', () => {
|
||||
render(Toast, { props: { message: 'Gespeichert', visible: true } });
|
||||
expect(screen.getByRole('status')).toHaveTextContent('Gespeichert');
|
||||
});
|
||||
|
||||
it('calls ondismiss when close button is clicked', async () => {
|
||||
const ondismiss = vi.fn();
|
||||
render(Toast, { props: { message: 'Fehler', visible: true, ondismiss } });
|
||||
await userEvent.click(screen.getByRole('button', { name: /schließen/i }));
|
||||
expect(ondismiss).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user