Improve AI text generation on the new post page by parsing product details

Update `new-post.tsx` to parse product information from text input before sending to `/api/ai/generate` endpoint.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/sjuGm8z
This commit is contained in:
michaelschal committed 2025-10-02 13:12:41 +00:00
1 parent 874e0ad171
commit 0ab89b77c8
2 files changed
+11 -2

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 KiB

+11 -2
View File
@@ -35,8 +35,17 @@ export default function NewPost() {
});
const generateTextMutation = useMutation({
mutationFn: (productInfo: string) =>
apiRequest('POST', '/api/ai/generate', { productInfo }),
mutationFn: (productInfoText: string) => {
const productInfo = {
name: productInfoText.match(/Produit:\s*(.+?)(?:\n|$)/i)?.[1] ||
productInfoText.match(/Nom:\s*(.+?)(?:\n|$)/i)?.[1] ||
productInfoText,
price: productInfoText.match(/Prix:\s*(.+?)(?:\n|$)/i)?.[1] || "",
description: productInfoText.match(/Description:\s*(.+?)(?:\n|$)/i)?.[1] || "",
features: productInfoText.match(/Caractéristiques:\s*(.+?)(?:\n|$)/i)?.[1]?.split(",") || [],
};
return apiRequest('POST', '/api/ai/generate', productInfo);
},
onSuccess: (data: any) => {
const variants = data.variants || [];
setGeneratedVariants(variants);