Açıklama Yok

SettingScreen.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import React, { useState, useEffect } from "react";
  2. import { Text, View, StyleSheet, Button, ScrollView, TextInput } from "react-native";
  3. import {Picker} from '@react-native-community/picker'
  4. import * as SecureStore from 'expo-secure-store';
  5. import axios from "axios";
  6. export default function SettingScreen() {
  7. const [currentFaculty, setCurrentFaculty] = useState('') // faculty of backend
  8. const [faculty, setFaculty] = useState('') // faculty of dropdown
  9. const getFaculty = async ()=>{
  10. const token = await SecureStore.getItemAsync('token')
  11. let id = await SecureStore.getItemAsync('id')
  12. let user_id = parseInt(id)
  13. try {
  14. let response = await axios(`http://8c4029a33a9a.ngrok.io/api/get_faculty_name?id=${user_id}`, {
  15. method: 'GET',
  16. headers: {
  17. 'content-type': 'application/json',
  18. Authorization: `Token ${token}`
  19. },
  20. })
  21. setCurrentFaculty(response.data.FacultyName[0])
  22. } catch(error){
  23. console.log(error)
  24. }
  25. }
  26. useEffect(()=>{
  27. console.log('dimelooo')
  28. getFaculty()
  29. },[currentFaculty])
  30. const updateFaculty = async()=>{
  31. const token = await SecureStore.getItemAsync('token')
  32. let id = await SecureStore.getItemAsync('id')
  33. let user_id = id
  34. let fac_id = faculty
  35. // console.log(typeof(fac_id))
  36. try {
  37. let response = await axios({
  38. method: 'PATCH',
  39. url: 'http://8c4029a33a9a.ngrok.io/api/update_faculty',
  40. headers: {
  41. Authorization: `Token ${token}`
  42. },
  43. data: {
  44. id: user_id,
  45. fac_id_id: fac_id
  46. }
  47. })
  48. console.log(response.data.list)
  49. } catch(error){
  50. console.log(error)
  51. }
  52. setCurrentFaculty(faculty)
  53. }
  54. console.log(faculty)
  55. return(
  56. <View style={styles.container}>
  57. {/* <DisplayFaculty/> */}
  58. <View style={{textAlignVertical: 'top'}}>
  59. <Text style={{ fontSize: 12, fontWeight: "bold" , height:30 }}>
  60. You currently belong to the faculty: {currentFaculty}
  61. </Text>
  62. </View>
  63. <View style={{alignItems: "center", backgroundColor: 'red', marginTop: 50, marginBottom: 300}}>
  64. <Text style={{ fontSize: 20, fontWeight: "bold" , height:30 }}> Faculty </Text>
  65. <Picker
  66. selectedValue={faculty}
  67. style={{ height: 0, width: 1000}}
  68. onValueChange={(itemValue, itemIndex) => setFaculty(itemValue) }>
  69. <Picker.Item label="Administración de Empresas" value="1" />
  70. <Picker.Item label="Administración de Empresas Graduado" value="2" />
  71. <Picker.Item label="Arquitectura" value="3" />
  72. <Picker.Item label="Arquitectura Graduado" value="4" />
  73. <Picker.Item label="Asuntos Académicos" value="5" />
  74. <Picker.Item label="Ciencias Militares" value="6" />
  75. <Picker.Item label="Ciencias Naturales" value="7" />
  76. <Picker.Item label="Ciencias Naturales Graduado" value="8" />
  77. <Picker.Item label="Ciencias Sociales" value="9" />
  78. <Picker.Item label="Ciencias Sociales Graduado" value="10" />
  79. <Picker.Item label="Escuela de Comunicación" value="11" />
  80. <Picker.Item label="Escuela de Comunicación Graduado" value="12" />
  81. <Picker.Item label="Educación" value="13" />
  82. <Picker.Item label="Educación Continua (BEOF)" value="14" />
  83. <Picker.Item label="Educación Graduada" value="15" />
  84. <Picker.Item label="Escuela de Derecho" value="16" />
  85. <Picker.Item label="Escuela Graduada de Ciencias y Tecnologías de la Información" value="17" />
  86. <Picker.Item label="Estudios Generales" value="18" />
  87. <Picker.Item label="Humanidades" value="19" />
  88. <Picker.Item label="Humanidades Graduado" value="20" />
  89. <Picker.Item label="Planificación" value="21" />
  90. </Picker>
  91. </View>
  92. <Button
  93. onPress={updateFaculty}
  94. title="Change Faculty"
  95. />
  96. </View>
  97. );
  98. }
  99. const styles = StyleSheet.create({
  100. container: {
  101. flex: 1,
  102. justifyContent: "center"
  103. }
  104. });