sort/app/(tabs)/signup.tsx

256 lines
7.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 } from '@react-navigation/native';
import { RootStackParamList } from '@/types';
import { DB } from '@/components/lib/db';
import { Ionicons } from '@expo/vector-icons';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { GestureHandlerRootView, ScrollView } from 'react-native-gesture-handler';
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 InfoLayer = ({info,navigation}:any) => {
return <>
<View style={{flex:1, backgroundColor:'blue', flexDirection:'column', justifyContent:'center', alignItems:'center'}}>
<Ionicons style={{fontSize:120, color:'yellow'}} name={'shield-checkmark-outline'} />
2024-10-16 03:37:18 +00:00
<Text style={{color:"white", fontSize:28}}>{lang.en.register.selamat}</Text>
<Text style={{color:"white", fontSize:28}}>{lang.en.register.akun_anda_berhasil_dibuat}</Text>
<Text style={{color:"white", fontSize:18,textAlign:'center'}}>{lang.en.register.silahkan_konfirmasi_ke_admin_untuk_aktivasi_akun_anda}</Text>
2024-09-07 01:22:11 +00:00
<TouchableOpacity onPress={()=>{
info(false);
navigation.navigate('index')
}}>
<Text style={{
paddingVertical:10
, paddingHorizontal:14
, fontSize:20
, marginVertical:20
, backgroundColor:'white'
, borderRadius:8
, fontWeight:'bold'
}}>Log In</Text>
</TouchableOpacity>
</View>
</>
}
const RegisterScreen = () => {
const navigation = useNavigation<NavigationProp<RootStackParamList>>();
const [fullname, setFullname] = useState('');
const [username, setUsername] = useState('');
const [phone, setPhone] = useState('');
const [password, setPassword] = useState('');
const [passwordRepeat, setPasswordRepeat] = useState('');
const [info, setInfo] = useState(false);
const handleRegister = async () => {
if (password !== passwordRepeat) {
Alert.alert('Password tidak sama');
return;
}
const query = `INSERT INTO "public".hr_employee (
name,work_phone
, work_email
, pin
, resource_id
, company_id
, resource_calendar_id
, color
, address_id
, work_contact_id
, create_uid
, write_uid
, marital
, certificate
, employee_type
)
VALUES (
'${fullname}'
,'${phone}'
,'${username}'
, '${password}'
, 6
, 1
, 1
, 0
, 1
, 17
, 6
, 2
, 'single'
, 'other'
, 'employee'
)`;
try {
await DB(query);
Alert.alert('Registrasi berhasil, silakan login');
const data = await DB(`SELECT * FROM "public".hr_employee WHERE work_email = '${username}' AND pin = '${password}'`)
await AsyncStorage.setItem('login', JSON.stringify(data));
navigation.navigate('home')
} catch (error) {
Alert.alert('Gagal mendaftar, silakan coba lagi');
console.error(error);
}
};
const handleSignIn = () => {
navigation.goBack();
};
return (
<>
{info?
<>
<InfoLayer info={setInfo} navigation={navigation} />
</>
:
2024-09-26 04:56:15 +00:00
<View style={{ flex: 1, backgroundColor: 'white'}}>
2024-09-07 01:22:11 +00:00
<GestureHandlerRootView>
<ScrollView>
<View style={{
2024-09-26 04:56:15 +00:00
flexDirection: "row"
, height: 140
, alignItems: "flex-end"
, paddingHorizontal: 30
2024-09-07 01:22:11 +00:00
}}>
2024-09-26 04:56:15 +00:00
<View style={{ flex: 1 }}>
</View>
2024-09-07 01:22:11 +00:00
<View style={{
width: "auto",
backgroundColor: "white",
padding: 10,
borderRadius: 20
}}>
<Image
2024-09-26 04:56:15 +00:00
source={require('../../assets/images/login/logo.png')}
2024-09-07 01:22:11 +00:00
style={{
2024-09-26 04:56:15 +00:00
width: 60
, height: 60
2024-09-07 01:22:11 +00:00
}}
resizeMode="contain" // You can adjust this based on how you want the image to scale
/>
</View>
</View>
<View style={styles.container}>
2024-10-16 03:37:18 +00:00
<Text style={styles.title}>{lang.en.register.buat_akun}</Text>
2024-09-07 01:22:11 +00:00
<TextInput
style={styles.input}
2024-10-16 03:37:18 +00:00
placeholder={lang.en.register.nama_anda}
2024-09-07 01:22:11 +00:00
value={fullname}
onChangeText={setFullname}
/>
2024-09-26 04:56:15 +00:00
2024-09-07 01:22:11 +00:00
<TextInput
style={styles.input}
2024-10-16 03:37:18 +00:00
placeholder={lang.en.register.email}
2024-09-07 01:22:11 +00:00
value={username}
onChangeText={setUsername}
/>
2024-09-26 04:56:15 +00:00
2024-09-07 01:22:11 +00:00
<TextInput
style={styles.input}
2024-10-16 03:37:18 +00:00
placeholder={lang.en.register.no_hp}
2024-09-07 01:22:11 +00:00
value={phone}
onChangeText={setPhone}
/>
2024-09-26 04:56:15 +00:00
2024-09-07 01:22:11 +00:00
<TextInput
style={styles.input}
2024-10-16 03:37:18 +00:00
placeholder={lang.en.register.password}
2024-09-07 01:22:11 +00:00
value={password}
onChangeText={setPassword}
secureTextEntry
/>
2024-09-26 04:56:15 +00:00
2024-09-07 01:22:11 +00:00
<TextInput
style={styles.input}
2024-10-16 03:37:18 +00:00
placeholder={lang.en.register.konfirmasi_password}
2024-09-07 01:22:11 +00:00
value={passwordRepeat}
onChangeText={setPasswordRepeat}
secureTextEntry
/>
<TouchableOpacity style={styles.button} onPress={handleRegister}>
<Text style={styles.buttonText}>{(`Register`).toUpperCase()}</Text>
</TouchableOpacity>
<View style={{ marginBottom:30, marginTop:20, flexDirection: "row" }}>
2024-09-26 04:56:15 +00:00
<View style={{ flex: 1 }}>
2024-10-16 03:37:18 +00:00
<Text>{lang.en.register.sudah_punya_akun}</Text>
2024-09-26 04:56:15 +00:00
</View>
2024-09-07 01:22:11 +00:00
<TouchableOpacity onPress={handleSignIn} style={{ marginHorizontal: 5 }}>
<Text style={{
color: "blue",
fontWeight: "bold"
2024-10-16 03:37:18 +00:00
}}>{lang.en.register.masuk_disini}</Text>
2024-09-07 01:22:11 +00:00
</TouchableOpacity>
</View>
</View>
</ScrollView>
</GestureHandlerRootView>
</View>
}
</>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
justifyContent: 'center',
2024-09-26 04:56:15 +00:00
paddingVertical: 10,
2024-09-07 01:22:11 +00:00
paddingHorizontal:40,
borderTopLeftRadius: 50
},
appName: {
fontSize: 36,
color: '#fff',
fontWeight: 'bold',
marginBottom: 10,
},
title: {
2024-09-26 04:56:15 +00:00
fontSize: 20,
2024-09-07 01:22:11 +00:00
color: config.color.primary,
2024-09-26 04:56:15 +00:00
fontWeight:"bold",
marginBottom:30
2024-09-07 01:22:11 +00:00
},
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-26 04:56:15 +00:00
shadowColor: "#000",
2024-09-07 01:22:11 +00:00
marginBottom: 20,
fontSize: 16,
},
button: {
backgroundColor: config.color.primary,
padding: 15,
2024-09-26 04:56:15 +00:00
borderRadius: 50,
2024-09-07 01:22:11 +00:00
width: '100%',
alignItems: 'center',
2024-09-26 04:56:15 +00:00
marginBottom: 30,
marginTop: 30,
2024-09-07 01:22:11 +00:00
},
buttonSecondary: {
backgroundColor: 'transparent',
borderWidth: 1,
borderColor: '#fff',
},
buttonText: {
fontSize: 18,
color: 'white',
fontWeight:'bold'
},
buttonTextSecondary: {
color: '#fff',
},
});
export default RegisterScreen;