fix: define eventID for toaster button on event creation
This commit is contained in:
parent
331bf5edda
commit
9af74e4df4
1 changed files with 13 additions and 3 deletions
|
@ -51,7 +51,12 @@ const EventForm: React.FC<EventFormProps> = (props) => {
|
||||||
const startFromUrl = searchParams.get('start');
|
const startFromUrl = searchParams.get('start');
|
||||||
const endFromUrl = searchParams.get('end');
|
const endFromUrl = searchParams.get('end');
|
||||||
|
|
||||||
const { mutate: createEvent, status, isSuccess, error } = usePostApiEvent();
|
const {
|
||||||
|
mutateAsync: 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!, {
|
||||||
query: { enabled: props.type === 'edit' },
|
query: { enabled: props.type === 'edit' },
|
||||||
|
@ -150,8 +155,10 @@ const EventForm: React.FC<EventFormProps> = (props) => {
|
||||||
participants: selectedParticipants.map((u) => u.id),
|
participants: selectedParticipants.map((u) => u.id),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let eventID: string | undefined;
|
||||||
|
|
||||||
if (props.type === 'edit' && props.eventId) {
|
if (props.type === 'edit' && props.eventId) {
|
||||||
await patchEvent.mutateAsync({
|
const mutationResult = await patchEvent.mutateAsync({
|
||||||
eventID: props.eventId,
|
eventID: props.eventId,
|
||||||
data: {
|
data: {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
|
@ -162,9 +169,12 @@ const EventForm: React.FC<EventFormProps> = (props) => {
|
||||||
participants: data.participants,
|
participants: data.participants,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
eventID = mutationResult.data.event.id;
|
||||||
console.log('Updating event');
|
console.log('Updating event');
|
||||||
} else {
|
} else {
|
||||||
console.log('Creating event');
|
console.log('Creating event');
|
||||||
|
const mutationResult = await createEvent({ data });
|
||||||
|
eventID = mutationResult.data.event.id;
|
||||||
createEvent({ data });
|
createEvent({ data });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +183,7 @@ const EventForm: React.FC<EventFormProps> = (props) => {
|
||||||
toastId={t}
|
toastId={t}
|
||||||
title='Event saved'
|
title='Event saved'
|
||||||
description={event?.title}
|
description={event?.title}
|
||||||
onAction={() => router.push(`/events/${event?.id}`)}
|
onAction={() => router.push(`/events/${eventID}`)}
|
||||||
variant='success'
|
variant='success'
|
||||||
buttonText='show'
|
buttonText='show'
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue