fix(native): mail-pattern domain extraction + drop Pressable from FormSheet
Two bugs reported on the new mail-pattern flow: 1. The sheet sent the full local@domain.tld pattern to the backend so a user blocking communications@only4-subscribers.com would only catch that exact local-part — newsletter@, info@, promo@ from the same sender would slip through. Casino affiliates rotate the local-part on every blast while keeping the domain stable, so we now strip the local-part on submit. The preview-card under the input shows what actually gets stored (only4-subscribers.com), so the user sees the pattern that will hit. Bare tokens without "@" stay as-is and reach the backend as display-name candidates. 2. FormSheet's backdrop was a <Pressable> — straight violation of the "TouchableOpacity, never Pressable" rule. Swapped for <TouchableOpacity activeOpacity={1}> so the tap-to-dismiss still works with no visible feedback on the dim layer.
This commit is contained in:
parent
5c6fa3d45b
commit
1e07e8303f
@ -5,8 +5,8 @@ import {
|
|||||||
Modal,
|
Modal,
|
||||||
PanResponder,
|
PanResponder,
|
||||||
Platform,
|
Platform,
|
||||||
Pressable,
|
|
||||||
Text,
|
Text,
|
||||||
|
TouchableOpacity,
|
||||||
View,
|
View,
|
||||||
useWindowDimensions,
|
useWindowDimensions,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
@ -188,7 +188,8 @@ export function FormSheet({
|
|||||||
return (
|
return (
|
||||||
<Modal visible={visible} transparent animationType="slide" onRequestClose={handleClose} statusBarTranslucent>
|
<Modal visible={visible} transparent animationType="slide" onRequestClose={handleClose} statusBarTranslucent>
|
||||||
{/* Backdrop */}
|
{/* Backdrop */}
|
||||||
<Pressable
|
<TouchableOpacity
|
||||||
|
activeOpacity={1}
|
||||||
onPress={dismissOnBackdrop ? handleClose : undefined}
|
onPress={dismissOnBackdrop ? handleClose : undefined}
|
||||||
style={{ flex: 1, backgroundColor: `rgba(0,0,0,${backdropOpacity})` }}
|
style={{ flex: 1, backgroundColor: `rgba(0,0,0,${backdropOpacity})` }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
ActivityIndicator,
|
ActivityIndicator,
|
||||||
Image,
|
Image,
|
||||||
@ -22,22 +22,42 @@ type InputKind = 'web' | 'mail';
|
|||||||
type Props = {
|
type Props = {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
tier: Tier;
|
tier: Tier;
|
||||||
|
initialType?: InputKind;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onAdd: (pattern: string, kind: InputKind) => Promise<{ ok: boolean; error?: string; alreadyGlobal?: boolean }>;
|
onAdd: (pattern: string, kind: InputKind) => Promise<{ ok: boolean; error?: string; alreadyGlobal?: boolean }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function AddDomainSheet({ visible, tier, onClose, onAdd }: Props) {
|
export function AddDomainSheet({ visible, tier, initialType, onClose, onAdd }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const colors = useColors();
|
const colors = useColors();
|
||||||
const [kind, setKind] = useState<InputKind>('web');
|
const [kind, setKind] = useState<InputKind>(initialType ?? 'web');
|
||||||
const [input, setInput] = useState('');
|
const [input, setInput] = useState('');
|
||||||
const [confirmPermanent, setConfirmPermanent] = useState(false);
|
const [confirmPermanent, setConfirmPermanent] = useState(false);
|
||||||
const [adding, setAdding] = useState(false);
|
const [adding, setAdding] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [fieldsDone, setFieldsDone] = useState(false);
|
const [fieldsDone, setFieldsDone] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (visible) setKind(initialType ?? 'web');
|
||||||
|
}, [visible, initialType]);
|
||||||
|
|
||||||
const normalizedWeb = kind === 'web' ? normalizeDomain(input) : '';
|
const normalizedWeb = kind === 'web' ? normalizeDomain(input) : '';
|
||||||
|
|
||||||
|
// For mail input: if the user typed a full address (local@domain.tld), strip
|
||||||
|
// the local-part and keep only the domain — casino affiliates rotate the
|
||||||
|
// local-part rapidly (communications@, newsletter@, info@, …) while the
|
||||||
|
// sender-domain stays stable. Blocking on the domain is more durable.
|
||||||
|
// A bare token without "@" stays as-is (will be matched as display-name on
|
||||||
|
// the backend).
|
||||||
|
const mailPattern = (() => {
|
||||||
|
if (kind !== 'mail') return '';
|
||||||
|
const raw = input.trim();
|
||||||
|
if (!raw) return '';
|
||||||
|
const atIdx = raw.lastIndexOf('@');
|
||||||
|
if (atIdx === -1) return raw;
|
||||||
|
return raw.slice(atIdx + 1).trim().toLowerCase();
|
||||||
|
})();
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
setInput('');
|
setInput('');
|
||||||
setConfirmPermanent(false);
|
setConfirmPermanent(false);
|
||||||
@ -63,7 +83,7 @@ export function AddDomainSheet({ visible, tier, onClose, onAdd }: Props) {
|
|||||||
if (!isInputValid() || !confirmPermanent || adding) return;
|
if (!isInputValid() || !confirmPermanent || adding) return;
|
||||||
setAdding(true);
|
setAdding(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
const pattern = kind === 'web' ? input : input.trim();
|
const pattern = kind === 'web' ? input : mailPattern;
|
||||||
const result = await onAdd(pattern, kind);
|
const result = await onAdd(pattern, kind);
|
||||||
setAdding(false);
|
setAdding(false);
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
@ -72,6 +92,10 @@ export function AddDomainSheet({ visible, tier, onClose, onAdd }: Props) {
|
|||||||
}
|
}
|
||||||
if (result.alreadyGlobal) {
|
if (result.alreadyGlobal) {
|
||||||
setError(t('blocker.add_sheet_already_global', { domain: normalizedWeb || input.trim() }));
|
setError(t('blocker.add_sheet_already_global', { domain: normalizedWeb || input.trim() }));
|
||||||
|
} else if (result.error?.includes('WEB_LIMIT_REACHED')) {
|
||||||
|
setError(t('blocker.error_web_limit_reached'));
|
||||||
|
} else if (result.error?.includes('MAIL_LIMIT_REACHED')) {
|
||||||
|
setError(t('blocker.error_mail_limit_reached'));
|
||||||
} else {
|
} else {
|
||||||
setError(result.error ?? t('blocker.add_sheet_add_failed'));
|
setError(result.error ?? t('blocker.add_sheet_add_failed'));
|
||||||
}
|
}
|
||||||
@ -223,7 +247,7 @@ export function AddDomainSheet({ visible, tier, onClose, onAdd }: Props) {
|
|||||||
}}
|
}}
|
||||||
numberOfLines={1}
|
numberOfLines={1}
|
||||||
>
|
>
|
||||||
{input.trim() || inputPlaceholder}
|
{mailPattern || inputPlaceholder}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user