feat(events): refactor event and participant list entries to use schema validation

This commit is contained in:
micha 2025-06-25 19:11:38 +02:00
parent 4a4d3b73d6
commit 8bbb7e4c85
6 changed files with 28 additions and 44 deletions

View file

@ -2,14 +2,10 @@ import { Card } from '@/components/ui/card';
import Logo from '@/components/misc/logo';
import { Label } from '@/components/ui/label';
import Link from 'next/link';
import zod from 'zod/v4';
import { EventSchema } from '@/app/api/event/validation';
type EventListEntryProps = {
title: string;
id: string;
start_time: string;
end_time: string;
location: string | null | undefined;
};
type EventListEntryProps = zod.output<typeof EventSchema>;
export default function EventListEntry({
title,

View file

@ -3,26 +3,24 @@ import Image from 'next/image';
import { user_default_dark } from '@/assets/usericon/default/defaultusericon-export';
import { user_default_light } from '@/assets/usericon/default/defaultusericon-export';
import { useTheme } from 'next-themes';
import zod from 'zod/v4';
import { ParticipantSchema } from '@/app/api/event/[eventID]/participant/validation';
type ParticipantListEntryProps = {
participant: string;
imageSrc?: string | null;
};
type ParticipantListEntryProps = zod.output<typeof ParticipantSchema>;
export default function ParticipantListEntry({
participant,
imageSrc,
user,
}: ParticipantListEntryProps) {
const { resolvedTheme } = useTheme();
const defaultImage =
resolvedTheme === 'dark' ? user_default_dark : user_default_light;
const finalImageSrc = imageSrc ?? defaultImage;
const finalImageSrc = user.image ?? defaultImage;
return (
<div className='flex items-center gap-2 py-1 ml-5'>
<Image src={finalImageSrc} alt='Avatar' width={30} height={30} />
<span>{participant}</span>
<span>{user.name}</span>
</div>
);
}

View file

@ -19,10 +19,10 @@ import ParticipantListEntry from '../custom-ui/participant-list-entry';
import { useSearchParams } from 'next/navigation';
interface User {
id: string;
name: string;
}
import zod from 'zod/v4';
import { PublicUserSchema } from '@/app/api/user/validation';
type User = zod.output<typeof PublicUserSchema>;
interface EventFormProps {
type: 'create' | 'edit';
@ -85,12 +85,7 @@ const EventForm: React.FC<EventFormProps> = (props) => {
}
setLocation(event.location || '');
setDescription(event.description || '');
setSelectedParticipants(
event.participants?.map((u) => ({
id: u.user.id,
name: u.user.name,
})) || [],
);
setSelectedParticipants(event.participants?.map((u) => u.user) || []);
} else if (props.type === 'create' && startFromUrl && endFromUrl) {
// If creating a new event with URL params, set title and dates
setTitle('');
@ -305,7 +300,11 @@ const EventForm: React.FC<EventFormProps> = (props) => {
/>
<div className='grid grid-cols-1 mt-3 sm:max-h-60 sm:grid-cols-2 sm:overflow-y-auto sm:mb-0'>
{selectedParticipants.map((user) => (
<ParticipantListEntry key={user.id} participant={user.name} />
<ParticipantListEntry
key={user.id}
user={user}
status='PENDING'
/>
))}
</div>
</div>

View file

@ -19,11 +19,10 @@ import {
PopoverTrigger,
} from '@/components/ui/popover';
import { useGetApiSearchUser } from '@/generated/api/search/search';
import zod from 'zod/v4';
import { PublicUserSchema } from '@/app/api/user/validation';
interface User {
id: string;
name: string;
}
type User = zod.output<typeof PublicUserSchema>;
export function UserSearchInput({
addUserAction,