mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 02:23:47 +00:00
fix: use direct dialog.popup call instead of useDestructiveConfirm
Avoid async/await hook chain that could lose the popup callback. Call dialog.popup().then() directly from usePlatform for reliability.
This commit is contained in:
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { promoApi, PromoOffer } from '../api/promo';
|
import { promoApi, PromoOffer } from '../api/promo';
|
||||||
import { ClockIcon, CheckIcon } from './icons';
|
import { ClockIcon, CheckIcon } from './icons';
|
||||||
import { useDestructiveConfirm } from '@/platform/hooks/useNativeDialog';
|
import { usePlatform } from '@/platform/hooks/usePlatform';
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
const formatTimeLeft = (
|
const formatTimeLeft = (
|
||||||
@@ -90,7 +90,7 @@ export default function PromoOffersSection({ className = '' }: PromoOffersSectio
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const destructiveConfirm = useDestructiveConfirm();
|
const { dialog, capabilities } = usePlatform();
|
||||||
const [claimingId, setClaimingId] = useState<number | null>(null);
|
const [claimingId, setClaimingId] = useState<number | null>(null);
|
||||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||||
@@ -159,21 +159,37 @@ export default function PromoOffersSection({ className = '' }: PromoOffersSectio
|
|||||||
navigate('/subscription', { state: { scrollToExtend: true } });
|
navigate('/subscription', { state: { scrollToExtend: true } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeactivateClick = async () => {
|
const handleDeactivateClick = () => {
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
setSuccessMessage(null);
|
setSuccessMessage(null);
|
||||||
|
|
||||||
const confirmed = await destructiveConfirm(
|
if (capabilities.hasNativeDialogs) {
|
||||||
|
dialog
|
||||||
|
.popup({
|
||||||
|
title: t('promo.deactivate.confirmTitle'),
|
||||||
|
message: t('promo.deactivate.confirmDescription', {
|
||||||
|
percent: activeDiscount?.discount_percent || 0,
|
||||||
|
}),
|
||||||
|
buttons: [
|
||||||
|
{ id: 'cancel', type: 'cancel', text: '' },
|
||||||
|
{ id: 'confirm', type: 'destructive', text: t('promo.deactivate.confirm') },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.then((buttonId) => {
|
||||||
|
if (buttonId === 'confirm') {
|
||||||
|
deactivateMutation.mutate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const confirmed = window.confirm(
|
||||||
t('promo.deactivate.confirmDescription', {
|
t('promo.deactivate.confirmDescription', {
|
||||||
percent: activeDiscount?.discount_percent || 0,
|
percent: activeDiscount?.discount_percent || 0,
|
||||||
}),
|
}),
|
||||||
t('promo.deactivate.confirm'),
|
|
||||||
t('promo.deactivate.confirmTitle'),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
deactivateMutation.mutate();
|
deactivateMutation.mutate();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Filter unclaimed and active offers
|
// Filter unclaimed and active offers
|
||||||
|
|||||||
Reference in New Issue
Block a user