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')} { window.open( `${(window as any).WNW_CONFIG?.wpAdminUrl || '/wp-admin'}/admin.php?page=wc-settings&tab=email`, '_blank' ); onClose(); }} > {__('Open WooCommerce Email Settings')} ); } // 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 */} {__('Notification Branding')} {__('Use Store Logo')} {__('Display your store logo in push notifications')} setSettings({...settings, use_logo: checked})} /> {__('Use Product Images')} {__('Show product images in order notifications')} setSettings({...settings, use_product_images: checked})} /> {__('Use Customer Gravatar')} {__('Display customer avatar when available')} setSettings({...settings, use_gravatar: checked})} /> {/* Behavior */} {__('Notification Behavior')} {__('Click Action URL')} setSettings({...settings, click_action: e.target.value})} /> {__('Where users are redirected when clicking the notification')} {__('Require Interaction')} {__('Notification stays until user dismisses it')} setSettings({...settings, require_interaction: checked})} /> {__('Silent Notifications')} {__('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.')} ) } {__('Cancel')} saveMutation.mutate()} disabled={saveMutation.isPending || isLoading}> {saveMutation.isPending ? ( <> {__('Saving...')} > ) : ( __('Save Configuration') )} ); } // Generic addon channel configuration return ( {channelLabel} {__('Configuration')} {__('Configure')} {channelLabel} {__('settings')} {__('Configuration for this channel is provided by the addon.')} {__('Close')} ); }
{__( 'Email notifications are powered by WooCommerce. You can configure SMTP settings, email templates, and sender information in the WooCommerce settings.' )}
{__('Display your store logo in push notifications')}
{__('Show product images in order notifications')}
{__('Display customer avatar when available')}
{__('Where users are redirected when clicking the notification')}
{__('Notification stays until user dismisses it')}
{__('Disable notification sound')}
💡 {__('Note: These settings will be saved and applied to all push notifications. Individual templates can override the icon and image.')}
{__('Configuration for this channel is provided by the addon.')}