Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make container ID as optional prop #110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/bricks/brand/brand.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,20 @@ describe('Test Brand Brick Component', () => {

expect(element.container.querySelector('#brandBrick_container')).toBeTruthy();
});
test('should found the id of Brand Brick div if specified', async () => {
MercadoPagoInstance.publicKey = 'PUBLIC_KEY';
const element = await render(
<Brand
customization={{
text: {
valueProp: 'payment_methods_logos',
},
}}
divId="customBrandBrick_container"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
divId="customBrandBrick_container"
id="customBrandBrick_container"

onReady={() => console.log('Brick is ready!')}
/>,
);

expect(element.container.querySelector('#customBrandBrick_container')).toBeTruthy();
});
});
11 changes: 8 additions & 3 deletions src/bricks/brand/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import { TBrand } from './types';
*
* @see {@link https://www.mercadopago.com.ar/developers/en/docs/checkout-bricks/brand-brick/introduction Brand Brick documentation} for more information.
*/
const Brand = ({ onReady = onReadyDefault, customization, locale }: TBrand) => {
const Brand = ({
onReady = onReadyDefault,
customization,
locale,
divId = 'brandBrick_container',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
divId = 'brandBrick_container',
id = 'brandBrick_container',

}: TBrand) => {
useEffect(() => {
// Brand uses a debounce to prevent unnecessary reRenders.
let timer: ReturnType<typeof setTimeout>;
Expand All @@ -37,7 +42,7 @@ const Brand = ({ onReady = onReadyDefault, customization, locale }: TBrand) => {
},
},
name: 'brand',
divId: 'brandBrick_container',
divId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
divId,
divId: id,

controller: 'brandBrickController',
};

Expand All @@ -50,7 +55,7 @@ const Brand = ({ onReady = onReadyDefault, customization, locale }: TBrand) => {
window.brandBrickController?.unmount();
};
}, [customization, onReady]);
return <div id="brandBrick_container"></div>;
return <div id={divId}></div>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return <div id={divId}></div>;
return <div id={id}></div>;

};

