diff --git a/src/components/Campaigns/CloneCampaign.tsx b/src/components/Campaigns/CloneCampaign.tsx index 67d3a4c7..2fad2d29 100644 --- a/src/components/Campaigns/CloneCampaign.tsx +++ b/src/components/Campaigns/CloneCampaign.tsx @@ -19,6 +19,7 @@ import { AdvertiserCampaignsDocument } from "graphql/advertiser.generated"; import { createCampaignFromFragment } from "form/fragmentUtil"; import { useAdvertiser } from "auth/hooks/queries/useAdvertiser"; import ContentCopyIcon from "@mui/icons-material/ContentCopy"; +import { useUser } from "auth/hooks/queries/useUser"; interface Props { campaignFragment?: CampaignFragment | null; @@ -27,6 +28,7 @@ interface Props { export function CloneCampaign({ campaignFragment, useChip }: Props) { const { advertiser } = useAdvertiser(); + const { userId } = useUser(); const history = useHistory(); const [open, setOpen] = useState(false); @@ -94,7 +96,7 @@ export function CloneCampaign({ campaignFragment, useChip }: Props) { if (campaignFragment) { copyCampaign({ variables: { - input: createCampaignFromFragment(campaignFragment), + input: createCampaignFromFragment(campaignFragment, userId), }, }); } else { diff --git a/src/form/fragmentUtil.ts b/src/form/fragmentUtil.ts index b7db3465..d95fd1ea 100644 --- a/src/form/fragmentUtil.ts +++ b/src/form/fragmentUtil.ts @@ -5,6 +5,7 @@ import { AdSetFragment } from "graphql/ad-set.generated"; export function createCampaignFromFragment( data: CampaignFragment, + userId?: string, ): CreateCampaignInput { const adSets: CreateAdSetInput[] = data.adSets.map((adSet) => createAdSetFromFragment(adSet), @@ -12,6 +13,7 @@ export function createCampaignFromFragment( const two = moment().utc().add(3, "days"); return { + userId, adSets: adSets && adSets.length > 0 ? adSets : undefined, advertiserId: data.advertiser.id, budget: data.budget, diff --git a/src/user/User.tsx b/src/user/User.tsx index 2b4e7c64..41ff4d2e 100644 --- a/src/user/User.tsx +++ b/src/user/User.tsx @@ -18,6 +18,7 @@ import { Navbar } from "components/Navigation/Navbar"; import { CampaignView } from "user/views/user/CampaignView"; import { CampaignReportView } from "user/views/user/CampaignReportView"; import { Profile } from "user/views/user/Profile"; +import { IAdvertiser } from "auth/context/auth.interface"; const buildApolloClient = () => { const httpLink = createHttpLink({ @@ -50,11 +51,13 @@ export function User() { a.selfServiceCreate} /> a.selfServiceEdit} /> boolean; } const ProtectedRoute = ({ authedComponent, unauthedComponent, path, + validateAdvertiserProperty = () => true, }: ProtectedProps) => { const { advertiser } = useAdvertiser(); @@ -105,6 +110,10 @@ const ProtectedRoute = ({ return ; } + if (!validateAdvertiserProperty(advertiser)) { + return ; + } + return ( void; } const CampaignCheckBox = (props: CheckBoxProps) => { - console.log(props.selectedCampaigns); const campaignSelected = props.selectedCampaigns.some( (c) => c === props.campaign.id, );