Skip to content

Commit

Permalink
fix: redirect preview onsubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
atrincas committed Jan 8, 2025
1 parent 8215202 commit 247ff18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 1 addition & 2 deletions client/src/containers/projects/new/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export default function Header() {
<Button
disabled={!methods.formState.isValid}
onClick={() => {
methods.handleSubmit((data) => onSubmit(data))();
router.push("/projects/preview");
methods.handleSubmit((data) => onSubmit(data, router))();
}}
>
Continue
Expand Down
17 changes: 14 additions & 3 deletions client/src/containers/projects/new/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { useEffect, useRef } from "react";

import { FormProvider, useForm } from "react-hook-form";

import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
import { useRouter } from "next/navigation";

import { zodResolver } from "@hookform/resolvers/zod";
import { ACTIVITY } from "@shared/entities/activity.enum";
import { EMISSION_FACTORS_TIER_TYPES } from "@shared/entities/carbon-inputs/emission-factors.entity";
Expand Down Expand Up @@ -32,7 +35,10 @@ import { formStepAtom } from "@/containers/projects/store";

import { ScrollArea } from "@/components/ui/scroll-area";

export const onSubmit = async (data: CreateCustomProjectForm) => {
export const onSubmit = async (
data: CreateCustomProjectForm,
router: AppRouterInstance,
) => {
const queryClient = getQueryClient();

const originalValues = { ...data };
Expand Down Expand Up @@ -143,13 +149,14 @@ export const onSubmit = async (data: CreateCustomProjectForm) => {

if (status === 201) {
queryClient.setQueryData(queryKeys.customProjects.cached.queryKey, body);
router.push("/projects/preview");
}
};

export default function CreateCustomProject() {
const ref = useRef<HTMLDivElement>(null);
const setIntersecting = useSetAtom(formStepAtom);

const router = useRouter();
const { queryKey } = queryKeys.customProjects.countries;
const { data: countryOptions } =
client.customProjects.getAvailableCountries.useQuery(
Expand Down Expand Up @@ -238,7 +245,11 @@ export default function CreateCustomProject() {
<ProjectSidebar />
<div className="mb-4 flex-1">
<ScrollArea className="flex h-full gap-3 pr-6">
<ProjectForm onSubmit={methods.handleSubmit(onSubmit)} />
<ProjectForm
onSubmit={methods.handleSubmit((data) =>
onSubmit(data, router),
)}
/>
</ScrollArea>
</div>
</div>
Expand Down

0 comments on commit 247ff18

Please sign in to comment.