Skip to content

Commit

Permalink
feat: make submit button take users to next page when creating projects
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed May 19, 2022
1 parent 184c5cb commit 31769cd
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 42 deletions.
37 changes: 23 additions & 14 deletions app/pages/cif/project-revision/[projectRevision]/form/contacts.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Button } from "@button-inc/bcgov-theme";
import ProjectContactForm from "components/Form/ProjectContactForm";
import ProjectContactFormSummary from "components/Form/ProjectContactFormSummary";
import DefaultLayout from "components/Layout/DefaultLayout";
import { withRelay, RelayProps } from "relay-nextjs";
import { graphql, usePreloadedQuery } from "react-relay/hooks";
import { contactsFormQuery } from "__generated__/contactsFormQuery.graphql";
import TaskList from "components/TaskList";
import useRedirectTo404IfFalsy from "hooks/useRedirectTo404IfFalsy";
import useRedirectToLatestRevision from "hooks/useRedirectToLatestRevision";
import withRelayOptions from "lib/relay/withRelayOptions";
import { useCreateProjectRevision } from "mutations/ProjectRevision/createProjectRevision";
import { useRouter } from "next/router";
import {
getProjectRevisionPageRoute,
getProjectRevisionContactsFormPageRoute,
getProjectRevisionPageRoute,
getProjectRevisionQuarterlyReportsFormPageRoute,
} from "pageRoutes";
import { useCreateProjectRevision } from "mutations/ProjectRevision/createProjectRevision";
import ProjectContactForm from "components/Form/ProjectContactForm";
import TaskList from "components/TaskList";
import useRedirectTo404IfFalsy from "hooks/useRedirectTo404IfFalsy";
import useRedirectToLatestRevision from "hooks/useRedirectToLatestRevision";
import ProjectContactFormSummary from "components/Form/ProjectContactFormSummary";
import { Button } from "@button-inc/bcgov-theme";
import { graphql, usePreloadedQuery } from "react-relay/hooks";
import { RelayProps, withRelay } from "relay-nextjs";
import { contactsFormQuery } from "__generated__/contactsFormQuery.graphql";

