sort/app/(tabs)/index.tsx

215 lines
6.3 KiB
TypeScript
Raw Normal View History

2024-09-07 01:22:11 +00:00
import React, { useState } from 'react';
import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, Image } from 'react-native';
import { useNavigation, NavigationProp, Link } from '@react-navigation/native';
2024-09-24 00:17:23 +00:00
// Update the import path to the correct one
import { RootStackParamList } from '../../types';
2024-09-07 01:22:11 +00:00
import AsyncStorage from '@react-native-async-storage/async-storage';
import { DB } from '@/components/lib/db';
import { GestureHandlerRootView, ScrollView } from 'react-native-gesture-handler';
2024-09-26 04:56:15 +00:00
import config from '../../components/data/config.json';
2024-10-16 03:37:18 +00:00
import lang from '../../components/data/lang.json';
2024-09-07 01:22:11 +00:00
const LoginScreen = () => {
const navigation = useNavigation<NavigationProp<RootStackParamList>>();
const [username, setUsername] = useState('sales@rumahjo.com');
const [password, setPassword] = useState('12345678');
const handleLogin = async () => {
try{
DB(`SELECT * FROM "public".hr_employee WHERE work_email = '${username}' AND pin = '${password}'`)
.then(async function(data){
if(data && Array.isArray(data) && data.length>0){
await AsyncStorage.setItem('login', JSON.stringify(data));
navigation.navigate('home')
}else{
Alert.alert("Warning", "Pastikan username atau password sudah benar")
}
})
.catch(function(err){
})
}catch(e){
Alert.alert(JSON.stringify(e))
}
};
const handleSignUp = () => {
navigation.navigate('signup');
};
const handleForgotPassword = () => {
2024-10-16 03:37:18 +00:00
Alert.alert(lang.en.login.lupa_password, lang.en.login.pesan);
2024-09-07 01:22:11 +00:00
};
return (
<>
2024-09-24 00:17:23 +00:00
<GestureHandlerRootView>
2024-09-26 04:56:15 +00:00
<ScrollView style={{backgroundColor:"white"}}>
<View style={{ flex: 1, backgroundColor:'white'}}>
2024-09-24 00:17:23 +00:00
<View style={{
2024-09-26 04:56:15 +00:00
flexDirection: "row"
, height: 140
, alignItems: "flex-end"
, paddingHorizontal: 30
, marginBottom: 20
}}>
<View style={{ flex: 1 }}>
</View>
<View style={{
width: "auto",
backgroundColor: "white",
padding: 10,
borderRadius: 20
2024-09-07 01:22:11 +00:00
}}>
2024-09-26 04:56:15 +00:00
<Image
source={require('../../assets/images/login/logo.png')}
style={{
width: 60
, height: 60
}}
resizeMode="contain" // You can adjust this based on how you want the image to scale
/>
</View>
2024-09-24 00:17:23 +00:00
</View>
<View style={[styles.container]}>
2024-09-26 04:56:15 +00:00
<View style={{marginBottom:40}}>
<Text style={{
fontSize:20
, fontWeight:'bold'
, color:config.color.textbiru
2024-10-16 03:37:18 +00:00
}}>{lang.en.login.hi}</Text>
2024-09-26 04:56:15 +00:00
<Text style={{
fontSize:20
, fontWeight:'bold'
, marginVertical:5
, color: config.color.textbiru
2024-10-16 03:37:18 +00:00
}}>{lang.en.login.selamat_datang},</Text>
2024-09-26 04:56:15 +00:00
</View>
{/* <Text style={{
2024-09-24 00:17:23 +00:00
textAlign:"left"
, fontSize:18
, fontWeight:'bold'
, color:"#777"
, marginTop:10
, marginBottom: 10
,width:'100%'
2024-09-26 04:56:15 +00:00
}}>EMAIL</Text> */}
2024-09-24 00:17:23 +00:00
<TextInput
style={styles.input}
placeholder="youremail@gmail.com"
value={username}
onChangeText={setUsername}
/>
2024-09-26 04:56:15 +00:00
{/* <Text style={{
2024-09-24 00:17:23 +00:00
textAlign: "left"
, fontSize: 18
, fontWeight: 'bold'
, color: "#777"
, marginBottom: 10
, marginTop: 10
, width: '100%'
2024-09-26 04:56:15 +00:00
}}>PASSWORD</Text> */}
2024-09-24 00:17:23 +00:00
<TextInput
style={styles.input}
placeholder="******"
value={password}
onChangeText={setPassword}
secureTextEntry
/>
2024-09-26 04:56:15 +00:00
<View style={{
flexDirection:"row",
marginBottom:50
}}>
<View style={{flex:1}}>
</View>
<TouchableOpacity onPress={handleForgotPassword}>
2024-10-16 03:37:18 +00:00
<Text style={styles.forgotPasswordText}>{lang.en.login.lupa_password}</Text>
2024-09-26 04:56:15 +00:00
</TouchableOpacity>
</View>
2024-09-24 00:17:23 +00:00
<TouchableOpacity style={styles.button} onPress={handleLogin}>
2024-09-26 04:56:15 +00:00
<Text style={styles.buttonText}>LOGIN</Text>
2024-09-24 00:17:23 +00:00
</TouchableOpacity>
2024-09-26 04:56:15 +00:00
<View style={{
flexDirection:"row"
, justifyContent:"center"
, marginTop: 30
}}>
2024-10-16 03:37:18 +00:00
<Text>{lang.en.login.belum_punya_akun}</Text>
2024-09-26 04:56:15 +00:00
<TouchableOpacity onPress={handleSignUp} style={{marginHorizontal:10}}>
<Text style={{
color:"blue",
fontWeight:"bold"
2024-10-16 03:37:18 +00:00
}}>{lang.en.login.daftar_disini}</Text>
2024-09-26 04:56:15 +00:00
</TouchableOpacity>
2024-09-24 00:17:23 +00:00
</View>
2024-09-07 01:22:11 +00:00
</View>
</View>
2024-09-24 00:17:23 +00:00
</ScrollView>
</GestureHandlerRootView>
2024-09-07 01:22:11 +00:00
</>
);
};
const styles = StyleSheet.create({
primary:{
backgroundColor:"#2563eb"
},
container: {
flex: 1,
paddingVertical:50,
backgroundColor: 'white',
justifyContent: 'center',
2024-09-26 04:56:15 +00:00
paddingHorizontal: 50
2024-09-07 01:22:11 +00:00
},
appName: {
fontSize: 36,
color: '#fff',
fontWeight: 'bold',
marginBottom: 10,
},
title: {
fontSize: 32,
color: '#fff',
marginBottom: 20,
},
input: {
width: '100%',
2024-09-26 04:56:15 +00:00
borderBottomWidth: 2,
borderBottomColor: config.color.line,
2024-09-07 01:22:11 +00:00
borderRadius: 10,
padding: 15,
2024-09-24 00:17:23 +00:00
shadowColor: "#000",
2024-09-07 01:22:11 +00:00
marginBottom: 20,
fontSize: 16,
},
button: {
backgroundColor: '#2563eb',
padding: 15,
2024-09-26 04:56:15 +00:00
borderRadius: 30,
2024-09-07 01:22:11 +00:00
width: '100%',
alignItems: 'center',
marginBottom: 10,
},
buttonSecondary: {
borderWidth: 1,
borderColor: '#fff',
},
buttonText: {
2024-09-26 04:56:15 +00:00
fontSize: 20,
2024-09-07 01:22:11 +00:00
color: 'white',
2024-09-26 04:56:15 +00:00
fontWeight:"bold"
2024-09-07 01:22:11 +00:00
},
buttonTextSecondary: {
color: '#fff',
},
forgotPasswordText: {
2024-09-26 04:56:15 +00:00
color: "#0f48a1",
2024-09-07 01:22:11 +00:00
fontSize: 16,
marginBottom: 20,
textDecorationLine: 'underline',
},
});
export default LoginScreen;