feat(event-form): fix view of created_at and updated_at on edit and implement redirect for save and cancel buttons

This commit is contained in:
micha 2025-06-18 22:47:10 +02:00
parent 05f56a2186
commit 4476ee6eb9
2 changed files with 19 additions and 3 deletions

View file

@ -17,6 +17,7 @@ export default function Home() {
</h1> </h1>
<RedirectButton redirectUrl='/logout' buttonText='Logout' /> <RedirectButton redirectUrl='/logout' buttonText='Logout' />
<RedirectButton redirectUrl='/settings' buttonText='Settings' /> <RedirectButton redirectUrl='/settings' buttonText='Settings' />
<RedirectButton redirectUrl='/home/new-event' buttonText='New Event' />
</div> </div>
</div> </div>
); );

View file

@ -12,6 +12,7 @@ import {
usePatchApiEventEventID, usePatchApiEventEventID,
} from '@/generated/api/event/event'; } from '@/generated/api/event/event';
import ParticipantListEntry from '@/components/custom-ui/participantListEntry'; import ParticipantListEntry from '@/components/custom-ui/participantListEntry';
import { useRouter } from 'next/navigation';
interface EventFormProps { interface EventFormProps {
type: 'create' | 'edit'; type: 'create' | 'edit';
@ -32,6 +33,7 @@ const EventForm: React.FC<EventFormProps> = (props) => {
query: { enabled: props.type === 'edit' }, query: { enabled: props.type === 'edit' },
}); });
const patchEvent = usePatchApiEventEventID(); const patchEvent = usePatchApiEventEventID();
const router = useRouter();
// Extract event fields for form defaults // Extract event fields for form defaults
const event = eventData?.data?.event; const event = eventData?.data?.event;
@ -130,14 +132,23 @@ const EventForm: React.FC<EventFormProps> = (props) => {
createEvent({ data }); createEvent({ data });
} }
router.back();
} }
// Calculate values for organiser, created, and updated // Calculate values for organiser, created, and updated
const organiserValue = isLoading const organiserValue = isLoading
? 'Loading...' ? 'Loading...'
: data?.data.user?.name || 'Unknown User'; : data?.data.user?.name || 'Unknown User';
const createdAtValue = new Date().toISOString();
const updatedAtValue = new Date().toISOString(); // Use DB values for created_at/updated_at in edit mode
const createdAtValue =
props.type === 'edit' && event?.created_at
? event.created_at
: new Date().toISOString();
const updatedAtValue =
props.type === 'edit' && event?.updated_at
? event.updated_at
: new Date().toISOString();
// Format date for display // Format date for display
const createdAtDisplay = new Date(createdAtValue).toLocaleDateString(); const createdAtDisplay = new Date(createdAtValue).toLocaleDateString();
@ -252,7 +263,11 @@ const EventForm: React.FC<EventFormProps> = (props) => {
<div className='flex flex-row gap-2 justify-end mt-4 mb-6'> <div className='flex flex-row gap-2 justify-end mt-4 mb-6'>
<div className='w-[20%] grid max-sm:w-[40%]'> <div className='w-[20%] grid max-sm:w-[40%]'>
<Button type='button' variant='secondary'> <Button
type='button'
variant='secondary'
onClick={() => router.back()}
>
cancel cancel
</Button> </Button>
{/* TODO: add onClick handler to cancel cancel */} {/* TODO: add onClick handler to cancel cancel */}