86 lines
3.1 KiB
JavaScript
86 lines
3.1 KiB
JavaScript
import React from 'react';
|
|
import {useState, useEffect} from 'react';
|
|
import {SafeAreaView, View} from 'react-native';
|
|
import Theme from '../../components/theme.style.js';
|
|
import CustomHeader from '../../components/header.js';
|
|
import DB from '../../components/storage';
|
|
import REQUEST from '../../components/api';
|
|
import REQUEST_POST_PAY from '../../components/api/postpayapi';
|
|
import Elements from '../../components/elements';
|
|
import MapFragment from './fragments/map.js';
|
|
import PanelFragment from './fragments/stationdetailspanel.js';
|
|
import CustomSafeArea from '../../components/safeArea.component.js';
|
|
|
|
export default function StationDetails(props){
|
|
|
|
const [loading, setloading] = useState(true)
|
|
const [station, setstation] = useState(null)
|
|
const [markers, setmarkers] = useState([])
|
|
const [initialRegion, setinitialRegion] = useState(null)
|
|
|
|
const init = async () => {
|
|
setmarkers(props.route.params?.markers)
|
|
setinitialRegion({
|
|
latitude: props.route.params?.data.geoLocation.latitude,
|
|
longitude: props.route.params?.data.geoLocation.longitude,
|
|
latitudeDelta: 0.0922,
|
|
longitudeDelta: 0.0421
|
|
})
|
|
getStationStoreDetails(props.route.params?.data.storeId)
|
|
}
|
|
|
|
const getStationStoreDetails = async (storeId) => {
|
|
await REQUEST_POST_PAY("getStoreDetails", "get", {}, {
|
|
storeId: storeId
|
|
}, {}, async (response) => {
|
|
setloading(false);
|
|
console.log(response.response);
|
|
if(response.success){
|
|
setstation(response.response)
|
|
}
|
|
}, (err) => {
|
|
setloading(false)
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
init()
|
|
}, [])
|
|
|
|
const navigate = (data) => {
|
|
props.navigation.navigate('PayatpumpStationDetails', {markers: markers, data: data, onBackPress: () => init()})
|
|
}
|
|
|
|
const navigateToPayatpumpTransaction = (response, storeId, selectedPump) => {
|
|
props.navigation.navigate('PayatpumpStationTransactionDetails', { response: response, storeId: storeId, storeName: station.storeName, selectedPump: selectedPump.pumpNumber })
|
|
}
|
|
|
|
return (
|
|
<CustomSafeArea>
|
|
<Elements.loader visible={loading} />
|
|
<CustomHeader title="" back={true} onBackPress={() => {
|
|
props.route.params?.onBackPress()
|
|
props.navigation.goBack()
|
|
}} navigation={props.navigation}/>
|
|
<View style={{flex: 1, flexDirection: 'column', justifyContent: 'center', height: Theme.screen.h, width: Theme.screen.w}}>
|
|
<MapFragment
|
|
region={initialRegion}
|
|
markers={markers}
|
|
onMapReady={() => {}}
|
|
pinSelected={true}/>
|
|
</View>
|
|
<PanelFragment
|
|
visible={false}
|
|
data={station}
|
|
onload={setloading}
|
|
stationId={props.route.params?.data.storeId}
|
|
loading={false}
|
|
error={null}
|
|
snapPoints={['0', '0', '0']}
|
|
onError={() => init()}
|
|
onTransaction={(response, storeId, selectedPump) => navigateToPayatpumpTransaction(response, storeId, selectedPump)}
|
|
lat={props.route.params?.location.latitude}
|
|
lon={props.route.params?.location.longitude}/>
|
|
</CustomSafeArea>
|
|
)
|
|
} |