From 2e80e3aa85e44c107711f641508ef6173e1488c2 Mon Sep 17 00:00:00 2001 From: Paolo Vincent Julian Date: Sun, 28 Jul 2024 12:52:27 +0800 Subject: [PATCH] feat: update recurred payment --- .../ReccuredPaymentModalForm.tsx | 26 ++++++++++++++++--- .../RecurredPaymentModal.tsx | 2 +- .../expense/useExpenseRecurredPayments.ts | 7 ++++- hooks/services/expense/useUpdateExpense.ts | 2 ++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/components/expenses/EditExpenseScreen/EditExpenseForm/RecurredPayments/RecurredPaymentModal/ReccuredPaymentModalForm/ReccuredPaymentModalForm.tsx b/components/expenses/EditExpenseScreen/EditExpenseForm/RecurredPayments/RecurredPaymentModal/ReccuredPaymentModalForm/ReccuredPaymentModalForm.tsx index 7819892..28b069a 100644 --- a/components/expenses/EditExpenseScreen/EditExpenseForm/RecurredPayments/RecurredPaymentModal/ReccuredPaymentModalForm/ReccuredPaymentModalForm.tsx +++ b/components/expenses/EditExpenseScreen/EditExpenseForm/RecurredPayments/RecurredPaymentModal/ReccuredPaymentModalForm/ReccuredPaymentModalForm.tsx @@ -1,8 +1,10 @@ import Button from '@/components/common/Button'; import Stack from '@/components/common/Stack'; import { Expense } from '@/hooks/services/expense/expense.types'; +import { useUpdateExpense } from '@/hooks/services/expense/useUpdateExpense'; import { Formik } from 'formik'; import { FC } from 'react'; +import { Alert } from 'react-native'; import { RECCURED_PAYMENT_MODAL_SCHEMA, RecurredPaymentModalValues, @@ -13,20 +15,36 @@ import { } from './ReccuredPaymentModalForm.style'; type ReccuredPaymentModalFormProps = { + onDismiss: () => void; expense: Expense; }; -const ReccuredPaymentModalForm: FC = ({ expense }) => { +const ReccuredPaymentModalForm: FC = ({ onDismiss, expense }) => { + const { mutateAsync: updateExpenseMutate } = useUpdateExpense(expense.id); + + const handleSubmit = async (values: RecurredPaymentModalValues) => { + try { + await updateExpenseMutate({ + amount: values.amount, + description: values.description, + }); + onDismiss(); + Alert.alert('Success', 'Expense updated successfully'); + } catch { + Alert.alert('Error', 'Failed to update expense'); + } + }; + return ( - onSubmit={() => {}} + onSubmit={handleSubmit} initialValues={{ amount: expense?.amount, description: expense?.description, }} validationSchema={RECCURED_PAYMENT_MODAL_SCHEMA} > - {({ handleBlur, handleChange, values }) => ( + {({ handleBlur, handleChange, handleSubmit, values }) => ( = ({ expense } value={values.description} /> -