useDisplayDataLostWarning.tsx 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. primaryButtonText: 'Proceed',
  17. secondaryButtonText: 'Cancel',
  18. onPrimaryButtonClick: () => {
  19. onConfirm?.()
  20. closeDialog()
  21. },
  22. onSecondaryButtonClick: () => {
  23. cancelDialog(onCancel)
  24. closeDialog()
  25. },
  26. onExitClick: () => {
  27. cancelDialog(onCancel)
  28. closeDialog()
  29. },
  30. variant: 'warning',
  31. })
  32. }
  33. return {
  34. openWarningDialog,
  35. }
  36. }