fix: optional price fields

This commit is contained in:
Kailasdevdas
2026-05-25 11:37:51 +05:30
parent 120ff12fef
commit cefaf3a850
2 changed files with 18 additions and 8 deletions
+17 -7
View File
@@ -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<HealthPackage> = {
...pkgForm,
inclusions: parsedInclusions,
};
if (!finalData.price) {
delete finalData.price;
}
if (!finalData.discountedPrice) {
delete finalData.discountedPrice;
}
if (editingPackage?.id) {
const changedFields: Record<string, any> = {};
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"