From 46eeb3740a23eacc367cfdda65982cbea8faef4c Mon Sep 17 00:00:00 2001
From: Ian Krieger <48930920+IanKrieger@users.noreply.github.com>
Date: Fri, 25 Aug 2023 10:39:51 -0400
Subject: [PATCH 1/3] chore: fix isEdit prop drilling and various routes (#871)
* chore: fix isEdit prop drilling and various routes
* fix: no need for payment ID's
* fix: better represent draft state
---
src/components/Button/DashboardButton.tsx | 7 ++--
src/components/Button/DashboardIconButton.tsx | 15 --------
.../Campaigns/CampaignDateRange.tsx | 6 ++-
src/components/Navigation/DraftMenu.tsx | 8 ++--
src/components/Navigation/Navbar.tsx | 6 +--
src/components/Steps/ActionButtons.tsx | 4 +-
src/components/Steps/StepDrawer.tsx | 2 +-
src/form/FormikHelpers.tsx | 37 ++++++-------------
src/user/library/index.ts | 2 +-
src/user/views/adsManager/types/index.ts | 3 +-
.../advanced/components/adSet/AdSetFields.tsx | 11 ++----
.../advanced/components/adSet/NewAdSet.tsx | 12 ++++--
.../components/campaign/BudgetSettings.tsx | 6 +--
.../components/campaign/CampaignSettings.tsx | 13 +++----
.../campaign/fields/BudgetField.tsx | 32 ++++++++--------
.../campaign/fields/PaymentMethodField.tsx | 14 ++-----
.../completionForm/CompletionForm.tsx | 13 +++----
.../advanced/components/form/EditCampaign.tsx | 2 +-
.../advanced/components/form/NewCampaign.tsx | 2 +-
.../components/form/components/BaseForm.tsx | 19 +++-------
.../form/components/PaymentButton.tsx | 10 ++---
.../review/components/ReviewContainer.tsx | 7 ++--
22 files changed, 90 insertions(+), 141 deletions(-)
delete mode 100644 src/components/Button/DashboardIconButton.tsx
diff --git a/src/components/Button/DashboardButton.tsx b/src/components/Button/DashboardButton.tsx
index 946480d4..7a7220de 100644
--- a/src/components/Button/DashboardButton.tsx
+++ b/src/components/Button/DashboardButton.tsx
@@ -1,15 +1,14 @@
import { Button } from "@mui/material";
import ArrowBack from "@mui/icons-material/ArrowBack";
-import { useHistory } from "react-router-dom";
+import { Link as RouterLink } from "react-router-dom";
export function DashboardButton() {
- const history = useHistory();
-
return (
}
- onClick={() => history.replace("/user/main")}
+ component={RouterLink}
+ to="/user/main"
>
Dashboard
diff --git a/src/components/Button/DashboardIconButton.tsx b/src/components/Button/DashboardIconButton.tsx
deleted file mode 100644
index 7a17145d..00000000
--- a/src/components/Button/DashboardIconButton.tsx
+++ /dev/null
@@ -1,15 +0,0 @@
-import { IconButton, Tooltip } from "@mui/material";
-import ArrowBack from "@mui/icons-material/ArrowBack";
-import { useHistory } from "react-router-dom";
-
-export function DashboardIconButton() {
- const history = useHistory();
-
- return (
-
- history.push("/user/main")}>
-
-
-
- );
-}
diff --git a/src/components/Campaigns/CampaignDateRange.tsx b/src/components/Campaigns/CampaignDateRange.tsx
index 18562fee..76deb961 100644
--- a/src/components/Campaigns/CampaignDateRange.tsx
+++ b/src/components/Campaigns/CampaignDateRange.tsx
@@ -6,8 +6,10 @@ import { useField } from "formik";
import { useState } from "react";
import { getDefaultTimezone, TimeZonePicker } from "../TimeZonePicker";
import { TimezoneAwareDatePicker } from "../TimeZonePicker/TimezoneAwareDatePicker";
+import { useIsEdit } from "form/FormikHelpers";
-export const CampaignDateRange = ({ isEdit }: { isEdit: boolean }) => {
+export const CampaignDateRange = () => {
+ const { isDraft } = useIsEdit();
const [tz, setTz] = useState(getDefaultTimezone());
const [, startMeta, startHelper] = useField("startAt");
const [, endMeta, endHelper] = useField("endAt");
@@ -25,7 +27,7 @@ export const CampaignDateRange = ({ isEdit }: { isEdit: boolean }) => {
startHelper.setValue(formatISO(dt));
startHelper.setTouched(true);
}}
- disabled={isEdit}
+ disabled={!isDraft}
/>
diff --git a/src/components/Navigation/DraftMenu.tsx b/src/components/Navigation/DraftMenu.tsx
index 929f64ac..0a4d7736 100644
--- a/src/components/Navigation/DraftMenu.tsx
+++ b/src/components/Navigation/DraftMenu.tsx
@@ -1,13 +1,12 @@
import { useContext, useState, MouseEvent } from "react";
-import { useHistory } from "react-router-dom";
+import { Link as RouterLink } from "react-router-dom";
import { Badge, Button, Menu, MenuItem } from "@mui/material";
import { DraftContext } from "state/context";
export function DraftMenu() {
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);
- const history = useHistory();
const { drafts } = useContext(DraftContext);
const handleClick = (event: MouseEvent) => {
@@ -46,10 +45,9 @@ export function DraftMenu() {
{drafts.map((d, idx) => (