AlertDialogHost.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { useCallback } from "react";
  2. import {
  3. AlertDialog,
  4. AlertDialogAction,
  5. AlertDialogContent,
  6. AlertDialogDescription,
  7. AlertDialogFooter,
  8. AlertDialogHeader,
  9. AlertDialogTitle,
  10. } from "@/components/ui/alert-dialog.js";
  11. import { cn } from "@/components/lib/utils.js";
  12. import { useZCodeIntl } from "@/i18n/IntlProvider.js";
  13. import { useAlertDialogStore } from "@/store/alertDialogStore.js";
  14. export function AlertDialogHost() {
  15. const { intl } = useZCodeIntl();
  16. const pendingRequest = useAlertDialogStore((state) => state.pendingRequest);
  17. const settleAlert = useAlertDialogStore((state) => state.settleAlert);
  18. const handleOpenChange = useCallback(
  19. (nextOpen: boolean) => {
  20. if (!nextOpen) {
  21. settleAlert(false);
  22. }
  23. },
  24. [settleAlert],
  25. );
  26. return (
  27. <AlertDialog open={Boolean(pendingRequest)} onOpenChange={handleOpenChange}>
  28. <AlertDialogContent className="gap-5">
  29. <AlertDialogHeader className="gap-2">
  30. <AlertDialogTitle>{pendingRequest?.title}</AlertDialogTitle>
  31. {pendingRequest?.description ? (
  32. <AlertDialogDescription>{pendingRequest.description}</AlertDialogDescription>
  33. ) : null}
  34. </AlertDialogHeader>
  35. <AlertDialogFooter className="gap-2 sm:justify-end">
  36. <AlertDialogAction
  37. onClick={() => settleAlert(true)}
  38. size="lg"
  39. className={cn("h-9 justify-between gap-3 sm:min-w-32")}
  40. >
  41. <span>
  42. {pendingRequest?.actionLabel ?? intl.formatMessage({ id: "common.confirm" })}
  43. </span>
  44. <span className="text-ui-base text-primary-foreground/60">⏎</span>
  45. </AlertDialogAction>
  46. </AlertDialogFooter>
  47. </AlertDialogContent>
  48. </AlertDialog>
  49. );
  50. }