Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {useState} from 'react';
- import createDataContext from './createDataContext';
- import axios from 'axios';
- import {AsyncStorage} from 'react-native';
- // const [driverId, setdriverID] = useState('');
- // const [companyId, setCompanyId] = useState('ini company id');
- // const [token, setToken] = useState('');
- this.state = {
- myState: '',
- };
- const truckReducer = (state, action) => {
- switch (action.type) {
- case 'fetch_task_schadule':
- return action.payload;
- default:
- return state;
- }
- };
- const fetchActiveTask = dispatch => async () => {};
- const fetchTaskSchadule = dispatch => async () => {
- try {
- await AsyncStorage.getItem('token', (error, result) => {
- if (result) {
- const a = JSON.parse(result);
- let token = a;
- }
- });
- await AsyncStorage.getItem('user_id', (error, userId) => {
- if (userId) {
- const b = JSON.parse(userId);
- this.setState(b);
- }
- });
- await AsyncStorage.getItem('company_id', (error, cmpyId) => {
- if (cmpyId) {
- const c = JSON.parse(cmpyId);
- let companyId = c;
- }
- });
- } catch (error) {
- console.log(error);
- }
- console.log('ini id driver cuk', myState );
- const responses = await axios.get(
- 'http://167.71.192.220:8686/trip/getbycomdrive',
- {
- headers: {
- Authorization: `Bearer ${token}`,
- },
- params: {
- driverID: driverId,
- assignedTripUserCompanyTransporterPlanByID: companyId,
- },
- },
- );
- dispatch({type: 'fetch_task_schadule', payload: responses.data});
- };
- export const {Provider, Context} = createDataContext(
- truckReducer,
- {fetchActiveTask, fetchTaskSchadule},
- [],
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement