Advertisement
Guest User

Untitled

a guest
Mar 26th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import React, {useState} from 'react';
  2. import createDataContext from './createDataContext';
  3. import axios from 'axios';
  4. import {AsyncStorage} from 'react-native';
  5.  
  6. // const [driverId, setdriverID] = useState('');
  7. // const [companyId, setCompanyId] = useState('ini company id');
  8. // const [token, setToken] = useState('');
  9.  
  10. this.state = {
  11. myState: '',
  12. };
  13.  
  14. const truckReducer = (state, action) => {
  15. switch (action.type) {
  16. case 'fetch_task_schadule':
  17. return action.payload;
  18. default:
  19. return state;
  20. }
  21. };
  22.  
  23. const fetchActiveTask = dispatch => async () => {};
  24.  
  25. const fetchTaskSchadule = dispatch => async () => {
  26. try {
  27. await AsyncStorage.getItem('token', (error, result) => {
  28. if (result) {
  29. const a = JSON.parse(result);
  30. let token = a;
  31. }
  32. });
  33. await AsyncStorage.getItem('user_id', (error, userId) => {
  34. if (userId) {
  35. const b = JSON.parse(userId);
  36. this.setState(b);
  37. }
  38. });
  39. await AsyncStorage.getItem('company_id', (error, cmpyId) => {
  40. if (cmpyId) {
  41. const c = JSON.parse(cmpyId);
  42. let companyId = c;
  43. }
  44. });
  45. } catch (error) {
  46. console.log(error);
  47. }
  48.  
  49. console.log('ini id driver cuk', myState );
  50.  
  51. const responses = await axios.get(
  52. 'http://167.71.192.220:8686/trip/getbycomdrive',
  53. {
  54. headers: {
  55. Authorization: `Bearer ${token}`,
  56. },
  57. params: {
  58. driverID: driverId,
  59. assignedTripUserCompanyTransporterPlanByID: companyId,
  60. },
  61. },
  62. );
  63.  
  64. dispatch({type: 'fetch_task_schadule', payload: responses.data});
  65. };
  66.  
  67. export const {Provider, Context} = createDataContext(
  68. truckReducer,
  69. {fetchActiveTask, fetchTaskSchadule},
  70. [],
  71. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement