Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
2.4 kB
1
Indexable
Never
import React, { useState, useEffect } from 'react';
import { View, Text } from 'react-native';
import Logo from '../components/Logo'
import Header from '../components/Header'
import Button from '../components/Button'
import Paragraph from '../components/Paragraph'
import Background from '../components/Background'
import { useSelector } from 'react-redux';
import { getRandomlyPaymentByOrderFk } from '../api/apiCalls';

export default function ChallengeScreen(props) {
    const payments = props.route.params.payments;
    const order = props.route.params.order;
    const myState = useSelector(state => state)

    console.log("ChallengeScreen'e gelen params:", props.route.params)
    const [selectedPayment, setSelectedPayment] = useState({});

    let isMe;

    useEffect(() => {
        if (typeof selectedPayment.customer == 'undefined') {
            getRandomlyPaymentByOrderFk(order.orderPk).then(response => {
                console.log("Response.data:", response.data)
                setSelectedPayment(response.data);
            })
        } else {
            isMe = selectedPayment.customer.customerPk === myState.customerPk
            console.log("isMe defined:", isMe)
        }
                        
    }, [selectedPayment])




    return (

        <Background>
            <Logo />
            <Header>Hesap Kimde?</Header>
            <Text style={{ fontWeight: 'bold', fontSize: 20, marginTop: 15 }}>
                Hesap: {order.orderPrice} TL
            </Text>


            {
                console.log("returndeki isMe",isMe),
                (typeof selectedPayment.customer != 'undefined') &&

                <View>
                    {
                        isMe ?
                            <View>
                                <Text>Sen Ödüyorsun</Text>
                                <Button mode="contained" onPress={() => { }}>
                                    Pay Now
                                </Button>
                            </View>
                            :
                            <View>
                                <Text>Seçilen Kişi: {selectedPayment.customer.user.userFirstName} {selectedPayment.customer.user.userLastName}</Text>
                            </View>
                    }

                </View>
            }









        </Background >
    );
}