/* * File: NameStep.tsx * Description: Name step component for signup flow * Design & Developed by Tech4Biz Solutions * Copyright (c) Spurrin Innovations. All rights reserved. */ import React, { useState } from 'react'; import { View, Text, TextInput, TouchableOpacity, StyleSheet, KeyboardAvoidingView, Platform, ScrollView, } from 'react-native'; import { theme } from '../../../../theme/theme'; import { NameStepProps } from '../../types/signup'; import Icon from 'react-native-vector-icons/Feather'; // ============================================================================ // NAME STEP COMPONENT // ============================================================================ /** * NameStep Component * * Purpose: Third step of signup flow - personal information * * Features: * - First name, last name, and username inputs * - Real-time validation with error handling * - Continue button with loading state * - Back navigation with modern header */ const NameStep: React.FC = ({ onContinue, onBack, data, isLoading, }) => { // ============================================================================ // STATE MANAGEMENT // ============================================================================ const [firstName, setFirstName] = useState(data.first_name || ''); const [lastName, setLastName] = useState(data.last_name || ''); const [username, setUsername] = useState(data.username || ''); const [errors, setErrors] = useState({ firstName: '', lastName: '', username: '', }); // ============================================================================ // VALIDATION FUNCTIONS // ============================================================================ /** * Validate Input Fields * * Purpose: Check if all fields are valid */ const validateFields = (): boolean => { const newErrors = { firstName: '', lastName: '', username: '', }; if (!firstName.trim()) { newErrors.firstName = 'First name is required'; } if (!lastName.trim()) { newErrors.lastName = 'Last name is required'; } if (!username.trim()) { newErrors.username = 'Username is required'; } else if (username.length < 3) { newErrors.username = 'Username must be at least 3 characters'; } setErrors(newErrors); return !Object.values(newErrors).some(error => error !== ''); }; /** * Handle Continue * * Purpose: Validate fields and proceed to next step */ const handleContinue = () => { if (validateFields()) { onContinue(firstName.trim(), lastName.trim(), username.trim()); } }; // ============================================================================ // RENDER // ============================================================================ return ( {/* Header */} Create Account Step 3 of 5 {/* Content */} Tell us about yourself Please provide your name and choose a username for your account. {/* First Name Input */} First Name { setFirstName(text); setErrors(prev => ({ ...prev, firstName: '' })); }} autoCapitalize="words" autoCorrect={false} editable={!isLoading} /> {errors.firstName ? ( {errors.firstName} ) : null} {/* Last Name Input */} Last Name { setLastName(text); setErrors(prev => ({ ...prev, lastName: '' })); }} autoCapitalize="words" autoCorrect={false} editable={!isLoading} /> {errors.lastName ? ( {errors.lastName} ) : null} {/* Username Input */} Username { setUsername(text); setErrors(prev => ({ ...prev, username: '' })); }} autoCapitalize="none" autoCorrect={false} editable={!isLoading} /> {errors.username ? ( {errors.username} ) : null} {/* Continue Button */} {isLoading ? 'Validating...' : 'Continue'} ); }; // ============================================================================ // STYLES // ============================================================================ const styles = StyleSheet.create({ // Main container container: { flex: 1, backgroundColor: theme.colors.background, }, // Scroll view scrollView: { flex: 1, }, // Scroll content scrollContent: { flexGrow: 1, paddingHorizontal: theme.spacing.sm, }, // Header section header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingTop: theme.spacing.xl, paddingBottom: theme.spacing.lg, marginBottom: theme.spacing.lg, }, // Back button backButton: { padding: theme.spacing.sm, borderRadius: theme.borderRadius.medium, backgroundColor: theme.colors.backgroundAlt, }, // Header content headerContent: { flex: 1, alignItems: 'center', }, // Header spacer headerSpacer: { width: 40, }, // Title title: { fontSize: theme.typography.fontSize.displaySmall, fontFamily: theme.typography.fontFamily.bold, color: theme.colors.textPrimary, marginBottom: theme.spacing.xs, }, // Subtitle subtitle: { fontSize: theme.typography.fontSize.bodyMedium, fontFamily: theme.typography.fontFamily.regular, color: theme.colors.textSecondary, }, // Content section content: { flex: 1, justifyContent: 'center', paddingBottom: theme.spacing.xl, }, // Section title sectionTitle: { fontSize: theme.typography.fontSize.displaySmall, fontFamily: theme.typography.fontFamily.bold, color: theme.colors.textPrimary, marginBottom: theme.spacing.sm, }, // Description description: { fontSize: theme.typography.fontSize.bodyMedium, fontFamily: theme.typography.fontFamily.regular, color: theme.colors.textSecondary, marginBottom: theme.spacing.xl, }, // Input container inputContainer: { marginBottom: theme.spacing.xl, }, // Input label inputLabel: { fontSize: theme.typography.fontSize.bodyMedium, fontFamily: theme.typography.fontFamily.medium, color: theme.colors.textPrimary, marginBottom: theme.spacing.sm, }, // Input field input: { borderWidth: 1, borderColor: theme.colors.border, borderRadius: theme.borderRadius.medium, paddingHorizontal: theme.spacing.md, paddingVertical: theme.spacing.md, fontSize: theme.typography.fontSize.bodyLarge, fontFamily: theme.typography.fontFamily.regular, color: theme.colors.textPrimary, backgroundColor: theme.colors.background, }, // Input error state inputError: { borderColor: theme.colors.error, }, // Error text errorText: { fontSize: theme.typography.fontSize.bodySmall, fontFamily: theme.typography.fontFamily.regular, color: theme.colors.error, marginTop: theme.spacing.xs, }, // Continue button continueButton: { backgroundColor: theme.colors.primary, borderRadius: theme.borderRadius.medium, paddingVertical: theme.spacing.md, paddingHorizontal: theme.spacing.lg, alignItems: 'center', marginBottom: theme.spacing.lg, ...theme.shadows.primary, }, // Continue button disabled continueButtonDisabled: { backgroundColor: theme.colors.border, opacity: 0.6, }, // Continue button text continueButtonText: { fontSize: theme.typography.fontSize.bodyLarge, fontFamily: theme.typography.fontFamily.bold, color: theme.colors.background, }, // Continue button text disabled continueButtonTextDisabled: { color: theme.colors.textMuted, }, }); export default NameStep; /* * End of File: NameStep.tsx * Design & Developed by Tech4Biz Solutions * Copyright (c) Spurrin Innovations. All rights reserved. */