Skip to content

Commit

Permalink
Merge pull request #152 from bosonprotocol/add-close-callbacks
Browse files Browse the repository at this point in the history
feat: add close callbacks
  • Loading branch information
albertfolch-redeemeum authored May 22, 2024
2 parents 01e6d27 + ce9a8ee commit 4d8d685
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
]
},
"dependencies": {
"@bosonprotocol/react-kit": "^0.30.1",
"@bosonprotocol/react-kit": "^0.31.0",
"@krakenjs/zoid": "^10.3.3",
"@svgr/webpack": "^8.1.0",
"@testing-library/jest-dom": "^5.16.5",
Expand Down
6 changes: 6 additions & 0 deletions public/scripts/commit-button-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ <h3>Commit button example</h3>
},
onClickTagline: function () {
console.log("you clicked on the tagline!");
},
onCloseCommitButton: function () {
console.log("commit button widget was closed!");
},
onCloseTagline: function () {
console.log("purchase overview widget was closed!");
}
});

Expand Down
16 changes: 16 additions & 0 deletions src/components/widgets/commitButton/CommitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ export function CommitButton() {
CommitWidgetModal({
bodyOverflow,
...commitWidgetProps,
onClose: () => {
if (
typeof props.onCloseCommitButton === "function" &&
props.onCloseCommitButton
) {
props.onCloseCommitButton();
}
},
modalMargin
}).renderTo(window.parent, renderToValue, validatedContext);
if (
Expand All @@ -120,6 +128,14 @@ export function CommitButton() {
onTaglineClick={() => {
PurchaseOverviewModal({
bodyOverflow,
onClose: () => {
if (
typeof props.onCloseTagline === "function" &&
props.onCloseTagline
) {
props.onCloseTagline();
}
},
modalMargin
}).renderTo(window.parent, renderToValue, validatedContext);
if (
Expand Down
28 changes: 11 additions & 17 deletions src/components/widgets/purchaseOverview/PurchaseOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,25 @@ export const PurchaseOverview = () => {
const validatedProps = useMemo(() => {
return yup
.object({
close: yup.mixed<() => any>().test({
test: (value) => {
return value === undefined || typeof value === "function";
}
}),
modalMargin: yup.string().optional()
modalMargin: yup.string().optional(),
bodyOverflow: yup.string().optional().nullable(true)
})
.validateSync(props);
}, [props]);
return (
<>
<GlobalStyle
$bodyOverflow={
typeof props.bodyOverflow === "string"
? props.bodyOverflow
: undefined
}
/>
<GlobalStyle $bodyOverflow={validatedProps.bodyOverflow} />
<PurchaseOverviewReactKit
lookAndFeel="modal"
modalMargin={validatedProps.modalMargin}
hideModal={
validatedProps.close ||
(() => console.log("close purchase overview modal"))
}
hideModal={() => {
if (
"close" in window.xprops &&
typeof window.xprops.close === "function"
) {
window.xprops.close();
}
}}
/>
</>
);
Expand Down
4 changes: 3 additions & 1 deletion src/components/widgets/redeem/Redeem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export function Redeem() {
const signatures = signaturesStr ? signaturesStr.split(",") : undefined;

const eventTag = searchParams.get("eventTag") as string;

const lookAndFeel =
(searchParams.get("lookAndFeel") as "regular" | "modal") || "regular";
// In case the deliveryInfo shall be transferred between frontend windows, the targetOrigin
// the deliveryInfo message shall be posted to
// (see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#targetorigin)
Expand All @@ -127,6 +128,7 @@ export function Redeem() {
signatures={signatures}
configId={configId}
forcedAccount={account}
lookAndFeel={lookAndFeel}
envName={CONFIG.envName}
metaTx={getMetaTxConfig(configId)}
dateFormat="YYYY/MM/DD"
Expand Down

0 comments on commit 4d8d685

Please sign in to comment.