Arga_Fauzianto

edit form

Oct 30th, 2023
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.66 KB | None | 0 0
  1. import {
  2. FlatList,
  3. SafeAreaView,
  4. StyleSheet,
  5. Text,
  6. View,
  7. TouchableOpacity,
  8. } from 'react-native';
  9. import React, {useState, useEffect, useMemo} from 'react';
  10. import {AccordionItem, Button, Gap, Header, Input} from '../../components';
  11. import {colors, fonts, getData, useForm} from '../../utils';
  12. import {IcNotFound} from '../../assets';
  13. import axios from 'axios';
  14. import base64 from 'react-native-base64';
  15. import {Dropdown} from 'react-native-element-dropdown';
  16. import {API_HOST} from '../../config';
  17. import Modal from 'react-native-modal';
  18. import {ScrollView} from 'react-native-gesture-handler';
  19. import {useDispatch, useSelector} from 'react-redux';
  20. import {store} from '../../redux/store';
  21. import {editHistory} from '../../redux/reducer/history';
  22.  
  23. // import { TouchableOpacity } from 'react-native-gesture-handler'
  24.  
  25. const DetailHistorySps = ({route}) => {
  26. const [kodeDepo, setKodeDepo] = useState('');
  27. const [depoData, setDepoData] = useState([]);
  28. const [dataDepo, setDataDepo] = useState(null);
  29. const [isFocus, setIsFocus] = useState(false);
  30. const [selectedDepo, setSelectedDepo] = useState(null);
  31. const {userProfile, setUserProfile} = useState({});
  32.  
  33. // const [filteredHistoryData, setFilteredHistoryData] = useState([]);
  34.  
  35. const getDepo = () => {
  36. let username = 'admin';
  37. let adminPassword = 'Databa53';
  38. const authHeader = 'Basic ' + base64.encode(`${username}:${adminPassword}`);
  39. axios
  40. .get(`${API_HOST.url_staging}/depo`, {
  41. headers: {
  42. Authorization: authHeader,
  43. },
  44. })
  45. .then(res => {
  46. // console.log('data line :', res.data);
  47. let count = Object.keys(res.data).length;
  48. let depoArray = [];
  49. for (let i = 0; i < count; i++) {
  50. depoArray.push({
  51. id: res.data[i].kode_depo,
  52. label: res.data[i].depo,
  53. // total: res.data[i].qty
  54. });
  55. }
  56. setDepoData(depoArray);
  57. // handleSkuChange(skuArray[0])
  58. setKodeDepo(depoArray[0].id);
  59. // console.log('kode :', depoArray);
  60. })
  61. .catch(err => {
  62. console.log('gagal', err);
  63. });
  64. }; // mengambil data listing depo
  65.  
  66. useEffect(() => {
  67. getDepo();
  68. }, []);
  69.  
  70. const getEdit = id_stock => {
  71. //get data edit ketika tombol edit history di click
  72.  
  73. setIsModalVisible(true);
  74. let username = 'admin';
  75. let adminPassword = 'Databa53';
  76. const authHeader = 'Basic ' + base64.encode(`${username}:${adminPassword}`);
  77.  
  78. const today = new Date().toISOString().slice(0, 10);
  79.  
  80. axios
  81. .get(`${API_HOST.url_staging}/stock_sps/data_stock/`+id_stock, {
  82. headers: {
  83. Authorization: authHeader,
  84. },
  85. params: {
  86. id_stock,
  87. },
  88. })
  89. .then(res => {
  90. // dispatch({type: 'SET_GET_HISTORY', value: res.data})
  91. dispatch({type: 'SET_EDIT_HISTORY', value: {
  92. id_stock: res.data.id_stock,
  93. id_line: res.data.id_line,
  94. titik_pallet: res.data.titik_pallet
  95. }});
  96.  
  97. console.log('successs gan": ', res.data);
  98. })
  99. .catch(err => console.log(err));
  100. };
  101. const [isModalVisible, setIsModalVisible] = useState(false);
  102.  
  103. const {historyData} = route.params; // mengirim parameter dari screen History
  104.  
  105. const dispatch = useDispatch();
  106.  
  107. const historyEdit = useSelector(state => state.historyEditReducer);
  108.  
  109. const [valueHistory, setValueHistory] = useState({
  110. id_line: historyEdit.id_line,
  111. titik_pallet: historyEdit.titik_pallet
  112. }); // selector form edit
  113.  
  114. console.log('returned', historyEdit);
  115.  
  116. const changeText = () => {
  117. setValueHistory({id_line: '', id_stock: '', titik_pallet: ''})
  118. dispatch({
  119. type: 'SET_EDIT_HISTORY',
  120. value: {
  121. ...historyEdit,
  122. [key]: value,
  123. },
  124. });
  125. };// mengambil hasil value untuk di ubah di input component
  126.  
  127. return (
  128. <>
  129. <Header title="Detail History SPS" type="default" />
  130. <View
  131. style={{
  132. flex: 1,
  133. top: 10,
  134. paddingHorizontal: 12,
  135. backgroundColor: '#FFFFFF',
  136. }}>
  137. <View style={{flex: 1}}>
  138. {kodeDepo === '001' && historyData.length > 0 ? (
  139. <>
  140. <Dropdown
  141. style={styles.dropdownCover}
  142. placeholderStyle={styles.placeholderStyle}
  143. selectedTextStyle={styles.selectedTextStyle}
  144. inputSearchStyle={styles.inputSearchStyle}
  145. search
  146. labelField="label"
  147. valueField="value"
  148. data={depoData}
  149. maxHeight={300}
  150. value={dataDepo}
  151. placeholder={!isFocus ? 'Pilih Depo' : '....'}
  152. searchPlaceholder="Search..."
  153. onChange={item => {
  154. setSelectedDepo(item.id);
  155. setKodeDepo(item.id);
  156. }}
  157. itemTextStyle={{
  158. color: colors.secondary,
  159. fontSize: 13,
  160. fontFamily: fonts.primary[200],
  161. }}
  162. />
  163.  
  164. <FlatList
  165. data={
  166. selectedDepo
  167. ? historyData.filter(item => item.id_depo === selectedDepo)
  168. : historyData
  169. }
  170. keyExtractor={(item, index) => index.toString()}
  171. renderItem={({item, index}) => (
  172. <AccordionItem
  173. key={index}
  174. id_line={item.line}
  175. title={item.line}
  176. depo={item.depo}
  177. tanggal={item.tanggal}
  178. sku={item.nama_produk}
  179. qty_pallet={item.titik_pallet}
  180. total={item.total_stock}
  181. rusak_karton={item.rusak_karton}
  182. afkir={item.afkir}
  183. button={
  184. <TouchableOpacity
  185. style={styles.btnEdit}
  186. activeOpacity={0.8}
  187. onPress={() => getEdit(item.id_stock)}>
  188. <Text style={styles.textEdit}>Edit History</Text>
  189. </TouchableOpacity>
  190. } // hasil dari function getEdit ditampilkan di component ini
  191. />
  192. )}
  193. />
  194. </>
  195. ) : (
  196. <FlatList
  197. data={historyData}
  198. keyExtractor={(item, index) => index.toString()}
  199. renderItem={({item, index}) => (
  200. <AccordionItem
  201. key={index}
  202. id_line={item.line}
  203. title={item.line}
  204. depo={item.depo}
  205. tanggal={item.tanggal}
  206. sku={item.nama_produk}
  207. qty_pallet={item.titik_pallet}
  208. total={item.total_stock}
  209. rusak_karton={item.rusak_karton}
  210. afkir={item.afkir}
  211. // button={buttonEdit()}
  212. />
  213. )}
  214. />
  215. )}
  216. </View>
  217.  
  218. <View>
  219. <Modal
  220. isVisible={isModalVisible}
  221. backdropColor="black"
  222. animationIn={'slideInDown'}>
  223. <ScrollView showsVerticalScrollIndicator={false}>
  224. <View
  225. style={{flex: 1, borderRadius: 5, backgroundColor: '#FFFF'}}>
  226. <Text
  227. style={{
  228. fontFamily: fonts.primary[300],
  229. fontSize: 16,
  230. left: 20,
  231. top: 16,
  232. }}>
  233. Edit History Anda
  234. </Text>
  235. <Gap height={20} />
  236. <View style={{paddingHorizontal: 16, marginBottom: 16}}>
  237. <Input
  238. label="Line"
  239. value={valueHistory.id_line}
  240. onChangeText={value => changeText('id_line', value)}
  241. disable
  242. />
  243.  
  244. <Gap height={15} />
  245.  
  246. <Input
  247. label="Titik Pallet"
  248. value={historyEdit.titik_pallet}
  249. onChangeText={value => changeText('titik-pallet', value)}
  250. disable
  251. />
  252. </View>
  253. </View>
  254. </ScrollView>
  255. </Modal>
  256. </View>
  257.  
  258. {/* {kodeDepo == '001' && historyData.length > 0 ? (
  259. <>
  260. <Dropdown
  261. style={styles.dropdownCover}
  262. placeholderStyle={styles.placeholderStyle}
  263. selectedTextStyle={styles.selectedTextStyle}
  264. inputSearchStyle={styles.inputSearchStyle}
  265. search
  266. labelField='label'
  267. valueField='id'
  268. data={depoData}
  269. maxHeight={300}
  270. value={kodeDepo}
  271. placeholder={!isFocus ? 'Pilih Depo' : '....'}
  272. searchPlaceholder='Search...'
  273. onChange={item => {
  274. setKodeDepo(item.id);
  275. setSelectedDepo(item.id);
  276. }}
  277. itemTextStyle={{ color: colors.secondary, fontSize: 13, fontFamily: fonts.primary[200] }}
  278. />
  279.  
  280. {selectedDepo && (
  281. <FlatList
  282. data={historyData.filter(item => item.id_depo === selectedDepo)}
  283. keyExtractor={(item, index) => index.toString()}
  284. renderItem={({ item, index }) =>
  285. <AccordionItem
  286. id_line={item.line}
  287. title={item.line}
  288. qty_pallet={item.titik_pallet}
  289. depo={item.depo}
  290. total={item.total_stock}
  291. />
  292. }
  293. />
  294.  
  295. ) (
  296. <View style={{ paddingVertical: 10, justifyContent: 'center', alignItems: 'center', flex: 1 }}>
  297. <IcNotFound />
  298. <Text style={{ top: 30, fontSize: 23, fontFamily: fonts.primary[300], color: '#020202' }}>
  299. Oops Belum Tersedia Inputan Hari Ini!
  300. </Text>
  301. </View>
  302. )}
  303. </>
  304. ) : historyData && (
  305. <FlatList
  306. data={historyData}
  307. keyExtractor={(item) => item.id_line}
  308. renderItem={({ item }) =>
  309. <AccordionItem
  310. id_line={item.line}
  311. title={item.line}
  312. qty_pallet={item.titik_pallet}
  313. depo={item.depo}
  314. total={item.total_stock}
  315. />
  316. }
  317. />
  318. )} */}
  319. </View>
  320. </>
  321. );
  322. };
  323.  
  324. export default DetailHistorySps;
  325.  
  326. const styles = StyleSheet.create({
  327. dropdownCover: {
  328. height: 50,
  329. backgroundColor: '#FFFFFF',
  330. borderRadius: 8,
  331. padding: 12,
  332. shadowColor: '#000',
  333. shadowOffset: {
  334. width: 0,
  335. height: 1,
  336. },
  337. borderWidth: 0.4,
  338. shadowOpacity: 0.2,
  339. shadowRadius: 1.41,
  340. elevation: 2,
  341. },
  342.  
  343. selectedTextStyle: {
  344. fontSize: 16,
  345. color: 'blue',
  346. },
  347.  
  348. inputSearchStyle: {
  349. height: 50,
  350. fontSize: 15,
  351. fontFamily: fonts.primary[200],
  352. color: colors.secondary,
  353. borderColor: colors.secondary,
  354. borderRadius: 4,
  355. },
  356.  
  357. selectedTextStyle: {
  358. fontFamily: fonts.primary[200],
  359. fontSize: 14,
  360. color: colors.primary,
  361. },
  362.  
  363. btnEdit: {
  364. backgroundColor: colors.secondary,
  365. justifyContent: 'center',
  366. padding: 12,
  367. width: 120,
  368. borderRadius: 5,
  369. marginLeft: 38,
  370. },
  371.  
  372. textEdit: {
  373. fontSize: 14,
  374. color: '#FFFFFF',
  375. textAlign: 'center',
  376. fontFamily: fonts.primary[300],
  377. },
  378. });
  379.  
Add Comment
Please, Sign In to add comment