Skip to content

Commit

Permalink
chore: simplify campaign management flags
Browse files Browse the repository at this point in the history
  • Loading branch information
IanKrieger committed Oct 12, 2023
1 parent 1e542ed commit e51637c
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/auth/components/AdvertiserAgreed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { PaymentType } from "graphql/types";
export function AdvertiserAgreed() {
const { advertiser } = useAdvertiser();
const requiresPaymentAgree =
advertiser.selfServiceCreate &&
advertiser.selfServiceManageCampaign &&
advertiser.selfServicePaymentType !== PaymentType.Netsuite;
const history = useHistory();
const { setSessionUser } = useAuthContext();
Expand Down
3 changes: 1 addition & 2 deletions src/auth/context/auth.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { PaymentType } from "graphql/types";
export type IAdvertiser = {
id: string;
name: string;
selfServiceCreate: boolean;
selfServiceEdit: boolean;
selfServiceManageCampaign: boolean;
selfServiceSetPrice: boolean;
selfServicePaymentType: PaymentType;
publicKey?: string | null;
Expand Down
3 changes: 1 addition & 2 deletions src/auth/hooks/queries/useAdvertiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export function useAdvertiser(): {
const defaultAdvertiser: IAdvertiser = {
id: "",
name: "",
selfServiceCreate: false,
selfServiceEdit: false,
selfServiceManageCampaign: false,
selfServiceSetPrice: false,
publicKey: null,
selfServicePaymentType: PaymentType.Stripe,
Expand Down
3 changes: 1 addition & 2 deletions src/auth/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { RegistrationForm } from "auth/registration/types";
export type Advertiser = Pick<
AdvertiserFragment,
| "selfServiceSetPrice"
| "selfServiceCreate"
| "selfServiceEdit"
| "selfServiceManageCampaign"
| "id"
| "name"
| "publicKey"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Drawer/MiniSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function MiniSideBar({ children }: PropsWithChildren) {
sx={{ color: "text.secondary" }}
/>
),
disabled: !advertiser.selfServiceCreate,
disabled: !advertiser.selfServiceManageCampaign,
},
{
label: "Creatives",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Navigation/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function Navbar() {
<Stack direction="row" alignItems="center" spacing={2}>
<img src={ads} alt="Ads" height="31px" width="180px" />
<Divider orientation="vertical" flexItem />
{advertiser.selfServiceCreate && <DraftMenu />}
{advertiser.selfServiceManageCampaign && <DraftMenu />}
</Stack>
<div style={{ flexGrow: 1 }} />
{
Expand Down
2 changes: 1 addition & 1 deletion src/components/Navigation/NewCampaignButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function NewCampaignButton() {
.utc()
.valueOf()}/settings`;

if (!advertiser.selfServiceCreate) {
if (!advertiser.selfServiceManageCampaign) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/Navigation/NewImageButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button } from "@mui/material";
export function NewImageButton(props: { onClick: () => void }) {
const { advertiser } = useAdvertiser();

if (!advertiser.selfServiceCreate) {
if (!advertiser.selfServiceManageCampaign) {
return null;
}

Expand Down
6 changes: 2 additions & 4 deletions src/graphql/advertiser.generated.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/graphql/advertiser.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ fragment Advertiser on Advertiser {
...AdvertiserSummary
referrer
phone
selfServiceEdit
selfServiceCreate
selfServiceManageCampaign
selfServiceSetPrice
mailingAddress {
street1
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/user/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ export function User() {
<ProtectedRoute
path="/user/main/adsmanager/advanced/new/:draftId"
authedComponent={NewCampaign}
validateAdvertiserProperty={(a) => a.selfServiceCreate}
validateAdvertiserProperty={(a) =>
a.selfServiceManageCampaign
}
/>

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

<ProtectedRoute
Expand Down
4 changes: 1 addition & 3 deletions src/user/views/user/CampaignView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export function CampaignView() {
const { advertiser } = useAdvertiser();
const { fromDate } = useContext(FilterContext);
const [selectedCampaigns, setSelectedCampaigns] = useState<string[]>([]);
const advertiserCanAction =
advertiser.selfServiceCreate && advertiser.selfServiceEdit;

const handleCampaignSelect = useCallback(
(c: string, include: boolean) => {
Expand Down Expand Up @@ -60,7 +58,7 @@ export function CampaignView() {
<MiniSideBar>
<CardContainer
header={
advertiserCanAction ? (
advertiser.selfServiceManageCampaign ? (
<CampaignHeader selectedCampaigns={selectedCampaigns} />
) : (
"Campaigns"
Expand Down

0 comments on commit e51637c

Please sign in to comment.