feat: Expo scaffold + auth screens + core screens (#39-#46, #48)

This commit is contained in:
Nemo
2026-03-23 18:40:04 +08:00
commit 745321e5bd
45 changed files with 10557 additions and 0 deletions

5
app/(auth)/_layout.tsx Normal file
View File

@@ -0,0 +1,5 @@
import { Stack } from 'expo-router';
export default function AuthLayout() {
return <Stack screenOptions={{ headerShown: false }} />;
}

View File

@@ -0,0 +1,68 @@
import { useState } from 'react';
import { View, Text, TextInput, TouchableOpacity, ActivityIndicator, Alert, KeyboardAvoidingView, Platform } from 'react-native';
import { router } from 'expo-router';
import { api } from '../../services/api';
export default function CompanyCodeScreen() {
const [slug, setSlug] = useState('');
const [loading, setLoading] = useState(false);
const handleContinue = async () => {
if (!slug.trim()) return Alert.alert('Required', 'Please enter your company code.');
setLoading(true);
try {
const res = await api.get(`/api/v1/auth/tenant/${slug.trim().toLowerCase()}/exists`);
if (res.data?.exists) {
router.push({ pathname: '/(auth)/login', params: { tenantSlug: slug.trim().toLowerCase() } });
} else {
Alert.alert('Not Found', 'Company code not found. Please check and try again.');
}
} catch {
Alert.alert('Error', 'Could not verify company code. Please try again.');
} finally {
setLoading(false);
}
};
return (
<KeyboardAvoidingView
className="flex-1 bg-white"
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
>
<View className="flex-1 justify-center px-8">
<View className="mb-10 items-center">
<View className="w-16 h-16 rounded-2xl bg-primary items-center justify-center mb-4">
<Text className="text-white text-3xl font-bold">F</Text>
</View>
<Text className="text-3xl font-bold text-gray-900">FiberOps</Text>
<Text className="text-gray-500 mt-1">Field Operations</Text>
</View>
<Text className="text-xl font-semibold text-gray-900 mb-2">Enter Company Code</Text>
<Text className="text-gray-500 mb-6">Ask your admin for your company's unique code.</Text>
<TextInput
className="border border-gray-300 rounded-xl px-4 py-3 text-base text-gray-900 mb-4"
placeholder="e.g. mybusiness"
value={slug}
onChangeText={setSlug}
autoCapitalize="none"
autoCorrect={false}
autoFocus
/>
<TouchableOpacity
className="bg-primary rounded-xl py-4 items-center"
onPress={handleContinue}
disabled={loading}
>
{loading ? (
<ActivityIndicator color="white" />
) : (
<Text className="text-white font-semibold text-base">Continue</Text>
)}
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
);
}

72
app/(auth)/login.tsx Normal file
View File

@@ -0,0 +1,72 @@
import { useState } from 'react';
import { View, Text, TextInput, TouchableOpacity, ActivityIndicator, Alert, KeyboardAvoidingView, Platform } from 'react-native';
import { useLocalSearchParams, router } from 'expo-router';
import { useAuthStore } from '../../stores/authStore';
export default function LoginScreen() {
const { tenantSlug } = useLocalSearchParams<{ tenantSlug: string }>();
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const { login, isLoading } = useAuthStore();
const handleLogin = async () => {
if (!username.trim() || !password) return Alert.alert('Required', 'Please enter username and password.');
try {
await login(tenantSlug, username.trim(), password);
router.replace('/(app)/dashboard');
} catch (e: any) {
const msg = e?.response?.data?.message ?? 'Login failed. Check your credentials.';
Alert.alert('Login Failed', Array.isArray(msg) ? msg.join('\n') : msg);
}
};
return (
<KeyboardAvoidingView
className="flex-1 bg-white"
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
>
<View className="flex-1 justify-center px-8">
<TouchableOpacity className="mb-8" onPress={() => router.back()}>
<Text className="text-primary text-base"> Back</Text>
</TouchableOpacity>
<Text className="text-2xl font-bold text-gray-900 mb-1">Welcome back</Text>
<Text className="text-gray-500 mb-8">
Signing in to <Text className="font-semibold text-gray-700">{tenantSlug}</Text>
</Text>
<Text className="text-sm font-medium text-gray-700 mb-1">Username</Text>
<TextInput
className="border border-gray-300 rounded-xl px-4 py-3 text-base text-gray-900 mb-4"
placeholder="Enter username"
value={username}
onChangeText={setUsername}
autoCapitalize="none"
autoCorrect={false}
autoFocus
/>
<Text className="text-sm font-medium text-gray-700 mb-1">Password</Text>
<TextInput
className="border border-gray-300 rounded-xl px-4 py-3 text-base text-gray-900 mb-6"
placeholder="Enter password"
value={password}
onChangeText={setPassword}
secureTextEntry
/>
<TouchableOpacity
className="bg-primary rounded-xl py-4 items-center"
onPress={handleLogin}
disabled={isLoading}
>
{isLoading ? (
<ActivityIndicator color="white" />
) : (
<Text className="text-white font-semibold text-base">Sign In</Text>
)}
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
);
}