"use client"; import React, { useState, useTransition } from 'react'; import { Save, Loader2, Zap, Calendar, Newspaper, Layout } from 'lucide-react'; import { updateOneShotPlan } from '@/app/actions/one-shot'; import { toast } from 'react-hot-toast'; import { OneShotType } from '@prisma/client'; interface OneShotPlan { id: string; type: OneShotType; name: string; priceXOF: number; priceEUR: number; description: string | null; } const TYPE_ICONS = { BUMP: Zap, POST_EVENT: Calendar, POST_NEWS: Newspaper, AD_DIRECTORY: Layout, }; const TYPE_LABELS = { BUMP: "Remonter dans l'annuaire", POST_EVENT: "Poster un événement", POST_NEWS: "Poster une actualité", AD_DIRECTORY: "Publicité dans l'annuaire", }; export default function OneShotPricingSettings({ initialPlans }: { initialPlans: OneShotPlan[] }) { const [plans, setPlans] = useState(initialPlans); const [isPending, startTransition] = useTransition(); // Ensure all types are present even if not in DB yet const allTypes: OneShotType[] = ['BUMP', 'POST_EVENT', 'POST_NEWS', 'AD_DIRECTORY']; const getPlanByType = (type: OneShotType) => { return plans.find(p => p.type === type) || { id: '', type, name: TYPE_LABELS[type], priceXOF: 0, priceEUR: 0, description: '' }; }; const handleUpdate = async (type: OneShotType, data: any) => { startTransition(async () => { const result = await updateOneShotPlan(type, data); if (result.success) { toast.success(`Plan ${TYPE_LABELS[type]} mis à jour`); } else { toast.error(result.error || "Erreur lors de la mise à jour"); } }); }; return (

Tarifs des Services Ponctuels (One-Shot)

Configurez les prix des services à l'acte. Ces tarifs seront affichés sur la page de tarification.

{allTypes.map((type) => { const plan = getPlanByType(type); const Icon = TYPE_ICONS[type]; return (

{TYPE_LABELS[type]}

{type}

{ e.preventDefault(); const formData = new FormData(e.currentTarget); handleUpdate(type, { name: formData.get('name'), priceXOF: parseInt(formData.get('priceXOF') as string || '0'), priceEUR: parseInt(formData.get('priceEUR') as string || '0'), description: formData.get('description'), }); }} className="flex-1 grid grid-cols-1 md:grid-cols-4 gap-4" >
); })}
); }