Skip to content

Commit

Permalink
Implemented redirect to event after creation (#496)
Browse files Browse the repository at this point in the history
Co-authored-by: hanan o <[email protected]>
  • Loading branch information
Ali-7s and heosman authored Jul 4, 2024
1 parent cc1733c commit 3d0e61a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions hooks/useEventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { Activity, FormErrors } from "@/models/activity";
import useDateTimeSelection from "./useDateTimeSelection";
import { ActivityDatabase } from "@/models/activityDatabase";
import { useQueryClient } from "@tanstack/react-query";
import { useRouter } from 'next/navigation';

export const useEventForm = (initialData: Activity | ActivityDatabase) => {

const router = useRouter();
const [eventData, setEventData] = useState<Activity | ActivityDatabase>(initialData);
const [errors, setErrors] = useState<FormErrors>({
eventTitle: "",
Expand Down Expand Up @@ -166,7 +167,9 @@ export const useEventForm = (initialData: Activity | ActivityDatabase) => {
await queryClient.refetchQueries({queryKey:['events', 'myEvents', 'archivedEvents']});
setSuccessMessage(data.message || "Event successfully created!");
setErrorMessage("");
// todo: navigate to a success page and clear form
setTimeout(() => {
router.push(`/event-detail?id=${data.activity._id}`)
}, 1200);
} else {
console.log("Failed to create activity:", response.status);
throw new Error(data.message || "Failed to create the event.");
Expand Down

0 comments on commit 3d0e61a

Please sign in to comment.