diff --git a/src/lib/flow/logout/index.ts b/src/lib/flow/logout/index.ts index e0eb8fa5..f6bdbd85 100644 --- a/src/lib/flow/logout/index.ts +++ b/src/lib/flow/logout/index.ts @@ -2,7 +2,7 @@ import { goto } from '$app/navigation' import { Query } from '$lib/api/executor.js' import { ApiMutation } from '$lib/api/index.js' import { useCustomerCtx } from '$lib/ctx/customer/index.svelte.js' -import { notifcation } from '$ui/core/Notifications/index.js' +import { notification } from '$ui/core/Notifications/index.js' const mutateLogout = ApiMutation( () => `mutation { @@ -21,7 +21,7 @@ export function useLogoutFlow() { .then(() => { customer.reload() - notifcation.info("You've been logged out") + notification.info("You've been logged out") }) } diff --git a/src/lib/ui/app/InsightCard/index.ts b/src/lib/ui/app/InsightCard/index.ts index d70d137c..fc0dc4ba 100644 --- a/src/lib/ui/app/InsightCard/index.ts +++ b/src/lib/ui/app/InsightCard/index.ts @@ -1 +1 @@ -export { default } from './InsightCard.svelte'; +export { default } from './InsightCard.svelte' diff --git a/src/lib/ui/app/PaymentForm/flow.ts b/src/lib/ui/app/PaymentForm/flow.ts index e631fb9e..a0625721 100644 --- a/src/lib/ui/app/PaymentForm/flow.ts +++ b/src/lib/ui/app/PaymentForm/flow.ts @@ -1,6 +1,6 @@ import { Query } from '$lib/api/executor.js' import { useStripeCtx } from '$lib/ctx/stripe/index.js' -import { notifcation as notification } from '$ui/core/Notifications/index.js' +import { notification } from '$ui/core/Notifications/index.js' import type { ConfirmCardSetupData, SetupIntent, Stripe, Token } from '@stripe/stripe-js' import { mutateSubscribe } from './api.js' import { usePaymentFormCtx } from './state.js' @@ -160,7 +160,7 @@ export function usePaymentFlow() { if (error) { notification.error(`Error during the payment`, { - description: error.message || 'Please try again or contact our support', + content: error.message || 'Please try again or contact our support', duration: 10000, }) trackEvent('payment_fail', { ...analytics, error_code: error.code || '3ds_error' }) @@ -212,7 +212,7 @@ export function usePaymentFlow() { }) .catch((error) => { notification.error(`Error during the payment`, { - description: 'Please try again or contact our support', + content: 'Please try again or contact our support', }) trackEvent('payment_fail', { ...analytics, error_code: 'api_error' }) diff --git a/src/lib/ui/app/PlanChangeDialog/PlanChangeDialog.svelte b/src/lib/ui/app/PlanChangeDialog/PlanChangeDialog.svelte index 0152d94e..bcc5f403 100644 --- a/src/lib/ui/app/PlanChangeDialog/PlanChangeDialog.svelte +++ b/src/lib/ui/app/PlanChangeDialog/PlanChangeDialog.svelte @@ -11,7 +11,7 @@ import { trackEvent } from '$lib/analytics/index.js' import Dialog, { dialogs$, type TDialogProps } from '$ui/core/Dialog/index.js' import Button from '$ui/core/Button/index.js' - import { notifcation as notification } from '$ui/core/Notifications/index.js' + import { notification } from '$ui/core/Notifications/index.js' import { useCustomerCtx } from '$lib/ctx/customer/index.svelte.js' import { Query } from '$lib/api/executor.js' import { getFormattedMonthDayYear } from '$lib/utils/dates.js' diff --git a/src/lib/ui/core/Notifications/Notification.svelte b/src/lib/ui/core/Notifications/Notification.svelte new file mode 100644 index 00000000..fabafef5 --- /dev/null +++ b/src/lib/ui/core/Notifications/Notification.svelte @@ -0,0 +1,66 @@ + + + + + + + + + {message} + + {#if content} + + {#if typeof content === 'function'} + {@render content()} + {:else} + {content} + {/if} + + {/if} + + {#if action} + + {action.label} + + {/if} + + + dispatch('closeToast')} + /> + diff --git a/src/lib/ui/core/Notifications/Notifications.svelte b/src/lib/ui/core/Notifications/Notifications.svelte index 053c59f0..739f12ed 100644 --- a/src/lib/ui/core/Notifications/Notifications.svelte +++ b/src/lib/ui/core/Notifications/Notifications.svelte @@ -1,19 +1,14 @@ {#if BROWSER} {/if} diff --git a/src/lib/ui/core/Notifications/index.ts b/src/lib/ui/core/Notifications/index.ts index 18471bba..f6c99501 100644 --- a/src/lib/ui/core/Notifications/index.ts +++ b/src/lib/ui/core/Notifications/index.ts @@ -1,2 +1,32 @@ +import type { ComponentProps, ComponentType } from 'svelte' +import { toast } from 'svelte-sonner' +import Component from './Notification.svelte' + export { default } from './Notifications.svelte' -export { toast as notifcation } from 'svelte-sonner' + +type TOptions = Omit, 'icon' | 'message'> & { duration?: number } +type TIcon = ComponentProps['icon'] + +function createToast(icon: TIcon, message: string, { duration = 5000, ...options }: TOptions = {}) { + return toast.custom(Component as unknown as ComponentType, { + duration, + componentProps: { ...options, icon, message }, + }) +} + +const createNotificationType = + (icon: TIcon) => + (...rest: [message: string, options?: TOptions]) => + createToast(icon, ...rest) + +const notification: Record< + 'info' | 'error' | 'warning' | 'success', + (message: string, options?: TOptions) => string | number +> = { + info: createNotificationType('info'), + error: createNotificationType('error'), + warning: createNotificationType('warning'), + success: createNotificationType('checkmark-circle'), +} + +export { notification } diff --git a/src/stories/Design System - Core UI/Notifications/index.svelte b/src/stories/Design System - Core UI/Notifications/index.svelte index 9e281e47..107607b2 100644 --- a/src/stories/Design System - Core UI/Notifications/index.svelte +++ b/src/stories/Design System - Core UI/Notifications/index.svelte @@ -1,21 +1,88 @@ - - - notifcation('Event has been created')}>Info +{#snippet content()} + We will check you insight and + publish it very soon + +{/snippet} + + + + + + + + + + + - notifcation.success('Event has been created', { - description: 'This is a description', - })}>Success + Info + + + + notification.info('Informational', { + content: 'We will check your insight and publish it very soon', + action: { + label: 'Button', + onClick: () => console.log('test'), + }, + })} + > + Info with button + + + + notification.info('Notification channel settings is changed', { + content, + action: { + label: 'Undo', + onClick: () => console.log('test'), + }, + })} + > + Info with button + + + + notification.success('Event has been created', { + content: 'We will check your insight and publish it very soon.', + })} + >Success + + + + notification.warning('Warning', { + content: + 'To activate your SanR NFT subscription, you will need to cancel your existing Sanbase Pro subscription first.', + className: 'bg-porcelain', + })} + >Warning + - notifcation.error('Event has been created')} + notification.error('Event has been created')} >Error
+ {#if typeof content === 'function'} + {@render content()} + {:else} + {content} + {/if} +