react-notify-sdk 1.0.16 → 1.0.18

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.
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { NotifyMessage } from './types';
3
+ interface FadeWrapperProps {
4
+ visible: boolean;
5
+ message: NotifyMessage;
6
+ device: string;
7
+ }
8
+ export declare const FadeWrapper: import("goober").StyledVNode<Omit<React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement> & import("goober").DefaultTheme & FadeWrapperProps, never>>;
9
+ export default FadeWrapper;
@@ -0,0 +1,15 @@
1
+ import { styled } from "goober";
2
+ import { fadeIn, fadeOut } from './animations';
3
+ export const FadeWrapper = styled("div") `
4
+ opacity: ${(props) => (props.visible ? 1 : 0)};
5
+ animation: ${(props) => (props.visible ? fadeIn : fadeOut)} 0.3s ease forwards;
6
+ transition: opacity 0.3s ease;
7
+ position: absolute;
8
+ width: ${(props) => props.device === 'Mobile' ? '95%' : props.device === 'Tablet' ? '420px' : '420px'};
9
+ top: ${(props) => props.message?.position === 'top' ? '24px' : ''};
10
+ bottom: ${(props) => props.message?.position === 'bottom' ? '24px' : ''};
11
+ left: 50%;
12
+ transform: translateX(-50%);
13
+ z-index: 5;
14
+ `;
15
+ export default FadeWrapper;
@@ -1,7 +1,6 @@
1
1
  import { NotifyMessage } from './types';
2
2
  interface NotifyMessageProps {
3
3
  message: NotifyMessage;
4
- device: string;
5
4
  }
6
- declare const NotificationMessage: ({ message, device }: NotifyMessageProps) => import("react/jsx-runtime").JSX.Element;
5
+ declare const NotificationMessage: ({ message }: NotifyMessageProps) => import("react/jsx-runtime").JSX.Element;
7
6
  export default NotificationMessage;
@@ -1,13 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- const NotificationMessage = ({ message, device }) => {
2
+ const NotificationMessage = ({ message }) => {
3
3
  return (_jsxs("div", { style: {
4
- position: 'absolute',
5
- top: message?.position === 'top' ? '24px' : undefined,
6
- bottom: message?.position === 'bottom' ? '24px' : undefined,
7
- left: '50%',
8
- transform: 'translateX(-50%)',
9
- zIndex: 5,
10
- width: device === 'Mobile' ? '100%' : device === 'Tablet' ? '80%' : `${message?.width}%`,
4
+ width: '100%',
11
5
  paddingTop: '4px', // p-4 = 1rem
12
6
  paddingBottom: '4px',
13
7
  paddingLeft: '12px',
@@ -3,23 +3,22 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useEffect, useState } from 'react';
4
4
  import { useLocation } from 'react-router-dom';
5
5
  import NotificationMessage from './NotifyMessage';
6
- import { styled } from "goober";
7
6
  import { supabase } from './supabase/supabaseClient';
8
7
  import useDeviceDetection from './UseDeviceDetection';
9
- import { fadeIn, fadeOut } from './animations';
10
- const FadeWrapper = styled("div") `
11
- opacity: ${(props) => (props.visible ? 1 : 0)};
12
- animation: ${(props) => (props.visible ? fadeIn : fadeOut)} 0.3s ease forwards;
13
- transition: opacity 0.3s ease;
14
- position: fixed;
15
- bottom: 20px;
16
- left: 20px;
17
- background: #1f2937;
18
- color: white;
19
- padding: 12px 16px;
20
- border-radius: 8px;
21
- z-index: 1000;
22
- `;
8
+ import FadeWrapper from './FadeWrapper';
9
+ // Wildcard route matching utility
10
+ const routeMatches = (pattern, path) => {
11
+ if (pattern === path)
12
+ return true;
13
+ const escapeRegex = (str) => str.replace(/([.+^=!:${}()|[\]/\\])/g, "\\$1");
14
+ const regexPattern = "^" + pattern.split("*").map(escapeRegex).join(".*") + "$";
15
+ try {
16
+ return new RegExp(regexPattern).test(path);
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ };
23
22
  export const NotifyProvider = ({ projectId,
24
23
  //className,
25
24
  //style,
@@ -39,11 +38,12 @@ export const NotifyProvider = ({ projectId,
39
38
  .eq('project_key', projectId)
40
39
  .eq('route', location.pathname)
41
40
  .eq('is_active', true)
42
- .order('created_at', { ascending: false })
43
- .limit(1)
44
- .single();
45
- if (data) {
46
- setMessage(data);
41
+ .order('created_at', { ascending: false });
42
+ //.limit(1)
43
+ //.single();
44
+ const match = data?.find((msg) => routeMatches(msg.route, location.pathname));
45
+ if (match) {
46
+ setMessage(match);
47
47
  setVisible(true); // Fade in
48
48
  }
49
49
  else {
@@ -61,7 +61,7 @@ export const NotifyProvider = ({ projectId,
61
61
  table: 'feature_messages',
62
62
  }, (payload) => {
63
63
  const msg = payload.new;
64
- if (msg.project_key === projectId && msg.route === location.pathname && msg.is_active) {
64
+ if (msg.project_key === projectId && msg.is_active && routeMatches(msg.route, location.pathname)) {
65
65
  setMessage(msg);
66
66
  setVisible(true);
67
67
  }
@@ -78,5 +78,5 @@ export const NotifyProvider = ({ projectId,
78
78
  if (!message)
79
79
  return null;
80
80
  //const defaultClasses = `absolute ${message?.position}-6 left-1/2 transform -translate-x-1/2 z-20 w-full md:w-[${message?.width}%] px-3 py-1 bg-[${message?.backgroundColor}] border border-[${message?.borderColor}] text-[${message?.textColor}] rounded-lg shadow`;
81
- return (_jsx(FadeWrapper, { visible: visible, children: _jsx(NotificationMessage, { message: message, device: device }) }));
81
+ return (_jsx(FadeWrapper, { visible: visible, device: device, message: message, children: _jsx(NotificationMessage, { message: message }) }));
82
82
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-notify-sdk",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "SDK for displaying real-time route-specific messages in React apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",