Adding API for EDIT in Recurring Expense.
This commit is contained in:
parent
b897a41f95
commit
324ad05771
@ -7,12 +7,17 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
|||||||
import { defaultRecurringExpense, PaymentRecurringExpense } from './RecurringExpenseSchema';
|
import { defaultRecurringExpense, PaymentRecurringExpense } from './RecurringExpenseSchema';
|
||||||
import { FREQUENCY_FOR_RECURRING, INR_CURRENCY_CODE } from '../../utils/constants';
|
import { FREQUENCY_FOR_RECURRING, INR_CURRENCY_CODE } from '../../utils/constants';
|
||||||
import { useCurrencies, useProjectName } from '../../hooks/useProjects';
|
import { useCurrencies, useProjectName } from '../../hooks/useProjects';
|
||||||
import { useCreateRecurringExpense, usePayee, useUpdateRecurringExpense } from '../../hooks/useExpense';
|
import { useCreateRecurringExpense, usePayee, useRecurringExpenseDetail, useUpdateRecurringExpense } from '../../hooks/useExpense';
|
||||||
import InputSuggestions from '../common/InputSuggestion';
|
import InputSuggestions from '../common/InputSuggestion';
|
||||||
import MultiEmployeeSearchInput from '../common/MultiEmployeeSearchInput';
|
import MultiEmployeeSearchInput from '../common/MultiEmployeeSearchInput';
|
||||||
|
|
||||||
function ManageRecurringExpense({ closeModal, requestToEdit = null }) {
|
function ManageRecurringExpense({ closeModal, requestToEdit = null }) {
|
||||||
const data = {}
|
const {
|
||||||
|
data,
|
||||||
|
isLoading,
|
||||||
|
isError,
|
||||||
|
error: requestError,
|
||||||
|
} = useRecurringExpenseDetail(requestToEdit);
|
||||||
|
|
||||||
//APIs
|
//APIs
|
||||||
const { projectNames, loading: projectLoading, error, isError: isProjectError, } = useProjectName();
|
const { projectNames, loading: projectLoading, error, isError: isProjectError, } = useProjectName();
|
||||||
|
|||||||
@ -102,14 +102,11 @@ const RecurringExpenseList = ({ search, filterStatuses }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const header = [
|
const header = [
|
||||||
"Recurring Payment ID",
|
|
||||||
"Category",
|
"Category",
|
||||||
"Title",
|
"Title",
|
||||||
"Strike Date",
|
|
||||||
"Amount",
|
"Amount",
|
||||||
"Payee",
|
"Payee",
|
||||||
"Frequency",
|
"Frequency",
|
||||||
"Last Generation Date",
|
|
||||||
"Next Generation",
|
"Next Generation",
|
||||||
"Status",
|
"Status",
|
||||||
"Action",
|
"Action",
|
||||||
@ -217,7 +214,7 @@ const RecurringExpenseList = ({ search, filterStatuses }) => {
|
|||||||
onClick={() =>
|
onClick={() =>
|
||||||
setManageRequest({
|
setManageRequest({
|
||||||
IsOpen: true,
|
IsOpen: true,
|
||||||
projectId: project.id,
|
RecurringId: recurringExpense.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
@ -3,9 +3,6 @@ import { useEmployeesName } from "../../hooks/useEmployees";
|
|||||||
import { useDebounce } from "../../utils/appUtils";
|
import { useDebounce } from "../../utils/appUtils";
|
||||||
import { useController } from "react-hook-form";
|
import { useController } from "react-hook-form";
|
||||||
import Avatar from "./Avatar";
|
import Avatar from "./Avatar";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const EmployeeSearchInput = ({
|
const EmployeeSearchInput = ({
|
||||||
control,
|
control,
|
||||||
name,
|
name,
|
||||||
|
|||||||
@ -29,19 +29,29 @@ const MultiEmployeeSearchInput = ({
|
|||||||
forAll
|
forAll
|
||||||
);
|
);
|
||||||
|
|
||||||
// Initialize selected employees from emails (comma-separated string)
|
useEffect(() => {
|
||||||
useEffect(() => {
|
if (value && employees?.data) {
|
||||||
if (value && employees?.data) {
|
// Ensure value is a string (sometimes it may come as array/object)
|
||||||
const emails = value.split(",").filter(Boolean);
|
const stringValue =
|
||||||
const foundEmps = employees.data.filter((emp) =>
|
typeof value === "string"
|
||||||
emails.includes(emp.email)
|
? value
|
||||||
);
|
: Array.isArray(value)
|
||||||
setSelectedEmployees(foundEmps);
|
? value.join(",")
|
||||||
if (forAll && foundEmps.length > 0) {
|
: "";
|
||||||
setSearch(""); // clear search field
|
|
||||||
}
|
const emails = stringValue.split(",").filter(Boolean);
|
||||||
|
const foundEmps = employees.data.filter((emp) =>
|
||||||
|
emails.includes(emp.email)
|
||||||
|
);
|
||||||
|
|
||||||
|
setSelectedEmployees(foundEmps);
|
||||||
|
|
||||||
|
if (forAll && foundEmps.length > 0) {
|
||||||
|
setSearch(""); // clear search field
|
||||||
}
|
}
|
||||||
}, [value, employees?.data, forAll]);
|
}
|
||||||
|
}, [value, employees?.data, forAll]);
|
||||||
|
|
||||||
|
|
||||||
const handleSelect = (employee) => {
|
const handleSelect = (employee) => {
|
||||||
if (!selectedEmployees.find((emp) => emp.email === employee.email)) {
|
if (!selectedEmployees.find((emp) => emp.email === employee.email)) {
|
||||||
|
|||||||
@ -454,8 +454,8 @@ export const useUpdateRecurringExpense = (onSuccessCallBack) => {
|
|||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
onSuccess: (updatedExpense, variables) => {
|
onSuccess: (updatedExpense, variables) => {
|
||||||
queryClient.removeQueries({ queryKey: ["RecurringExpense", variables.id] });
|
queryClient.removeQueries({ queryKey: ["recurringExpense", variables.id] });
|
||||||
queryClient.invalidateQueries({ queryKey: ["RecurringExpenseList"] });
|
queryClient.invalidateQueries({ queryKey: ["recurringExpenseList"] });
|
||||||
showToast("Recurring Expense updated Successfully", "success");
|
showToast("Recurring Expense updated Successfully", "success");
|
||||||
|
|
||||||
if (onSuccessCallBack) onSuccessCallBack();
|
if (onSuccessCallBack) onSuccessCallBack();
|
||||||
@ -481,4 +481,16 @@ export const useRecurringExpenseList = (
|
|||||||
},
|
},
|
||||||
keepPreviousData: true,
|
keepPreviousData: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useRecurringExpenseDetail =(RequestId)=>{
|
||||||
|
return useQuery({
|
||||||
|
queryKey:['recurringExpense',RequestId],
|
||||||
|
queryFn:async()=>{
|
||||||
|
RequestId
|
||||||
|
const resp = await ExpenseRepository.GetRecurringExpense(RequestId);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
enabled:!!RequestId
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -38,7 +38,7 @@ const ExpenseRepository = {
|
|||||||
},
|
},
|
||||||
CreateRecurringExpense: (data) => api.post("/api/Expense/recurring-payment/create", data),
|
CreateRecurringExpense: (data) => api.post("/api/Expense/recurring-payment/create", data),
|
||||||
UpdateRecurringExpense: (id, data) => api.put(`/api/Expense/recurring-payment/edit/${id}`, data),
|
UpdateRecurringExpense: (id, data) => api.put(`/api/Expense/recurring-payment/edit/${id}`, data),
|
||||||
|
GetRecurringExpense: (id) => api.get(`/api/Expense/get/recurring-payment/details/${id}`),
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user