@oxyhq/services
Version:
276 lines (275 loc) • 8.14 kB
JavaScript
"use strict";
import React, { useState, useCallback } from 'react';
import { View, Text, TextInput, TouchableOpacity, StyleSheet, Modal, ActivityIndicator, KeyboardAvoidingView, Platform } from 'react-native';
import OxyIcon from "../icon/OxyIcon.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const DeleteAccountModal = ({
visible,
username,
onClose,
onDelete,
colors,
t
}) => {
const [password, setPassword] = useState('');
const [confirmUsername, setConfirmUsername] = useState('');
const [isDeleting, setIsDeleting] = useState(false);
const [error, setError] = useState(null);
const [showPassword, setShowPassword] = useState(false);
const isValid = password.length > 0 && confirmUsername === username;
const handleDelete = 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 = useCallback(() => {
if (isDeleting) return;
setPassword('');
setConfirmUsername('');
setError(null);
onClose();
}, [isDeleting, onClose]);
return /*#__PURE__*/_jsx(Modal, {
visible: visible,
transparent: true,
animationType: "fade",
onRequestClose: handleClose,
children: /*#__PURE__*/_jsxs(KeyboardAvoidingView, {
behavior: Platform.OS === 'ios' ? 'padding' : 'height',
style: styles.overlay,
children: [/*#__PURE__*/_jsx(TouchableOpacity, {
style: styles.backdrop,
activeOpacity: 1,
onPress: handleClose
}), /*#__PURE__*/_jsxs(View, {
style: [styles.modal, {
backgroundColor: colors.background
}],
children: [/*#__PURE__*/_jsxs(View, {
style: styles.header,
children: [/*#__PURE__*/_jsx(OxyIcon, {
name: "alert",
size: 32,
color: colors.danger
}), /*#__PURE__*/_jsx(Text, {
style: [styles.title, {
color: colors.danger
}],
children: t('deleteAccount.title') || 'Delete Account'
})]
}), /*#__PURE__*/_jsx(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__*/_jsx(View, {
style: [styles.errorContainer, {
backgroundColor: colors.danger + '20'
}],
children: /*#__PURE__*/_jsx(Text, {
style: [styles.errorText, {
color: colors.danger
}],
children: error
})
}), /*#__PURE__*/_jsxs(View, {
style: styles.inputGroup,
children: [/*#__PURE__*/_jsx(Text, {
style: [styles.label, {
color: colors.secondaryText
}],
children: t('deleteAccount.passwordLabel') || 'Enter your password'
}), /*#__PURE__*/_jsxs(View, {
style: [styles.inputContainer, {
borderColor: colors.border,
backgroundColor: colors.inputBackground
}],
children: [/*#__PURE__*/_jsx(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__*/_jsx(TouchableOpacity, {
onPress: () => setShowPassword(!showPassword),
style: styles.eyeButton,
children: /*#__PURE__*/_jsx(OxyIcon, {
name: showPassword ? 'eye-off' : 'eye',
size: 20,
color: colors.secondaryText
})
})]
})]
}), /*#__PURE__*/_jsxs(View, {
style: styles.inputGroup,
children: [/*#__PURE__*/_jsx(Text, {
style: [styles.label, {
color: colors.secondaryText
}],
children: t('deleteAccount.confirmLabel', {
username
}) || `Type "${username}" to confirm`
}), /*#__PURE__*/_jsx(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__*/_jsxs(View, {
style: styles.buttons,
children: [/*#__PURE__*/_jsx(TouchableOpacity, {
style: [styles.button, styles.cancelButton, {
borderColor: colors.border
}],
onPress: handleClose,
disabled: isDeleting,
children: /*#__PURE__*/_jsx(Text, {
style: [styles.buttonText, {
color: colors.text
}],
children: t('common.cancel') || 'Cancel'
})
}), /*#__PURE__*/_jsx(TouchableOpacity, {
style: [styles.button, styles.deleteButton, {
backgroundColor: isValid ? colors.danger : colors.danger + '50'
}],
onPress: handleDelete,
disabled: !isValid || isDeleting,
children: isDeleting ? /*#__PURE__*/_jsx(ActivityIndicator, {
color: "#fff",
size: "small"
}) : /*#__PURE__*/_jsx(Text, {
style: styles.deleteButtonText,
children: t('deleteAccount.confirm') || 'Delete Forever'
})
})]
})]
})]
})
});
};
const styles = StyleSheet.create({
overlay: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
backdrop: {
...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'
}
});
export default DeleteAccountModal;
//# sourceMappingURL=DeleteAccountModal.js.map