Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions app/(auth)/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
KeyboardAvoidingView,
Platform,
TouchableOpacity,
Image,
Alert,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useRouter } from 'expo-router';
import { ChevronLeft, Camera } from 'lucide-react-native';
import { ChevronLeft, Camera, AlertCircle, X } from 'lucide-react-native';
import { colors } from '../../constants/colors';
import { Button } from '../../components/shared/Button';

Check warning on line 14 in app/(auth)/register.tsx

View workflow job for this annotation

GitHub Actions / Lint / Typecheck / Test

'Button' is defined but never used
import { Input } from '../../components/shared/Input';
import { useUserStore } from '../../stores/user.store';
import { useAuthStore } from '../../stores/auth.store';
Expand All @@ -32,6 +30,7 @@

const [displayName, setDisplayName] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false);
const [submitError, setSubmitError] = useState<string | null>(null);

// Learner fields
const [school, setSchool] = useState('');
Expand All @@ -51,6 +50,7 @@
const handleComplete = async () => {
if (!isValid) return;
setIsSubmitting(true);
setSubmitError(null);

try {
const profile: LearnerProfile = {
Expand All @@ -68,11 +68,13 @@

await setTokens('mock-access-token', 'mock-refresh-token');
await setWallet(publicKey ?? '');
} catch (error) {
// Surface the failure to the user and log context for diagnosis;
// the user stays on the screen so they can retry.
console.error('[register] failed to complete registration', error);
Alert.alert(t('common.somethingWentWrong'), t('auth.register.saveFailed'));
} catch (err) {
console.error('[register] failed to complete registration', err);
const message =
err instanceof Error
? err.message
: 'An unexpected error occurred while saving your profile.';
setSubmitError(message);
} finally {
setIsSubmitting(false);
}
Expand Down Expand Up @@ -130,6 +132,23 @@
</Text>
</View>

{/* Error banner */}
{submitError && (
<View
className="mb-2 flex-row items-start gap-2 rounded-xl p-3"
style={{ backgroundColor: colors.errorDim }}>
<AlertCircle size={16} color={colors.error} style={{ marginTop: 2 }} />
<Text className="flex-1 text-sm" style={{ color: colors.error }}>
{submitError}
</Text>
<TouchableOpacity
onPress={() => setSubmitError(null)}
hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}>
<X size={16} color={colors.error} />
</TouchableOpacity>
</View>
)}

<View className="flex-col gap-4">
{/* Avatar Upload Area */}
<View className="mb-4 mt-2 flex-col items-center justify-center">
Expand Down
Loading
Loading