Arga_Fauzianto

conditional

Oct 21st, 2023
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. import { FlatList, SafeAreaView, StyleSheet, Text, View } from 'react-native'
  2. import React, { useState, useEffect, useMemo } from 'react'
  3. import { AccordionItem, Header } from '../../components'
  4. import { colors, fonts, getData } from '../../utils'
  5. import { IcNotFound } from '../../assets'
  6. import axios from 'axios'
  7. import base64 from 'react-native-base64';
  8. import { Dropdown } from 'react-native-element-dropdown'
  9. import { API_HOST } from '../../config'
  10.  
  11.  
  12.  
  13. const DetailHistorySps = ({ route }) => {
  14.  
  15. const [kodeDepo , setKodeDepo] = useState('')
  16. const [depoData, setDepoData] = useState([]);
  17. const [dataDepo, setDataDepo] = useState(null);
  18. const [isFocus, setIsFocus] = useState(false)
  19. const [selectedDepo, setSelectedDepo] = useState(null)
  20.  
  21.  
  22. const getDepo = () => {
  23. let username = 'admin'
  24. let adminPassword = 'Databa53'
  25. const authHeader = 'Basic ' + base64.encode(`${username}:${adminPassword}`);
  26. axios.get(`${API_HOST.url_staging}/depo`, {
  27. headers: {
  28. Authorization: authHeader
  29. }
  30. })
  31. .then(res => {
  32. // console.log('data line :', res.data);
  33. let count = Object.keys(res.data).length;
  34. let depoArray = []
  35. for (let i = 0; i < count; i++) {
  36. depoArray.push({
  37. id: res.data[i].kode_depo,
  38. label: res.data[i].depo,
  39. // total: res.data[i].qty
  40. })
  41. }
  42. setDepoData(depoArray)
  43. // handleSkuChange(skuArray[0])
  44. setKodeDepo(depoArray[0].id);
  45. console.log('kode :', kodeDepo);
  46. }).catch(err => {
  47. console.log('gagal', err);
  48. })
  49. } // mengambil data listing depo
  50.  
  51. useEffect(() => {
  52. getDepo();
  53. }, [])
  54.  
  55. const { historyData, type_user} = route.params;
  56. // const isPusat = type_user === '001'
  57.  
  58. return (
  59. <>
  60. <Header title="Detail History SPS" type='default' />
  61. <View style={{ flex: 1, top: 10, paddingHorizontal: 12, backgroundColor: "#FFFFFF" }}>
  62. {type_user == '001' && historyData.length < 0 ? (
  63. <>
  64. <Dropdown
  65. style={styles.dropdownCover}
  66. placeholderStyle={styles.placeholderStyle}
  67. selectedTextStyle={styles.selectedTextStyle}
  68. inputSearchStyle={styles.inputSearchStyle}
  69. search
  70. labelField='label'
  71. valueField='id'
  72. data={depoData}
  73. maxHeight={300}
  74. value={dataDepo}
  75. placeholder={!isFocus ? 'Pilih Depo' : '....'}
  76. searchPlaceholder='Search...'
  77. onChange={item => {
  78. setKodeDepo(item.id);
  79. setSelectedDepo(item.id);
  80. }}
  81. itemTextStyle={{ color: colors.secondary, fontSize: 13, fontFamily: fonts.primary[200] }}
  82. />
  83. {selectedDepo ? (
  84. <FlatList
  85. data={historyData.filter(item => item.id_depo === selectedDepo)}
  86. keyExtractor={(item) => item.line}
  87. renderItem={({ item, index }) =>
  88. <AccordionItem
  89. key={index}
  90. id_line={item.line}
  91. title={item.line}
  92. qty_pallet={item.titik_pallet}
  93. total={item.total_stock}
  94. />
  95. }
  96. />
  97. ) : (
  98. <View style={{ paddingVertical: 10, justifyContent: 'center', alignItems: 'center', flex: 1 }}>
  99. <IcNotFound />
  100. <Text style={{ top: 30, fontSize: 23, fontFamily: fonts.primary[300], color: '#020202' }}>
  101. Oops Belum Tersedia Inputan Hari Ini!
  102. </Text>
  103. </View>
  104. )}
  105. </>
  106. ) : (
  107. <FlatList
  108. data={historyData}
  109. keyExtractor={(item) => item.id_line}
  110. renderItem={({ item }) =>
  111. <AccordionItem
  112. id_line={item.line}
  113. title={item.line}
  114. qty_pallet={item.titik_pallet}
  115. total={item.total_stock}
  116. />
  117. }
  118. />
  119. )}
  120. </View>
  121. </>
  122. )
  123. }
  124.  
  125.  
  126. export default DetailHistorySps;
  127.  
  128. const styles = StyleSheet.create({
  129. dropdownCover: {
  130. height: 50,
  131. backgroundColor: "#FFFFFF",
  132. borderRadius: 8,
  133. padding: 12,
  134. shadowColor: '#000',
  135. shadowOffset: {
  136. width: 0,
  137. height: 1,
  138. },
  139. borderWidth: 0.4,
  140. shadowOpacity: 0.2,
  141. shadowRadius: 1.41,
  142. elevation: 2,
  143. },
  144.  
  145. selectedTextStyle: {
  146. fontSize: 16,
  147. color: 'blue',
  148. },
  149.  
  150. inputSearchStyle: {
  151. height: 50,
  152. fontSize: 15,
  153. fontFamily: fonts.primary[200],
  154. color: colors.secondary,
  155. borderColor: colors.secondary,
  156. borderRadius: 4,
  157. },
  158.  
  159. selectedTextStyle: {
  160. fontFamily: fonts.primary[200],
  161. fontSize: 14,
  162. color: colors.primary
  163. }
  164. })
Add Comment
Please, Sign In to add comment