Skip to content

Commit

Permalink
Merge pull request #1281 from brave/master
Browse files Browse the repository at this point in the history
Production Release 2024-07-30
  • Loading branch information
IanKrieger authored Jul 30, 2024
2 parents 77d8066 + 37993ed commit da333b4
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 132 deletions.
23 changes: 12 additions & 11 deletions src/components/Creatives/CreativeStatusSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ import {
AdvertiserCreativesDocument,
CampaignsForCreativeDocument,
CreativeFragment,
UpdateCreativeDocument,
} from "@/graphql-client/graphql";
import { useLazyQuery, useMutation } from "@apollo/client";
import { graphql } from "@/graphql-client/index";

interface Props {
creative: CreativeFragment;
}

const Creative_State_Update = graphql(`
mutation AdsManagerUpdateCreativeState($id: String!, $state: String!) {
adsManagerUpdateCreativeState(id: $id, state: $state) {
id
}
}
`);

type RelatedCampaign = { id: string; name: string; state: string };
export function CreativeStatusSwitch({ creative }: Props) {
const { advertiser } = useAdvertiser();
Expand All @@ -41,20 +49,13 @@ export function CreativeStatusSwitch({ creative }: Props) {
);
const [creativeState, setCreativeState] = useState(input.state);
const [update, { loading: updateLoading }] = useMutation(
UpdateCreativeDocument,
Creative_State_Update,
{
refetchQueries: [
{
query: AdvertiserCreativesDocument,
variables: { advertiserId: advertiser.id },
},
{
query: CampaignsForCreativeDocument,
variables: {
creativeId: creative.id,
advertiserId: advertiser.id,
},
},
],
onCompleted() {
setRelatedCampaigns([]);
Expand Down Expand Up @@ -86,7 +87,7 @@ export function CreativeStatusSwitch({ creative }: Props) {
update({
variables: {
id: creative.id,
input: { ...input, state: theState },
state: theState,
},
});
}
Expand Down Expand Up @@ -137,7 +138,7 @@ export function CreativeStatusSwitch({ creative }: Props) {
update({
variables: {
id: creative.id,
input: { ...input, state: creativeState },
state: creativeState,
},
});
}}
Expand Down
25 changes: 22 additions & 3 deletions src/components/Creatives/hooks/useSubmitCreative.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useCallback } from "react";
import {
AdvertiserCreativesDocument,
CreateCreativeDocument,
UpdateCreativeDocument,
} from "@/graphql-client/graphql";
import { useAdvertiser } from "@/auth/hooks/queries/useAdvertiser";
import { useHistory } from "react-router-dom";
Expand All @@ -11,6 +10,17 @@ import _ from "lodash";
import { useTrackMatomoEvent } from "@/hooks/useTrackWithMatomo";
import { useMutation } from "@apollo/client";
import { CreativeInputWithType } from "@/user/views/adsManager/types";
import { graphql } from "@/graphql-client/index";

const Update_Creative_Payload = graphql(`
mutation AdsManagerUpdateCreativePayload(
$input: AdsManagerUpdateCreativeInput!
) {
adsManagerUpdateCreativePayload(adsManagerUpdateCreativeInput: $input) {
id
}
}
`);

export function useSubmitCreative(props: { id: string }) {
const { trackMatomoEvent } = useTrackMatomoEvent();
Expand Down Expand Up @@ -39,7 +49,7 @@ export function useSubmitCreative(props: { id: string }) {
});

const [updateCreative, { error: updateError, loading: updateLoading }] =
useMutation(UpdateCreativeDocument, {
useMutation(Update_Creative_Payload, {
refetchQueries,
onCompleted,
onError,
Expand All @@ -65,7 +75,16 @@ export function useSubmitCreative(props: { id: string }) {
});
} else {
await updateCreative({
variables: { input: input, id: props.id },
variables: {
input: {
id: props.id,
payloadNotification: input.payloadNotification,
payloadInlineContent: _.omit(
input.payloadInlineContent,
"dimensions",
),
},
},
});
}
} finally {
Expand Down
14 changes: 12 additions & 2 deletions src/graphql-client/gql.ts

Large diffs are not rendered by default.

67 changes: 51 additions & 16 deletions src/graphql-client/graphql.ts

Large diffs are not rendered by default.

Loading

0 comments on commit da333b4

Please sign in to comment.