import React, { useState } from 'react'; import { TamaguiProvider, Stack, Input, Button, Text, useToast } from 'tamagui'; const AddFriendScreen = () => { const [friendUsername, setFriendUsername] = useState(''); const [error, setError] = useState(''); //const toast = useToast(); const handleAddFriend = async () => { if (!friendUsername.trim()) { setError('Username cannot be empty.'); return; } try { const yourAuthToken = localStorage.getItem("jwtToken"); const response = await fetch("http://localhost:4000/friend-request", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${yourAuthToken}`, // Include the auth token if required by your `authenticate` middleware }, body: JSON.stringify({ receiverUsername: friendUsername }), }); if (!response.ok) { const errorText = await response.text(); //toast.show(errorText || "Error sending friend request", { type: 'error' }); return; } const result = await response.json(); console.log(result) //toast.show("Friend request sent successfully", { type: 'success' }); setFriendUsername(''); // Clear the input field } catch (error) { console.error("Error sending friend request:", error); //toast.show("Failed to send friend request", { type: 'error' }); } }; return ( Add a Friend {error ? ( {error} ) : null} ); }; export default AddFriendScreen;