feat: enhance EventForm to handle URL parameters for creating events
This commit is contained in:
parent
10080b8513
commit
a529b939c4
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 { UserSearchInput } from '@/components/misc/user-search';
|
||||||
import ParticipantListEntry from '../custom-ui/participant-list-entry';
|
import ParticipantListEntry from '../custom-ui/participant-list-entry';
|
||||||
|
|
||||||
|
import { useSearchParams } from 'next/navigation';
|
||||||
|
|
||||||
interface User {
|
interface User {
|
||||||
id: string;
|
id: string;
|
||||||
name: 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 { mutate: createEvent, status, isSuccess, error } = usePostApiEvent();
|
||||||
const { data, isLoading, error: fetchError } = useGetApiUserMe();
|
const { data, isLoading, error: fetchError } = useGetApiUserMe();
|
||||||
const { data: eventData } = useGetApiEventEventID(props.eventId!, {
|
const { data: eventData } = useGetApiEventEventID(props.eventId!, {
|
||||||
|
@ -70,12 +76,12 @@ const EventForm: React.FC<EventFormProps> = (props) => {
|
||||||
if (event.start_time) {
|
if (event.start_time) {
|
||||||
const start = new Date(event.start_time);
|
const start = new Date(event.start_time);
|
||||||
setStartDate(start);
|
setStartDate(start);
|
||||||
setStartTime(start.toISOString().slice(11, 16)); // "HH:mm"
|
setStartTime(start.toTimeString().slice(0, 5)); // "HH:mm"
|
||||||
}
|
}
|
||||||
if (event.end_time) {
|
if (event.end_time) {
|
||||||
const end = new Date(event.end_time);
|
const end = new Date(event.end_time);
|
||||||
setEndDate(end);
|
setEndDate(end);
|
||||||
setEndTime(end.toISOString().slice(11, 16)); // "HH:mm"
|
setEndTime(end.toTimeString().slice(0, 5)); // "HH:mm"
|
||||||
}
|
}
|
||||||
setLocation(event.location || '');
|
setLocation(event.location || '');
|
||||||
setDescription(event.description || '');
|
setDescription(event.description || '');
|
||||||
|
@ -85,8 +91,17 @@ const EventForm: React.FC<EventFormProps> = (props) => {
|
||||||
name: u.user.name,
|
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>) {
|
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue