import React, { useState, useEffect } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { api } from '@/lib/api'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Input } from '@/components/ui/input'; import { Switch } from '@/components/ui/switch'; import { ExternalLink, Loader2 } from 'lucide-react'; import { toast } from 'sonner'; import { __ } from '@/lib/i18n'; interface ChannelConfigProps { open: boolean; onClose: () => void; channelId: string; channelLabel: string; } export default function ChannelConfig({ open, onClose, channelId, channelLabel }: ChannelConfigProps) { // Email configuration - redirect to WooCommerce if (channelId === 'email') { return ( {__('Email Configuration')} {__('Email settings are managed by WooCommerce')}

{__( 'Email notifications are powered by WooCommerce. You can configure SMTP settings, email templates, and sender information in the WooCommerce settings.' )}

{__('Available Settings')}

  • • {__('SMTP Configuration')}
  • • {__('Email Templates')}
  • • {__('Sender Name & Email')}
  • • {__('Email Headers & Footers')}
); } // Push notification configuration if (channelId === 'push') { const queryClient = useQueryClient(); const [settings, setSettings] = useState({ use_logo: true, use_product_images: true, use_gravatar: false, click_action: '/wp-admin/admin.php?page=woonoow#/orders', require_interaction: false, silent: false, }); // Fetch push settings const { data: pushSettings, isLoading } = useQuery({ queryKey: ['push-settings'], queryFn: () => api.get('/notifications/push/settings'), enabled: open, }); // Update local state when data is fetched useEffect(() => { if (pushSettings) { setSettings(pushSettings); } }, [pushSettings]); // Save settings mutation const saveMutation = useMutation({ mutationFn: async () => { return api.post('/notifications/push/settings', settings); }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['push-settings'] }); toast.success(__('Push notification settings saved')); onClose(); }, onError: (error: any) => { toast.error(error?.message || __('Failed to save settings')); }, }); return ( {__('Push Notification Configuration')} {__('Configure how push notifications appear and behave')} {isLoading ? (
) : (
{/* Branding */}

{__('Display your store logo in push notifications')}

{__('Show product images in order notifications')}

setSettings({...settings, use_product_images: checked})} />

{__('Display customer avatar when available')}

setSettings({...settings, use_gravatar: checked})} />
{/* Behavior */}
setSettings({...settings, click_action: e.target.value})} />

{__('Where users are redirected when clicking the notification')}

{__('Notification stays until user dismisses it')}

setSettings({...settings, require_interaction: checked})} />

{__('Disable notification sound')}

setSettings({...settings, silent: checked})} />

💡 {__('Note: These settings will be saved and applied to all push notifications. Individual templates can override the icon and image.')}

) }
); } // Generic addon channel configuration return ( {channelLabel} {__('Configuration')} {__('Configure')} {channelLabel} {__('settings')}

{__('Configuration for this channel is provided by the addon.')}

); }