diff --git a/src/components/Expenses/Filelist.jsx b/src/components/Expenses/Filelist.jsx index c91c044d..c9c3ce8e 100644 --- a/src/components/Expenses/Filelist.jsx +++ b/src/components/Expenses/Filelist.jsx @@ -3,7 +3,6 @@ import { formatFileSize, getIconByFileType } from "../../utils/appUtils"; import Tooltip from "../common/Tooltip"; const Filelist = ({ files, removeFile, expenseToEdit, sm = 6, md = 4 }) => { - debugger return (
{files @@ -23,15 +22,15 @@ const Filelist = ({ files, removeFile, expenseToEdit, sm = 6, md = 4 }) => { style={{ minWidth: "30px" }} > - +
- - {file.fileName} - - - {file.fileSize ? formatFileSize(file.fileSize) : ""} - -
+ + {file.fileName} + + + {file.fileSize ? formatFileSize(file.fileSize) : ""} + +
@@ -42,7 +41,7 @@ const Filelist = ({ files, removeFile, expenseToEdit, sm = 6, md = 4 }) => { role="button" onClick={(e) => { e.preventDefault(); - removeFile(expenseToEdit ? file.documentId : idx); + removeFile(expenseToEdit ? file.documentId ?? idx : idx); }} > diff --git a/src/components/InfoBlock/WarningBlock.jsx b/src/components/InfoBlock/WarningBlock.jsx new file mode 100644 index 00000000..6c756593 --- /dev/null +++ b/src/components/InfoBlock/WarningBlock.jsx @@ -0,0 +1,16 @@ +import React from 'react' + +const WarningBlock = ({content}) => { + return ( +
+
+ +

+ {content} +

+
+
+ ) +} + +export default WarningBlock diff --git a/src/components/purchase/DeliveryChallane.jsx b/src/components/purchase/DeliveryChallane.jsx index 1600b77d..834f049d 100644 --- a/src/components/purchase/DeliveryChallane.jsx +++ b/src/components/purchase/DeliveryChallane.jsx @@ -19,6 +19,8 @@ import SelectField from "../common/Forms/SelectField"; import Filelist from "../Expenses/Filelist"; import SingleFileUploader from "../common/SigleFileUploader"; import { localToUtc } from "../../utils/appUtils"; +import WarningBlock from "../InfoBlock/WarningBlock"; +import { FILE_UPLOAD_INFO } from "../../utils/staticContent"; const DeliveryChallane = ({ purchaseId }) => { const [file, setFile] = useState(null); @@ -178,15 +180,7 @@ const DeliveryChallane = ({ purchaseId }) => { {!isUploaded && ( -
-
- -

- If want upload document, Please select a document type before - uploading the document. -

-
-
+ )} diff --git a/src/components/purchase/ManagePurchase.jsx b/src/components/purchase/ManagePurchase.jsx index a011a3c7..b4df00ca 100644 --- a/src/components/purchase/ManagePurchase.jsx +++ b/src/components/purchase/ManagePurchase.jsx @@ -36,7 +36,7 @@ const ManagePurchase = ({ onClose, purchaseId }) => { name: "Payment Details", icon: "bx bx-credit-card bx-md", subtitle: "Amount, tax & due date", - component: , + component: , }, ]; @@ -65,17 +65,18 @@ const ManagePurchase = ({ onClose, purchaseId }) => { fileName: doc.fileName, base64Data: null, contentType: doc.contentType, - documentId: doc.id, + documentId: doc.documentId, + invoiceAttachmentTypeId:doc.invoiceAttachmentTypeId ?? null, fileSize: 0, description: "", preSignedUrl: doc.preSignedUrl, isActive: doc.isActive ?? true, })) - : [] + : [], }); setCompletedTabs([0, 1, 2]); } - }, [purchaseId, data, reset]); + }, []); const handleNext = async (e) => { e.preventDefault(); @@ -117,7 +118,8 @@ const ManagePurchase = ({ onClose, purchaseId }) => { if (purchaseId) { const changedData = Object.keys(dirtyFields).reduce((acc, key) => { - if (dirtyFields[key]) { + debugger; + if (dirtyFields[key] && key !== "invoiceAttachmentTypeId") { acc.push({ operationType: 0, path: `/${key}`, @@ -128,15 +130,16 @@ const ManagePurchase = ({ onClose, purchaseId }) => { } return acc; }, []); - - updatePurchase({ - purchaseId, - payload: changedData, - }); + console.log(changedData) + // updatePurchase({ + // purchaseId, + // payload: changedData, + // }); } else { CreateInvoice(formData); } }; + console.log(errors) return (
{ onClick={handleNext} disabled={isPending || isUpdating} > - Next + Next ) : (
diff --git a/src/components/purchase/PurchaseSchema.jsx b/src/components/purchase/PurchaseSchema.jsx index cce47575..2fc1cead 100644 --- a/src/components/purchase/PurchaseSchema.jsx +++ b/src/components/purchase/PurchaseSchema.jsx @@ -10,10 +10,9 @@ const ALLOWED_TYPES = [ ]; export const AttachmentSchema = z.object({ - documentId: z.string().optional(), - invoiceAttachmentTypeId: z.string().min(1, { message: "Attachment type is required" }), + invoiceAttachmentTypeId: z.string().nullable(), fileName: z.string().min(1, { message: "Filename is required" }), - base64Data: z.string().min(1, { message: "File data is required" }), + base64Data: z.string().nullable(), contentType: z .string() .refine((val) => ALLOWED_TYPES.includes(val), { @@ -25,39 +24,7 @@ export const AttachmentSchema = z.object({ description: z.string().optional().default(""), isActive: z.boolean().default(true), }); -// export const AttachmentSchema = (allowedContentType, maxSizeAllowedInMB) => { -// const allowedTypes = normalizeAllowedContentTypes(allowedContentType); -// return z.object({ -// fileName: z.string().min(1, { message: "File name is required" }), -// base64Data: z.string().min(1, { message: "File data is required" }), -// invoiceAttachmentTypeId: z -// .string() -// .min(1, { message: "File data is required" }), - -// contentType: z -// .string() -// .min(1, { message: "MIME type is required" }) -// .refine( -// (val) => (allowedTypes.length ? allowedTypes.includes(val) : true), -// { -// message: `File type must be one of: ${allowedTypes.join(", ")}`, -// } -// ), - -// fileSize: z -// .number() -// .int() -// .nonnegative("fileSize must be ≥ 0") -// .max( -// (maxSizeAllowedInMB ?? 25) * 1024 * 1024, -// `fileSize must be ≤ ${maxSizeAllowedInMB ?? 25}MB` -// ), - -// description: z.string().optional().default(""), -// isActive: z.boolean(), -// }); -// }; export const PurchaseSchema = z.object({ title: z.string().min(1, { message: "Title is required" }), @@ -89,9 +56,10 @@ export const PurchaseSchema = z.object({ paymentDueDate: z.coerce.date().nullable(), transportCharges: z.number().nullable(), description: z.string().min(1, { message: "Description is required" }), + invoiceAttachmentTypeId:z.string().nullable(), attachments: z .array(AttachmentSchema) - .nonempty({ message: "At least one file attachment is required" }), + }); @@ -130,9 +98,8 @@ export const defaultPurchaseValue = { paymentDueDate: null, transportCharges: null, description: "", + invoiceAttachmentTypeId:null, attachments: [], - - // attachments: [], }; export const getStepFields = (stepIndex) => { @@ -165,7 +132,9 @@ export const getStepFields = (stepIndex) => { "totalAmount", "transportCharges", "paymentDueDate", + "invoiceAttachmentTypeId", "description", + "attachments" ], }; diff --git a/src/utils/staticContent.jsx b/src/utils/staticContent.jsx new file mode 100644 index 00000000..5e4b5783 --- /dev/null +++ b/src/utils/staticContent.jsx @@ -0,0 +1,4 @@ +export const FILE_UPLOAD_INFO = ` +If you want to upload a document, please select a document type +before uploading the document. +`;