diff --git a/src/actions/place.ts b/src/actions/place.ts index 4630700..3357ed8 100644 --- a/src/actions/place.ts +++ b/src/actions/place.ts @@ -40,7 +40,7 @@ export async function addNewPlace(body: FormData) { throw new Error(getErrorMessage(error)); } } -export async function deletePlace(placeId: string, redirectHome = false) { +export async function deletePlace(placeId: string) { try { const endpoint = apiConfig.places.delete(placeId); await apiHandler({ @@ -48,7 +48,6 @@ export async function deletePlace(placeId: string, redirectHome = false) { method: "DELETE", }); revalidateTag(Tags.places); - redirectHome && redirect(DASHBOARD_PATHS.places.root); } catch (error) { console.log(error); throw new Error(getErrorMessage(error)); diff --git a/src/app/(dashboard)/places/sections/new/CreatePlaceForm.tsx b/src/app/(dashboard)/places/sections/new/CreatePlaceForm.tsx index e3049b7..57a33be 100644 --- a/src/app/(dashboard)/places/sections/new/CreatePlaceForm.tsx +++ b/src/app/(dashboard)/places/sections/new/CreatePlaceForm.tsx @@ -1,19 +1,18 @@ "use client"; +import { addNewPlace } from "@/actions/place"; +import FileUpload from "@/components/shared/input/FileUpload"; import TextField from "@/components/shared/input/TextField"; -import { useReactHookForm } from "@/hooks/useReactHookForm"; -import { Category } from "@/types/category"; -import { Button, Select, SelectItem } from "@nextui-org/react"; -import React from "react"; -import { Controller } from "react-hook-form"; -import CreatePlaceDetails from "./CreatePlaceDetails"; import HStack from "@/components/shared/layout/HStack"; import { DASHBOARD_PATHS } from "@/config/routes"; -import { CreatePlaceField, createPlaceSchema } from "@/rules/validations/place"; -import FileUpload from "@/components/shared/input/FileUpload"; +import { useReactHookForm } from "@/hooks/useReactHookForm"; import { useServerAction } from "@/hooks/useServerAction"; -import { addNewPlace } from "@/actions/place"; -import { toast } from "sonner"; +import { CreatePlaceField, createPlaceSchema } from "@/rules/validations/place"; +import { Category } from "@/types/category"; import { getErrorMessage } from "@/utils/helpers"; +import { Button } from "@nextui-org/react"; +import { useRouter } from "next/navigation"; +import { toast } from "sonner"; +import CreatePlaceDetails from "./CreatePlaceDetails"; interface Props { categories: Category[]; @@ -23,7 +22,6 @@ export default function CreatePlaceForm({ categories }: Props) { control, handleSubmit, formState: { errors, isValid }, - reset, register, } = useReactHookForm(createPlaceSchema); @@ -31,6 +29,7 @@ export default function CreatePlaceForm({ categories }: Props) { addNewPlace, ); + const router = useRouter(); const onSubmit = async (data: CreatePlaceField) => { try { const { @@ -60,7 +59,7 @@ export default function CreatePlaceForm({ categories }: Props) { await createPlace(formData); toast.success("New place created"); - reset(); + router.push(DASHBOARD_PATHS.places.root); } catch (error) { toast.error(getErrorMessage(error)); } @@ -71,7 +70,7 @@ export default function CreatePlaceForm({ categories }: Props) {

Add New Place