PageContentsUtilities.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { useTranslation } from 'next-i18next';
  2. import { useUpdateStateAfterSave } from '~/client/services/page-operation';
  3. import { useDrawioModalLauncherForView } from '~/client/services/side-effects/drawio-modal-launcher-for-view';
  4. import { useHandsontableModalLauncherForView } from '~/client/services/side-effects/handsontable-modal-launcher-for-view';
  5. import { toastSuccess, toastError, toastWarning } from '~/client/util/toastr';
  6. import { PageUpdateErrorCode } from '~/interfaces/apiv3';
  7. import { useCurrentPageId } from '~/stores/page';
  8. export const PageContentsUtilities = (): null => {
  9. const { t } = useTranslation();
  10. const { data: pageId } = useCurrentPageId();
  11. const updateStateAfterSave = useUpdateStateAfterSave(pageId);
  12. useHandsontableModalLauncherForView({
  13. onSaveSuccess: () => {
  14. toastSuccess(t('toaster.save_succeeded'));
  15. updateStateAfterSave?.();
  16. },
  17. onSaveError: (errors) => {
  18. for (const error of errors) {
  19. if (error.code === PageUpdateErrorCode.CONFLICT) {
  20. toastWarning(t('modal_resolve_conflict.conflicts_with_new_body_on_server_side'));
  21. return;
  22. }
  23. }
  24. toastError(errors);
  25. },
  26. });
  27. useDrawioModalLauncherForView({
  28. onSaveSuccess: () => {
  29. toastSuccess(t('toaster.save_succeeded'));
  30. updateStateAfterSave?.();
  31. },
  32. onSaveError: (errors) => {
  33. for (const error of errors) {
  34. if (error.code === PageUpdateErrorCode.CONFLICT) {
  35. toastWarning(t('modal_resolve_conflict.conflicts_with_new_body_on_server_side'));
  36. return;
  37. }
  38. }
  39. toastError(errors);
  40. },
  41. });
  42. return null;
  43. };