Skip to content

Commit

Permalink
fix: change funtion signature
Browse files Browse the repository at this point in the history
  • Loading branch information
IanKrieger committed Aug 17, 2023
1 parent 0554369 commit 38a2315
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/form/fragmentUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AdSetFragment } from "graphql/ad-set.generated";

export function createCampaignFromFragment(
data: CampaignFragment,
userId: string,
userId?: string,
): CreateCampaignInput {
const adSets: CreateAdSetInput[] = data.adSets.map((adSet) =>
createAdSetFromFragment(adSet),
Expand Down
19 changes: 5 additions & 14 deletions src/user/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,13 @@ export function User() {
<ProtectedRoute
path="/user/main/adsmanager/advanced/new/:draftId"
authedComponent={NewCampaign}
validateAdvertiserProperty={{
key: "selfServiceCreate",
val: true,
}}
validateAdvertiserProperty={(a) => a.selfServiceCreate}
/>

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

<ProtectedRoute
Expand Down Expand Up @@ -101,25 +95,22 @@ interface ProtectedProps {
authedComponent?: ComponentType;
unauthedComponent?: ComponentType;
path?: string;
validateAdvertiserProperty?: { key: keyof IAdvertiser; val: any };
validateAdvertiserProperty?: (a: IAdvertiser) => boolean;
}

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

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

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

Expand Down

0 comments on commit 38a2315

Please sign in to comment.