diff --git a/static/js/src/advantage/distributor/components/DistributorBuyButton/DistributorBuyButton.test.tsx b/static/js/src/advantage/distributor/components/DistributorBuyButton/DistributorBuyButton.test.tsx index cd25a4084f4..f383770dc2c 100644 --- a/static/js/src/advantage/distributor/components/DistributorBuyButton/DistributorBuyButton.test.tsx +++ b/static/js/src/advantage/distributor/components/DistributorBuyButton/DistributorBuyButton.test.tsx @@ -12,7 +12,7 @@ import { FormContext, defaultValues, } from "advantage/distributor/utils/FormContext"; -import { DistributorProduct } from "advantage/subscribe/checkout/utils/test/Mocks"; +import { distributorProduct } from "advantage/subscribe/checkout/utils/test/Mocks"; import { ChannelOfferFactory } from "advantage/offers/tests/factories/channelOffers"; import { UserSubscriptionMarketplace } from "advantage/api/enum"; @@ -27,7 +27,7 @@ const mockSubscription: SubscriptionItem = { const mockContextValue = { ...defaultValues, subscriptionList: [mockSubscription] as SubscriptionItem[], - products: [DistributorProduct] as ChannelProduct[], + products: [distributorProduct] as ChannelProduct[], offer: ChannelOfferFactory.build({ id: "offer-id-1" }), }; diff --git a/static/js/src/advantage/distributor/components/DistributorShopForm/AddSubscriptions/SubscriptionCard.tsx/SubscriptionCard.test.tsx b/static/js/src/advantage/distributor/components/DistributorShopForm/AddSubscriptions/SubscriptionCard.tsx/SubscriptionCard.test.tsx index d453fd8e2b8..2c4b62c302c 100644 --- a/static/js/src/advantage/distributor/components/DistributorShopForm/AddSubscriptions/SubscriptionCard.tsx/SubscriptionCard.test.tsx +++ b/static/js/src/advantage/distributor/components/DistributorShopForm/AddSubscriptions/SubscriptionCard.tsx/SubscriptionCard.test.tsx @@ -11,7 +11,7 @@ import { FormContext, defaultValues, } from "advantage/distributor/utils/FormContext"; -import { DistributorProduct } from "advantage/subscribe/checkout/utils/test/Mocks"; +import { distributorProduct } from "advantage/subscribe/checkout/utils/test/Mocks"; const mockSubscription: SubscriptionItem = { id: "mocked-id-1", @@ -25,7 +25,7 @@ const mockContextValue = { ...defaultValues, subscriptionList: [mockSubscription] as SubscriptionItem[], setSubscriptionList: jest.fn(), - products: [DistributorProduct] as ChannelProduct[], + products: [distributorProduct] as ChannelProduct[], duration: 1, }; diff --git a/static/js/src/advantage/subscribe/checkout/components/Taxes/Taxes.test.tsx b/static/js/src/advantage/subscribe/checkout/components/Taxes/Taxes.test.tsx index 629d990da3d..f1fc24acca7 100644 --- a/static/js/src/advantage/subscribe/checkout/components/Taxes/Taxes.test.tsx +++ b/static/js/src/advantage/subscribe/checkout/components/Taxes/Taxes.test.tsx @@ -3,7 +3,7 @@ import { Formik } from "formik"; import { Elements } from "@stripe/react-stripe-js"; import { loadStripe } from "@stripe/stripe-js"; import { fireEvent, render, screen } from "@testing-library/react"; -import { DistributorProduct, UAProduct } from "../../utils/test/Mocks"; +import { UAProduct } from "../../utils/test/Mocks"; import Taxes from "./Taxes"; describe("TaxesTests", () => { @@ -112,7 +112,7 @@ describe("TaxesTests", () => { global.window = Object.create(window); Object.defineProperty(window, "accountId", { value: "ABCDEF" }); - const initialValues = { + const intialValues = { country: "GB", }; const products = [ @@ -123,7 +123,7 @@ describe("TaxesTests", () => { ]; render( - + @@ -158,7 +158,7 @@ describe("TaxesTests", () => { global.window = Object.create(window); Object.defineProperty(window, "accountId", { value: "ABCDEF" }); - const initialValues = { + const intialValues = { country: "GB", VATNumber: "GB123123123", }; @@ -171,7 +171,7 @@ describe("TaxesTests", () => { ]; render( - + @@ -212,62 +212,4 @@ describe("TaxesTests", () => { expect(screen.getByTestId("country")).toHaveTextContent("United Kingdom"); expect(screen.getByTestId("vat-number")).toHaveTextContent("GB123123123"); }); - - it("Edit button should be displayed for pro users", () => { - global.window = Object.create(window); - Object.defineProperty(window, "accountId", { value: "ABCDEF" }); - - const initialValues = { - country: "GB", - VATNumber: "GB123123123", - marketPlace: "canonical-ua", - }; - - const products = [ - { - product: UAProduct, - quantity: 1, - }, - ]; - render( - - - - - - - , - ); - - expect(screen.queryByRole("button", { name: "Edit" })).toBeInTheDocument(); - }); - - it("Edit button should not be displayed for channel users", () => { - global.window = Object.create(window); - Object.defineProperty(window, "accountId", { value: "ABCDEF" }); - - const initialValues = { - country: "GB", - VATNumber: "GB123123123", - marketPlace: "canonical-pro-channel", - }; - - const products = [ - { - product: DistributorProduct, - quantity: 1, - }, - ]; - render( - - - - - - - , - ); - - expect(screen.queryByTestId("tax-edit-button")).not.toBeInTheDocument(); - }); }); diff --git a/static/js/src/advantage/subscribe/checkout/components/Taxes/Taxes.tsx b/static/js/src/advantage/subscribe/checkout/components/Taxes/Taxes.tsx index fcacd38bbd2..6025410fe23 100644 --- a/static/js/src/advantage/subscribe/checkout/components/Taxes/Taxes.tsx +++ b/static/js/src/advantage/subscribe/checkout/components/Taxes/Taxes.tsx @@ -18,7 +18,6 @@ import { import { getLabel } from "advantage/subscribe/react/utils/utils"; import postCustomerTaxInfo from "../../hooks/postCustomerTaxInfo"; import { CheckoutProducts, FormValues } from "../../utils/types"; -import { UserSubscriptionMarketplace } from "advantage/api/enum"; type TaxesProps = { products: CheckoutProducts[]; @@ -36,14 +35,7 @@ const Taxes = ({ products, setError }: TaxesProps) => { setErrors: setFormikErrors, } = useFormikContext(); const [isEditing, setIsEditing] = useState(!initialValues.country); - const isChannelUser = - products[0]?.product?.marketplace === - UserSubscriptionMarketplace.CanonicalProChannel; const queryClient = useQueryClient(); - const postCustomerTaxInfoMutation = postCustomerTaxInfo(); - const hasZeroPriceValue = products.some( - (item) => item.product.price.value === 0, - ); useEffect(() => { if (errors.VATNumber) { @@ -61,6 +53,10 @@ const Taxes = ({ products, setError }: TaxesProps) => { } }, [initialValues]); + const postCustomerTaxInfoMutation = postCustomerTaxInfo(); + const hasZeroPriceValue = products.some( + (item) => item.product.price.value === 0, + ); const onSaveClick = () => { setIsEditing(false); setFieldTouched("isTaxSaved", false); @@ -74,12 +70,8 @@ const Taxes = ({ products, setError }: TaxesProps) => { }, { onSuccess: () => { - queryClient.invalidateQueries({ - queryKey: ["preview"], - }); - queryClient.invalidateQueries({ - queryKey: ["customerInfo"], - }); + queryClient.invalidateQueries({ queryKey: ["preview"] }); + queryClient.invalidateQueries({ queryKey: ["customerInfo"] }); }, onError: (error) => { setFieldValue("Description", false); @@ -298,52 +290,43 @@ const Taxes = ({ products, setError }: TaxesProps) => { error={touched?.isTaxSaved && errors?.isTaxSaved} /> - {!isChannelUser && ( - <> -
-
- {isEditing ? ( - <> - {window.accountId && !!initialValues.country && ( - { - setFieldValue("country", initialValues.country); - setFieldValue("usState", initialValues.usState); - setFieldValue("caProvince", initialValues.caProvince); - setFieldValue("VATNumber", initialValues.VATNumber); - setIsEditing(false); - setFieldValue("isTaxSaved", true); - setFieldTouched("isTaxSaved", false); - }} - > - Cancel - - )} - - Save - - - ) : ( +
+
+ {isEditing ? ( + <> + {window.accountId && !!initialValues.country ? ( { + setFieldValue("country", initialValues.country); + setFieldValue("usState", initialValues.usState); + setFieldValue("caProvince", initialValues.caProvince); + setFieldValue("VATNumber", initialValues.VATNumber); + setIsEditing(false); + setFieldValue("isTaxSaved", true); + setFieldTouched("isTaxSaved", false); + }} > - Edit + Cancel - )} -
- - )} + ) : null} + + Save + + + ) : ( + Edit + )} +
); diff --git a/static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.test.tsx b/static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.test.tsx index aaf27cad4fc..039251199f4 100644 --- a/static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.test.tsx +++ b/static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.test.tsx @@ -4,7 +4,6 @@ import { Elements } from "@stripe/react-stripe-js"; import { loadStripe } from "@stripe/stripe-js"; import { fireEvent, render, screen } from "@testing-library/react"; import UserInfoForm from "./UserInfoForm"; -import { UserSubscriptionMarketplace } from "advantage/api/enum"; describe("UserInfoFormTests", () => { let queryClient: QueryClient; @@ -18,7 +17,7 @@ describe("UserInfoFormTests", () => { global.window = Object.create(window); Object.defineProperty(window, "accountId", { value: "ABCDEF" }); - const initialValues = { + const intialValues = { name: "Joe", organisationName: "Canonical", buyingFor: "organisation", @@ -37,7 +36,7 @@ describe("UserInfoFormTests", () => { render( - + @@ -76,54 +75,4 @@ describe("UserInfoFormTests", () => { "AB12 3CD", ); }); - - it("Channel user should be able to edit only card number", () => { - global.window = Object.create(window); - Object.defineProperty(window, "accountId", { value: "ABCDEF" }); - - const initialValues = { - name: "Min", - marketplace: UserSubscriptionMarketplace.CanonicalProChannel, - buyingFor: "organisation", - organisationName: "Canonical", - address: "ABC Street", - city: "DEF City", - postalCode: "AB12 3CD", - defaultPaymentMethod: { - brand: "visa", - country: "US", - expMonth: 4, - expYear: 2024, - id: "pm_ABCDEF", - last4: "4242", - }, - }; - - render( - - - - - - - , - ); - - fireEvent.click(screen.getByRole("button", { name: "Edit" })); - fireEvent.change(screen.getByTestId("field-card-number"), { - target: { value: "1234 5678 1234 5678" }, - }); - - expect(screen.getByTestId("customer-name")).toHaveTextContent("Min"); - expect(screen.getByTestId("organisation-name")).toHaveTextContent( - "Canonical", - ); - expect(screen.getByTestId("customer-address")).toHaveTextContent( - "ABC Street", - ); - expect(screen.getByTestId("customer-city")).toHaveTextContent("DEF City"); - expect(screen.getByTestId("customer-postal-code")).toHaveTextContent( - "AB12 3CD", - ); - }); }); diff --git a/static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.tsx b/static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.tsx index 92bbcfbac71..bcc0ed77fcb 100644 --- a/static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.tsx +++ b/static/js/src/advantage/subscribe/checkout/components/UserInfoForm/UserInfoForm.tsx @@ -15,7 +15,6 @@ import registerPaymentMethod from "../../hooks/postCustomerInfo"; import { FormValues } from "../../utils/types"; import FormRow from "../FormRow"; import PaymentMethodSummary from "./PaymentMethodSummary"; -import { UserSubscriptionMarketplace } from "advantage/api/enum"; type Error = { type: "validation_error"; @@ -46,8 +45,6 @@ const UserInfoForm = ({ setError }: Props) => { const [cardFieldHasFocus, setCardFieldFocus] = useState(false); const [cardFieldError, setCardFieldError] = useState(null); const [showCardValidation, setShowCardValidation] = useState(false); - const isChannelUser = - values.marketplace === UserSubscriptionMarketplace.CanonicalProChannel; const toggleEditing = () => { if (isEditing) { @@ -90,9 +87,7 @@ const UserInfoForm = ({ setError }: Props) => { { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["customerInfo"] }); - queryClient.invalidateQueries({ - queryKey: ["preview"], - }); + queryClient.invalidateQueries({ queryKey: ["preview"] }); setIsButtonDisabled(false); setIsEditing(false); }, @@ -149,9 +144,10 @@ const UserInfoForm = ({ setError }: Props) => { return errorMessage; }; - const UserInfoSummary = () => ( + const displayMode = ( <> - {values.buyingFor === "organisation" && ( + + {values.buyingFor === "organisation" ? ( <> @@ -167,7 +163,7 @@ const UserInfoForm = ({ setError }: Props) => {
- )} + ) : null}

Your name:

@@ -216,13 +212,6 @@ const UserInfoForm = ({ setError }: Props) => { ); - const displayMode = ( - <> - - - - ); - const editMode = ( <> { }} required error={touched?.isCardValid && errors?.isCardValid} - data-testid="field-card-number" /> - {isChannelUser ? ( - - ) : ( - <> - - -
- - {({ field }: any) => ( - <> - setFieldValue("buyingFor", "myself")} - label="Myself" - disabled={ - window.accountId && initialValues.organisationName - } - /> - - setFieldValue("buyingFor", "organisation") - } - label="An organisation" - disabled={ - window.accountId && initialValues.organisationName - } - /> - - )} - -
-
- {initialValues.buyingFor === "myself" && - window.accountId && - initialValues.organisationName ? null : ( - - )} - - - - + + +
+ + {({ field }: any) => ( + <> + setFieldValue("buyingFor", "myself")} + label="Myself" + disabled={window.accountId && initialValues.organisationName} + /> + setFieldValue("buyingFor", "organisation")} + label="An organisation" + disabled={window.accountId && initialValues.organisationName} + /> + + )} + +
+
+ {initialValues.buyingFor === "myself" && + window.accountId && + initialValues.organisationName ? null : ( + )} + + + ); diff --git a/static/js/src/advantage/subscribe/checkout/utils/test/Mocks.ts b/static/js/src/advantage/subscribe/checkout/utils/test/Mocks.ts index 52f4f5371a1..c5b6d4f9421 100644 --- a/static/js/src/advantage/subscribe/checkout/utils/test/Mocks.ts +++ b/static/js/src/advantage/subscribe/checkout/utils/test/Mocks.ts @@ -152,7 +152,7 @@ export const BlenderProduct: Product = { canBeTrialled: false, }; -export const DistributorProduct: ChannelProduct = { +export const distributorProduct: ChannelProduct = { id: "uai-essential-desktop-1y-channel-eur-v2", longId: "lANXjQ-H8fzvf_Ea8bIK1KW7Wi2W0VHnV0ZUsrEGbUiQ", name: "uai-essential-desktop-1y-channel-eur-v2",