+
+
+
+ {errors.projectId && (
+ {errors.projectId.message}
+ )}
+
- useEffect(() => {
- if (requestToEdit && data) {
- reset({
- title: data.title || "",
- description: data.description || "",
- payee: data.payee || "",
- notifyTo: data.notifyTo || "",
- currencyId: data.currency.id || "",
- amount: data.amount || "",
- strikeDate: data.strikeDate?.slice(0, 10) || "",
- projectId: data.project.id || "",
- paymentBufferDays: data.paymentBufferDays || "",
- numberOfIteration: data.numberOfIteration || "",
- expenseCategoryId: data.expenseCategory.id || "",
- statusId: data.statusId || "",
- frequency: data.frequency || "",
- isVariable: data.isVariable || false,
-
- });
- }
- }, [data, reset]);
-
- // console.log("Veer",data)
-
- const onSubmit = (fromdata) => {
- let payload = {
- ...fromdata,
- // strikeDate: localToUtc(fromdata.strikeDate),
- strikeDate: fromdata.strikeDate ? new Date(fromdata.strikeDate).toISOString() : null,
- };
- if (requestToEdit) {
- const editPayload = { ...payload, id: data.id};
- PaymentRequestUpdate({ id: data.id, payload: editPayload });
- } else {
- CreateRecurringExpense(payload);
- }
- console.log("Kartik", payload)
- };
-
- return (
-
-
- {requestToEdit ? "Update Expense Recurring " : "Create Expense Recurring"}
-
-
+
+
+
+ {errors.expenseCategoryId && (
+
+ {errors.expenseCategoryId.message}
+
+ )}
+
- )
+
+ {/* Title and Is Variable */}
+
+
+
+
+ {errors.title && (
+ {errors.title.message}
+ )}
+
+
+
+
+
+
(
+
+ )}
+ />
+ {errors.isVariable && (
+ {errors.isVariable.message}
+ )}
+
+
+
+ {/* Date and Amount */}
+
+
+
+
+ {errors.strikeDate && (
+ {errors.strikeDate.message}
+ )}
+
+
+
+
+
+ {errors.amount && (
+ {errors.amount.message}
+ )}
+
+
+
+ {/* Payee and Currency */}
+
+
+
+
+ setValue("payee", val, { shouldValidate: true })
+ }
+ error={errors.payee?.message}
+ placeholder="Select or enter payee"
+ />
+
+
+
+
+
+ {errors.currencyId && (
+ {errors.currencyId.message}
+ )}
+
+
+
+ {/* Frequency To and Status Id */}
+
+
+
+
+ {errors.frequency && (
+ {errors.frequency.message}
+ )}
+
+
+
+
+
+ {errors.statusId && (
+ {errors.statusId.message}
+ )}
+
+
+
+ {/* Payment Buffer Days and Number of Iteration */}
+
+
+
+
+
+
+
+
+
+
+ {/* Description */}
+
+
+
+
+ {errors.description && (
+
+ {errors.description.message}
+
+ )}
+
+
+
+
+
+
+
+
+
+ );
}
-export default ManageRecurringExpense
+export default ManageRecurringExpense;
diff --git a/src/components/RecurringExpense/RecurringExpenseSchema.js b/src/components/RecurringExpense/RecurringExpenseSchema.js
index b7c312a2..da62b341 100644
--- a/src/components/RecurringExpense/RecurringExpenseSchema.js
+++ b/src/components/RecurringExpense/RecurringExpenseSchema.js
@@ -80,7 +80,7 @@ export const defaultRecurringExpense = {
notifyTo: "",
currencyId: "",
amount: 0,
- strikeDate: "", // or null if your DatePicker accepts null
+ strikeDate: "",
projectId: "",
paymentBufferDays: 0,
numberOfIteration: 1,
diff --git a/src/components/common/MultiEmployeeSearchInput.jsx b/src/components/common/MultiEmployeeSearchInput.jsx
index bb42e2b2..23a3a5a0 100644
--- a/src/components/common/MultiEmployeeSearchInput.jsx
+++ b/src/components/common/MultiEmployeeSearchInput.jsx
@@ -5,177 +5,178 @@ import { useController } from "react-hook-form";
import Avatar from "../common/Avatar";
const MultiEmployeeSearchInput = ({
- control,
- name,
- projectId,
- placeholder,
- forAll,
+ control,
+ name,
+ projectId,
+ placeholder,
+ forAll,
}) => {
- const {
- field: { onChange, value, ref },
- fieldState: { error },
- } = useController({ name, control });
+ const {
+ field: { onChange, value, ref },
+ fieldState: { error },
+ } = useController({ name, control });
- const [search, setSearch] = useState("");
- const [showDropdown, setShowDropdown] = useState(false);
- const [selectedEmployees, setSelectedEmployees] = useState([]);
- const dropdownRef = useRef(null);
+ const [search, setSearch] = useState("");
+ const [showDropdown, setShowDropdown] = useState(false);
+ const [selectedEmployees, setSelectedEmployees] = useState([]);
+ const dropdownRef = useRef(null);
- const debouncedSearch = useDebounce(search, 500);
+ const debouncedSearch = useDebounce(search, 500);
- const { data: employees, isLoading } = useEmployeesName(
- projectId,
- debouncedSearch,
- forAll
- );
+ const { data: employees, isLoading } = useEmployeesName(
+ projectId,
+ debouncedSearch,
+ forAll
+ );
-useEffect(() => {
+ useEffect(() => {
if (value && employees?.data) {
- // Ensure value is a string (sometimes it may come as array/object)
- const stringValue =
- typeof value === "string"
- ? value
- : Array.isArray(value)
- ? value.join(",")
- : "";
+ // Ensure value is a string (sometimes it may come as array/object)
+ const stringValue =
+ typeof value === "string"
+ ? value
+ : Array.isArray(value)
+ ? value.join(",")
+ : "";
- const emails = stringValue.split(",").filter(Boolean);
- const foundEmps = employees.data.filter((emp) =>
- emails.includes(emp.email)
- );
+ const emails = stringValue.split(",").filter(Boolean);
+ const foundEmps = employees.data.filter((emp) =>
+ emails.includes(emp.email)
+ );
- setSelectedEmployees(foundEmps);
+ setSelectedEmployees(foundEmps);
- if (forAll && foundEmps.length > 0) {
- setSearch(""); // clear search field
- }
+ if (forAll && foundEmps.length > 0) {
+ setSearch(""); // clear search field
+ }
}
-}, [value, employees?.data, forAll]);
+ }, [value, employees?.data, forAll]);
+ const handleSelect = (employee) => {
+ if (!selectedEmployees.find((emp) => emp.email === employee.email)) {
+ const newSelected = [...selectedEmployees, employee];
+ setSelectedEmployees(newSelected);
+ // Store emails instead of IDs
+ onChange(
+ newSelected
+ .map((e) => e.email)
+ .filter(Boolean)
+ .join(",")
+ );
+ setSearch("");
+ setShowDropdown(false);
+ }
+ };
- const handleSelect = (employee) => {
- if (!selectedEmployees.find((emp) => emp.email === employee.email)) {
- const newSelected = [...selectedEmployees, employee];
- setSelectedEmployees(newSelected);
- // Store emails instead of IDs
- onChange(
- newSelected
- .map((e) => e.email)
- .filter(Boolean)
- .join(",")
- );
- setSearch("");
- setShowDropdown(false);
- }
- };
-
- const handleRemove = (email) => {
- const newSelected = selectedEmployees.filter((e) => e.email !== email);
- setSelectedEmployees(newSelected);
- onChange(
- newSelected
- .map((e) => e.email)
- .filter(Boolean)
- .join(",")
- );
- };
-
- useEffect(() => {
- const handleClickOutside = (event) => {
- if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
- setShowDropdown(false);
- }
- };
- const handleEsc = (event) => {
- if (event.key === "Escape") setShowDropdown(false);
- };
-
- document.addEventListener("mousedown", handleClickOutside);
- document.addEventListener("keydown", handleEsc);
-
- return () => {
- document.removeEventListener("mousedown", handleClickOutside);
- document.removeEventListener("keydown", handleEsc);
- };
- }, []);
-
- return (
-