Refactor modal and add check onCancel action

This commit is contained in:
Nicola Benaglia 2025-06-06 19:45:13 +02:00
parent e9aa965542
commit ff4eed5b8b
2 changed files with 14 additions and 8 deletions

View File

@ -65,7 +65,6 @@ export const BlockedUsersModal = () => {
}, [isOpenBlockedModal]); }, [isOpenBlockedModal]);
const getNames = async () => { const getNames = async () => {
// const validApi = await findUsableApi();
const addresses = Object.keys(blockedUsers?.addresses); const addresses = Object.keys(blockedUsers?.addresses);
const addressNames = {}; const addressNames = {};
@ -142,6 +141,10 @@ export const BlockedUsersModal = () => {
executeEvent('updateChatMessagesWithBlocks', true); executeEvent('updateChatMessagesWithBlocks', true);
} }
} catch (error) { } catch (error) {
if (error?.isCanceled) {
// user pressed Escape or canceled — do nothing
return;
}
setOpenSnackGlobal(true); setOpenSnackGlobal(true);
setInfoSnackCustom({ setInfoSnackCustom({
type: 'error', type: 'error',
@ -173,20 +176,22 @@ export const BlockedUsersModal = () => {
return ( return (
<Dialog <Dialog
open={isOpenBlockedModal}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description" aria-describedby="alert-dialog-description"
aria-labelledby="alert-dialog-title"
onClose={onCancel}
open={isOpenBlockedModal}
> >
<DialogTitle <DialogTitle
sx={{ sx={{
textAlign: 'center',
color: theme.palette.text.primary, color: theme.palette.text.primary,
fontWeight: 'bold', fontWeight: 'bold',
opacity: 1, opacity: 1,
textAlign: 'center',
}} }}
> >
{t('auth:blocked_users', { postProcess: 'capitalizeFirstChar' })} {t('auth:blocked_users', { postProcess: 'capitalizeAll' })}
</DialogTitle> </DialogTitle>
<DialogContent <DialogContent
sx={{ sx={{
padding: '20px', padding: '20px',
@ -293,7 +298,7 @@ export const BlockedUsersModal = () => {
<Spacer height="20px" /> <Spacer height="20px" />
<DialogContentText id="alert-dialog-description"> <DialogContentText id="alert-dialog-description">
{t('core:message.generic.blocked_names', { {t('auth:message.generic.blocked_names', {
postProcess: 'capitalizeFirstChar', postProcess: 'capitalizeFirstChar',
})} })}
</DialogContentText> </DialogContentText>
@ -375,6 +380,7 @@ export const BlockedUsersModal = () => {
<Dialog <Dialog
open={isShow} open={isShow}
onClose={onCancel}
aria-labelledby="alert-dialog-title" aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description" aria-describedby="alert-dialog-description"
> >
@ -388,7 +394,7 @@ export const BlockedUsersModal = () => {
}} }}
> >
{t('auth:message.generic.decide_block', { {t('auth:message.generic.decide_block', {
postProcess: 'capitalizeFirstChar', postProcess: 'capitalizeAll',
})} })}
</DialogTitle> </DialogTitle>

View File

@ -35,7 +35,7 @@ export const useModal = () => {
const onCancel = useCallback(() => { const onCancel = useCallback(() => {
const { reject } = promiseConfig.current || {}; const { reject } = promiseConfig.current || {};
hide(); hide();
reject?.('Declined'); reject?.({ isCanceled: true });
}, [hide]); }, [hide]);
return useMemo( return useMemo(