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

CMS-437: Update URL paths, use resolvers #148

Open
wants to merge 3 commits into
base: CMS-634-header-footer
Choose a base branch
from
Open
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
11 changes: 5 additions & 6 deletions frontend/src/components/EditAndReviewTable.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMemo } from "react";
import PropTypes from "prop-types";
import { Link, useNavigate } from "react-router-dom";
import classNames from "classnames";
Expand All @@ -8,19 +9,17 @@ import {
faChevronRight,
} from "@fa-kit/icons/classic/solid";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import paths from "@/router/paths";
import StatusBadge from "@/components/StatusBadge";
import NotReadyFlag from "@/components/NotReadyFlag";

function TableRow(park) {
const navigate = useNavigate();

function getParkLink() {
return `/park/${park.orcs}`;
}
const parkLink = useMemo(() => paths.park(park.orcs), [park.orcs]);

// navigate to park details page
function navigateToPark() {
navigate(getParkLink());
navigate(parkLink);
}

return (
Expand All @@ -31,7 +30,7 @@ function TableRow(park) {
<NotReadyFlag show={!park.readyToPublish} />
</td>
<td className="text-end">
<Link to={getParkLink()} aria-label={`View ${park.name} park details`}>
<Link to={parkLink} aria-label={`View ${park.name} park details`}>
<FontAwesomeIcon
className="me-2"
icon={faChevronRight}
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/components/ParkDetailsSeason.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { useNavigate, useParams } from "react-router-dom";
import classNames from "classnames";
import PropTypes from "prop-types";
import { faChevronDown, faPen, faChevronUp } from "@fa-kit/icons/classic/solid";
Expand All @@ -24,6 +24,8 @@ export default function ParkSeason({
getTitle,
DetailsComponent,
}) {
const { parkId } = useParams();

const navigate = useNavigate();

const errorFlashMessage = useFlashMessage();
Expand Down Expand Up @@ -90,7 +92,7 @@ export default function ParkSeason({
);

if (confirm) {
navigate(getEditRoutePath(season.id));
navigate(getEditRoutePath(parkId, season.id));
}
} else if (season.status === "approved") {
const confirm = await openConfirmation(
Expand All @@ -100,7 +102,7 @@ export default function ParkSeason({
);

if (confirm) {
navigate(getEditRoutePath(season.id));
navigate(getEditRoutePath(parkId, season.id));
}
} else if (season.status === "on API") {
const confirm = await openConfirmation(
Expand All @@ -110,15 +112,15 @@ export default function ParkSeason({
);

if (confirm) {
navigate(getEditRoutePath(season.id));
navigate(getEditRoutePath(parkId, season.id));
}
} else {
navigate(getEditRoutePath(season.id));
navigate(getEditRoutePath(parkId, season.id));
}
}

function navigateToPreview() {
navigate(getPreviewRoutePath(season.id));
navigate(getPreviewRoutePath(parkId, season.id));
}

return (
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/router/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PreviewWinterFeesChanges from "./pages/PreviewWinterFeesChanges";
import MainLayout from "./layouts/MainLayout";
import LandingPageTabs from "./layouts/LandingPageTabs";
import ErrorPage from "./pages/Error";
import paths from "./paths";

const RouterConfig = createBrowserRouter(
[
Expand Down Expand Up @@ -44,31 +45,31 @@ const RouterConfig = createBrowserRouter(

// view park details
{
path: "/park/:parkId",
path: paths.park(":parkId"),
element: <ParkDetails />,
},

// edit/submit dates for a season
{
path: "/park/:parkId/edit/:seasonId",
path: paths.seasonEdit(":parkId", ":seasonId"),
element: <SubmitDates />,
},

// review changes
{
path: "/park/:parkId/edit/:seasonId/preview",
path: paths.seasonPreview(":parkId", ":seasonId"),
element: <PreviewChanges />,
},

// edit/submit winter fees dates
{
path: "/park/:parkId/winter-fees/:seasonId/edit",
path: paths.winterFeesEdit(":parkId", ":seasonId"),
element: <SubmitWinterFeesDates />,
},

// review winter fees dates
{
path: "/park/:parkId/winter-fees/:seasonId/preview",
path: paths.winterFeesPreview(":parkId", ":seasonId"),
element: <PreviewWinterFeesChanges />,
},
],
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/router/pages/ParkDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect } from "react";
import { useParams, useSearchParams } from "react-router-dom";
import paths from "@/router/paths";
import { useApiGet } from "@/hooks/useApi";
import { useFlashMessage } from "@/hooks/useFlashMessage";
import NavBack from "@/components/NavBack";
Expand Down Expand Up @@ -45,7 +46,7 @@ function ParkDetails() {
// Remove the query string so the flash message won't show again
searchParams.delete("approved");
searchParams.delete("saved");
setSearchParams(searchParams);
setSearchParams(searchParams, { replace: true });

// Find the season in the park data by its ID
const allSeasons = [
Expand Down Expand Up @@ -100,9 +101,8 @@ function ParkDetails() {
seasons={seasons}
seasonProps={{
getDataEndpoint: (seasonId) => `/seasons/${seasonId}`,
getEditRoutePath: (seasonId) => `/park/${parkId}/edit/${seasonId}`,
getPreviewRoutePath: (seasonId) =>
`/park/${parkId}/edit/${seasonId}/preview`,
getEditRoutePath: paths.seasonEdit,
getPreviewRoutePath: paths.seasonPreview,
getTitle: (season) => `${season.operatingYear} season`,
DetailsComponent: SeasonDates,
}}
Expand All @@ -117,10 +117,8 @@ function ParkDetails() {
seasons={park.winterFees}
seasonProps={{
getDataEndpoint: (seasonId) => `/winter-fees/${seasonId}`,
getEditRoutePath: (seasonId) =>
`/park/${parkId}/winter-fees/${seasonId}/edit`,
getPreviewRoutePath: (seasonId) =>
`/park/${parkId}/winter-fees/${seasonId}/preview`,
getEditRoutePath: paths.winterFeesEdit,
getPreviewRoutePath: paths.winterFeesPreview,
getTitle: (season) =>
`${season.operatingYear} – ${season.operatingYear + 1}`,
DetailsComponent: WinterFeesDates,
Expand Down
17 changes: 8 additions & 9 deletions frontend/src/router/pages/PreviewChanges.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import PropTypes from "prop-types";
import { useNavigate, useParams } from "react-router-dom";
import { useNavigate, useParams, Link } from "react-router-dom";
import { useEffect, useState } from "react";
import { useApiGet, useApiPost } from "@/hooks/useApi";
import { useNavigationGuard } from "@/hooks/useNavigationGuard";
import { useConfirmation } from "@/hooks/useConfirmation";
import { useMissingDatesConfirmation } from "@/hooks/useMissingDatesConfirmation";
import { useFlashMessage } from "@/hooks/useFlashMessage";
import paths from "@/router/paths";

import { faPen } from "@fa-kit/icons/classic/solid";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
Expand All @@ -21,8 +22,6 @@ import ConfirmationDialog from "@/components/ConfirmationDialog";
import MissingDatesConfirmationDialog from "@/components/MissingDatesConfirmationDialog";
import FlashMessage from "@/components/FlashMessage";

import { Link } from "react-router-dom";

import "./PreviewChanges.scss";

function PreviewChanges() {
Expand Down Expand Up @@ -65,7 +64,7 @@ function PreviewChanges() {
useNavigationGuard(hasChanges, openConfirmation);

function navigateToEdit() {
navigate(`/park/${parkId}/edit/${seasonId}`);
navigate(paths.seasonEdit(parkId, seasonId));
}

function getPrevSeasonDates(feature, dateType) {
Expand Down Expand Up @@ -114,7 +113,7 @@ function PreviewChanges() {
readyToPublish,
});

navigate(`/park/${parkId}?saved=${data.id}`);
navigate(`${paths.park(parkId)}?saved=${data.id}`);
} catch (err) {
console.error("Error saving preview", err);

Expand Down Expand Up @@ -215,7 +214,7 @@ function PreviewChanges() {
missingDatesConfirmation.setInputMessage("");
// Redirect back to the Park Details page on success.
// Use the "approved" query param to show a flash message.
navigate(`/park/${parkId}?approved=${data.id}`);
navigate(`${paths.park(parkId)}?approved=${data.id}`);
}
} else {
await approveData({
Expand All @@ -224,7 +223,7 @@ function PreviewChanges() {
});
// Redirect back to the Park Details page on success.
// Use the "approved" query param to show a flash message.
navigate(`/park/${parkId}?approved=${data.id}`);
navigate(`${paths.park(parkId)}?approved=${data.id}`);
}
} catch (err) {
console.error("Error approving preview", err);
Expand Down Expand Up @@ -368,7 +367,7 @@ function PreviewChanges() {
onCancel={missingDatesConfirmation.handleCancel}
onConfirm={missingDatesConfirmation.handleConfirm}
/>
<NavBack routePath={`/park/${parkId}/edit/${seasonId}`}>
<NavBack routePath={paths.park(parkId)}>
Back to {data?.park.name} dates
</NavBack>
Comment on lines -371 to 372
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also fixed this; these "NavBack" buttons should always go back to the Park details page, so it was incorrect here on the non-winter preview page.


Expand Down Expand Up @@ -424,7 +423,7 @@ function PreviewChanges() {

<div className="controls d-flex flex-column flex-sm-row gap-2">
<Link
to={`/park/${parkId}/edit/${seasonId}`}
to={paths.seasonEdit(parkId, seasonId)}
type="button"
className="btn btn-outline-primary"
>
Expand Down
17 changes: 8 additions & 9 deletions frontend/src/router/pages/PreviewWinterFeesChanges.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import PropTypes from "prop-types";
import { useNavigate, useParams } from "react-router-dom";
import { useNavigate, useParams, Link } from "react-router-dom";
import { useEffect, useState } from "react";
import { useApiGet, useApiPost } from "@/hooks/useApi";
import { useNavigationGuard } from "@/hooks/useNavigationGuard";
import { useConfirmation } from "@/hooks/useConfirmation";
import { useMissingDatesConfirmation } from "@/hooks/useMissingDatesConfirmation";
import { useFlashMessage } from "@/hooks/useFlashMessage";
import paths from "@/router/paths";

import { faPen } from "@fa-kit/icons/classic/solid";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
Expand All @@ -21,8 +22,6 @@ import ConfirmationDialog from "@/components/ConfirmationDialog";
import MissingDatesConfirmationDialog from "@/components/MissingDatesConfirmationDialog";
import FlashMessage from "@/components/FlashMessage";

import { Link } from "react-router-dom";

import "./PreviewChanges.scss";

function PreviewChanges() {
Expand Down Expand Up @@ -65,7 +64,7 @@ function PreviewChanges() {
useNavigationGuard(hasChanges, openConfirmation);

function navigateToEdit() {
navigate(`/park/${parkId}/winter-fees/${seasonId}/edit`);
navigate(paths.winterFeesEdit(parkId, seasonId));
}

function getDates(dates) {
Expand Down Expand Up @@ -97,7 +96,7 @@ function PreviewChanges() {
readyToPublish,
});

navigate(`/park/${parkId}?saved=${data.id}`);
navigate(`${paths.park(parkId)}?saved=${data.id}`);
} catch (err) {
console.error("Error saving preview", err);

Expand Down Expand Up @@ -134,7 +133,7 @@ function PreviewChanges() {
missingDatesConfirmation.setInputMessage("");
// Redirect back to the Park Details page on success.
// Use the "approved" query param to show a flash message.
navigate(`/park/${parkId}?approved=${data.id}`);
navigate(`${paths.park(parkId)}?approved=${data.id}`);
}
} else {
await approveData({
Expand All @@ -143,7 +142,7 @@ function PreviewChanges() {
});
// Redirect back to the Park Details page on success.
// Use the "approved" query param to show a flash message.
navigate(`/park/${parkId}?approved=${data.id}`);
navigate(`${paths.park(parkId)}?approved=${data.id}`);
}
} catch (err) {
console.error("Error approving preview", err);
Expand Down Expand Up @@ -257,7 +256,7 @@ function PreviewChanges() {
onConfirm={missingDatesConfirmation.handleConfirm}
/>

<NavBack routePath={`/park/${parkId}`}>
<NavBack routePath={paths.park(parkId)}>
Back to {data?.park.name} dates
</NavBack>

Expand Down Expand Up @@ -313,7 +312,7 @@ function PreviewChanges() {

<div className="controls d-flex flex-column flex-sm-row gap-2">
<Link
to={`/park/${parkId}/winter-fees/${seasonId}/edit`}
to={paths.winterFeesEdit(parkId, seasonId)}
type="button"
className="btn btn-outline-primary"
>
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/router/pages/SubmitDates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
normalizeToUTCDate,
normalizeToLocalDate,
} from "@/lib/utils";
import paths from "@/router/paths";

import "./SubmitDates.scss";

Expand Down Expand Up @@ -125,7 +126,7 @@ function SubmitDates() {
const response = await sendData(payload);

if (savingDraft) {
navigate(`/park/${parkId}?saved=${data.id}`);
navigate(`${paths.park(parkId)}?saved=${data.id}`);
}

return response;
Expand Down Expand Up @@ -165,7 +166,7 @@ function SubmitDates() {
const submitOk = await submitChanges();

if (submitOk) {
navigate(`/park/${parkId}/edit/${seasonId}/preview`);
navigate(paths.seasonPreview(parkId, seasonId));
}
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -725,7 +726,7 @@ function SubmitDates() {
variant="error"
/>

<NavBack routePath={`/park/${parkId}`}>
<NavBack routePath={paths.park(parkId)}>
Back to {season?.park.name} season dates
</NavBack>

Expand Down Expand Up @@ -807,7 +808,7 @@ function SubmitDates() {

<div className="controls d-flex flex-column flex-sm-row gap-2">
<Link
to={`/park/${parkId}`}
to={paths.park(parkId)}
type="button"
className="btn btn-outline-primary"
>
Expand Down
Loading