Skip to content

Commit

Permalink
Merge pull request #1071 from brave/master
Browse files Browse the repository at this point in the history
Production Release 2024-02-06
  • Loading branch information
IanKrieger authored Feb 6, 2024
2 parents 06c7a3a + 7a692de commit 3c37c35
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
15 changes: 9 additions & 6 deletions src/auth/components/AdvertiserDetailsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PaymentType } from "graphql/types";
import { AdvertiserAgreed } from "auth/components/AdvertiserAgreed";
import { FormikSubmitButton } from "form/FormikButton";
import { AdvertiserSchema } from "validation/AdvertiserSchema";
import { useState } from "react";

export function AdvertiserDetailsForm() {
const history = useHistory();
Expand All @@ -23,6 +24,9 @@ export function AdvertiserDetailsForm() {
const requiresPaymentAgree =
advertiser.selfServiceManageCampaign &&
advertiser.selfServicePaymentType !== PaymentType.Netsuite;
const [initial, setInitial] = useState<AdvertiserForm>(
initialAdvertiserForm(!requiresPaymentAgree),
);

const [mutation] = useUpdateAdvertiserMutation({
async onCompleted() {
Expand All @@ -34,25 +38,24 @@ export function AdvertiserDetailsForm() {

const { data, loading } = useAdvertiserBillingAddressQuery({
variables: { id: advertiser.id },
onCompleted: (data) => {
setInitial(initialAdvertiserForm(!requiresPaymentAgree, data.advertiser));
},
});

const initial = initialAdvertiserForm(
!requiresPaymentAgree,
data?.advertiser,
);

return (
<Container maxWidth="lg" sx={{ mt: 5 }}>
<Formik
initialValues={initial}
enableReinitialize
onSubmit={async (v: AdvertiserForm, { setSubmitting }) => {
setSubmitting(true);
await mutation({
variables: {
updateAdvertiserInput: {
id: advertiser.id,
agreed: v.terms && v.tracking && v.payment,
billingAddress: v.address,
billingAddress: v.address.id ? undefined : v.address,
},
},
});
Expand Down
30 changes: 16 additions & 14 deletions src/auth/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type AdvertiserForm = {
payment: boolean;
terms: boolean;
address: {
id?: string | null;
street1: string;
street2?: string | null;
city: string;
Expand All @@ -18,17 +19,18 @@ type MaybeAddress = AdvertiserBillingAddressFragment;
export const initialAdvertiserForm = (
paymentAgree: boolean,
maybeAddress?: MaybeAddress | null,
): AdvertiserForm => ({
tracking: false,
payment: paymentAgree,
terms: false,
address: maybeAddress?.billingAddress
? { ...maybeAddress.billingAddress }
: {
street1: "",
city: "",
state: "",
country: "",
zipcode: "",
},
});
): AdvertiserForm => {
return {
tracking: false,
payment: paymentAgree,
terms: false,
address: {
id: maybeAddress?.billingAddress?.id ?? null,
street1: maybeAddress?.billingAddress?.street1 ?? "",
city: maybeAddress?.billingAddress?.city ?? "",
state: maybeAddress?.billingAddress?.state ?? "",
country: maybeAddress?.billingAddress?.country ?? "",
zipcode: maybeAddress?.billingAddress?.zipcode ?? "",
},
};
};
3 changes: 3 additions & 0 deletions src/graphql/advertiser.generated.tsx

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

1 change: 1 addition & 0 deletions src/graphql/advertiser.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fragment AdvertiserSummary on Advertiser {

fragment AdvertiserBillingAddress on Advertiser {
billingAddress {
id
street1
street2
city
Expand Down
1 change: 1 addition & 0 deletions src/validation/AdvertiserSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const AdvertiserSchema = object().shape({
.default(false)
.isTrue("Terms & Conditions acknowledgement is required"),
address: object().shape({
id: string().nullable(),
street1: string().label("Street address").required(),
street2: string().label("Street address line 2").nullable(),
city: string().label("City").required(),
Expand Down

0 comments on commit 3c37c35

Please sign in to comment.