Refactor asset image handling in event theme form.
Some checks failed
Build and Push Docker Images / changes (push) Successful in 4s
Build and Push Docker Images / build-backend (push) Has been skipped
Build and Push Docker Images / build-frontend (push) Failing after 49s

Ensure asset_image_urls are merged instead of replaced during updates. Add a useEffect hook to log theme assets when editing an existing theme. These changes improve data handling consistency and debugging clarity.
This commit is contained in:
2025-03-14 05:10:02 +01:00
parent 9bf8025389
commit c82d80bc4c

View File

@@ -57,7 +57,9 @@ export function EventThemeForm({ theme, mode }: ThemeFormProps) {
background: "#FFFFFF",
text: "#1F2937",
},
asset_image_urls: theme?.asset_image_urls || {},
asset_image_urls: theme?.asset_image_urls
? { ...theme.asset_image_urls }
: {},
fonts: theme?.fonts || { heading: "Inter", body: "Inter" },
is_active: theme?.is_active !== undefined ? theme.is_active : true,
});
@@ -77,6 +79,11 @@ export function EventThemeForm({ theme, mode }: ThemeFormProps) {
value,
})),
);
useEffect(() => {
if (mode === "edit" && theme?.asset_image_urls) {
console.log("Theme assets loaded:", theme.asset_image_urls);
}
}, [theme, mode]);
// Submission state
const [isSubmitting, setIsSubmitting] = useState(false);
@@ -124,7 +131,11 @@ export function EventThemeForm({ theme, mode }: ThemeFormProps) {
// Handle asset images change
const handleAssetImagesChange = (assets: Record<string, string>) => {
setFormState((prev) => ({ ...prev, asset_image_urls: assets }));
setFormState((prev) => ({
...prev,
// Merge with existing assets rather than replacing
asset_image_urls: { ...prev.asset_image_urls, ...assets },
}));
};
// Add a new color input