Refactor asset image handling in event theme form.
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user