feat: enhance EventForm to handle URL parameters for creating events
This commit is contained in:
parent
24628a13f5
commit
9baf4d6be6
1 changed files with 18 additions and 3 deletions
|
@ -17,6 +17,8 @@ import { ToastInner } from '@/components/misc/toast-inner';
|
|||
import { UserSearchInput } from '@/components/misc/user-search';
|
||||
import ParticipantListEntry from '../custom-ui/participant-list-entry';
|
||||
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
interface User {
|
||||
id: string;
|
||||
name: string;
|
||||
|
@ -35,6 +37,10 @@ const EventForm: React.FC<EventFormProps> = (props) => {
|
|||
);
|
||||
}
|
||||
|
||||
const searchParams = useSearchParams();
|
||||
const startFromUrl = searchParams.get('start');
|
||||
const endFromUrl = searchParams.get('end');
|
||||
|
||||
const { mutate: createEvent, status, isSuccess, error } = usePostApiEvent();
|
||||
const { data, isLoading, error: fetchError } = useGetApiUserMe();
|
||||
const { data: eventData } = useGetApiEventEventID(props.eventId!, {
|
||||
|
@ -70,12 +76,12 @@ const EventForm: React.FC<EventFormProps> = (props) => {
|
|||
if (event.start_time) {
|
||||
const start = new Date(event.start_time);
|
||||
setStartDate(start);
|
||||
setStartTime(start.toISOString().slice(11, 16)); // "HH:mm"
|
||||
setStartTime(start.toTimeString().slice(0, 5)); // "HH:mm"
|
||||
}
|
||||
if (event.end_time) {
|
||||
const end = new Date(event.end_time);
|
||||
setEndDate(end);
|
||||
setEndTime(end.toISOString().slice(11, 16)); // "HH:mm"
|
||||
setEndTime(end.toTimeString().slice(0, 5)); // "HH:mm"
|
||||
}
|
||||
setLocation(event.location || '');
|
||||
setDescription(event.description || '');
|
||||
|
@ -85,8 +91,17 @@ const EventForm: React.FC<EventFormProps> = (props) => {
|
|||
name: u.user.name,
|
||||
})) || [],
|
||||
);
|
||||
} else if (props.type === 'create' && startFromUrl && endFromUrl) {
|
||||
// If creating a new event with URL params, set title and dates
|
||||
setTitle('');
|
||||
const start = new Date(startFromUrl);
|
||||
setStartDate(start);
|
||||
setStartTime(start.toTimeString().slice(0, 5)); // "HH:mm"
|
||||
const end = new Date(endFromUrl);
|
||||
setEndDate(end);
|
||||
setEndTime(end.toTimeString().slice(0, 5)); // "HH:mm"
|
||||
}
|
||||
}, [event, props.type]);
|
||||
}, [event, props.type, startFromUrl, endFromUrl]);
|
||||
|
||||
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
||||
e.preventDefault();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue