Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 8a2e905

Browse files
committed
update: update recipient spent when add gift
1 parent 92801f6 commit 8a2e905

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/app/(gifts)/add-gift.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import Modal from 'react-native-modal';
1616

1717
import Loading from '@/components/Loading';
1818
import { addGift } from '@/features/gifts/giftSlice';
19-
import { fetchRecipients } from '@/features/recipients/recipientService';
19+
import {
20+
fetchRecipients,
21+
updateRecipient,
22+
} from '@/features/recipients/recipientService';
2023
import { useAppDispatch, useAppSelector } from '@/redux/hooks';
2124
import { uploadGiftThumbnail } from '@/services/uploadImage';
2225
import { formatPrice } from '@/utils/priceUtils';
@@ -134,8 +137,14 @@ const AddGiftScreen = () => {
134137
};
135138

136139
await dispatch(addGift(giftData)).unwrap();
137-
alert('Gift added successfully!');
138140

141+
const selectedRecipient = recipients.find((r) => r.id === recipient);
142+
if (selectedRecipient) {
143+
const updatedSpent = selectedRecipient.spent + parseFloat(price);
144+
await updateRecipient(recipient!, { spent: updatedSpent });
145+
}
146+
147+
alert('Gift added successfully!');
139148
router.push('/(gifts)');
140149
} catch (error) {
141150
console.error('Error saving gift:', error);

0 commit comments

Comments
 (0)