import { settingsApi } from '@/admin/api/settings'; import { settingsQuery } from '@/admin/queries/settings'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { Separator } from '@/components/ui/separator'; import { Skeleton } from '@/components/ui/skeleton'; import { Spinner } from '@/components/ui/spinner'; import { Switch } from '@/components/ui/switch'; import { Textarea } from '@/components/ui/textarea'; import { useForm } from '@tanstack/react-form'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { __ } from '@wordpress/i18n'; import { CreditCard } from 'lucide-react'; import { useEffect } from 'react'; import { toast } from 'sonner'; const CURRENCIES = __ALLCOACH_ADMIN__.currencies.map((c) => ({ value: c.code, label: `${c.code} – ${c.name} (${c.symbol})`, })); const FUTURE_METHODS = [ { name: 'Stripe', description: __('Online card payments via Stripe.', 'allcoach'), }, ]; const PaymentSettings = () => { const queryClient = useQueryClient(); const { data: settings, isLoading } = useQuery({ ...settingsQuery(), retry: false, }); const form = useForm({ defaultValues: { currency: 'USD', offline_payment: { enabled: true, title: 'Pay in person', description: 'Pay at the time of your session.', }, }, }); useEffect(() => { if (!settings) return; form.reset({ currency: settings.currency ?? 'USD', offline_payment: { enabled: settings.payment_offline_enabled ?? true, title: settings.payment_offline_title ?? 'Pay in person', description: settings.payment_offline_description ?? 'Pay at the time of your session.', }, }); }, [settings]); const save = useMutation({ mutationFn: (values: typeof form.state.values) => settingsApi.update({ ...settings, currency: values.currency, payment_offline_enabled: values.offline_payment.enabled, payment_offline_title: values.offline_payment.title, payment_offline_description: values.offline_payment.description, }), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['settings'] }); toast.success(__('Payment settings saved.', 'allcoach')); }, onError: () => { toast.error(__('Failed to save settings.', 'allcoach')); }, }); return (
{/* Header */}

{__('Payment', 'allcoach')}

{isLoading ? (
) : ( <>
{/* Currency */}
{(field) => ( )}
{/* Payment methods */}

{__('Payment methods', 'allcoach')}

{__( 'Choose which payment methods clients can use.', 'allcoach', )}

{/* Offline payment */}

{__('Offline payment', 'allcoach')}

{__('Accept payment outside the platform.', 'allcoach')}

{(field) => ( )}
s.values.offline_payment.enabled} > {(enabled) => enabled && (
{(field) => (
field.handleChange(e.target.value) } onBlur={field.handleBlur} className="bg-white text-[13px]" />
)}
{(field) => (