const pageQuery = graphql`
query contactsFormQuery($projectRevision: ID!) {
Expand Down Expand Up @@ -53,6 +54,8 @@ export function ProjectContactsPage({
: query.projectRevision.changeStatus === "committed"
? "view"
: "edit";
const existingRevision =
query.projectRevision?.projectByProjectId?.pendingProjectRevision ?? null;

const [createProjectRevision, isCreatingProjectRevision] =
useCreateProjectRevision();
Expand Down Expand Up @@ -88,8 +91,6 @@ export function ProjectContactsPage({
};

const createEditButton = () => {
const existingRevision =
query.projectRevision.projectByProjectId.pendingProjectRevision;
return (
<div>
<Button
Expand All @@ -113,7 +114,15 @@ export function ProjectContactsPage({
const taskList = <TaskList projectRevision={query.projectRevision} />;

const handleSubmit = () => {
router.push(getProjectRevisionPageRoute(query.projectRevision.id));
if (existingRevision) {
router.push(getProjectRevisionPageRoute(query.projectRevision.id));
} else {
router.push(
getProjectRevisionQuarterlyReportsFormPageRoute(
query.projectRevision.id
)
);
}
};
return (
<DefaultLayout session={query.session} leftSideNav={taskList}>
Expand Down
36 changes: 21 additions & 15 deletions app/pages/cif/project-revision/[projectRevision]/form/managers.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import DefaultLayout from "components/Layout/DefaultLayout";
import { withRelay, RelayProps } from "relay-nextjs";
import { graphql, usePreloadedQuery } from "react-relay/hooks";
import { managersFormQuery } from "__generated__/managersFormQuery.graphql";
import withRelayOptions from "lib/relay/withRelayOptions";
import { Button } from "@button-inc/bcgov-theme";
import ProjectManagerFormGroup from "components/Form/ProjectManagerFormGroup";
import ProjectManagerFormSummary from "components/Form/ProjectManagerFormSummary";
import DefaultLayout from "components/Layout/DefaultLayout";
import TaskList from "components/TaskList";
import {
getProjectRevisionPageRoute,
getProjectRevisionManagersFormPageRoute,
} from "pageRoutes";
import { useCreateProjectRevision } from "mutations/ProjectRevision/createProjectRevision";
import useRedirectTo404IfFalsy from "hooks/useRedirectTo404IfFalsy";
import useRedirectToLatestRevision from "hooks/useRedirectToLatestRevision";
import withRelayOptions from "lib/relay/withRelayOptions";
import { useCreateProjectRevision } from "mutations/ProjectRevision/createProjectRevision";
import { useRouter } from "next/router";
import { Button } from "@button-inc/bcgov-theme";
import {
getProjectRevisionContactsFormPageRoute,
getProjectRevisionManagersFormPageRoute,
getProjectRevisionPageRoute,
} from "pageRoutes";
import { graphql, usePreloadedQuery } from "react-relay/hooks";
import { RelayProps, withRelay } from "relay-nextjs";
import { managersFormQuery } from "__generated__/managersFormQuery.graphql";

const pageQuery = graphql`
query managersFormQuery($projectRevision: ID!) {
Expand Down Expand Up @@ -48,7 +49,8 @@ export function ProjectManagersForm({
}: RelayProps<{}, managersFormQuery>) {
const { query } = usePreloadedQuery(pageQuery, preloadedQuery);
const router = useRouter();

const existingRevision =
query.projectRevision?.projectByProjectId?.pendingProjectRevision ?? null;
const [createProjectRevision, isCreatingProjectRevision] =
useCreateProjectRevision();

Expand All @@ -74,8 +76,6 @@ export function ProjectManagersForm({
};

const createEditButton = () => {
const existingRevision =
query.projectRevision.projectByProjectId.pendingProjectRevision;
return (
<div>
<Button
Expand Down Expand Up @@ -108,7 +108,13 @@ export function ProjectManagersForm({
const taskList = <TaskList projectRevision={query.projectRevision} />;

const handleSubmit = () => {
router.push(getProjectRevisionPageRoute(query.projectRevision.id));
if (existingRevision) {
router.push(getProjectRevisionPageRoute(query.projectRevision.id));
} else {
router.push(
getProjectRevisionContactsFormPageRoute(query.projectRevision.id)
);
}
};

return (
Expand Down
35 changes: 22 additions & 13 deletions app/pages/cif/project-revision/[projectRevision]/form/overview.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import DefaultLayout from "components/Layout/DefaultLayout";
import { withRelay, RelayProps } from "relay-nextjs";
import { graphql, usePreloadedQuery } from "react-relay/hooks";
import { overviewFormQuery } from "__generated__/overviewFormQuery.graphql";
import withRelayOptions from "lib/relay/withRelayOptions";
import { Button } from "@button-inc/bcgov-theme";
import ProjectForm from "components/Form/ProjectForm";
import ProjectFormSummary from "components/Form/ProjectFormSummary";
import DefaultLayout from "components/Layout/DefaultLayout";
import TaskList from "components/TaskList";
import useRedirectTo404IfFalsy from "hooks/useRedirectTo404IfFalsy";
import useRedirectToLatestRevision from "hooks/useRedirectToLatestRevision";
import withRelayOptions from "lib/relay/withRelayOptions";
import { useCreateProjectRevision } from "mutations/ProjectRevision/createProjectRevision";
import { useRouter } from "next/router";
import {
getProjectRevisionPageRoute,
getProjectRevisionManagersFormPageRoute,
getProjectRevisionOverviewFormPageRoute,
getProjectRevisionPageRoute,
} from "pageRoutes";
import ProjectFormSummary from "components/Form/ProjectFormSummary";
import { useCreateProjectRevision } from "mutations/ProjectRevision/createProjectRevision";
import useRedirectToLatestRevision from "hooks/useRedirectToLatestRevision";
import { Button } from "@button-inc/bcgov-theme";
import { graphql, usePreloadedQuery } from "react-relay/hooks";
import { RelayProps, withRelay } from "relay-nextjs";
import { overviewFormQuery } from "__generated__/overviewFormQuery.graphql";

const pageQuery = graphql`
query overviewFormQuery($projectRevision: ID!) {
Expand Down Expand Up @@ -52,6 +53,10 @@ export function ProjectOverviewForm({
const mode =
query.projectRevision?.changeStatus === "committed" ? "view" : "update";

const existingRevision =
query.projectRevision?.projectByProjectId?.pendingProjectRevision ?? null;
// console.log("query", query);

const [createProjectRevision, isCreatingProjectRevision] =
useCreateProjectRevision();

Expand Down Expand Up @@ -85,8 +90,6 @@ export function ProjectOverviewForm({
};

const createEditButton = () => {
const existingRevision =
query.projectRevision.projectByProjectId.pendingProjectRevision;
return (
<div>
<Button
Expand All @@ -110,7 +113,13 @@ export function ProjectOverviewForm({
const taskList = <TaskList projectRevision={query.projectRevision} />;

const handleSubmit = () => {
router.push(getProjectRevisionPageRoute(query.projectRevision.id));
if (existingRevision) {
router.push(getProjectRevisionPageRoute(query.projectRevision.id));
} else {
router.push(
getProjectRevisionManagersFormPageRoute(query.projectRevision.id)
);
}
};

return (
Expand Down

0 comments on commit 31769cd

Please sign in to comment.