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

fix: ensure correct url is used for "subscribe to push window" #13

Merged
merged 4 commits into from
Nov 9, 2022
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
5 changes: 5 additions & 0 deletions .changeset/beige-coins-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@magicbell/magicbell-react': patch
---

Fix embeddable web notifications: since embeddable aliases axios (redaxios) and redaxios does not implement `.getUri`, the code was failing for the embeddable package (that uses redaxios) but not for the react package (that uses axios).
1 change: 0 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"@emotion/react": "^11.4.1",
"@magicbell/react-headless": "4.2.2",
"@tippyjs/react": "^4.2.5",
"axios": "^0.27.2",
"dayjs": "^1.11.5",
"humps": "^2.0.1",
"immer": "^9.0.7",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import { clientSettings, useConfig } from '@magicbell/react-headless';
import axios from 'axios';
import { path, pathOr } from 'ramda';
import { useLocalStorage } from 'react-use';

Expand Down Expand Up @@ -35,18 +34,17 @@ export default function EnablePushNotificationsBanner() {

const enablePushNotifications = () => {
const subscribeUrl = path<string>(['webPush', 'config', 'subscribeUrl'], channels);
const url = axios.getUri({
url: subscribeUrl,
params: {
user_email: userEmail,
user_external_id: userExternalId,
background_color: theme.header.backgroundColor,
text_color: theme.header.textColor,
},
});

const { backgroundColor, textColor } = theme.header;

const url = new URL(subscribeUrl);
if (userEmail) url.searchParams.append('user_email', userEmail);
if (userExternalId) url.searchParams.append('user_external_id', userExternalId);
if (backgroundColor) url.searchParams.append('background_color', backgroundColor);
if (textColor) url.searchParams.append('text_color', textColor);

setRequestedAt(Date.now());
openWindow(url);
openWindow(url.toString());
};

const closeBanner = () => {
Expand Down