Files
myeasycms-v2/apps/web/app/[locale]/home/[account]/newsletter/[campaignId]/dispatch-newsletter-button.tsx
Zaid Marzguioui b26e5aaafa
Some checks failed
Workflow / ʦ TypeScript (push) Failing after 6m20s
Workflow / ⚫️ Test (push) Has been skipped
feat: pre-existing local changes — fischerei, verband, modules, members, packages
Commits all remaining uncommitted local work:

- apps/web: fischerei, verband, modules, members-cms, documents,
  newsletter, meetings, site-builder, courses, bookings, events,
  finance pages and components
- apps/web: marketing page updates, layout, paths config,
  next.config.mjs, styles/makerkit.css
- apps/web/i18n: documents, fischerei, marketing, verband (de+en)
- packages/features: finance, fischerei, member-management,
  module-builder, newsletter, sitzungsprotokolle, verbandsverwaltung
  server APIs and components
- packages/ui: button.tsx updates
- pnpm-lock.yaml
2026-04-02 01:19:54 +02:00

80 lines
2.1 KiB
TypeScript

'use client';
import { useTransition } from 'react';
import { useRouter } from 'next/navigation';
import { Send } from 'lucide-react';
import { dispatchNewsletter } from '@kit/newsletter/actions/newsletter-actions';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@kit/ui/alert-dialog';
import { Button } from '@kit/ui/button';
import { useActionWithToast } from '@kit/ui/use-action-with-toast';
interface DispatchNewsletterButtonProps {
newsletterId: string;
recipientCount: number;
}
export function DispatchNewsletterButton({
newsletterId,
recipientCount,
}: DispatchNewsletterButtonProps) {
const router = useRouter();
const [isPending, startTransition] = useTransition();
const { execute, isPending: isDispatching } = useActionWithToast(
dispatchNewsletter,
{
successMessage: 'Newsletter wird versendet',
errorMessage: 'Fehler beim Versenden',
onSuccess: () => {
startTransition(() => {
router.refresh();
});
},
},
);
return (
<AlertDialog>
<AlertDialogTrigger
render={
<Button
disabled={isDispatching || isPending || recipientCount === 0}
data-test="newsletter-send-btn"
>
<Send className="mr-2 h-4 w-4" aria-hidden="true" />
Newsletter versenden
</Button>
}
/>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Newsletter versenden?</AlertDialogTitle>
<AlertDialogDescription>
Der Newsletter wird an {recipientCount} Empfänger versendet. Dieser
Vorgang kann nicht rückgängig gemacht werden.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Abbrechen</AlertDialogCancel>
<AlertDialogAction onClick={() => execute({ newsletterId })}>
Jetzt versenden
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}