@saasquatch/mint-components 1.13.3-2 → 1.13.3-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ErrorView-b2fcf954.js +35 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/mint-components.cjs.js +1 -1
- package/dist/cjs/sqm-banking-info-form_17.cjs.entry.js +3 -2
- package/dist/cjs/{sqm-invoice-table-view-baded4af.js → sqm-invoice-table-view-16ac73d0.js} +2 -31
- package/dist/cjs/{sqm-qr-code-view-7b26582e.js → sqm-qr-code-view-a212589a.js} +5 -3
- package/dist/cjs/sqm-qr-code.cjs.entry.js +76 -23
- package/dist/cjs/sqm-stencilbook.cjs.entry.js +11 -3
- package/dist/collection/components/sqm-qr-code/QRCode.stories.js +6 -0
- package/dist/collection/components/sqm-qr-code/sqm-qr-code-view.js +5 -3
- package/dist/collection/components/sqm-qr-code/sqm-qr-code.js +51 -1
- package/dist/collection/components/sqm-qr-code/useQRCode.js +67 -23
- package/dist/esm/ErrorView-48e2b969.js +33 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/mint-components.js +1 -1
- package/dist/esm/sqm-banking-info-form_17.entry.js +2 -1
- package/dist/esm/{sqm-invoice-table-view-af69cd33.js → sqm-invoice-table-view-2c726568.js} +2 -30
- package/dist/esm/{sqm-qr-code-view-814b2929.js → sqm-qr-code-view-e04ce586.js} +5 -3
- package/dist/esm/sqm-qr-code.entry.js +77 -24
- package/dist/esm/sqm-stencilbook.entry.js +11 -3
- package/dist/esm-es5/ErrorView-48e2b969.js +1 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/mint-components.js +1 -1
- package/dist/esm-es5/sqm-banking-info-form_17.entry.js +1 -1
- package/dist/esm-es5/sqm-invoice-table-view-2c726568.js +1 -0
- package/dist/esm-es5/sqm-qr-code-view-e04ce586.js +1 -0
- package/dist/esm-es5/sqm-qr-code.entry.js +1 -1
- package/dist/esm-es5/sqm-stencilbook.entry.js +1 -1
- package/dist/mint-components/mint-components.esm.js +1 -1
- package/dist/mint-components/{p-f29eda2f.entry.js → p-012af236.entry.js} +4 -4
- package/dist/mint-components/p-25f908a0.system.entry.js +1 -0
- package/dist/mint-components/p-37996351.system.js +1 -1
- package/dist/mint-components/p-3a62a7e2.system.js +1 -0
- package/dist/mint-components/p-3a9121ce.entry.js +17 -0
- package/dist/mint-components/p-3f067fd5.js +1 -0
- package/dist/mint-components/p-494572ef.system.js +1 -0
- package/dist/mint-components/p-567d24c8.system.entry.js +1 -0
- package/dist/mint-components/p-5afd7e38.system.entry.js +1 -0
- package/dist/mint-components/p-9acb5038.js +1 -0
- package/dist/mint-components/p-a7746488.system.js +1 -0
- package/dist/mint-components/p-e9772bf3.js +1 -0
- package/dist/mint-components/{p-10cc43c9.entry.js → p-fcd121db.entry.js} +2 -2
- package/dist/types/components/sqm-qr-code/QRCode.stories.d.ts +1 -0
- package/dist/types/components/sqm-qr-code/sqm-qr-code-view.d.ts +4 -1
- package/dist/types/components/sqm-qr-code/sqm-qr-code.d.ts +8 -0
- package/dist/types/components/sqm-qr-code/useQRCode.d.ts +2 -13
- package/dist/types/components.d.ts +16 -0
- package/docs/docs.docx +0 -0
- package/docs/raisins.json +1 -1
- package/grapesjs/grapesjs.js +1 -1
- package/package.json +1 -1
- package/dist/esm-es5/sqm-invoice-table-view-af69cd33.js +0 -1
- package/dist/esm-es5/sqm-qr-code-view-814b2929.js +0 -1
- package/dist/mint-components/p-30362262.system.entry.js +0 -1
- package/dist/mint-components/p-313feb4a.system.entry.js +0 -1
- package/dist/mint-components/p-49670357.entry.js +0 -13
- package/dist/mint-components/p-5aae2d61.system.js +0 -1
- package/dist/mint-components/p-9320582e.system.js +0 -1
- package/dist/mint-components/p-962f3200.js +0 -1
- package/dist/mint-components/p-b93fd99c.system.entry.js +0 -1
- package/dist/mint-components/p-bcac3ecf.js +0 -1
|
@@ -9,7 +9,8 @@ const cjs = require('./cjs-1066ec21.js');
|
|
|
9
9
|
const utils = require('./utils-6847bc06.js');
|
|
10
10
|
require('./JSS-8503a151.js');
|
|
11
11
|
const useReferralCodes = require('./useReferralCodes-82e8797b.js');
|
|
12
|
-
|
|
12
|
+
require('./ErrorView-b2fcf954.js');
|
|
13
|
+
const sqmQrCodeView = require('./sqm-qr-code-view-a212589a.js');
|
|
13
14
|
|
|
14
15
|
const ShareLinkQuery = index_module.dist.gql `
|
|
15
16
|
query shareLink($programId: ID, $engagementMedium: UserEngagementMedium!) {
|
|
@@ -24,44 +25,88 @@ const ShareLinkQuery = index_module.dist.gql `
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
`;
|
|
28
|
+
const WIDGET_ENGAGEMENT_EVENT = index_module.dist.gql `
|
|
29
|
+
mutation loadEvent($eventMeta: UserAnalyticsEvent!) {
|
|
30
|
+
createUserAnalyticsEvent(eventMeta: $eventMeta)
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
27
33
|
function useQRCode(props) {
|
|
28
34
|
const programId = index_module.H();
|
|
29
35
|
const user = index_module.J();
|
|
30
36
|
const engagementMedium = index_module.B();
|
|
31
37
|
const contextData = index_module.Fn(useReferralCodes.REFERRAL_CODES_NAMESPACE);
|
|
32
38
|
const [dialogIsOpen, setDialog] = stencilHooks_module.useState(false);
|
|
39
|
+
const [error, setError] = stencilHooks_module.useState(false);
|
|
33
40
|
const { data } = index_module.wn(ShareLinkQuery, { programId, engagementMedium }, !(user === null || user === void 0 ? void 0 : user.jwt) || (contextData === null || contextData === void 0 ? void 0 : contextData.shareLink) !== undefined);
|
|
34
|
-
const
|
|
41
|
+
const [sendLoadEvent] = index_module.$e(WIDGET_ENGAGEMENT_EVENT);
|
|
42
|
+
const qrLink = data ? `${data.user.shareLink}?qrCode` : "";
|
|
43
|
+
const fireEvent = async () => {
|
|
44
|
+
sendLoadEvent({
|
|
45
|
+
eventMeta: {
|
|
46
|
+
programId,
|
|
47
|
+
id: user === null || user === void 0 ? void 0 : user.id,
|
|
48
|
+
accountId: user === null || user === void 0 ? void 0 : user.accountId,
|
|
49
|
+
type: "USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENET",
|
|
50
|
+
meta: {
|
|
51
|
+
engagementMedium,
|
|
52
|
+
shareMedium: "DIRECT",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
};
|
|
35
57
|
const createDownloadable = async () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
try {
|
|
59
|
+
const res = await fetch(`${qrLink}&qrCodeSize=800&qrCodeImageFormat=png`);
|
|
60
|
+
const blob = await res.blob();
|
|
61
|
+
const url = URL.createObjectURL(blob);
|
|
62
|
+
// Successful
|
|
63
|
+
if (blob)
|
|
64
|
+
fireEvent();
|
|
65
|
+
// Trigger download
|
|
66
|
+
const link = document.createElement("a");
|
|
67
|
+
link.href = url;
|
|
68
|
+
link.download = "qrCode.png";
|
|
69
|
+
document.body.appendChild(link);
|
|
70
|
+
link.click();
|
|
71
|
+
document.body.removeChild(link);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
console.error("Failed to fetch QR code:", e);
|
|
75
|
+
setError(true);
|
|
76
|
+
}
|
|
45
77
|
};
|
|
46
78
|
const createPrintable = async () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
page.
|
|
56
|
-
|
|
57
|
-
|
|
79
|
+
try {
|
|
80
|
+
const res = await fetch(`${qrLink}&qrCodeSize=1000&qrCodeImageFormat=png&qrCodeErrorCorrectionLevel=H`);
|
|
81
|
+
const blob = await res.blob();
|
|
82
|
+
const url = URL.createObjectURL(blob);
|
|
83
|
+
// Successful
|
|
84
|
+
if (blob)
|
|
85
|
+
fireEvent();
|
|
86
|
+
// Trigger print
|
|
87
|
+
const page = window.open("about:blank", "_new");
|
|
88
|
+
const img = page.document.createElement("img");
|
|
89
|
+
img.src = url;
|
|
90
|
+
img.onload = () => {
|
|
91
|
+
page.print();
|
|
92
|
+
page.close();
|
|
93
|
+
};
|
|
94
|
+
page.document.body.appendChild(img);
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
console.error("Failed to fetch QR code: ", e);
|
|
98
|
+
setError(true);
|
|
99
|
+
}
|
|
58
100
|
};
|
|
59
101
|
return {
|
|
60
102
|
...props,
|
|
61
103
|
qrLink,
|
|
62
104
|
dialogIsOpen,
|
|
105
|
+
error,
|
|
63
106
|
showDialog: () => setDialog(true),
|
|
64
|
-
hideDialog: () =>
|
|
107
|
+
hideDialog: () => {
|
|
108
|
+
setDialog(false), setError(false);
|
|
109
|
+
},
|
|
65
110
|
createDownloadable,
|
|
66
111
|
createPrintable,
|
|
67
112
|
};
|
|
@@ -86,6 +131,14 @@ const QrCode = class {
|
|
|
86
131
|
* @uiName Print QR code text
|
|
87
132
|
*/
|
|
88
133
|
this.printCodeText = "Print";
|
|
134
|
+
/**
|
|
135
|
+
* @uiName Header for error banner
|
|
136
|
+
*/
|
|
137
|
+
this.errorHeaderText = "There was an error loading your QR code";
|
|
138
|
+
/**
|
|
139
|
+
* @uiName Description for error banner
|
|
140
|
+
*/
|
|
141
|
+
this.errorDescriptionText = "Please refresh this page and try again";
|
|
89
142
|
stencilHooks_module.h$1(this);
|
|
90
143
|
}
|
|
91
144
|
disconnectedCallback() { }
|
|
@@ -33,10 +33,11 @@ const sqmPortalProfileView = require('./sqm-portal-profile-view-33164798.js');
|
|
|
33
33
|
require('./utilities-78f5e169.js');
|
|
34
34
|
const sqmPortalResetPasswordView = require('./sqm-portal-reset-password-view-fe602822.js');
|
|
35
35
|
const sqmPortalVerifyEmailView = require('./sqm-portal-verify-email-view-7b678f34.js');
|
|
36
|
-
|
|
36
|
+
require('./ErrorView-b2fcf954.js');
|
|
37
|
+
const sqmQrCodeView = require('./sqm-qr-code-view-a212589a.js');
|
|
37
38
|
const ShadowViewAddon = require('./ShadowViewAddon-3ddee92b.js');
|
|
38
39
|
const sqmPortalContainerView = require('./sqm-portal-container-view-4f15143a.js');
|
|
39
|
-
const sqmInvoiceTableView = require('./sqm-invoice-table-view-
|
|
40
|
+
const sqmInvoiceTableView = require('./sqm-invoice-table-view-16ac73d0.js');
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* lodash (Custom Build) <https://lodash.com/>
|
|
@@ -15678,6 +15679,7 @@ const QRCode_stories = {
|
|
|
15678
15679
|
};
|
|
15679
15680
|
const defaultProps$r = {
|
|
15680
15681
|
dialogIsOpen: false,
|
|
15682
|
+
error: false,
|
|
15681
15683
|
showDialog: () => void 0,
|
|
15682
15684
|
hideDialog: () => void 0,
|
|
15683
15685
|
qrLink: "https://media.istockphoto.com/id/1251071788/vector/qr-code-bar-code-black-icon-digital-technology.jpg?s=612x612&w=0&k=20&c=maw4OqMSEegAdSo8Drm9HO7i1ddddvP2YaL1UuWbRig=",
|
|
@@ -15691,6 +15693,8 @@ const defaultProps$r = {
|
|
|
15691
15693
|
viewCodeText: "View QR code",
|
|
15692
15694
|
downloadCodeText: "Download",
|
|
15693
15695
|
printCodeText: "Print",
|
|
15696
|
+
errorHeaderText: "There was an error loading your QR code",
|
|
15697
|
+
errorDescriptionText: "Please refresh this page and try again",
|
|
15694
15698
|
};
|
|
15695
15699
|
const Default$o = () => {
|
|
15696
15700
|
return index.h(sqmQrCodeView.QrCodeView, Object.assign({}, defaultProps$r));
|
|
@@ -15698,12 +15702,16 @@ const Default$o = () => {
|
|
|
15698
15702
|
const Expanded = () => {
|
|
15699
15703
|
return index.h(sqmQrCodeView.QrCodeView, Object.assign({}, defaultProps$r, { dialogIsOpen: true }));
|
|
15700
15704
|
};
|
|
15705
|
+
const Error$b = () => {
|
|
15706
|
+
return (index.h(sqmQrCodeView.QrCodeView, Object.assign({}, defaultProps$r, { dialogIsOpen: true, error: true })));
|
|
15707
|
+
};
|
|
15701
15708
|
|
|
15702
15709
|
const QRCode = /*#__PURE__*/Object.freeze({
|
|
15703
15710
|
__proto__: null,
|
|
15704
15711
|
'default': QRCode_stories,
|
|
15705
15712
|
Default: Default$o,
|
|
15706
|
-
Expanded: Expanded
|
|
15713
|
+
Expanded: Expanded,
|
|
15714
|
+
Error: Error$b
|
|
15707
15715
|
});
|
|
15708
15716
|
|
|
15709
15717
|
/**
|
|
@@ -5,6 +5,7 @@ export default {
|
|
|
5
5
|
};
|
|
6
6
|
const defaultProps = {
|
|
7
7
|
dialogIsOpen: false,
|
|
8
|
+
error: false,
|
|
8
9
|
showDialog: () => void 0,
|
|
9
10
|
hideDialog: () => void 0,
|
|
10
11
|
qrLink: "https://media.istockphoto.com/id/1251071788/vector/qr-code-bar-code-black-icon-digital-technology.jpg?s=612x612&w=0&k=20&c=maw4OqMSEegAdSo8Drm9HO7i1ddddvP2YaL1UuWbRig=",
|
|
@@ -18,6 +19,8 @@ const defaultProps = {
|
|
|
18
19
|
viewCodeText: "View QR code",
|
|
19
20
|
downloadCodeText: "Download",
|
|
20
21
|
printCodeText: "Print",
|
|
22
|
+
errorHeaderText: "There was an error loading your QR code",
|
|
23
|
+
errorDescriptionText: "Please refresh this page and try again",
|
|
21
24
|
};
|
|
22
25
|
export const Default = () => {
|
|
23
26
|
return h(QrCodeView, Object.assign({}, defaultProps));
|
|
@@ -25,3 +28,6 @@ export const Default = () => {
|
|
|
25
28
|
export const Expanded = () => {
|
|
26
29
|
return h(QrCodeView, Object.assign({}, defaultProps, { dialogIsOpen: true }));
|
|
27
30
|
};
|
|
31
|
+
export const Error = () => {
|
|
32
|
+
return (h(QrCodeView, Object.assign({}, defaultProps, { dialogIsOpen: true, error: true })));
|
|
33
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { h } from "@stencil/core";
|
|
2
2
|
import { createStyleSheet } from "../../styling/JSS";
|
|
3
|
+
import { ErrorView } from "../tax-and-cash/sqm-tax-and-cash/ErrorView";
|
|
3
4
|
const style = {
|
|
4
5
|
DialogContainer: {
|
|
5
6
|
maxWidth: "390px !important",
|
|
@@ -63,7 +64,7 @@ const vanillaStyle = `
|
|
|
63
64
|
display: block;
|
|
64
65
|
}
|
|
65
66
|
}`;
|
|
66
|
-
export function QrCodeView({ dialogIsOpen, showDialog, hideDialog, qrLink, titleText, viewCodeText, downloadCodeText, printCodeText, createDownloadable, createPrintable, }) {
|
|
67
|
+
export function QrCodeView({ dialogIsOpen, error, showDialog, hideDialog, qrLink, titleText, viewCodeText, downloadCodeText, printCodeText, errorHeaderText, errorDescriptionText, createDownloadable, createPrintable, }) {
|
|
67
68
|
return (h("div", { class: sheet.classes.Container, part: "sqm-base" },
|
|
68
69
|
h("style", null, vanillaStyle),
|
|
69
70
|
h("style", null, styleString),
|
|
@@ -74,9 +75,10 @@ export function QrCodeView({ dialogIsOpen, showDialog, hideDialog, qrLink, title
|
|
|
74
75
|
h("sl-button", { type: "text", onClick: createDownloadable }, downloadCodeText),
|
|
75
76
|
h("sl-button", { type: "text", onClick: createPrintable }, printCodeText))),
|
|
76
77
|
h("sl-dialog", { class: sheet.classes.DialogContainer, width: "250px", open: dialogIsOpen, label: titleText, "onSl-hide": hideDialog },
|
|
78
|
+
error && (h(ErrorView, { loadingErrorAlertDescription: errorHeaderText, loadingErrorAlertHeader: errorDescriptionText })),
|
|
77
79
|
h("div", { class: sheet.classes.CodeContainer },
|
|
78
80
|
h("img", { class: sheet.classes.Code, src: `${qrLink}&qrCodeImageFormat=svg` })),
|
|
79
81
|
h("div", { slot: "footer", class: sheet.classes.FooterContainer },
|
|
80
|
-
h("sl-button", { variant: "default", onClick: createDownloadable }, downloadCodeText),
|
|
81
|
-
h("sl-button", { variant: "default", onClick: createPrintable }, printCodeText)))));
|
|
82
|
+
h("sl-button", { disabled: error, variant: "default", onClick: createDownloadable }, downloadCodeText),
|
|
83
|
+
h("sl-button", { disabled: error, variant: "default", onClick: createPrintable }, printCodeText)))));
|
|
82
84
|
}
|
|
@@ -28,6 +28,14 @@ export class QrCode {
|
|
|
28
28
|
* @uiName Print QR code text
|
|
29
29
|
*/
|
|
30
30
|
this.printCodeText = "Print";
|
|
31
|
+
/**
|
|
32
|
+
* @uiName Header for error banner
|
|
33
|
+
*/
|
|
34
|
+
this.errorHeaderText = "There was an error loading your QR code";
|
|
35
|
+
/**
|
|
36
|
+
* @uiName Description for error banner
|
|
37
|
+
*/
|
|
38
|
+
this.errorDescriptionText = "Please refresh this page and try again";
|
|
31
39
|
withHooks(this);
|
|
32
40
|
}
|
|
33
41
|
disconnectedCallback() { }
|
|
@@ -123,12 +131,54 @@ export class QrCode {
|
|
|
123
131
|
"reflect": false,
|
|
124
132
|
"defaultValue": "\"Print\""
|
|
125
133
|
},
|
|
134
|
+
"errorHeaderText": {
|
|
135
|
+
"type": "string",
|
|
136
|
+
"mutable": false,
|
|
137
|
+
"complexType": {
|
|
138
|
+
"original": "string",
|
|
139
|
+
"resolved": "string",
|
|
140
|
+
"references": {}
|
|
141
|
+
},
|
|
142
|
+
"required": false,
|
|
143
|
+
"optional": true,
|
|
144
|
+
"docs": {
|
|
145
|
+
"tags": [{
|
|
146
|
+
"text": "Header for error banner",
|
|
147
|
+
"name": "uiName"
|
|
148
|
+
}],
|
|
149
|
+
"text": ""
|
|
150
|
+
},
|
|
151
|
+
"attribute": "error-header-text",
|
|
152
|
+
"reflect": false,
|
|
153
|
+
"defaultValue": "\"There was an error loading your QR code\""
|
|
154
|
+
},
|
|
155
|
+
"errorDescriptionText": {
|
|
156
|
+
"type": "string",
|
|
157
|
+
"mutable": false,
|
|
158
|
+
"complexType": {
|
|
159
|
+
"original": "string",
|
|
160
|
+
"resolved": "string",
|
|
161
|
+
"references": {}
|
|
162
|
+
},
|
|
163
|
+
"required": false,
|
|
164
|
+
"optional": true,
|
|
165
|
+
"docs": {
|
|
166
|
+
"tags": [{
|
|
167
|
+
"text": "Description for error banner",
|
|
168
|
+
"name": "uiName"
|
|
169
|
+
}],
|
|
170
|
+
"text": ""
|
|
171
|
+
},
|
|
172
|
+
"attribute": "error-description-text",
|
|
173
|
+
"reflect": false,
|
|
174
|
+
"defaultValue": "\"Please refresh this page and try again\""
|
|
175
|
+
},
|
|
126
176
|
"demoData": {
|
|
127
177
|
"type": "unknown",
|
|
128
178
|
"mutable": false,
|
|
129
179
|
"complexType": {
|
|
130
180
|
"original": "DemoData<QRCodeViewProps>",
|
|
131
|
-
"resolved": "{ titleText?: string; dialogIsOpen?: boolean; showDialog?: () => void; hideDialog?: () => void; qrLink?: string; createDownloadable?: () => void; viewCodeText?: string; downloadCodeText?: string; printCodeText?: string; createPrintable?: () => void; }",
|
|
181
|
+
"resolved": "{ titleText?: string; error?: boolean; dialogIsOpen?: boolean; showDialog?: () => void; hideDialog?: () => void; qrLink?: string; createDownloadable?: () => void; viewCodeText?: string; downloadCodeText?: string; printCodeText?: string; errorHeaderText?: string; errorDescriptionText?: string; createPrintable?: () => void; }",
|
|
132
182
|
"references": {
|
|
133
183
|
"DemoData": {
|
|
134
184
|
"location": "import",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEngagementMedium, useParentValue, useProgramId, useQuery, useUserIdentity, } from "@saasquatch/component-boilerplate";
|
|
1
|
+
import { useEngagementMedium, useMutation, useParentValue, useProgramId, useQuery, useUserIdentity, } from "@saasquatch/component-boilerplate";
|
|
2
2
|
import { useState } from "@saasquatch/stencil-hooks";
|
|
3
3
|
import { gql } from "graphql-request";
|
|
4
4
|
import { REFERRAL_CODES_NAMESPACE, } from "../sqm-referral-codes/useReferralCodes";
|
|
@@ -15,44 +15,88 @@ const ShareLinkQuery = gql `
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
`;
|
|
18
|
+
const WIDGET_ENGAGEMENT_EVENT = gql `
|
|
19
|
+
mutation loadEvent($eventMeta: UserAnalyticsEvent!) {
|
|
20
|
+
createUserAnalyticsEvent(eventMeta: $eventMeta)
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
18
23
|
export function useQRCode(props) {
|
|
19
24
|
const programId = useProgramId();
|
|
20
25
|
const user = useUserIdentity();
|
|
21
26
|
const engagementMedium = useEngagementMedium();
|
|
22
27
|
const contextData = useParentValue(REFERRAL_CODES_NAMESPACE);
|
|
23
28
|
const [dialogIsOpen, setDialog] = useState(false);
|
|
29
|
+
const [error, setError] = useState(false);
|
|
24
30
|
const { data } = useQuery(ShareLinkQuery, { programId, engagementMedium }, !(user === null || user === void 0 ? void 0 : user.jwt) || (contextData === null || contextData === void 0 ? void 0 : contextData.shareLink) !== undefined);
|
|
25
|
-
const
|
|
31
|
+
const [sendLoadEvent] = useMutation(WIDGET_ENGAGEMENT_EVENT);
|
|
32
|
+
const qrLink = data ? `${data.user.shareLink}?qrCode` : "";
|
|
33
|
+
const fireEvent = async () => {
|
|
34
|
+
sendLoadEvent({
|
|
35
|
+
eventMeta: {
|
|
36
|
+
programId,
|
|
37
|
+
id: user === null || user === void 0 ? void 0 : user.id,
|
|
38
|
+
accountId: user === null || user === void 0 ? void 0 : user.accountId,
|
|
39
|
+
type: "USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENET",
|
|
40
|
+
meta: {
|
|
41
|
+
engagementMedium,
|
|
42
|
+
shareMedium: "DIRECT",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
};
|
|
26
47
|
const createDownloadable = async () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetch(`${qrLink}&qrCodeSize=800&qrCodeImageFormat=png`);
|
|
50
|
+
const blob = await res.blob();
|
|
51
|
+
const url = URL.createObjectURL(blob);
|
|
52
|
+
// Successful
|
|
53
|
+
if (blob)
|
|
54
|
+
fireEvent();
|
|
55
|
+
// Trigger download
|
|
56
|
+
const link = document.createElement("a");
|
|
57
|
+
link.href = url;
|
|
58
|
+
link.download = "qrCode.png";
|
|
59
|
+
document.body.appendChild(link);
|
|
60
|
+
link.click();
|
|
61
|
+
document.body.removeChild(link);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.error("Failed to fetch QR code:", e);
|
|
65
|
+
setError(true);
|
|
66
|
+
}
|
|
36
67
|
};
|
|
37
68
|
const createPrintable = async () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
page.
|
|
47
|
-
|
|
48
|
-
|
|
69
|
+
try {
|
|
70
|
+
const res = await fetch(`${qrLink}&qrCodeSize=1000&qrCodeImageFormat=png&qrCodeErrorCorrectionLevel=H`);
|
|
71
|
+
const blob = await res.blob();
|
|
72
|
+
const url = URL.createObjectURL(blob);
|
|
73
|
+
// Successful
|
|
74
|
+
if (blob)
|
|
75
|
+
fireEvent();
|
|
76
|
+
// Trigger print
|
|
77
|
+
const page = window.open("about:blank", "_new");
|
|
78
|
+
const img = page.document.createElement("img");
|
|
79
|
+
img.src = url;
|
|
80
|
+
img.onload = () => {
|
|
81
|
+
page.print();
|
|
82
|
+
page.close();
|
|
83
|
+
};
|
|
84
|
+
page.document.body.appendChild(img);
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
console.error("Failed to fetch QR code: ", e);
|
|
88
|
+
setError(true);
|
|
89
|
+
}
|
|
49
90
|
};
|
|
50
91
|
return {
|
|
51
92
|
...props,
|
|
52
93
|
qrLink,
|
|
53
94
|
dialogIsOpen,
|
|
95
|
+
error,
|
|
54
96
|
showDialog: () => setDialog(true),
|
|
55
|
-
hideDialog: () =>
|
|
97
|
+
hideDialog: () => {
|
|
98
|
+
setDialog(false), setError(false);
|
|
99
|
+
},
|
|
56
100
|
createDownloadable,
|
|
57
101
|
createPrintable,
|
|
58
102
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { h } from './index-91e7729f.js';
|
|
2
|
+
import { c as createStyleSheet } from './JSS-67b5cff8.js';
|
|
3
|
+
|
|
4
|
+
const styles = {
|
|
5
|
+
Alert: {
|
|
6
|
+
"&::part(base)": {
|
|
7
|
+
backgroundColor: "var(--sl-color-danger-100)",
|
|
8
|
+
border: "1px solid var(--sl-color-danger-200)",
|
|
9
|
+
padding: "0 16px",
|
|
10
|
+
},
|
|
11
|
+
"& sl-icon": {
|
|
12
|
+
margin: 0,
|
|
13
|
+
},
|
|
14
|
+
"& sl-icon::part(base)": {
|
|
15
|
+
color: "var(--sl-color-danger-500)",
|
|
16
|
+
margin: 0,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const ErrorView = (props) => {
|
|
21
|
+
const sheet = createStyleSheet(styles);
|
|
22
|
+
const styleString = sheet.toString();
|
|
23
|
+
const { classes } = sheet;
|
|
24
|
+
return (h("div", null,
|
|
25
|
+
h("style", null, styleString),
|
|
26
|
+
h("sl-alert", { exportparts: "base: alert-base, icon:alert-icon", type: "danger", open: true, class: classes.Alert },
|
|
27
|
+
h("sl-icon", { slot: "icon", name: "exclamation-octagon", class: "Error" }),
|
|
28
|
+
h("strong", null, props.loadingErrorAlertHeader),
|
|
29
|
+
h("br", null),
|
|
30
|
+
props.loadingErrorAlertDescription)));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { ErrorView as E };
|