Merge branch 'upgrade_Expense' of https://git.marcoaiot.com/admin/marco.pms.web into upgrade_Expense
This commit is contained in:
commit
e79702661d
@ -1,4 +1,4 @@
|
||||
import React, { useEffect } from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useCurrencies, useProjectName } from '../../hooks/useProjects';
|
||||
import Label from '../common/Label';
|
||||
import { useForm } from 'react-hook-form';
|
||||
@ -10,6 +10,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { formatFileSize, localToUtc } from '../../utils/appUtils';
|
||||
import { defaultPaymentRequest, PaymentRequestSchema } from './PaymentRequestSchema';
|
||||
import { INR_CURRENCY_CODE } from '../../utils/constants';
|
||||
import { useProfile } from '../../hooks/useProfile';
|
||||
|
||||
function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
|
||||
const { data, isLoading, isError, error: requestError } = usePaymentRequestDetail(requestToEdit)
|
||||
@ -27,13 +28,15 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
|
||||
error: ExpenseError,
|
||||
} = useExpenseCategory();
|
||||
|
||||
const schema = PaymentRequestSchema(ExpenseCategories);
|
||||
const { profile } = useProfile();
|
||||
|
||||
const schema = PaymentRequestSchema(ExpenseTypes);
|
||||
const { register, control, watch, handleSubmit, setValue, reset, formState: { errors }, } = useForm({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: defaultPaymentRequest,
|
||||
});
|
||||
|
||||
|
||||
const [isItself, setisItself] = useState(false);
|
||||
|
||||
const files = watch("billAttachments");
|
||||
const onFileChange = async (e) => {
|
||||
@ -151,18 +154,23 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
|
||||
}, [currencyData, requestToEdit, setValue]);
|
||||
|
||||
const onSubmit = (fromdata) => {
|
||||
|
||||
let payload = {
|
||||
...fromdata,
|
||||
dueDate: localToUtc(fromdata.dueDate),
|
||||
payee:isItself ? profile?.employeeInfo?.id : fromdata.payee
|
||||
};
|
||||
if (requestToEdit) {
|
||||
const editPayload = { ...payload, id: data.id };
|
||||
const editPayload = { ...payload, id: data.id, payee:isItself ? profile?.employeeInfo?.id : fromdata.payee };
|
||||
PaymentRequestUpdate({ id: data.id, payload: editPayload });
|
||||
} else {
|
||||
CreatePaymentRequest(payload);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSetItSelf=(e)=>{
|
||||
setisItself(e.target.value);
|
||||
setValue('payee',profile?.employeeInfo.id)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container p-3">
|
||||
@ -313,20 +321,37 @@ function ManagePaymentRequest({ closeModal, requestToEdit = null }) {
|
||||
<div className="row my-2 text-start">
|
||||
<div className="col-md-6">
|
||||
<Label htmlFor="payee" className="form-label" required>
|
||||
Payee(Supplier Name/Transporter Name/Other)
|
||||
Payee (Supplier Name/Transporter Name/Other)
|
||||
</Label>
|
||||
<input
|
||||
type="text"
|
||||
id="payee"
|
||||
className="form-control form-control-sm"
|
||||
{...register("payee")}
|
||||
disabled={isItself}
|
||||
|
||||
/>
|
||||
{errors.payee && (
|
||||
<small className="danger-text">
|
||||
{errors.payee.message}
|
||||
</small>
|
||||
)}
|
||||
|
||||
{/* Checkbox below input */}
|
||||
<div className="form-check mt-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="sameAsSupplier"
|
||||
className="form-check-input"
|
||||
value={isItself}
|
||||
onChange={handleSetItSelf}
|
||||
/>
|
||||
<Label htmlFor="sameAsSupplier" className="form-check-label">
|
||||
Same as Supplier
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="col-md-6">
|
||||
<Label htmlFor="currencyId" className="form-label" required>
|
||||
|
||||
@ -7,7 +7,7 @@ const ALLOWED_TYPES = [
|
||||
"image/jpg",
|
||||
"image/jpeg",
|
||||
];
|
||||
export const PaymentRequestSchema = (expenseTypes) => {
|
||||
export const PaymentRequestSchema = (expenseTypes,isItself) => {
|
||||
return z
|
||||
.object({
|
||||
title: z.string().min(1, { message: "Project is required" }),
|
||||
@ -47,8 +47,11 @@ export const PaymentRequestSchema = (expenseTypes) => {
|
||||
description: z.string().optional(),
|
||||
isActive: z.boolean().default(true),
|
||||
})
|
||||
)
|
||||
,
|
||||
).refine((data)=>{
|
||||
if(isItself){
|
||||
payee.z.string().optional();
|
||||
}
|
||||
}),
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user