fix
This commit is contained in:
@@ -369,8 +369,87 @@ export default function CmsPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
function validateContent(): string | null {
|
||||||
|
if (!editContent) return null;
|
||||||
|
const c = editContent as any;
|
||||||
|
|
||||||
|
// Validate Featured Agents (all fields required)
|
||||||
|
if (Array.isArray(c.featuredAgents)) {
|
||||||
|
for (let i = 0; i < c.featuredAgents.length; i++) {
|
||||||
|
const a = c.featuredAgents[i];
|
||||||
|
if (!a.name?.trim()) return `Featured Agent #${i + 1}: Name is required`;
|
||||||
|
if (!a.role?.trim()) return `Featured Agent #${i + 1}: Role is required`;
|
||||||
|
if (!a.rating?.toString().trim()) return `Featured Agent #${i + 1}: Rating is required`;
|
||||||
|
if (!a.location?.trim()) return `Featured Agent #${i + 1}: Location is required`;
|
||||||
|
if (!a.experience?.trim()) return `Featured Agent #${i + 1}: Experience is required`;
|
||||||
|
if (!a.imageUrl?.trim()) return `Featured Agent #${i + 1}: Photo is required`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate Features
|
||||||
|
if (Array.isArray(c.features)) {
|
||||||
|
for (let i = 0; i < c.features.length; i++) {
|
||||||
|
const f = c.features[i];
|
||||||
|
if (!f.title?.trim()) return `Feature #${i + 1}: Title is required`;
|
||||||
|
if (!f.description?.trim()) return `Feature #${i + 1}: Description is required`;
|
||||||
|
if (!f.iconPath?.trim()) return `Feature #${i + 1}: Icon is required`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate Top Professionals agents (all fields required)
|
||||||
|
if (Array.isArray(c.agents)) {
|
||||||
|
for (let i = 0; i < c.agents.length; i++) {
|
||||||
|
const a = c.agents[i];
|
||||||
|
if (!a.name?.trim()) return `Agent #${i + 1}: Name is required`;
|
||||||
|
if (!a.subtitle?.trim()) return `Agent #${i + 1}: Subtitle is required`;
|
||||||
|
if (!a.location?.trim()) return `Agent #${i + 1}: Location is required`;
|
||||||
|
if (!a.experience?.trim()) return `Agent #${i + 1}: Experience is required`;
|
||||||
|
if (!Array.isArray(a.expertise) || a.expertise.length === 0 || a.expertise.every((e: string) => !e?.trim())) {
|
||||||
|
return `Agent #${i + 1}: At least one expertise is required`;
|
||||||
|
}
|
||||||
|
if (!a.imageUrl?.trim()) return `Agent #${i + 1}: Photo is required`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate Top Professionals lenders (all fields required)
|
||||||
|
if (Array.isArray(c.lenders)) {
|
||||||
|
for (let i = 0; i < c.lenders.length; i++) {
|
||||||
|
const l = c.lenders[i];
|
||||||
|
if (!l.name?.trim()) return `Lender #${i + 1}: Name is required`;
|
||||||
|
if (!l.subtitle?.trim()) return `Lender #${i + 1}: Subtitle is required`;
|
||||||
|
if (!l.location?.trim()) return `Lender #${i + 1}: Location is required`;
|
||||||
|
if (!l.experience?.trim()) return `Lender #${i + 1}: Experience is required`;
|
||||||
|
if (!Array.isArray(l.expertise) || l.expertise.length === 0 || l.expertise.every((e: string) => !e?.trim())) {
|
||||||
|
return `Lender #${i + 1}: At least one expertise is required`;
|
||||||
|
}
|
||||||
|
if (!l.imageUrl?.trim()) return `Lender #${i + 1}: Photo is required`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate testimonials
|
||||||
|
if (Array.isArray(c.testimonials)) {
|
||||||
|
for (let i = 0; i < c.testimonials.length; i++) {
|
||||||
|
const t = c.testimonials[i];
|
||||||
|
if (!t.author?.trim()) return `Testimonial #${i + 1}: Author is required`;
|
||||||
|
if (!t.content?.trim()) return `Testimonial #${i + 1}: Content is required`;
|
||||||
|
if (!t.title?.trim()) return `Testimonial #${i + 1}: Title is required`;
|
||||||
|
if (!t.role?.trim()) return `Testimonial #${i + 1}: Role is required`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
if (!editingSection || editContent == null) return;
|
if (!editingSection || editContent == null) return;
|
||||||
|
|
||||||
|
// Validate before saving
|
||||||
|
const validationError = validateContent();
|
||||||
|
if (validationError) {
|
||||||
|
setModalError(validationError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
setModalError('');
|
setModalError('');
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user