| 12345678910111213141516171819202122232425262728293031 |
- import AsyncStorage from '@react-native-async-storage/async-storage';
- export const fetchInvoices = async (setInvoices) => {
- try {
- const token = await AsyncStorage.getItem('token');
- const response = await fetch('http://localhost:3000/invoices', {
- headers: { 'Authorization': token },
- });
- if (response.ok) {
- const data = await response.json();
- setInvoices(data);
- } else {
- throw new Error('Failed to fetch invoices');
- }
- } catch (error) {
- Alert.alert('Error', 'Failed to fetch invoices');
- }
- };
- export const markAsPaid = async (invoiceId, setInvoices) => {
- try {
- const token = await AsyncStorage.getItem('token');
- await fetch(`http://localhost:3000/invoice/${invoiceId}/pay`, {
- method: 'POST',
- headers: { 'Authorization': token },
- });
- fetchInvoices(setInvoices);
- } catch (error) {
- Alert.alert('Error', 'Failed to mark invoice as paid');
- }
- };
|