Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redirect preview onsubmit #210

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading