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

feat: add close callbacks #152

Merged
merged 2 commits into from
May 22, 2024
Merged
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
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
Loading