useDisplayDataLostWarning.tsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { useDialog } from '../providers/dialogs'
  2. type OpenWarningDialogArgs = {
  3. onCancel?: () => void
  4. onConfirm?: () => void
  5. }
  6. export const useDisplayDataLostWarning = () => {
  7. const [openDialog, closeDialog] = useDialog()
  8. const cancelDialog = (onCancel?: () => void) => {
  9. onCancel?.()
  10. }
  11. const openWarningDialog = ({ onCancel, onConfirm }: OpenWarningDialogArgs) => {
  12. openDialog({
  13. title: "Drafts' video & image data will be lost",
  14. description:
  15. "Drafts' assets aren't stored permanently. If you proceed, you will need to reselect the files again.",
  16. primaryButton: {
  17. text: 'Proceed',
  18. onClick: () => {
  19. onConfirm?.()
  20. closeDialog()
  21. },
  22. },
  23. secondaryButton: {
  24. text: 'Cancel',
  25. onClick: () => {
  26. cancelDialog(onCancel)
  27. closeDialog()
  28. },
  29. },
  30. onExitClick: () => {
  31. cancelDialog(onCancel)
  32. closeDialog()
  33. },
  34. variant: 'warning',
  35. })
  36. }
  37. return {
  38. openWarningDialog,
  39. }
  40. }