Skip to content

Commit

Permalink
fix: make sure campaign creation is not exposed accidentally
Browse files Browse the repository at this point in the history
  • Loading branch information
IanKrieger committed Aug 17, 2023
1 parent c186788 commit 5f88fc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/user/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -50,11 +51,19 @@ export function User() {
<ProtectedRoute
path="/user/main/adsmanager/advanced/new/:draftId"
authedComponent={NewCampaign}
validateAdvertiserProperty={{
key: "selfServiceCreate",
val: true,
}}
/>

<ProtectedRoute
path="/user/main/adsmanager/advanced/:campaignId"
authedComponent={EditCampaign}
validateAdvertiserProperty={{
key: "selfServiceEdit",
val: true,
}}
/>

<ProtectedRoute
Expand Down Expand Up @@ -92,19 +101,28 @@ interface ProtectedProps {
authedComponent?: ComponentType;
unauthedComponent?: ComponentType;
path?: string;
validateAdvertiserProperty?: { key: keyof IAdvertiser; val: any };
}

const ProtectedRoute = ({
authedComponent,
unauthedComponent,
path,
validateAdvertiserProperty,
}: ProtectedProps) => {
const { advertiser } = useAdvertiser();

if (!advertiser.agreed && unauthedComponent === undefined) {
return <Redirect to="/user/main" />;
}

if (
validateAdvertiserProperty &&
advertiser[validateAdvertiserProperty.key] != validateAdvertiserProperty.val
) {
return <Redirect to="/user/main" />;
}

return (
<Route
path={path}
Expand Down
1 change: 0 additions & 1 deletion src/user/campaignList/CampaignList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ interface CheckBoxProps {
onCampaignSelect: (c: string, insert: boolean) => void;
}
const CampaignCheckBox = (props: CheckBoxProps) => {
console.log(props.selectedCampaigns);
const campaignSelected = props.selectedCampaigns.some(
(c) => c === props.campaign.id,
);
Expand Down

0 comments on commit 5f88fc2

Please sign in to comment.