Skip to content

Commit

Permalink
Merge pull request #1443 from culturecreates/bugfix/issue-1431
Browse files Browse the repository at this point in the history
fix: fixed bug popup blockers preventing unsaved chnages popup from s…
  • Loading branch information
AbhishekPAnil authored Nov 15, 2024
2 parents 17e87d1 + b874dbb commit d754a61
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/Modal/Confirm/Confirm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Modal } from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import './confirm.css';

export const Confirm = ({ title, content, onAction, okText, cancelText, className }) => {
export const Confirm = ({ title, content, onAction, okText, cancelText, className, closable }) => {
const { confirm } = Modal;

let modalClassName = ['global-delete-modal-container'];
Expand All @@ -29,7 +29,7 @@ export const Confirm = ({ title, content, onAction, okText, cancelText, classNam
cancelText: cancelText,
centered: true,
className: modalClassName,
closable: true,
closable: closable ?? true,
header: null,
onOk() {
onAction();
Expand Down
16 changes: 15 additions & 1 deletion src/hooks/usePrompt.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { useBlocker, useBeforeUnload, useNavigate, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { Confirm } from '../components/Modal/Confirm/Confirm';

export const RouteLeavingGuard = ({ isBlocking }) => {
let confirm = false;

function useCallbackPrompt(when) {
const navigate = useNavigate();
const { t } = useTranslation();
Expand All @@ -16,13 +19,24 @@ export const RouteLeavingGuard = ({ isBlocking }) => {
return false;
}

const confirm = window.confirm(`${t('common.unsavedChanges')}`);
if (confirm) {
setConfirmedNavigation(true);
setLastLocation(history.nextLocation);
return false;
}

Confirm({
content: t('common.unsavedChanges'),
closable: false,
className: 'unsaved-changes-popup',
onAction: () => {
setConfirmedNavigation(true);
confirm = true;
setLastLocation(history.nextLocation);
return false;
},
});

return true;
},
[confirmedNavigation, location.pathname, when, t],
Expand Down
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ body.inheritCursors * {
cursor: -webkit-grabbing;
}

.unsaved-changes-popup .ant-modal-confirm-title {
padding: 28px;
}

@media screen and (max-width: 480px) {
.ant-pagination {
display: flex;
Expand Down

0 comments on commit d754a61

Please sign in to comment.