fixed going wrong request for Expense payload - Transaction

This commit is contained in:
pramod mahajan 2025-09-15 17:00:36 +05:30
parent 94eb283b2d
commit 4927680fe3
2 changed files with 12 additions and 7 deletions

View File

@ -2,7 +2,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
import React, { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import { defaultExpense, ExpenseSchema } from "./ExpenseSchema";
import { formatFileSize } from "../../utils/appUtils";
import { formatFileSize, localToUtc } from "../../utils/appUtils";
import { useProjectName } from "../../hooks/useProjects";
import { useDispatch, useSelector } from "react-redux";
import { changeMaster } from "../../slices/localVariablesSlice";
@ -183,9 +183,8 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
const onSubmit = (fromdata) => {
let payload = {
...fromdata,
transactionDate: moment
.utc(fromdata.transactionDate, "DD-MM-YYYY")
.toISOString(),
transactionDate: localToUtc(fromdata.transactionDate)
};
if (expenseToEdit) {
const editPayload = { ...payload, id: data.id };
@ -331,7 +330,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
<Label htmlFor="transactionDate" className="form-label" required>
Transaction Date
</Label>
<DatePicker name="transactionDate" control={control} />
<DatePicker name="transactionDate" control={control} maxDate={new Date()}/>
{errors.transactionDate && (
<small className="danger-text">

View File

@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { format, parseISO } from "date-fns";
export const formatFileSize=(bytes)=> {
if (bytes < 1024) return bytes + " B";
else if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + " KB";
@ -68,4 +68,10 @@ export const normalizeAllowedContentTypes = (allowedContentType) => {
if (Array.isArray(allowedContentType)) return allowedContentType;
if (typeof allowedContentType === "string") return allowedContentType.split(",");
return [];
};
};
export function localToUtc(localDateString) {
const date = new Date(localDateString);
return date.toISOString();
}