From cefaf3a8506c1687b8d3bfcf79818133ff867df2 Mon Sep 17 00:00:00 2001 From: Kailasdevdas Date: Mon, 25 May 2026 11:37:51 +0530 Subject: [PATCH] fix: optional price fields --- frontend/src/api/healthCheck.ts | 2 +- frontend/src/pages/HealthPackagePage.tsx | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/frontend/src/api/healthCheck.ts b/frontend/src/api/healthCheck.ts index ae5430e..d6eb04a 100644 --- a/frontend/src/api/healthCheck.ts +++ b/frontend/src/api/healthCheck.ts @@ -6,7 +6,7 @@ export interface HealthPackage { name: string; slug: string; description?: string; - price: number; + price?: number; image?: string; discountedPrice?: number; inclusions: Record; diff --git a/frontend/src/pages/HealthPackagePage.tsx b/frontend/src/pages/HealthPackagePage.tsx index c6d471b..e2efc84 100644 --- a/frontend/src/pages/HealthPackagePage.tsx +++ b/frontend/src/pages/HealthPackagePage.tsx @@ -270,10 +270,6 @@ export default function HealthPackagePage() { if (!pkgForm.slug?.trim()) return toast.error("URL Slug is required."); if (!pkgForm.categoryId) return toast.error("Please select a valid category."); - if (pkgForm.price === undefined || pkgForm.price <= 0) - return toast.error( - "Regular Price must be a valid amount greater than 0.", - ); if (!pkgForm.description?.trim()) return toast.error("Description is required."); @@ -299,8 +295,18 @@ export default function HealthPackagePage() { } }); - const finalData = { ...pkgForm, inclusions: parsedInclusions }; + const finalData: Partial = { + ...pkgForm, + inclusions: parsedInclusions, + }; + if (!finalData.price) { + delete finalData.price; + } + + if (!finalData.discountedPrice) { + delete finalData.discountedPrice; + } if (editingPackage?.id) { const changedFields: Record = {}; Object.keys(finalData).forEach((key) => { @@ -836,7 +842,9 @@ export default function HealthPackagePage() { onChange={(e) => setPkgForm({ ...pkgForm, - price: Number(e.target.value), + price: e.target.value + ? Number(e.target.value) + : undefined, }) } className="text-base" @@ -852,7 +860,9 @@ export default function HealthPackagePage() { onChange={(e) => setPkgForm({ ...pkgForm, - discountedPrice: Number(e.target.value), + discountedPrice: e.target.value + ? Number(e.target.value) + : undefined, }) } className="text-base" -- 2.43.0