export default Brand;
4 changes: 4 additions & 0 deletions src/bricks/brand/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export type TBrand = {
* @see {@link https://www.mercadopago.com/developers/en/docs/checkout-bricks/additional-content/select-language Bricks language customization} documentation.
*/
locale?: 'es-AR' | 'es-CL' | 'es-CO' | 'es-MX' | 'es-VE' | 'es-UY' | 'es-PE' | 'pt-BR' | 'en-US';
/**
* Optional. Container ID where the Brick will be rendered. Default: 'walletBrick_container'
*/
divId?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
divId?: string;
id?: string;

};

export interface IBrandCustomization {
Expand Down
14 changes: 14 additions & 0 deletions src/bricks/cardPayment/cardPayment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,18 @@ describe('Test Card Payment Brick Component', () => {

expect(element.container.querySelector('#cardPaymentBrick_container')).toBeTruthy();
});
test('should found the id of Card Payment Brick div if specified', async () => {
MercadoPagoInstance.publicKey = 'PUBLIC_KEY';
const element = await render(
<CardPayment
divId="customCardPaymentBrick_container"
initialization={{ amount: 100 }}
onSubmit={async (param) => {
console.log(param);
}}
/>,
);

expect(element.container.querySelector('#customCardPaymentBrick_container')).toBeTruthy();
});
});
5 changes: 3 additions & 2 deletions src/bricks/cardPayment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const CardPayment = ({
initialization,
customization,
locale,
divId = 'cardPaymentBrick_container',
}: TCardPayment) => {
useEffect(() => {
// CardPayment uses a debounce to prevent unnecessary reRenders.
Expand All @@ -59,7 +60,7 @@ const CardPayment = ({
locale,
},
name: 'cardPayment',
divId: 'cardPaymentBrick_container',
divId,
controller: 'cardPaymentBrickController',
};
timer = setTimeout(() => {
Expand All @@ -72,7 +73,7 @@ const CardPayment = ({
};
}, [initialization, customization, onBinChange, onReady, onError, onSubmit]);

return <div id="cardPaymentBrick_container"></div>;
return <div id={divId}></div>;
};

const useCardPaymentBrick = () => {
Expand Down
4 changes: 4 additions & 0 deletions src/bricks/cardPayment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export type TCardPayment = {
*/
visual?: object;
};
/**
* Optional. Container ID where the Brick will be rendered. Default: 'walletBrick_container'
*/
divId?: string;
};

export interface ICardPaymentBrickPayer {
Expand Down
5 changes: 3 additions & 2 deletions src/bricks/payment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const Payment = ({
initialization,
customization,
locale,
divId = 'paymentBrick_container',
}: TPaymentType) => {
useEffect(() => {
// Payment uses a debounce to prevent unnecessary reRenders.
Expand All @@ -70,7 +71,7 @@ const Payment = ({
},
},
name: 'payment',
divId: 'paymentBrick_container',
divId,
controller: 'paymentBrickController',
};
timer = setTimeout(() => {
Expand All @@ -83,7 +84,7 @@ const Payment = ({
};
}, [initialization, customization, onReady, onError, onSubmit, onBinChange]);

return <div id="paymentBrick_container"></div>;
return <div id={divId}></div>;
};

const usePaymentBrick = () => {
Expand Down
24 changes: 24 additions & 0 deletions src/bricks/payment/payment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,28 @@ describe('Test Payment Brick Component', () => {

expect(element.container.querySelector('#paymentBrick_container')).toBeTruthy();
});
test('should found the id of Payment Brick divif specified', async () => {
MercadoPagoInstance.publicKey = 'PUBLIC_KEY';
const element = await render(
<BrickPayment
initialization={{ amount: 100 }}
customization={{
paymentMethods: {
bankTransfer: ['pix'],
ticket: 'all',
atm: 'all',
creditCard: 'all',
debitCard: 'all',
mercadoPago: 'all',
},
}}
divId="customPaymentBrick_container"
onSubmit={async (param) => {
console.log(param);
}}
/>,
);

expect(element.container.querySelector('#customPaymentBrick_container')).toBeTruthy();
});
});
4 changes: 4 additions & 0 deletions src/bricks/payment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export type TPaymentType = {
* @see {@link https://www.mercadopago.com/developers/en/docs/checkout-bricks/additional-content/select-language General Customizations # Select Language} documentation.
*/
locale?: string;
/**
* Optional. Container ID where the Brick will be rendered. Default: 'walletBrick_container'
*/
divId?: string;
};
export interface IReviewConfirmItems {
/**
Expand Down
5 changes: 3 additions & 2 deletions src/bricks/statusScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const StatusScreen = ({
customization,
initialization,
locale,
divId = 'statusScreenBrick_container',
}: IStatusScreenBrickSettings) => {
useEffect(() => {
// Status Screen uses a debounce to prevent unnecessary reRenders.
Expand All @@ -50,7 +51,7 @@ const StatusScreen = ({
},
},
name: 'statusScreen',
divId: 'statusScreenBrick_container',
divId,
controller: 'statusScreenBrickController',
};
timer = setTimeout(() => {
Expand All @@ -62,7 +63,7 @@ const StatusScreen = ({
window.statusScreenBrickController?.unmount();
};
}, [initialization, customization, onReady, onError]);
return <div id="statusScreenBrick_container"></div>;
return <div id={divId}></div>;
};

export default StatusScreen;
11 changes: 11 additions & 0 deletions src/bricks/statusScreen/statusScreenBrick.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@ describe('Test Status Screen Brick Component', () => {

expect(element.container.querySelector('#statusScreenBrick_container')).toBeTruthy();
});
test('should found the id of Status Screen Brick div if specified', async () => {
MercadoPagoInstance.publicKey = 'PUBLIC_KEY';
const element = await render(
<StatusScreen
divId="customStatusScreenBrick_container"
initialization={{ paymentId: '<PAYMENT_ID>' }}
/>,
);

expect(element.container.querySelector('#customStatusScreenBrick_container')).toBeTruthy();
});
});
4 changes: 4 additions & 0 deletions src/bricks/statusScreen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export interface IStatusScreenBrickSettings extends IStatusScreenBrickCallbacks
* @see {@link https://www.mercadopago.com/developers/en/docs/checkout-bricks/additional-content/select-language General Customization # Select Language} documentation.
*/
locale?: 'es-AR' | 'es-CL' | 'es-CO' | 'es-MX' | 'es-VE' | 'es-UY' | 'es-PE' | 'pt-BR' | 'en-US';
/**
* Optional. Container ID where the Brick will be rendered. Default: 'walletBrick_container'
*/
divId?: string;
}

export interface IStatusScreenBrickInitialization {
Expand Down
5 changes: 3 additions & 2 deletions src/bricks/wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Wallet = ({
initialization,
brand,
locale,
divId = 'walletBrick_container',
}: TWallet) => {
useEffect(() => {
// CardPayment uses a debounce to prevent unnecessary reRenders.
Expand All @@ -49,7 +50,7 @@ const Wallet = ({
},
},
name: 'wallet',
divId: 'walletBrick_container',
divId,
controller: 'walletBrickController',
};

Expand All @@ -62,7 +63,7 @@ const Wallet = ({
window.walletBrickController?.unmount();
};
}, [customization, initialization, onReady, onError, onSubmit]);
return <div id="walletBrick_container"></div>;
return <div id={divId}></div>;
};

export default Wallet;
8 changes: 8 additions & 0 deletions src/bricks/wallet/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export interface PreferenceOnSubmit extends IBrickSettings {
* @see {@link https://www.mercadopago.com/developers/en/docs/checkout-bricks/additional-content/select-language Bricks language customization} documentation.
*/
locale?: 'es-AR' | 'es-CL' | 'es-CO' | 'es-MX' | 'es-VE' | 'es-UY' | 'es-PE' | 'pt-BR' | 'en-US';
/**
* Optional. Container ID where the Brick will be rendered. Default: 'walletBrick_container'
*/
divId?: string;
}

export interface PreferenceOnInitialization extends IBrickSettings {
Expand Down Expand Up @@ -175,6 +179,10 @@ export interface PreferenceOnInitialization extends IBrickSettings {
* @see {@link https://www.mercadopago.com/developers/en/docs/checkout-bricks/additional-content/select-language Bricks language customization} documentation.
*/
locale?: 'es-AR' | 'es-CL' | 'es-CO' | 'es-MX' | 'es-VE' | 'es-UY' | 'es-PE' | 'pt-BR' | 'en-US';
/**
* Optional. Container ID where the Brick will be rendered. Default: 'walletBrick_container'
*/
divId?: string;
}

export type TWallet = PreferenceOnInitialization | PreferenceOnSubmit;
11 changes: 11 additions & 0 deletions src/bricks/wallet/walletBrick.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ describe('Test Wallet Brick Component', () => {

expect(element.container.querySelector('#walletBrick_container')).toBeTruthy();
});
test('should found the id of Wallet Brick div if specified', async () => {
MercadoPagoInstance.publicKey = 'PUBLIC_KEY';
const element = await render(
<WalletBrick
initialization={{ preferenceId: '<PREFERENCE_ID>' }}
divId="customWalletBrick_container"
/>,
);

expect(element.container.querySelector('#customWalletBrick_container')).toBeTruthy();
});
});