Add Stripe notifications, messaging improvements, and code cleanup
Stripe Notifications: - Add periodic task to check Stripe Connect accounts for requirements - Create in-app notifications for business owners when action needed - Add management command to setup Stripe periodic tasks - Display Stripe notifications with credit card icon in notification bell - Navigate to payments page when Stripe notification clicked Messaging Improvements: - Add "Everyone" option to broadcast message recipients - Allow sending messages to yourself (remove self-exclusion) - Fix broadcast message ID not returned after creation - Add real-time websocket support for broadcast notifications - Show toast when broadcast message received via websocket UI Fixes: - Remove "View all" button from notifications (no page exists) - Add StripeNotificationBanner component for Connect alerts - Connect useUserNotifications hook in TopBar for app-wide websocket Code Cleanup: - Remove legacy automations app and plugin system - Remove safe_scripting module (moved to Activepieces) - Add migration to remove plugin-related models - Various test improvements and coverage additions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -543,3 +543,109 @@ export const reactivateSubscription = (subscriptionId: string) =>
|
||||
apiClient.post<ReactivateSubscriptionResponse>('/payments/subscriptions/reactivate/', {
|
||||
subscription_id: subscriptionId,
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// Stripe Settings (Connect Accounts)
|
||||
// ============================================================================
|
||||
|
||||
export type PayoutInterval = 'daily' | 'weekly' | 'monthly' | 'manual';
|
||||
export type WeeklyAnchor = 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday';
|
||||
|
||||
export interface PayoutSchedule {
|
||||
interval: PayoutInterval;
|
||||
delay_days: number;
|
||||
weekly_anchor: WeeklyAnchor | null;
|
||||
monthly_anchor: number | null;
|
||||
}
|
||||
|
||||
export interface PayoutSettings {
|
||||
schedule: PayoutSchedule;
|
||||
statement_descriptor: string;
|
||||
}
|
||||
|
||||
export interface BusinessProfile {
|
||||
name: string;
|
||||
support_email: string;
|
||||
support_phone: string;
|
||||
support_url: string;
|
||||
}
|
||||
|
||||
export interface BrandingSettings {
|
||||
primary_color: string;
|
||||
secondary_color: string;
|
||||
icon: string;
|
||||
logo: string;
|
||||
}
|
||||
|
||||
export interface BankAccount {
|
||||
id: string;
|
||||
bank_name: string;
|
||||
last4: string;
|
||||
currency: string;
|
||||
default_for_currency: boolean;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface StripeSettings {
|
||||
payouts: PayoutSettings;
|
||||
business_profile: BusinessProfile;
|
||||
branding: BrandingSettings;
|
||||
bank_accounts: BankAccount[];
|
||||
}
|
||||
|
||||
export interface StripeSettingsUpdatePayouts {
|
||||
schedule?: Partial<PayoutSchedule>;
|
||||
statement_descriptor?: string;
|
||||
}
|
||||
|
||||
export interface StripeSettingsUpdate {
|
||||
payouts?: StripeSettingsUpdatePayouts;
|
||||
business_profile?: Partial<BusinessProfile>;
|
||||
branding?: Pick<BrandingSettings, 'primary_color' | 'secondary_color'>;
|
||||
}
|
||||
|
||||
export interface StripeSettingsUpdateResponse {
|
||||
success: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface StripeSettingsErrorResponse {
|
||||
errors: Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Stripe account settings for Connect accounts.
|
||||
* Includes payout schedule, business profile, branding, and bank accounts.
|
||||
*/
|
||||
export const getStripeSettings = () =>
|
||||
apiClient.get<StripeSettings>('/payments/settings/');
|
||||
|
||||
/**
|
||||
* Update Stripe account settings.
|
||||
* Can update payout settings, business profile, or branding.
|
||||
*/
|
||||
export const updateStripeSettings = (updates: StripeSettingsUpdate) =>
|
||||
apiClient.patch<StripeSettingsUpdateResponse>('/payments/settings/', updates);
|
||||
|
||||
// ============================================================================
|
||||
// Connect Login Link
|
||||
// ============================================================================
|
||||
|
||||
export interface LoginLinkRequest {
|
||||
return_url?: string;
|
||||
refresh_url?: string;
|
||||
}
|
||||
|
||||
export interface LoginLinkResponse {
|
||||
url: string;
|
||||
type: 'login_link' | 'account_link';
|
||||
expires_at?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a dashboard link for the Connect account.
|
||||
* For Express accounts: Returns a one-time login link.
|
||||
* For Custom accounts: Returns an account link (requires return/refresh URLs).
|
||||
*/
|
||||
export const createConnectLoginLink = (request?: LoginLinkRequest) =>
|
||||
apiClient.post<LoginLinkResponse>('/payments/connect/login-link/', request || {});
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* onboarding experience without redirecting users away from the app.
|
||||
*/
|
||||
|
||||
import React, { useState, useCallback } from 'react';
|
||||
import React, { useState, useCallback, useEffect, useRef } from 'react';
|
||||
import {
|
||||
ConnectComponentsProvider,
|
||||
ConnectAccountOnboarding,
|
||||
@@ -22,6 +22,65 @@ import {
|
||||
} from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { createAccountSession, refreshConnectStatus, ConnectAccountInfo } from '../api/payments';
|
||||
import { useDarkMode } from '../hooks/useDarkMode';
|
||||
|
||||
// Get appearance config based on dark mode
|
||||
const getAppearance = (isDark: boolean) => ({
|
||||
overlays: 'drawer' as const,
|
||||
variables: {
|
||||
// Brand colors - using your blue theme
|
||||
colorPrimary: '#3b82f6', // brand-500
|
||||
colorBackground: isDark ? '#1f2937' : '#ffffff', // gray-800 / white
|
||||
colorText: isDark ? '#f9fafb' : '#111827', // gray-50 / gray-900
|
||||
colorSecondaryText: isDark ? '#9ca3af' : '#6b7280', // gray-400 / gray-500
|
||||
colorBorder: isDark ? '#374151' : '#e5e7eb', // gray-700 / gray-200
|
||||
colorDanger: '#ef4444', // red-500
|
||||
|
||||
// Typography - matching Inter font
|
||||
fontFamily: 'Inter, system-ui, -apple-system, sans-serif',
|
||||
fontSizeBase: '14px',
|
||||
fontSizeSm: '12px',
|
||||
fontSizeLg: '16px',
|
||||
fontSizeXl: '18px',
|
||||
fontWeightNormal: '400',
|
||||
fontWeightMedium: '500',
|
||||
fontWeightBold: '600',
|
||||
|
||||
// Spacing & Borders - matching your rounded-lg style
|
||||
spacingUnit: '12px',
|
||||
borderRadius: '8px',
|
||||
|
||||
// Form elements
|
||||
formBackgroundColor: isDark ? '#111827' : '#f9fafb', // gray-900 / gray-50
|
||||
formBorderColor: isDark ? '#374151' : '#d1d5db', // gray-700 / gray-300
|
||||
formHighlightColorBorder: '#3b82f6', // brand-500
|
||||
formAccentColor: '#3b82f6', // brand-500
|
||||
|
||||
// Buttons
|
||||
buttonPrimaryColorBackground: '#3b82f6', // brand-500
|
||||
buttonPrimaryColorText: '#ffffff',
|
||||
buttonSecondaryColorBackground: isDark ? '#374151' : '#f3f4f6', // gray-700 / gray-100
|
||||
buttonSecondaryColorText: isDark ? '#f9fafb' : '#374151', // gray-50 / gray-700
|
||||
buttonSecondaryColorBorder: isDark ? '#4b5563' : '#d1d5db', // gray-600 / gray-300
|
||||
|
||||
// Action colors
|
||||
actionPrimaryColorText: '#3b82f6', // brand-500
|
||||
actionSecondaryColorText: isDark ? '#9ca3af' : '#6b7280', // gray-400 / gray-500
|
||||
|
||||
// Badge colors
|
||||
badgeNeutralColorBackground: isDark ? '#374151' : '#f3f4f6', // gray-700 / gray-100
|
||||
badgeNeutralColorText: isDark ? '#d1d5db' : '#4b5563', // gray-300 / gray-600
|
||||
badgeSuccessColorBackground: isDark ? '#065f46' : '#d1fae5', // green-800 / green-100
|
||||
badgeSuccessColorText: isDark ? '#6ee7b7' : '#065f46', // green-300 / green-800
|
||||
badgeWarningColorBackground: isDark ? '#92400e' : '#fef3c7', // amber-800 / amber-100
|
||||
badgeWarningColorText: isDark ? '#fcd34d' : '#92400e', // amber-300 / amber-800
|
||||
badgeDangerColorBackground: isDark ? '#991b1b' : '#fee2e2', // red-800 / red-100
|
||||
badgeDangerColorText: isDark ? '#fca5a5' : '#991b1b', // red-300 / red-800
|
||||
|
||||
// Offset background (used for layered sections)
|
||||
offsetBackgroundColor: isDark ? '#111827' : '#f9fafb', // gray-900 / gray-50
|
||||
},
|
||||
});
|
||||
|
||||
interface ConnectOnboardingEmbedProps {
|
||||
connectAccount: ConnectAccountInfo | null;
|
||||
@@ -39,13 +98,62 @@ const ConnectOnboardingEmbed: React.FC<ConnectOnboardingEmbedProps> = ({
|
||||
onError,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const isDark = useDarkMode();
|
||||
const [stripeConnectInstance, setStripeConnectInstance] = useState<StripeConnectInstance | null>(null);
|
||||
const [loadingState, setLoadingState] = useState<LoadingState>('idle');
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
|
||||
// Track the theme that was used when initializing
|
||||
const initializedThemeRef = useRef<boolean | null>(null);
|
||||
// Flag to trigger auto-reinitialize
|
||||
const [needsReinit, setNeedsReinit] = useState(false);
|
||||
|
||||
const isActive = connectAccount?.status === 'active' && connectAccount?.charges_enabled;
|
||||
|
||||
// Initialize Stripe Connect
|
||||
// Detect theme changes when onboarding is already open
|
||||
useEffect(() => {
|
||||
if (loadingState === 'ready' && initializedThemeRef.current !== null && initializedThemeRef.current !== isDark) {
|
||||
// Theme changed while onboarding is open - trigger reinitialize
|
||||
setNeedsReinit(true);
|
||||
}
|
||||
}, [isDark, loadingState]);
|
||||
|
||||
// Handle reinitialization
|
||||
useEffect(() => {
|
||||
if (needsReinit) {
|
||||
setStripeConnectInstance(null);
|
||||
initializedThemeRef.current = null;
|
||||
setNeedsReinit(false);
|
||||
// Re-run initialization
|
||||
(async () => {
|
||||
setLoadingState('loading');
|
||||
setErrorMessage(null);
|
||||
|
||||
try {
|
||||
const response = await createAccountSession();
|
||||
const { client_secret, publishable_key } = response.data;
|
||||
|
||||
const instance = await loadConnectAndInitialize({
|
||||
publishableKey: publishable_key,
|
||||
fetchClientSecret: async () => client_secret,
|
||||
appearance: getAppearance(isDark),
|
||||
});
|
||||
|
||||
setStripeConnectInstance(instance);
|
||||
setLoadingState('ready');
|
||||
initializedThemeRef.current = isDark;
|
||||
} catch (err: any) {
|
||||
console.error('Failed to reinitialize Stripe Connect:', err);
|
||||
const message = err.response?.data?.error || err.message || t('payments.failedToInitializePayment');
|
||||
setErrorMessage(message);
|
||||
setLoadingState('error');
|
||||
onError?.(message);
|
||||
}
|
||||
})();
|
||||
}
|
||||
}, [needsReinit, isDark, t, onError]);
|
||||
|
||||
// Initialize Stripe Connect (user-triggered)
|
||||
const initializeStripeConnect = useCallback(async () => {
|
||||
if (loadingState === 'loading' || loadingState === 'ready') return;
|
||||
|
||||
@@ -57,27 +165,16 @@ const ConnectOnboardingEmbed: React.FC<ConnectOnboardingEmbedProps> = ({
|
||||
const response = await createAccountSession();
|
||||
const { client_secret, publishable_key } = response.data;
|
||||
|
||||
// Initialize the Connect instance
|
||||
// Initialize the Connect instance with theme-aware appearance
|
||||
const instance = await loadConnectAndInitialize({
|
||||
publishableKey: publishable_key,
|
||||
fetchClientSecret: async () => client_secret,
|
||||
appearance: {
|
||||
overlays: 'drawer',
|
||||
variables: {
|
||||
colorPrimary: '#635BFF',
|
||||
colorBackground: '#ffffff',
|
||||
colorText: '#1a1a1a',
|
||||
colorDanger: '#df1b41',
|
||||
fontFamily: 'system-ui, -apple-system, sans-serif',
|
||||
fontSizeBase: '14px',
|
||||
spacingUnit: '12px',
|
||||
borderRadius: '8px',
|
||||
},
|
||||
},
|
||||
appearance: getAppearance(isDark),
|
||||
});
|
||||
|
||||
setStripeConnectInstance(instance);
|
||||
setLoadingState('ready');
|
||||
initializedThemeRef.current = isDark;
|
||||
} catch (err: any) {
|
||||
console.error('Failed to initialize Stripe Connect:', err);
|
||||
const message = err.response?.data?.error || err.message || t('payments.failedToInitializePayment');
|
||||
@@ -85,7 +182,7 @@ const ConnectOnboardingEmbed: React.FC<ConnectOnboardingEmbedProps> = ({
|
||||
setLoadingState('error');
|
||||
onError?.(message);
|
||||
}
|
||||
}, [loadingState, onError, t]);
|
||||
}, [loadingState, onError, t, isDark]);
|
||||
|
||||
// Handle onboarding completion
|
||||
const handleOnboardingExit = useCallback(async () => {
|
||||
@@ -242,7 +339,7 @@ const ConnectOnboardingEmbed: React.FC<ConnectOnboardingEmbedProps> = ({
|
||||
|
||||
<button
|
||||
onClick={initializeStripeConnect}
|
||||
className="w-full flex items-center justify-center gap-2 px-4 py-3 text-sm font-medium text-white bg-[#635BFF] rounded-lg hover:bg-[#5851ea] transition-colors"
|
||||
className="w-full flex items-center justify-center gap-2 px-4 py-3 text-sm font-medium text-white bg-brand-500 rounded-lg hover:bg-brand-600 transition-colors"
|
||||
>
|
||||
<CreditCard size={18} />
|
||||
{t('payments.startPaymentSetup')}
|
||||
@@ -255,7 +352,7 @@ const ConnectOnboardingEmbed: React.FC<ConnectOnboardingEmbedProps> = ({
|
||||
if (loadingState === 'loading') {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-12">
|
||||
<Loader2 className="animate-spin text-[#635BFF] mb-4" size={40} />
|
||||
<Loader2 className="animate-spin text-brand-500 mb-4" size={40} />
|
||||
<p className="text-gray-600 dark:text-gray-400">{t('payments.initializingPaymentSetup')}</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Bell, Check, CheckCheck, Trash2, X, Ticket, Calendar, MessageSquare, Clock } from 'lucide-react';
|
||||
import { Bell, Check, CheckCheck, Trash2, X, Ticket, Calendar, MessageSquare, Clock, CreditCard } from 'lucide-react';
|
||||
import {
|
||||
useNotifications,
|
||||
useUnreadNotificationCount,
|
||||
@@ -64,6 +64,13 @@ const NotificationDropdown: React.FC<NotificationDropdownProps> = ({ variant = '
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle Stripe requirements notifications - navigate to payments page
|
||||
if (notification.data?.type === 'stripe_requirements') {
|
||||
navigate('/dashboard/payments');
|
||||
setIsOpen(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Navigate to target if available
|
||||
if (notification.target_url) {
|
||||
navigate(notification.target_url);
|
||||
@@ -85,6 +92,11 @@ const NotificationDropdown: React.FC<NotificationDropdownProps> = ({ variant = '
|
||||
return <Clock size={16} className="text-amber-500" />;
|
||||
}
|
||||
|
||||
// Check for Stripe requirements notifications
|
||||
if (notification.data?.type === 'stripe_requirements') {
|
||||
return <CreditCard size={16} className="text-purple-500" />;
|
||||
}
|
||||
|
||||
switch (notification.target_type) {
|
||||
case 'ticket':
|
||||
return <Ticket size={16} className="text-blue-500" />;
|
||||
@@ -192,9 +204,9 @@ const NotificationDropdown: React.FC<NotificationDropdownProps> = ({ variant = '
|
||||
{' '}
|
||||
{notification.verb}
|
||||
</p>
|
||||
{notification.target_display && (
|
||||
{(notification.target_display || notification.data?.description) && (
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400 truncate mt-0.5">
|
||||
{notification.target_display}
|
||||
{notification.target_display || notification.data?.description}
|
||||
</p>
|
||||
)}
|
||||
<p className="text-xs text-gray-400 dark:text-gray-500 mt-1">
|
||||
@@ -213,7 +225,7 @@ const NotificationDropdown: React.FC<NotificationDropdownProps> = ({ variant = '
|
||||
|
||||
{/* Footer */}
|
||||
{notifications.length > 0 && (
|
||||
<div className="px-4 py-3 border-t border-gray-200 dark:border-gray-700 flex items-center justify-between">
|
||||
<div className="px-4 py-3 border-t border-gray-200 dark:border-gray-700 flex items-center justify-center">
|
||||
<button
|
||||
onClick={handleClearAll}
|
||||
disabled={clearAllMutation.isPending}
|
||||
@@ -222,15 +234,6 @@ const NotificationDropdown: React.FC<NotificationDropdownProps> = ({ variant = '
|
||||
<Trash2 size={12} />
|
||||
{t('notifications.clearRead', 'Clear read')}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
navigate('/dashboard/notifications');
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className="text-xs text-brand-600 hover:text-brand-700 dark:text-brand-400 font-medium"
|
||||
>
|
||||
{t('notifications.viewAll', 'View all')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -20,6 +20,7 @@ import { Business } from '../types';
|
||||
import { usePaymentConfig } from '../hooks/usePayments';
|
||||
import StripeApiKeysForm from './StripeApiKeysForm';
|
||||
import ConnectOnboardingEmbed from './ConnectOnboardingEmbed';
|
||||
import StripeSettingsPanel from './StripeSettingsPanel';
|
||||
|
||||
interface PaymentSettingsSectionProps {
|
||||
business: Business;
|
||||
@@ -260,11 +261,22 @@ const PaymentSettingsSection: React.FC<PaymentSettingsSectionProps> = ({ busines
|
||||
onSuccess={() => refetch()}
|
||||
/>
|
||||
) : (
|
||||
<ConnectOnboardingEmbed
|
||||
connectAccount={config?.connect_account || null}
|
||||
tier={tier}
|
||||
onComplete={() => refetch()}
|
||||
/>
|
||||
<>
|
||||
<ConnectOnboardingEmbed
|
||||
connectAccount={config?.connect_account || null}
|
||||
tier={tier}
|
||||
onComplete={() => refetch()}
|
||||
/>
|
||||
|
||||
{/* Stripe Settings Panel - show when Connect account is active */}
|
||||
{config?.connect_account?.charges_enabled && config?.connect_account?.stripe_account_id && (
|
||||
<div className="mt-6 pt-6 border-t border-gray-200 dark:border-gray-700">
|
||||
<StripeSettingsPanel
|
||||
stripeAccountId={config.connect_account.stripe_account_id}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Upgrade notice for free tier with deprecated keys */}
|
||||
|
||||
142
frontend/src/components/StripeNotificationBanner.tsx
Normal file
142
frontend/src/components/StripeNotificationBanner.tsx
Normal file
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* Stripe Connect Notification Banner
|
||||
*
|
||||
* Displays important alerts and action items from Stripe to connected account holders.
|
||||
* Shows verification requirements, upcoming deadlines, account restrictions, etc.
|
||||
*/
|
||||
|
||||
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import {
|
||||
ConnectComponentsProvider,
|
||||
ConnectNotificationBanner,
|
||||
} from '@stripe/react-connect-js';
|
||||
import { loadConnectAndInitialize } from '@stripe/connect-js';
|
||||
import type { StripeConnectInstance } from '@stripe/connect-js';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { createAccountSession } from '../api/payments';
|
||||
import { useDarkMode } from '../hooks/useDarkMode';
|
||||
|
||||
// Get appearance config based on dark mode
|
||||
// See: https://docs.stripe.com/connect/customize-connect-embedded-components
|
||||
const getAppearance = (isDark: boolean) => ({
|
||||
overlays: 'drawer' as const,
|
||||
variables: {
|
||||
colorPrimary: '#3b82f6',
|
||||
colorBackground: isDark ? '#1f2937' : '#ffffff',
|
||||
colorText: isDark ? '#f9fafb' : '#111827',
|
||||
colorSecondaryText: isDark ? '#9ca3af' : '#6b7280',
|
||||
colorBorder: isDark ? '#374151' : '#e5e7eb',
|
||||
colorDanger: '#ef4444',
|
||||
fontFamily: 'Inter, system-ui, -apple-system, sans-serif',
|
||||
fontSizeBase: '14px',
|
||||
borderRadius: '8px',
|
||||
formBackgroundColor: isDark ? '#111827' : '#f9fafb',
|
||||
formHighlightColorBorder: '#3b82f6',
|
||||
buttonPrimaryColorBackground: '#3b82f6',
|
||||
buttonPrimaryColorText: '#ffffff',
|
||||
buttonSecondaryColorBackground: isDark ? '#374151' : '#f3f4f6',
|
||||
buttonSecondaryColorText: isDark ? '#f9fafb' : '#374151',
|
||||
badgeNeutralColorBackground: isDark ? '#374151' : '#f3f4f6',
|
||||
badgeNeutralColorText: isDark ? '#d1d5db' : '#4b5563',
|
||||
badgeSuccessColorBackground: isDark ? '#065f46' : '#d1fae5',
|
||||
badgeSuccessColorText: isDark ? '#6ee7b7' : '#065f46',
|
||||
badgeWarningColorBackground: isDark ? '#92400e' : '#fef3c7',
|
||||
badgeWarningColorText: isDark ? '#fcd34d' : '#92400e',
|
||||
badgeDangerColorBackground: isDark ? '#991b1b' : '#fee2e2',
|
||||
badgeDangerColorText: isDark ? '#fca5a5' : '#991b1b',
|
||||
},
|
||||
});
|
||||
|
||||
interface StripeNotificationBannerProps {
|
||||
/** Called when there's an error loading the banner (optional, silently fails by default) */
|
||||
onError?: (error: string) => void;
|
||||
}
|
||||
|
||||
const StripeNotificationBanner: React.FC<StripeNotificationBannerProps> = ({
|
||||
onError,
|
||||
}) => {
|
||||
const isDark = useDarkMode();
|
||||
const [stripeConnectInstance, setStripeConnectInstance] = useState<StripeConnectInstance | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [hasError, setHasError] = useState(false);
|
||||
const initializedThemeRef = useRef<boolean | null>(null);
|
||||
|
||||
// Initialize the Stripe Connect instance
|
||||
const initializeStripeConnect = useCallback(async () => {
|
||||
try {
|
||||
const response = await createAccountSession();
|
||||
const { client_secret, publishable_key } = response.data;
|
||||
|
||||
const instance = await loadConnectAndInitialize({
|
||||
publishableKey: publishable_key,
|
||||
fetchClientSecret: async () => client_secret,
|
||||
appearance: getAppearance(isDark),
|
||||
});
|
||||
|
||||
setStripeConnectInstance(instance);
|
||||
initializedThemeRef.current = isDark;
|
||||
setIsLoading(false);
|
||||
} catch (err: any) {
|
||||
console.error('[StripeNotificationBanner] Failed to initialize:', err);
|
||||
setHasError(true);
|
||||
setIsLoading(false);
|
||||
onError?.(err.message || 'Failed to load notifications');
|
||||
}
|
||||
}, [isDark, onError]);
|
||||
|
||||
// Initialize on mount
|
||||
useEffect(() => {
|
||||
initializeStripeConnect();
|
||||
}, [initializeStripeConnect]);
|
||||
|
||||
// Reinitialize on theme change
|
||||
useEffect(() => {
|
||||
if (
|
||||
stripeConnectInstance &&
|
||||
initializedThemeRef.current !== null &&
|
||||
initializedThemeRef.current !== isDark
|
||||
) {
|
||||
// Theme changed, reinitialize
|
||||
setStripeConnectInstance(null);
|
||||
setIsLoading(true);
|
||||
initializeStripeConnect();
|
||||
}
|
||||
}, [isDark, stripeConnectInstance, initializeStripeConnect]);
|
||||
|
||||
// Handle load errors from the component itself
|
||||
const handleLoadError = useCallback((loadError: { error: { message?: string }; elementTagName: string }) => {
|
||||
console.error('Stripe notification banner load error:', loadError);
|
||||
// Don't show error to user - just hide the banner
|
||||
setHasError(true);
|
||||
onError?.(loadError.error.message || 'Failed to load notification banner');
|
||||
}, [onError]);
|
||||
|
||||
// Don't render anything if there's an error (fail silently)
|
||||
if (hasError) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Show subtle loading state
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="mb-4 flex items-center justify-center py-2">
|
||||
<Loader2 className="animate-spin text-gray-400" size={16} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Render the notification banner
|
||||
if (stripeConnectInstance) {
|
||||
return (
|
||||
<div className="mb-4">
|
||||
<ConnectComponentsProvider connectInstance={stripeConnectInstance}>
|
||||
<ConnectNotificationBanner onLoadError={handleLoadError} />
|
||||
</ConnectComponentsProvider>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default StripeNotificationBanner;
|
||||
842
frontend/src/components/StripeSettingsPanel.tsx
Normal file
842
frontend/src/components/StripeSettingsPanel.tsx
Normal file
@@ -0,0 +1,842 @@
|
||||
/**
|
||||
* Stripe Settings Panel Component
|
||||
*
|
||||
* Comprehensive settings panel for Stripe Connect accounts.
|
||||
* Allows tenants to configure payout schedules, business profile,
|
||||
* branding, and view bank accounts.
|
||||
*/
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Calendar,
|
||||
Building2,
|
||||
Palette,
|
||||
Landmark,
|
||||
Loader2,
|
||||
AlertCircle,
|
||||
CheckCircle,
|
||||
ExternalLink,
|
||||
Save,
|
||||
RefreshCw,
|
||||
} from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useStripeSettings, useUpdateStripeSettings, useCreateConnectLoginLink } from '../hooks/usePayments';
|
||||
import type {
|
||||
PayoutInterval,
|
||||
WeeklyAnchor,
|
||||
StripeSettingsUpdate,
|
||||
} from '../api/payments';
|
||||
|
||||
interface StripeSettingsPanelProps {
|
||||
stripeAccountId: string;
|
||||
}
|
||||
|
||||
type TabId = 'payouts' | 'business' | 'branding' | 'bank';
|
||||
|
||||
const StripeSettingsPanel: React.FC<StripeSettingsPanelProps> = ({ stripeAccountId }) => {
|
||||
const { t } = useTranslation();
|
||||
const [activeTab, setActiveTab] = useState<TabId>('payouts');
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
const { data: settings, isLoading, error, refetch } = useStripeSettings();
|
||||
const updateMutation = useUpdateStripeSettings();
|
||||
const loginLinkMutation = useCreateConnectLoginLink();
|
||||
|
||||
// Clear success message after 3 seconds
|
||||
useEffect(() => {
|
||||
if (successMessage) {
|
||||
const timer = setTimeout(() => setSuccessMessage(null), 3000);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [successMessage]);
|
||||
|
||||
// Handle opening Stripe Dashboard
|
||||
const handleOpenStripeDashboard = async () => {
|
||||
try {
|
||||
// Pass the current page URL as return/refresh URLs for Custom accounts
|
||||
const currentUrl = window.location.href;
|
||||
const result = await loginLinkMutation.mutateAsync({
|
||||
return_url: currentUrl,
|
||||
refresh_url: currentUrl,
|
||||
});
|
||||
|
||||
if (result.type === 'login_link') {
|
||||
// Express accounts: Open dashboard in new tab (user stays there)
|
||||
window.open(result.url, '_blank');
|
||||
} else {
|
||||
// Custom accounts: Navigate in same window (redirects back when done)
|
||||
window.location.href = result.url;
|
||||
}
|
||||
} catch {
|
||||
// Error is shown via mutation state
|
||||
}
|
||||
};
|
||||
|
||||
const tabs = [
|
||||
{ id: 'payouts' as TabId, label: t('payments.stripeSettings.payouts'), icon: Calendar },
|
||||
{ id: 'business' as TabId, label: t('payments.stripeSettings.businessProfile'), icon: Building2 },
|
||||
{ id: 'branding' as TabId, label: t('payments.stripeSettings.branding'), icon: Palette },
|
||||
{ id: 'bank' as TabId, label: t('payments.stripeSettings.bankAccounts'), icon: Landmark },
|
||||
];
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="animate-spin text-brand-500 mr-3" size={24} />
|
||||
<span className="text-gray-600 dark:text-gray-400">{t('payments.stripeSettings.loading')}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<AlertCircle className="text-red-600 dark:text-red-400 shrink-0 mt-0.5" size={20} />
|
||||
<div className="flex-1">
|
||||
<h4 className="font-medium text-red-800 dark:text-red-300">{t('payments.stripeSettings.loadError')}</h4>
|
||||
<p className="text-sm text-red-700 dark:text-red-400 mt-1">
|
||||
{error instanceof Error ? error.message : t('payments.stripeSettings.unknownError')}
|
||||
</p>
|
||||
<button
|
||||
onClick={() => refetch()}
|
||||
className="mt-3 flex items-center gap-2 px-3 py-1.5 text-sm font-medium text-red-700 dark:text-red-300 bg-red-100 dark:bg-red-900/30 rounded-lg hover:bg-red-200 dark:hover:bg-red-900/50"
|
||||
>
|
||||
<RefreshCw size={14} />
|
||||
{t('common.retry')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!settings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleSave = async (updates: StripeSettingsUpdate) => {
|
||||
try {
|
||||
await updateMutation.mutateAsync(updates);
|
||||
setSuccessMessage(t('payments.stripeSettings.savedSuccessfully'));
|
||||
} catch {
|
||||
// Error is handled by mutation state
|
||||
}
|
||||
};
|
||||
|
||||
// For sub-tab links that need the static URL structure
|
||||
const stripeDashboardUrl = `https://dashboard.stripe.com/${stripeAccountId.startsWith('acct_') ? stripeAccountId : ''}`;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header with Stripe Dashboard link */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-gray-900 dark:text-white">
|
||||
{t('payments.stripeSettings.title')}
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400 mt-1">
|
||||
{t('payments.stripeSettings.description')}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleOpenStripeDashboard}
|
||||
disabled={loginLinkMutation.isPending}
|
||||
className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-brand-600 dark:text-brand-400 bg-brand-50 dark:bg-brand-900/20 rounded-lg hover:bg-brand-100 dark:hover:bg-brand-900/30 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{loginLinkMutation.isPending ? (
|
||||
<Loader2 className="animate-spin" size={16} />
|
||||
) : (
|
||||
<ExternalLink size={16} />
|
||||
)}
|
||||
{t('payments.stripeSettings.stripeDashboard')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Login link error */}
|
||||
{loginLinkMutation.isError && (
|
||||
<div className="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3">
|
||||
<div className="flex items-center gap-2 text-red-700 dark:text-red-300">
|
||||
<AlertCircle size={16} />
|
||||
<span className="text-sm font-medium">
|
||||
{loginLinkMutation.error instanceof Error
|
||||
? loginLinkMutation.error.message
|
||||
: t('payments.stripeSettings.loginLinkError')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Success message */}
|
||||
{successMessage && (
|
||||
<div className="bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-3">
|
||||
<div className="flex items-center gap-2 text-green-700 dark:text-green-300">
|
||||
<CheckCircle size={16} />
|
||||
<span className="text-sm font-medium">{successMessage}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Error message */}
|
||||
{updateMutation.isError && (
|
||||
<div className="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3">
|
||||
<div className="flex items-center gap-2 text-red-700 dark:text-red-300">
|
||||
<AlertCircle size={16} />
|
||||
<span className="text-sm font-medium">
|
||||
{updateMutation.error instanceof Error
|
||||
? updateMutation.error.message
|
||||
: t('payments.stripeSettings.saveError')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Tabs */}
|
||||
<div className="border-b border-gray-200 dark:border-gray-700">
|
||||
<nav className="flex -mb-px space-x-6">
|
||||
{tabs.map((tab) => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActiveTab(tab.id)}
|
||||
className={`flex items-center gap-2 px-1 py-3 text-sm font-medium border-b-2 transition-colors ${
|
||||
activeTab === tab.id
|
||||
? 'border-brand-500 text-brand-600 dark:text-brand-400'
|
||||
: 'border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 hover:border-gray-300 dark:hover:border-gray-600'
|
||||
}`}
|
||||
>
|
||||
<tab.icon size={16} />
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{/* Tab content */}
|
||||
<div className="min-h-[300px]">
|
||||
{activeTab === 'payouts' && (
|
||||
<PayoutsTab
|
||||
settings={settings.payouts}
|
||||
onSave={handleSave}
|
||||
isSaving={updateMutation.isPending}
|
||||
/>
|
||||
)}
|
||||
{activeTab === 'business' && (
|
||||
<BusinessProfileTab
|
||||
settings={settings.business_profile}
|
||||
onSave={handleSave}
|
||||
isSaving={updateMutation.isPending}
|
||||
/>
|
||||
)}
|
||||
{activeTab === 'branding' && (
|
||||
<BrandingTab
|
||||
settings={settings.branding}
|
||||
onSave={handleSave}
|
||||
isSaving={updateMutation.isPending}
|
||||
stripeDashboardUrl={stripeDashboardUrl}
|
||||
/>
|
||||
)}
|
||||
{activeTab === 'bank' && (
|
||||
<BankAccountsTab
|
||||
accounts={settings.bank_accounts}
|
||||
stripeDashboardUrl={stripeDashboardUrl}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Payouts Tab
|
||||
// ============================================================================
|
||||
|
||||
interface PayoutsTabProps {
|
||||
settings: {
|
||||
schedule: {
|
||||
interval: PayoutInterval;
|
||||
delay_days: number;
|
||||
weekly_anchor: WeeklyAnchor | null;
|
||||
monthly_anchor: number | null;
|
||||
};
|
||||
statement_descriptor: string;
|
||||
};
|
||||
onSave: (updates: StripeSettingsUpdate) => Promise<void>;
|
||||
isSaving: boolean;
|
||||
}
|
||||
|
||||
const PayoutsTab: React.FC<PayoutsTabProps> = ({ settings, onSave, isSaving }) => {
|
||||
const { t } = useTranslation();
|
||||
const [interval, setInterval] = useState<PayoutInterval>(settings.schedule.interval);
|
||||
const [delayDays, setDelayDays] = useState(settings.schedule.delay_days);
|
||||
const [weeklyAnchor, setWeeklyAnchor] = useState<WeeklyAnchor | null>(settings.schedule.weekly_anchor);
|
||||
const [monthlyAnchor, setMonthlyAnchor] = useState<number | null>(settings.schedule.monthly_anchor);
|
||||
const [statementDescriptor, setStatementDescriptor] = useState(settings.statement_descriptor);
|
||||
const [descriptorError, setDescriptorError] = useState<string | null>(null);
|
||||
|
||||
const weekDays: WeeklyAnchor[] = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
|
||||
|
||||
const validateDescriptor = (value: string) => {
|
||||
if (value.length > 22) {
|
||||
setDescriptorError(t('payments.stripeSettings.descriptorTooLong'));
|
||||
return false;
|
||||
}
|
||||
if (value && !/^[a-zA-Z0-9\s.\-]+$/.test(value)) {
|
||||
setDescriptorError(t('payments.stripeSettings.descriptorInvalidChars'));
|
||||
return false;
|
||||
}
|
||||
setDescriptorError(null);
|
||||
return true;
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!validateDescriptor(statementDescriptor)) return;
|
||||
|
||||
const updates: StripeSettingsUpdate = {
|
||||
payouts: {
|
||||
schedule: {
|
||||
interval,
|
||||
delay_days: delayDays,
|
||||
...(interval === 'weekly' && weeklyAnchor ? { weekly_anchor: weeklyAnchor } : {}),
|
||||
...(interval === 'monthly' && monthlyAnchor ? { monthly_anchor: monthlyAnchor } : {}),
|
||||
},
|
||||
...(statementDescriptor ? { statement_descriptor: statementDescriptor } : {}),
|
||||
},
|
||||
};
|
||||
await onSave(updates);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
|
||||
<p className="text-sm text-blue-700 dark:text-blue-300">
|
||||
{t('payments.stripeSettings.payoutsDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Payout Schedule */}
|
||||
<div className="space-y-4">
|
||||
<h4 className="font-medium text-gray-900 dark:text-white">{t('payments.stripeSettings.payoutSchedule')}</h4>
|
||||
|
||||
{/* Interval */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.payoutInterval')}
|
||||
</label>
|
||||
<select
|
||||
value={interval}
|
||||
onChange={(e) => setInterval(e.target.value as PayoutInterval)}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
>
|
||||
<option value="daily">{t('payments.stripeSettings.intervalDaily')}</option>
|
||||
<option value="weekly">{t('payments.stripeSettings.intervalWeekly')}</option>
|
||||
<option value="monthly">{t('payments.stripeSettings.intervalMonthly')}</option>
|
||||
<option value="manual">{t('payments.stripeSettings.intervalManual')}</option>
|
||||
</select>
|
||||
<p className="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
{t('payments.stripeSettings.intervalHint')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Delay Days */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.delayDays')}
|
||||
</label>
|
||||
<select
|
||||
value={delayDays}
|
||||
onChange={(e) => setDelayDays(Number(e.target.value))}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
>
|
||||
{[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].map((days) => (
|
||||
<option key={days} value={days}>
|
||||
{days} {t('payments.stripeSettings.days')}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<p className="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
{t('payments.stripeSettings.delayDaysHint')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Weekly Anchor */}
|
||||
{interval === 'weekly' && (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.weeklyAnchor')}
|
||||
</label>
|
||||
<select
|
||||
value={weeklyAnchor || 'monday'}
|
||||
onChange={(e) => setWeeklyAnchor(e.target.value as WeeklyAnchor)}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
>
|
||||
{weekDays.map((day) => (
|
||||
<option key={day} value={day}>
|
||||
{t(`payments.stripeSettings.${day}`)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Monthly Anchor */}
|
||||
{interval === 'monthly' && (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.monthlyAnchor')}
|
||||
</label>
|
||||
<select
|
||||
value={monthlyAnchor || 1}
|
||||
onChange={(e) => setMonthlyAnchor(Number(e.target.value))}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
>
|
||||
{Array.from({ length: 31 }, (_, i) => i + 1).map((day) => (
|
||||
<option key={day} value={day}>
|
||||
{t('payments.stripeSettings.dayOfMonth', { day })}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Statement Descriptor */}
|
||||
<div>
|
||||
<h4 className="font-medium text-gray-900 dark:text-white mb-4">{t('payments.stripeSettings.statementDescriptor')}</h4>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.descriptorLabel')}
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={statementDescriptor}
|
||||
onChange={(e) => {
|
||||
setStatementDescriptor(e.target.value);
|
||||
validateDescriptor(e.target.value);
|
||||
}}
|
||||
maxLength={22}
|
||||
placeholder={t('payments.stripeSettings.descriptorPlaceholder')}
|
||||
className={`w-full px-3 py-2 border rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent ${
|
||||
descriptorError ? 'border-red-500' : 'border-gray-300 dark:border-gray-600'
|
||||
}`}
|
||||
/>
|
||||
{descriptorError ? (
|
||||
<p className="mt-1 text-xs text-red-500">{descriptorError}</p>
|
||||
) : (
|
||||
<p className="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
{t('payments.stripeSettings.descriptorHint')} ({statementDescriptor.length}/22)
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Save Button */}
|
||||
<div className="flex justify-end pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={isSaving || !!descriptorError}
|
||||
className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-brand-500 rounded-lg hover:bg-brand-600 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{isSaving ? (
|
||||
<Loader2 className="animate-spin" size={16} />
|
||||
) : (
|
||||
<Save size={16} />
|
||||
)}
|
||||
{t('common.save')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Business Profile Tab
|
||||
// ============================================================================
|
||||
|
||||
interface BusinessProfileTabProps {
|
||||
settings: {
|
||||
name: string;
|
||||
support_email: string;
|
||||
support_phone: string;
|
||||
support_url: string;
|
||||
};
|
||||
onSave: (updates: StripeSettingsUpdate) => Promise<void>;
|
||||
isSaving: boolean;
|
||||
}
|
||||
|
||||
const BusinessProfileTab: React.FC<BusinessProfileTabProps> = ({ settings, onSave, isSaving }) => {
|
||||
const { t } = useTranslation();
|
||||
const [name, setName] = useState(settings.name);
|
||||
const [supportEmail, setSupportEmail] = useState(settings.support_email);
|
||||
const [supportPhone, setSupportPhone] = useState(settings.support_phone);
|
||||
const [supportUrl, setSupportUrl] = useState(settings.support_url);
|
||||
|
||||
const handleSave = async () => {
|
||||
const updates: StripeSettingsUpdate = {
|
||||
business_profile: {
|
||||
name,
|
||||
support_email: supportEmail,
|
||||
support_phone: supportPhone,
|
||||
support_url: supportUrl,
|
||||
},
|
||||
};
|
||||
await onSave(updates);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
|
||||
<p className="text-sm text-blue-700 dark:text-blue-300">
|
||||
{t('payments.stripeSettings.businessProfileDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4">
|
||||
{/* Business Name */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.businessName')}
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Support Email */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.supportEmail')}
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
value={supportEmail}
|
||||
onChange={(e) => setSupportEmail(e.target.value)}
|
||||
placeholder="support@yourbusiness.com"
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
/>
|
||||
<p className="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
{t('payments.stripeSettings.supportEmailHint')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Support Phone */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.supportPhone')}
|
||||
</label>
|
||||
<input
|
||||
type="tel"
|
||||
value={supportPhone}
|
||||
onChange={(e) => setSupportPhone(e.target.value)}
|
||||
placeholder="+1 (555) 123-4567"
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Support URL */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.supportUrl')}
|
||||
</label>
|
||||
<input
|
||||
type="url"
|
||||
value={supportUrl}
|
||||
onChange={(e) => setSupportUrl(e.target.value)}
|
||||
placeholder="https://yourbusiness.com/support"
|
||||
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
/>
|
||||
<p className="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
{t('payments.stripeSettings.supportUrlHint')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Save Button */}
|
||||
<div className="flex justify-end pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={isSaving}
|
||||
className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-brand-500 rounded-lg hover:bg-brand-600 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{isSaving ? (
|
||||
<Loader2 className="animate-spin" size={16} />
|
||||
) : (
|
||||
<Save size={16} />
|
||||
)}
|
||||
{t('common.save')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Branding Tab
|
||||
// ============================================================================
|
||||
|
||||
interface BrandingTabProps {
|
||||
settings: {
|
||||
primary_color: string;
|
||||
secondary_color: string;
|
||||
icon: string;
|
||||
logo: string;
|
||||
};
|
||||
onSave: (updates: StripeSettingsUpdate) => Promise<void>;
|
||||
isSaving: boolean;
|
||||
stripeDashboardUrl: string;
|
||||
}
|
||||
|
||||
const BrandingTab: React.FC<BrandingTabProps> = ({ settings, onSave, isSaving, stripeDashboardUrl }) => {
|
||||
const { t } = useTranslation();
|
||||
const [primaryColor, setPrimaryColor] = useState(settings.primary_color || '#3b82f6');
|
||||
const [secondaryColor, setSecondaryColor] = useState(settings.secondary_color || '#10b981');
|
||||
const [colorError, setColorError] = useState<string | null>(null);
|
||||
|
||||
const validateColor = (color: string): boolean => {
|
||||
if (!color) return true;
|
||||
return /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(color);
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
if (primaryColor && !validateColor(primaryColor)) {
|
||||
setColorError(t('payments.stripeSettings.invalidColorFormat'));
|
||||
return;
|
||||
}
|
||||
if (secondaryColor && !validateColor(secondaryColor)) {
|
||||
setColorError(t('payments.stripeSettings.invalidColorFormat'));
|
||||
return;
|
||||
}
|
||||
setColorError(null);
|
||||
|
||||
const updates: StripeSettingsUpdate = {
|
||||
branding: {
|
||||
primary_color: primaryColor,
|
||||
secondary_color: secondaryColor,
|
||||
},
|
||||
};
|
||||
await onSave(updates);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
|
||||
<p className="text-sm text-blue-700 dark:text-blue-300">
|
||||
{t('payments.stripeSettings.brandingDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{colorError && (
|
||||
<div className="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3">
|
||||
<p className="text-sm text-red-700 dark:text-red-300">{colorError}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid gap-6 sm:grid-cols-2">
|
||||
{/* Primary Color */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.primaryColor')}
|
||||
</label>
|
||||
<div className="flex items-center gap-3">
|
||||
<input
|
||||
type="color"
|
||||
value={primaryColor || '#3b82f6'}
|
||||
onChange={(e) => setPrimaryColor(e.target.value)}
|
||||
className="h-10 w-14 rounded border border-gray-300 dark:border-gray-600 cursor-pointer"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={primaryColor}
|
||||
onChange={(e) => setPrimaryColor(e.target.value)}
|
||||
placeholder="#3b82f6"
|
||||
className="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Secondary Color */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{t('payments.stripeSettings.secondaryColor')}
|
||||
</label>
|
||||
<div className="flex items-center gap-3">
|
||||
<input
|
||||
type="color"
|
||||
value={secondaryColor || '#10b981'}
|
||||
onChange={(e) => setSecondaryColor(e.target.value)}
|
||||
className="h-10 w-14 rounded border border-gray-300 dark:border-gray-600 cursor-pointer"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={secondaryColor}
|
||||
onChange={(e) => setSecondaryColor(e.target.value)}
|
||||
placeholder="#10b981"
|
||||
className="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-brand-500 focus:border-transparent"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Logo & Icon Info */}
|
||||
<div className="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4">
|
||||
<h4 className="font-medium text-gray-900 dark:text-white mb-2">{t('payments.stripeSettings.logoAndIcon')}</h4>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400 mb-3">
|
||||
{t('payments.stripeSettings.logoAndIconDescription')}
|
||||
</p>
|
||||
<a
|
||||
href={`${stripeDashboardUrl}/settings/branding`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-2 text-sm font-medium text-brand-600 dark:text-brand-400 hover:underline"
|
||||
>
|
||||
<ExternalLink size={14} />
|
||||
{t('payments.stripeSettings.uploadInStripeDashboard')}
|
||||
</a>
|
||||
|
||||
{/* Display current logo/icon if set */}
|
||||
{(settings.icon || settings.logo) && (
|
||||
<div className="flex items-center gap-4 mt-4 pt-4 border-t border-gray-200 dark:border-gray-600">
|
||||
{settings.icon && (
|
||||
<div className="text-center">
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400 mb-1">{t('payments.stripeSettings.icon')}</p>
|
||||
<div className="w-12 h-12 bg-gray-200 dark:bg-gray-600 rounded flex items-center justify-center">
|
||||
<CheckCircle className="text-green-500" size={20} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{settings.logo && (
|
||||
<div className="text-center">
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400 mb-1">{t('payments.stripeSettings.logo')}</p>
|
||||
<div className="w-24 h-12 bg-gray-200 dark:bg-gray-600 rounded flex items-center justify-center">
|
||||
<CheckCircle className="text-green-500" size={20} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Save Button */}
|
||||
<div className="flex justify-end pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={isSaving}
|
||||
className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-brand-500 rounded-lg hover:bg-brand-600 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{isSaving ? (
|
||||
<Loader2 className="animate-spin" size={16} />
|
||||
) : (
|
||||
<Save size={16} />
|
||||
)}
|
||||
{t('common.save')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Bank Accounts Tab
|
||||
// ============================================================================
|
||||
|
||||
interface BankAccountsTabProps {
|
||||
accounts: Array<{
|
||||
id: string;
|
||||
bank_name: string;
|
||||
last4: string;
|
||||
currency: string;
|
||||
default_for_currency: boolean;
|
||||
status: string;
|
||||
}>;
|
||||
stripeDashboardUrl: string;
|
||||
}
|
||||
|
||||
const BankAccountsTab: React.FC<BankAccountsTabProps> = ({ accounts, stripeDashboardUrl }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
|
||||
<p className="text-sm text-blue-700 dark:text-blue-300">
|
||||
{t('payments.stripeSettings.bankAccountsDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{accounts.length === 0 ? (
|
||||
<div className="text-center py-8">
|
||||
<Landmark className="mx-auto text-gray-400 mb-3" size={40} />
|
||||
<h4 className="font-medium text-gray-900 dark:text-white mb-1">
|
||||
{t('payments.stripeSettings.noBankAccounts')}
|
||||
</h4>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400 mb-4">
|
||||
{t('payments.stripeSettings.noBankAccountsDescription')}
|
||||
</p>
|
||||
<a
|
||||
href={`${stripeDashboardUrl}/settings/payouts`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-brand-500 rounded-lg hover:bg-brand-600"
|
||||
>
|
||||
<ExternalLink size={16} />
|
||||
{t('payments.stripeSettings.addInStripeDashboard')}
|
||||
</a>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{accounts.map((account) => (
|
||||
<div
|
||||
key={account.id}
|
||||
className="flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-700/50 rounded-lg"
|
||||
>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="p-2 bg-white dark:bg-gray-600 rounded-lg">
|
||||
<Landmark className="text-gray-600 dark:text-gray-300" size={20} />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium text-gray-900 dark:text-white">
|
||||
{account.bank_name || t('payments.stripeSettings.bankAccount')}
|
||||
</p>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400">
|
||||
••••{account.last4} · {account.currency.toUpperCase()}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
{account.default_for_currency && (
|
||||
<span className="px-2 py-1 text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-300 rounded-full">
|
||||
{t('payments.stripeSettings.default')}
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
className={`px-2 py-1 text-xs font-medium rounded-full ${
|
||||
account.status === 'verified'
|
||||
? 'bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-300'
|
||||
: 'bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-300'
|
||||
}`}
|
||||
>
|
||||
{account.status}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div className="pt-4 border-t border-gray-200 dark:border-gray-700">
|
||||
<a
|
||||
href={`${stripeDashboardUrl}/settings/payouts`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-2 text-sm font-medium text-brand-600 dark:text-brand-400 hover:underline"
|
||||
>
|
||||
<ExternalLink size={14} />
|
||||
{t('payments.stripeSettings.manageInStripeDashboard')}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default StripeSettingsPanel;
|
||||
@@ -8,6 +8,7 @@ import NotificationDropdown from './NotificationDropdown';
|
||||
import SandboxToggle from './SandboxToggle';
|
||||
import HelpButton from './HelpButton';
|
||||
import { useSandbox } from '../contexts/SandboxContext';
|
||||
import { useUserNotifications } from '../hooks/useUserNotifications';
|
||||
|
||||
interface TopBarProps {
|
||||
user: User;
|
||||
@@ -21,6 +22,9 @@ const TopBar: React.FC<TopBarProps> = ({ user, isDarkMode, toggleTheme, onMenuCl
|
||||
const { t } = useTranslation();
|
||||
const { isSandbox, sandboxEnabled, toggleSandbox, isToggling } = useSandbox();
|
||||
|
||||
// Connect to user notifications WebSocket for real-time updates
|
||||
useUserNotifications({ enabled: !!user });
|
||||
|
||||
return (
|
||||
<header className="flex items-center justify-between h-16 px-4 sm:px-8 bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700 transition-colors duration-200 shrink-0">
|
||||
<div className="flex items-center gap-4">
|
||||
|
||||
@@ -320,15 +320,6 @@ describe('NotificationDropdown', () => {
|
||||
expect(mockClearAll).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('navigates to notifications page when "View all" is clicked', () => {
|
||||
render(<NotificationDropdown />, { wrapper: createWrapper() });
|
||||
fireEvent.click(screen.getByRole('button', { name: /open notifications/i }));
|
||||
|
||||
const viewAllButton = screen.getByText('View all');
|
||||
fireEvent.click(viewAllButton);
|
||||
|
||||
expect(mockNavigate).toHaveBeenCalledWith('/notifications');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Notification icons', () => {
|
||||
@@ -444,7 +435,6 @@ describe('NotificationDropdown', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: /open notifications/i }));
|
||||
|
||||
expect(screen.getByText('Clear read')).toBeInTheDocument();
|
||||
expect(screen.getByText('View all')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides footer when there are no notifications', () => {
|
||||
@@ -457,7 +447,6 @@ describe('NotificationDropdown', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: /open notifications/i }));
|
||||
|
||||
expect(screen.queryByText('Clear read')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('View all')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,6 +15,7 @@ export const paymentKeys = {
|
||||
config: () => [...paymentKeys.all, 'config'] as const,
|
||||
apiKeys: () => [...paymentKeys.all, 'apiKeys'] as const,
|
||||
connectStatus: () => [...paymentKeys.all, 'connectStatus'] as const,
|
||||
stripeSettings: () => [...paymentKeys.all, 'stripeSettings'] as const,
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
@@ -152,3 +153,52 @@ export const useRefreshConnectLink = () => {
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Stripe Settings Hooks (Connect Accounts)
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* Get Stripe account settings.
|
||||
* Only enabled when Connect account is active with charges enabled.
|
||||
*/
|
||||
export const useStripeSettings = (enabled = true) => {
|
||||
return useQuery({
|
||||
queryKey: paymentKeys.stripeSettings(),
|
||||
queryFn: () => paymentsApi.getStripeSettings().then(res => res.data),
|
||||
staleTime: 60 * 1000, // 1 minute
|
||||
enabled,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Stripe account settings.
|
||||
* Can update payouts, business profile, or branding.
|
||||
*/
|
||||
export const useUpdateStripeSettings = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (updates: paymentsApi.StripeSettingsUpdate) =>
|
||||
paymentsApi.updateStripeSettings(updates).then(res => res.data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: paymentKeys.stripeSettings() });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Connect Login Link Hook
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* Create a dashboard link for the Connect account.
|
||||
* For Express accounts: Returns a one-time login link.
|
||||
* For Custom accounts: Returns an account link (pass return/refresh URLs).
|
||||
*/
|
||||
export const useCreateConnectLoginLink = () => {
|
||||
return useMutation({
|
||||
mutationFn: (request?: paymentsApi.LoginLinkRequest) =>
|
||||
paymentsApi.createConnectLoginLink(request).then(res => res.data),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -5,16 +5,22 @@
|
||||
|
||||
import { useEffect, useRef, useCallback } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import toast from 'react-hot-toast';
|
||||
import { getCookie } from '../utils/cookies';
|
||||
import { getWebSocketUrl } from '../utils/domain';
|
||||
import { UserEmail } from '../api/profile';
|
||||
|
||||
interface WebSocketMessage {
|
||||
type: 'connection_established' | 'email_verified' | 'profile_updated' | 'pong';
|
||||
type: 'connection_established' | 'email_verified' | 'profile_updated' | 'pong' | 'broadcast_message' | 'notification';
|
||||
email_id?: number;
|
||||
email?: string;
|
||||
user_id?: string;
|
||||
message?: string;
|
||||
message_id?: number;
|
||||
subject?: string;
|
||||
sender?: string;
|
||||
preview?: string;
|
||||
timestamp?: string;
|
||||
fields?: string[];
|
||||
}
|
||||
|
||||
@@ -148,6 +154,23 @@ export function useUserNotifications(options: UseUserNotificationsOptions = {})
|
||||
// Invalidate profile queries to refresh data
|
||||
queryClient.invalidateQueries({ queryKey: ['currentUser'] });
|
||||
break;
|
||||
case 'broadcast_message':
|
||||
console.log('UserNotifications WebSocket: Broadcast message received', message.subject);
|
||||
// Show toast notification
|
||||
toast(message.subject || 'New message received', {
|
||||
icon: '📬',
|
||||
duration: 5000,
|
||||
});
|
||||
// Invalidate notifications queries to refresh immediately
|
||||
queryClient.invalidateQueries({ queryKey: ['notifications'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['unreadNotificationCount'] });
|
||||
break;
|
||||
case 'notification':
|
||||
console.log('UserNotifications WebSocket: New notification received', message.message);
|
||||
// Invalidate notifications queries to refresh immediately
|
||||
queryClient.invalidateQueries({ queryKey: ['notifications'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['unreadNotificationCount'] });
|
||||
break;
|
||||
default:
|
||||
console.log('UserNotifications WebSocket: Unknown message type', message);
|
||||
}
|
||||
|
||||
@@ -1851,6 +1851,71 @@
|
||||
"cancel": "Cancel",
|
||||
"validationFailed": "Validation failed",
|
||||
"failedToSaveKeys": "Failed to save keys"
|
||||
},
|
||||
"stripeSettings": {
|
||||
"title": "Stripe Account Settings",
|
||||
"description": "Configure your Stripe Connect account settings including payout schedule, business profile, and branding.",
|
||||
"loading": "Loading settings...",
|
||||
"loadError": "Failed to load settings",
|
||||
"unknownError": "An unknown error occurred",
|
||||
"saveError": "Failed to save settings",
|
||||
"savedSuccessfully": "Settings saved successfully",
|
||||
"stripeDashboard": "Stripe Dashboard",
|
||||
"payouts": "Payouts",
|
||||
"businessProfile": "Business Profile",
|
||||
"branding": "Branding",
|
||||
"bankAccounts": "Bank Accounts",
|
||||
"payoutsDescription": "Configure when and how your payouts are sent to your bank account. Changes take effect immediately.",
|
||||
"payoutSchedule": "Payout Schedule",
|
||||
"payoutInterval": "Payout Frequency",
|
||||
"intervalDaily": "Daily",
|
||||
"intervalWeekly": "Weekly",
|
||||
"intervalMonthly": "Monthly",
|
||||
"intervalManual": "Manual",
|
||||
"intervalHint": "How often funds are transferred to your bank account",
|
||||
"delayDays": "Payout Delay",
|
||||
"days": "days",
|
||||
"delayDaysHint": "Number of days to hold funds before payout (2-14 days)",
|
||||
"weeklyAnchor": "Payout Day",
|
||||
"monthlyAnchor": "Day of Month",
|
||||
"dayOfMonth": "Day {{day}}",
|
||||
"monday": "Monday",
|
||||
"tuesday": "Tuesday",
|
||||
"wednesday": "Wednesday",
|
||||
"thursday": "Thursday",
|
||||
"friday": "Friday",
|
||||
"saturday": "Saturday",
|
||||
"sunday": "Sunday",
|
||||
"statementDescriptor": "Statement Descriptor",
|
||||
"descriptorLabel": "Statement Descriptor",
|
||||
"descriptorPlaceholder": "Your Business Name",
|
||||
"descriptorHint": "This appears on customer bank statements",
|
||||
"descriptorTooLong": "Statement descriptor must be 22 characters or less",
|
||||
"descriptorInvalidChars": "Only letters, numbers, spaces, hyphens, and periods are allowed",
|
||||
"businessProfileDescription": "Update your business contact information. This appears on receipts and is used by Stripe for customer support purposes.",
|
||||
"businessName": "Business Name",
|
||||
"supportEmail": "Support Email",
|
||||
"supportEmailHint": "Email address customers can use for payment-related inquiries",
|
||||
"supportPhone": "Support Phone",
|
||||
"supportUrl": "Support URL",
|
||||
"supportUrlHint": "URL to your customer support or help page",
|
||||
"brandingDescription": "Customize how your brand appears on Stripe-hosted pages like receipts and checkout.",
|
||||
"primaryColor": "Primary Color",
|
||||
"secondaryColor": "Secondary Color",
|
||||
"invalidColorFormat": "Invalid color format. Use #RGB or #RRGGBB format.",
|
||||
"logoAndIcon": "Logo & Icon",
|
||||
"logoAndIconDescription": "To upload or update your logo and icon, use the Stripe Dashboard.",
|
||||
"uploadInStripeDashboard": "Upload in Stripe Dashboard",
|
||||
"icon": "Icon",
|
||||
"logo": "Logo",
|
||||
"bankAccountsDescription": "View your connected bank accounts. To add or remove bank accounts, use the Stripe Dashboard for security reasons.",
|
||||
"noBankAccounts": "No Bank Accounts",
|
||||
"noBankAccountsDescription": "Add a bank account in the Stripe Dashboard to receive payouts.",
|
||||
"addInStripeDashboard": "Add Bank Account",
|
||||
"bankAccount": "Bank Account",
|
||||
"default": "Default",
|
||||
"manageInStripeDashboard": "Manage bank accounts in Stripe Dashboard",
|
||||
"loginLinkError": "Unable to open Stripe Dashboard. Please try again."
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
|
||||
@@ -181,13 +181,26 @@ const Messages: React.FC = () => {
|
||||
},
|
||||
});
|
||||
|
||||
// All available target roles (excluding 'everyone' which is a meta-option)
|
||||
const allRoles = ['owner', 'staff', 'customer'];
|
||||
|
||||
// Handlers
|
||||
const handleRoleToggle = (role: string) => {
|
||||
setSelectedRoles((prev) =>
|
||||
prev.includes(role) ? prev.filter((r) => r !== role) : [...prev, role]
|
||||
);
|
||||
if (role === 'everyone') {
|
||||
// Toggle all roles on/off
|
||||
setSelectedRoles((prev) =>
|
||||
prev.length === allRoles.length ? [] : [...allRoles]
|
||||
);
|
||||
} else {
|
||||
setSelectedRoles((prev) =>
|
||||
prev.includes(role) ? prev.filter((r) => r !== role) : [...prev, role]
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Check if all roles are selected (for "Everyone" tile)
|
||||
const isEveryoneSelected = allRoles.every(role => selectedRoles.includes(role));
|
||||
|
||||
const handleAddUser = (user: RecipientOption) => {
|
||||
if (!selectedUsers.find(u => u.id === user.id)) {
|
||||
setSelectedUsers((prev) => [...prev, user]);
|
||||
@@ -253,6 +266,7 @@ const Messages: React.FC = () => {
|
||||
{ value: 'owner', label: 'Owners', icon: Users, description: 'Business owners' },
|
||||
{ value: 'staff', label: 'Staff', icon: Users, description: 'Employees' },
|
||||
{ value: 'customer', label: 'Customers', icon: Users, description: 'Clients' },
|
||||
{ value: 'everyone', label: 'Everyone', icon: Users, description: 'All users' },
|
||||
];
|
||||
|
||||
const deliveryMethodOptions = [
|
||||
@@ -425,7 +439,7 @@ const Messages: React.FC = () => {
|
||||
label={role.label}
|
||||
icon={role.icon}
|
||||
description={role.description}
|
||||
selected={selectedRoles.includes(role.value)}
|
||||
selected={role.value === 'everyone' ? isEveryoneSelected : selectedRoles.includes(role.value)}
|
||||
onClick={() => handleRoleToggle(role.value)}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -33,6 +33,7 @@ import { User, Business, PaymentMethod } from '../types';
|
||||
import PaymentSettingsSection from '../components/PaymentSettingsSection';
|
||||
import TransactionDetailModal from '../components/TransactionDetailModal';
|
||||
import Portal from '../components/Portal';
|
||||
import StripeNotificationBanner from '../components/StripeNotificationBanner';
|
||||
import {
|
||||
useTransactions,
|
||||
useTransactionSummary,
|
||||
@@ -223,6 +224,11 @@ const Payments: React.FC = () => {
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{/* Stripe Notification Banner - Show beneath tabs, persists across all tabs */}
|
||||
{canAcceptPayments && paymentConfig?.payment_mode === 'connect' && (
|
||||
<StripeNotificationBanner />
|
||||
)}
|
||||
|
||||
{/* Tab Content */}
|
||||
{activeTab === 'overview' && (
|
||||
<div className="space-y-6">
|
||||
|
||||
Reference in New Issue
Block a user