@opexa/portal-components 0.0.148 → 0.0.150

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.
@@ -9,6 +9,7 @@ import { useMarkMessageAsReadMutation } from '../../client/hooks/useMarkMessageA
9
9
  import { useMessageContext } from './MessageContext.js';
10
10
  import { MessageIcon } from './MessageIcon.js';
11
11
  import { useMessagesPropsContext } from './MessagesContext.js';
12
+ import { normalizeActionUrl } from './utils.js';
12
13
  export function Message() {
13
14
  const messagesProps = useMessagesPropsContext();
14
15
  const transactionsPageUrl = messagesProps.transactionsPageUrl ?? '/transactions';
@@ -26,23 +27,9 @@ export function Message() {
26
27
  if (!message.markedAsRead)
27
28
  markMessageAsReadMutation.mutate(message.id);
28
29
  };
29
- function normalizeRedirectUrl(value) {
30
- const searchParams = new URLSearchParams(value);
31
- if (searchParams.has('personalCenter')) {
32
- if (searchParams.get('personalCenter') === 'deposit' &&
33
- searchParams.has('id')) {
34
- return `${transactionsPageUrl}?tab=deposits&id=${searchParams.get('id')}`;
35
- }
36
- if (searchParams.get('personalCenter') === 'withdrawal' &&
37
- searchParams.has('id')) {
38
- return `${transactionsPageUrl}?tab=withdrawals&id=${searchParams.get('id')}`;
39
- }
40
- }
41
- return value;
42
- }
43
30
  return (_jsxs("div", { role: "button", tabIndex: 0, className: "border-border-secondary rounded-xs bg-bg-secondary flex h-auto flex-shrink-0 cursor-pointer flex-col border px-3.5 py-2.5", onClick: handleViewMessage, "aria-pressed": "false", children: [_jsxs("div", { className: "flex items-center space-x-2", children: [_jsx("p", { className: "text-text-tertiary-600 text-xs font-normal", children: format(new Date(message.dateTimeCreated), 'M/d/yyyy - h:mma', {
44
31
  in: tz(localeInfo.timezone),
45
- }) }), !message.markedAsRead && (_jsx("div", { className: "bg-utility-success-500 h-2.5 w-2.5 rounded-full" }))] }), _jsxs("div", { className: "mb-2 flex items-center space-x-2", children: [_jsx(MessageIcon, { type: message.icon, className: "text-brand-400 size-5" }), _jsx("p", { className: "text-text-primary-brand text-sm font-semibold", children: message.title })] }), _jsx("p", { className: "line-clamp-3 text-wrap text-sm font-normal", dangerouslySetInnerHTML: { __html: message.content } }), message.actions.length > 0 && (_jsx("div", { className: "mt-2 flex flex-wrap items-center justify-end gap-2", children: message.actions.map((action, index) => (_jsx(Link, { className: "border-button-secondary-border text-button-secondary-fg rounded-md border px-3 py-2 text-sm", href: normalizeRedirectUrl(action.url), onClick: (e) => {
32
+ }) }), !message.markedAsRead && (_jsx("div", { className: "bg-utility-success-500 h-2.5 w-2.5 rounded-full" }))] }), _jsxs("div", { className: "flex items-center space-x-2", children: [_jsx(MessageIcon, { type: message.icon, className: "text-brand-400 size-5" }), _jsx("p", { className: "text-text-primary-brand text-sm font-semibold", children: message.title })] }), message.content && (_jsx("p", { className: "mt-2 line-clamp-3 text-wrap text-sm font-normal", dangerouslySetInnerHTML: { __html: message.content } })), message.actions.length > 0 && (_jsx("div", { className: "mt-2 flex flex-wrap items-center justify-end gap-2", children: message.actions.map((action, index) => (_jsx(Link, { className: "border-button-secondary-border text-button-secondary-fg rounded-md border px-3 py-2 text-sm", href: normalizeActionUrl(transactionsPageUrl, action.url), onClick: (e) => {
46
33
  e.stopPropagation();
47
34
  globalStore.messages.setOpen(false);
48
35
  globalStore.messages.setTab('ALL');
@@ -1 +1 @@
1
- export declare const MessagePopup: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare function MessagePopup(): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,6 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import Image from 'next/image';
3
4
  import Link from 'next/link';
4
5
  import { useShallow } from 'zustand/shallow';
5
6
  import { useGlobalStore } from '../../client/hooks/useGlobalStore.js';
@@ -7,13 +8,17 @@ import { XIcon } from '../../icons/XIcon.js';
7
8
  import { Dialog } from '../../ui/Dialog/index.js';
8
9
  import { Portal } from '../../ui/Portal/index.js';
9
10
  import { MessageIcon } from './MessageIcon.js';
10
- export const MessagePopup = () => {
11
+ import { useMessagesPropsContext } from './MessagesContext.js';
12
+ import { normalizeActionUrl } from './utils.js';
13
+ export function MessagePopup() {
14
+ const messagesProps = useMessagesPropsContext();
15
+ const transactionsPageUrl = messagesProps.transactionsPageUrl ?? '/transactions';
11
16
  const globalStore = useGlobalStore(useShallow((ctx) => ({ message: ctx.message })));
12
17
  return (_jsx(Dialog.Root, { lazyMount: true, unmountOnExit: true, open: globalStore.message.open, onOpenChange: ({ open }) => {
13
18
  globalStore.message.setOpen(open);
14
- }, closeOnEscape: false, closeOnInteractOutside: false, children: _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, { className: "!z-[calc(var(--z-dialog)+1)]" }), _jsx(Dialog.Positioner, { className: "!z-[calc(var(--z-dialog)+2)] flex items-center justify-center", children: _jsxs(Dialog.Content, { className: "min-h-auto mx-auto min-w-[21.438rem] max-w-[21.438rem] rounded-xl px-xl pb-0 pt-5 shadow-xl", children: [_jsx(Dialog.CloseTrigger, { children: _jsx(XIcon, {}) }), _jsxs("div", { className: "pb-6", children: [_jsx("div", { className: "bg-bg-brand-secondary mx-auto w-fit rounded-full p-3", children: _jsx(MessageIcon, { type: globalStore.message.data?.icon ?? 'INFO', className: "text-text-brand size-6" }) }), _jsx("p", { className: "text-text-primary-brand mt-lg text-center text-lg font-semibold leading-tight", children: globalStore.message.data?.title }), _jsx("div", { className: "text-shadow-text-secondary-700 mt-xs text-center text-sm font-normal leading-tight", dangerouslySetInnerHTML: {
15
- __html: globalStore.message.data?.content ?? '',
16
- } })] }), globalStore.message.data?.actions.length ? (_jsx("div", { className: "flex flex-col space-y-2 px-4 pb-8 pt-6 text-center", children: globalStore.message.data.actions.map((action, index) => (_jsx(Link, { className: "bg-button-primary-bg rounded-xs text-button-primary-fg w-full px-4 py-2.5 text-base font-semibold", href: action.url, onClick: () => {
19
+ }, closeOnEscape: false, closeOnInteractOutside: false, children: _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, { className: "!z-[calc(var(--z-dialog)+1)]" }), _jsx(Dialog.Positioner, { className: "!z-[calc(var(--z-dialog)+2)] flex items-center justify-center", children: _jsxs(Dialog.Content, { className: "min-h-auto mx-auto min-w-[21.438rem] max-w-[21.438rem] rounded-xl px-xl pb-0 pt-5 shadow-xl", children: [_jsx(Dialog.CloseTrigger, { children: _jsx(XIcon, {}) }), _jsxs("div", { className: "pb-6", children: [_jsx("div", { className: "bg-bg-brand-secondary mx-auto w-fit rounded-full p-3", children: _jsx(MessageIcon, { type: globalStore.message.data?.icon ?? 'INFO', className: "text-text-brand size-6" }) }), _jsx("p", { className: "text-text-primary-brand mt-lg text-center text-lg font-semibold leading-tight", children: globalStore.message.data?.title }), globalStore.message.data?.content && (_jsx("div", { className: "text-shadow-text-secondary-700 mt-xs text-center text-sm font-normal leading-tight", dangerouslySetInnerHTML: {
20
+ __html: globalStore.message.data.content,
21
+ } })), globalStore.message.data?.image && (_jsx(Image, { src: globalStore.message.data.image, alt: "", width: 400, height: 400, loading: "lazy", unoptimized: true, className: "mt-5 h-auto w-full" }))] }), globalStore.message.data?.actions.length ? (_jsx("div", { className: "flex flex-col space-y-2 px-4 pb-8 pt-6 text-center", children: globalStore.message.data.actions.map((action, index) => (_jsx(Link, { className: "bg-button-primary-bg rounded-xs text-button-primary-fg w-full px-4 py-2.5 text-base font-semibold", href: normalizeActionUrl(transactionsPageUrl, action.url), onClick: () => {
17
22
  globalStore.message.setOpen(false);
18
23
  }, children: action.name }, index))) })) : null] }) })] }) }));
19
- };
24
+ }
@@ -43,7 +43,7 @@ export function Messages(props) {
43
43
  return (_jsxs(MessagesPropsProvider, { value: props, children: [_jsx(Drawer.Root, { open: globalStore.messages.open, onOpenChange: ({ open }) => globalStore.messages.setOpen(open), lazyMount: true, unmountOnExit: true, children: _jsx(Portal, { children: _jsx(Drawer.Positioner, { children: _jsx(Drawer.Content, { className: twMerge('flex', 'flex-col', 'border-border-secondary', 'top-[var(--offset-top-mobile)]', 'h-[calc(100%-var(--offset-top-mobile))]', 'lg:border-l', 'lg:top-[var(--offset-top-desktop)]', 'lg:h-[calc(100%-var(--offset-top-desktop))]'), style: {
44
44
  ['--offset-top-mobile']: mobileOffsetTop,
45
45
  ['--offset-top-desktop']: desktopOffsetTop,
46
- }, children: _jsxs("div", { className: "flex flex-col space-y-6", children: [_jsxs("div", { className: "flex items-end justify-between px-4 pt-6", children: [_jsx("p", { className: "text-text-primary-brand text-xl font-semibold", children: "Notifications" }), _jsx(Drawer.CloseTrigger, { className: "p-2", children: _jsx(XIcon, {}) })] }), _jsxs(Tabs.Root, { value: globalStore.messages.tab, onValueChange: (details) => globalStore.messages.setTab(z.enum(TABS).parse(details.value)), lazyMount: true, unmountOnExit: true, children: [_jsx("div", { className: "mb-4 w-full px-4", children: _jsxs(Tabs.List, { className: "border-border-secondary w-full border", children: [_jsx(Tabs.Trigger, { value: "ALL", className: "flex-1/5 ui-selected:text-text-primary-brand text-text-tertiary-600", children: "All" }), _jsxs(Tabs.Trigger, { value: "UNREAD", className: "flex-1/5 ui-selected:text-text-primary-brand text-text-tertiary-600 flex items-center justify-center space-x-2", children: [_jsx("div", { children: "Unread" }), !!unreadMessagesCount && (_jsx("div", { className: "border-border-primary bg-bg-secondary rounded-full border px-2 py-0.5", children: unreadMessagesCount }))] }), _jsx(Tabs.Indicator, { className: "bg-bg-active" })] }) }), _jsx("div", { className: "border-border-secondary w-full border-t" }), TABS.map((tab) => (_jsxs(Tabs.Content, { value: tab, className: "scrollbar:w-2 scrollbar-track:bg-bg-primary-alt scrollbar-track:rounded-full scrollbar-thumb:bg-bg-quaternary scrollbar-thumb:rounded-full max-h-[calc(100vh-197px)] overflow-y-auto p-xl", style: { scrollbarGutter: 'stable' }, children: [messages.length > 0 && (_jsx("div", { className: "flex flex-col space-y-4", children: messages.map((message) => (_jsx(MessageProvider, { value: message, children: _jsx(Message, {}) }, message.id))) })), _jsx(InfiniteScroll, { loader: _jsx(SpinnerIcon, { className: "mx-auto size-5" }), hasMore: !!messagesQuery.hasNextPage, loadMore: async () => {
46
+ }, children: _jsxs("div", { className: "flex h-full flex-col", children: [_jsxs("div", { className: "flex items-end justify-between p-xl", children: [_jsx("p", { className: "text-text-primary-brand text-xl font-semibold", children: "Notifications" }), _jsx(Drawer.CloseTrigger, { className: "p-2", children: _jsx(XIcon, {}) })] }), _jsxs(Tabs.Root, { value: globalStore.messages.tab, onValueChange: (details) => globalStore.messages.setTab(z.enum(TABS).parse(details.value)), lazyMount: true, unmountOnExit: true, className: "flex grow flex-col overflow-y-auto", children: [_jsx("div", { className: "p-xl pt-0", children: _jsxs(Tabs.List, { className: "w-full", children: [_jsx(Tabs.Trigger, { value: "ALL", className: "w-full", children: "All" }), _jsxs(Tabs.Trigger, { value: "UNREAD", className: "w-full", children: ["Unread", !!unreadMessagesCount && (_jsx("span", { className: "border-border-primary bg-bg-secondary ml-md rounded-full border px-2 py-0.5", children: unreadMessagesCount }))] }), _jsx(Tabs.Indicator, {})] }) }), TABS.map((tab) => (_jsxs(Tabs.Content, { value: tab, className: "scrollbar:w-2 scrollbar-track:bg-bg-primary-alt scrollbar-track:rounded-full scrollbar-thumb:bg-bg-quaternary scrollbar-thumb:rounded-full border-border-secondary grow overflow-y-auto border-t p-xl", children: [messages.length > 0 && (_jsx("div", { className: "flex flex-col space-y-3", children: messages.map((message) => (_jsx(MessageProvider, { value: message, children: _jsx(Message, {}) }, message.id))) })), _jsx(InfiniteScroll, { loader: _jsx(SpinnerIcon, { className: "mx-auto size-5" }), hasMore: !!messagesQuery.hasNextPage, loadMore: async () => {
47
47
  await messagesQuery.fetchNextPage();
48
48
  }, className: "mt-4" })] }, tab)))] })] }) }) }) }) }), _jsx(MessagePopup, {})] }));
49
49
  }
@@ -1,3 +1 @@
1
- import { BellRingIcon } from '../../icons/BellRingIcon';
2
- import type { MessageIcon } from '../../types';
3
- export declare function getMessageIcon(logo: MessageIcon): typeof BellRingIcon;
1
+ export declare function normalizeActionUrl(baseUrl: string, actionUrl: string): string;
@@ -1,27 +1,14 @@
1
- import { BellRingIcon } from '../../icons/BellRingIcon.js';
2
- // TODO: request icon assets for each type of MessageIcon
3
- const IMAGES = {
4
- BELL: BellRingIcon,
5
- BONUS: BellRingIcon,
6
- CHECK: BellRingIcon,
7
- CONFETTI: BellRingIcon,
8
- GIFT: BellRingIcon,
9
- STAR: BellRingIcon,
10
- TROPHY: BellRingIcon,
11
- INFO: BellRingIcon,
12
- };
13
- export function getMessageIcon(logo) {
14
- if (logo === 'ALERT')
15
- return IMAGES.INFO;
16
- if (logo === 'CHECK')
17
- return IMAGES.CHECK;
18
- if (logo === 'MESSAGE')
19
- return IMAGES.BELL;
20
- if (logo === 'CELEBRATE')
21
- return IMAGES.CONFETTI;
22
- if (logo === 'GIFT')
23
- return IMAGES.GIFT;
24
- if (logo === 'INFO')
25
- return IMAGES.INFO;
26
- return IMAGES.TROPHY;
1
+ export function normalizeActionUrl(baseUrl, actionUrl) {
2
+ const searchParams = new URLSearchParams(actionUrl);
3
+ if (searchParams.has('personalCenter')) {
4
+ if (searchParams.get('personalCenter') === 'deposit' &&
5
+ searchParams.has('id')) {
6
+ return `${baseUrl}?tab=deposits&id=${searchParams.get('id')}`;
7
+ }
8
+ if (searchParams.get('personalCenter') === 'withdrawal' &&
9
+ searchParams.has('id')) {
10
+ return `${baseUrl}?tab=withdrawals&id=${searchParams.get('id')}`;
11
+ }
12
+ }
13
+ return actionUrl;
27
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opexa/portal-components",
3
- "version": "0.0.148",
3
+ "version": "0.0.150",
4
4
  "exports": {
5
5
  "./ui/*": {
6
6
  "types": "./dist/ui/*/index.d.ts",