unioil-loyalty-rn-app/app/screens/products/lubes.js

63 lines
1.8 KiB
JavaScript

import * as React from 'react';
import { useState, useEffect } from 'react';
import { SafeAreaView, ScrollView, TouchableOpacity, Button, View, Text, Platform } from 'react-native';
import CustomHeader from '../../components/header.js';
import Assets from '../../components/assets.manager.js';
import Elements from '../../components/elements.js';
import DB from '../../components/storage';
import REQUEST from '../../components/api/';
export default function Lubes({navigation, onLoaded}) {
const [Products, setproducts] = useState({})
const [lubes, setlubes] = useState([])
const init = async () => {
const SESSION = await DB.session()
await REQUEST("products", "get", {
Authorization: SESSION.token,
}, {}, {},
async (res) => {
if(res.status == 1 && res.data.length > 0){
await setproducts(res.data)
await setlubes(res.data[0].products)
await onLoaded()
}else{
onLoaded()
}
}, function(err){
Alert.alert("Information", `\n${err.message}`);
onLoaded()
}, "Product", "Fetch"
)
}
useEffect(() => {
init()
}, [])
const renderPoducts = () => {
return lubes ? lubes.map((data, index) => {
return (
<Elements.product
onPress={() => {
navigation.navigation.navigate("ProductDetails", {
data: data
});
}}
key={index}
title={data.name + "\n" + data.description}
image={{uri: data.image || ''}} />)
}) : false
}
return (
<SafeAreaView style={{flex: 1}}>
<ScrollView style={{flex: 1}}>
<View style={{flex: 1, width: '100%', flexDirection: 'row', flexWrap: 'wrap', padding: 0}}>
{renderPoducts()}
</View>
</ScrollView>
</SafeAreaView>
);
}