UNPKG

@oxyhq/services

Version:

OxyHQ Expo/React Native SDK — UI components, screens, and native features

282 lines (281 loc) 9.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _OxyIcon = _interopRequireDefault(require("../icon/OxyIcon.js")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const DeleteAccountModal = ({ visible, username, onClose, onDelete, colors, t }) => { const [password, setPassword] = (0, _react.useState)(''); const [confirmUsername, setConfirmUsername] = (0, _react.useState)(''); const [isDeleting, setIsDeleting] = (0, _react.useState)(false); const [error, setError] = (0, _react.useState)(null); const [showPassword, setShowPassword] = (0, _react.useState)(false); const isValid = password.length > 0 && confirmUsername === username; const handleDelete = (0, _react.useCallback)(async () => { if (!isValid) return; setError(null); setIsDeleting(true); try { await onDelete(password); // Modal will be closed by parent on success } catch (err) { setError(err?.message || t('deleteAccount.error') || 'Failed to delete account'); } finally { setIsDeleting(false); } }, [isValid, password, onDelete, t]); const handleClose = (0, _react.useCallback)(() => { if (isDeleting) return; setPassword(''); setConfirmUsername(''); setError(null); onClose(); }, [isDeleting, onClose]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Modal, { visible: visible, transparent: true, animationType: "fade", onRequestClose: handleClose, children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.KeyboardAvoidingView, { behavior: _reactNative.Platform.OS === 'ios' ? 'padding' : 'height', style: styles.overlay, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, { style: styles.backdrop, activeOpacity: 1, onPress: handleClose }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.modal, { backgroundColor: colors.background }], children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.header, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_OxyIcon.default, { name: "alert", size: 32, color: colors.danger }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.title, { color: colors.danger }], children: t('deleteAccount.title') || 'Delete Account' })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.warning, { color: colors.text }], children: t('deleteAccount.warning') || 'This action cannot be undone. Your account and all associated data will be permanently deleted.' }), error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: [styles.errorContainer, { backgroundColor: colors.danger + '20' }], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.errorText, { color: colors.danger }], children: error }) }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.inputGroup, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.label, { color: colors.secondaryText }], children: t('deleteAccount.passwordLabel') || 'Enter your password' }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: [styles.inputContainer, { borderColor: colors.border, backgroundColor: colors.inputBackground }], children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TextInput, { style: [styles.input, { color: colors.text }], value: password, onChangeText: setPassword, placeholder: t('deleteAccount.passwordPlaceholder') || 'Password', placeholderTextColor: colors.secondaryText, secureTextEntry: !showPassword, autoCapitalize: "none", editable: !isDeleting }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, { onPress: () => setShowPassword(!showPassword), style: styles.eyeButton, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_OxyIcon.default, { name: showPassword ? 'eye-off' : 'eye', size: 20, color: colors.secondaryText }) })] })] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.inputGroup, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.label, { color: colors.secondaryText }], children: t('deleteAccount.confirmLabel', { username }) || `Type "${username}" to confirm` }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TextInput, { style: [styles.input, styles.confirmInput, { borderColor: confirmUsername === username ? '#34C759' : colors.border, backgroundColor: colors.inputBackground, color: colors.text }], value: confirmUsername, onChangeText: setConfirmUsername, placeholder: username, placeholderTextColor: colors.secondaryText, autoCapitalize: "none", autoCorrect: false, editable: !isDeleting })] }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.buttons, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, { style: [styles.button, styles.cancelButton, { borderColor: colors.border }], onPress: handleClose, disabled: isDeleting, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.buttonText, { color: colors.text }], children: t('common.cancel') || 'Cancel' }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, { style: [styles.button, styles.deleteButton, { backgroundColor: isValid ? colors.danger : colors.danger + '50' }], onPress: handleDelete, disabled: !isValid || isDeleting, children: isDeleting ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, { color: "#fff", size: "small" }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: styles.deleteButtonText, children: t('deleteAccount.confirm') || 'Delete Forever' }) })] })] })] }) }); }; const styles = _reactNative.StyleSheet.create({ overlay: { flex: 1, justifyContent: 'center', alignItems: 'center' }, backdrop: { ..._reactNative.StyleSheet.absoluteFillObject, backgroundColor: 'rgba(0, 0, 0, 0.5)' }, modal: { width: '90%', maxWidth: 400, borderRadius: 16, padding: 24, shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.3, shadowRadius: 8, elevation: 8 }, header: { flexDirection: 'row', alignItems: 'center', marginBottom: 16, gap: 12 }, title: { fontSize: 20, fontWeight: '700' }, warning: { fontSize: 14, lineHeight: 20, marginBottom: 20 }, errorContainer: { padding: 12, borderRadius: 8, marginBottom: 16 }, errorText: { fontSize: 14, textAlign: 'center' }, inputGroup: { marginBottom: 16 }, label: { fontSize: 13, marginBottom: 8 }, inputContainer: { flexDirection: 'row', alignItems: 'center', borderWidth: 1, borderRadius: 8 }, input: { flex: 1, fontSize: 16, paddingVertical: 12, paddingHorizontal: 16 }, confirmInput: { borderWidth: 1, borderRadius: 8 }, eyeButton: { padding: 12 }, buttons: { flexDirection: 'row', gap: 12, marginTop: 8 }, button: { flex: 1, paddingVertical: 14, borderRadius: 8, alignItems: 'center', justifyContent: 'center' }, cancelButton: { borderWidth: 1 }, deleteButton: { minHeight: 48 }, buttonText: { fontSize: 16, fontWeight: '600' }, deleteButtonText: { fontSize: 16, fontWeight: '600', color: '#fff' } }); var _default = exports.default = DeleteAccountModal; //# sourceMappingURL=DeleteAccountModal.js.map