Problem: When uploading an image in the confirmation dialog, it was being added to the background chat instead of staying in the dialog.
Root Cause: The dialog was using the same file input and state as the main chat interface, causing the image to appear in the chat messages.
Solution: Created separate state management and file input specifically for the dialog.
Before:
// Single state for both chat and dialog
const [selectedImage, setSelectedImage] = useState(null);
const [imagePreview, setImagePreview] = useState(null);
const fileInputRef = useRef(null);After:
// Separate states for chat and dialog
const [selectedImage, setSelectedImage] = useState(null);
const [imagePreview, setImagePreview] = useState(null);
const [selectedImageForPost, setSelectedImageForPost] = useState(null);
const [dialogImagePreview, setDialogImagePreview] = useState(null); // NEW
const fileInputRef = useRef(null);
const dialogFileInputRef = useRef(null); // NEWChat Image Handler:
const handleImageSelect = (e) => {
const file = e.target.files[0];
if (file) {
setSelectedImage(file);
const reader = new FileReader();
reader.onloadend = () => {
setImagePreview(reader.result);
};
reader.readAsDataURL(file);
}
};Dialog Image Handler (NEW):
const handleDialogImageSelect = (e) => {
const file = e.target.files[0];
if (file) {
setSelectedImageForPost(file);
const reader = new FileReader();
reader.onloadend = () => {
setDialogImagePreview(reader.result); // Separate preview
};
reader.readAsDataURL(file);
}
};
const removeDialogImage = () => {
setSelectedImageForPost(null);
setDialogImagePreview(null);
if (dialogFileInputRef.current) {
dialogFileInputRef.current.value = "";
}
};{/* Image Preview and Upload in Dialog */}
<div className="mb-4">
{selectedImageForPost && dialogImagePreview ? (
// Show image preview with remove button
<div className="relative inline-block">
<img
src={dialogImagePreview} {/* Uses dialog-specific preview */}
alt="Post attachment"
className="max-h-48 rounded-xl border border-zinc-700"
/>
<button
onClick={removeDialogImage} {/* Dialog-specific remove */}
className="absolute -top-2 -right-2 bg-red-500 hover:bg-red-600 text-white rounded-full p-1.5"
>
<X size={14} />
</button>
</div>
) : (
// Show upload button
<div>
<input
ref={dialogFileInputRef} {/* Separate file input */}
type="file"
accept="image/*"
onChange={handleDialogImageSelect} {/* Dialog-specific handler */}
className="hidden"
id="dialog-image-upload"
/>
<label htmlFor="dialog-image-upload">
<ImagePlus size={18} />
Add Image to Post
</label>
</div>
)}
</div>1. User creates post (with or without image)
2. AI generates response
3. User clicks "Post to LinkedIn"
4. Confirmation dialog opens
✅ If image was attached, shows in dialog
✅ If no image, shows "Add Image to Post" button
5. User clicks "Add Image to Post"
✅ File picker opens
✅ User selects image
✅ Image preview appears IN THE DIALOG
✅ Background chat remains unchanged
6. User can:
- Remove image (X button)
- Upload different image
- Refine post (image stays attached)
- Post to LinkedIn with image
7. After posting:
✅ Dialog closes
✅ Dialog image state cleared
✅ Success message in chat
[Dialog Opens]
User clicks "Add Image"
→ Image appears in BACKGROUND CHAT ❌
→ Dialog doesn't show image ❌
→ Confusing UX ❌
[Dialog Opens]
User clicks "Add Image"
→ File picker opens ✅
→ Image preview appears IN DIALOG ✅
→ Background chat unchanged ✅
→ Can remove/change image IN DIALOG ✅
→ Posts with image to LinkedIn ✅
selectedImage- Image selected in main chatimagePreview- Preview for main chatfileInputRef- File input for main chathandleImageSelect()- Handler for main chatremoveImage()- Remove from main chat
selectedImageForPost- Image for postingdialogImagePreview- Preview for dialog onlydialogFileInputRef- File input for dialog onlyhandleDialogImageSelect()- Handler for dialog onlyremoveDialogImage()- Remove from dialog only
// When opening dialog
handlePostToLinkedIn(postContent) {
setSelectedPostForPublish(postContent);
// Transfer existing image to dialog if available
if (selectedImageForPost && imagePreview) {
setDialogImagePreview(imagePreview);
}
setShowConfirmDialog(true);
}
// When uploading in dialog
handleDialogImageSelect(e) {
const file = e.target.files[0];
setSelectedImageForPost(file);
setDialogImagePreview(preview); // Only affects dialog
}
// When closing dialog
onCancel() {
setShowConfirmDialog(false);
setDialogImagePreview(null); // Clear dialog state
}
// When posting
onPost() {
await postsAPI.createPost(content, selectedImageForPost);
setDialogImagePreview(null); // Clear dialog state
setSelectedImageForPost(null);
}1. Create post without image
2. Click "Post to LinkedIn"
3. ✅ Dialog opens with "Add Image to Post" button
4. Click "Add Image to Post"
5. ✅ File picker opens
6. Select image
7. ✅ Image preview appears IN DIALOG
8. ✅ Background chat unchanged
9. ✅ Can see post content and image together
10. Post to LinkedIn
11. ✅ Both posted successfully
1. Upload image in main chat
2. Create post about image
3. Click "Post to LinkedIn"
4. ✅ Dialog shows existing image
5. Click X to remove
6. ✅ Image removed from dialog
7. Click "Add Image to Post"
8. Select different image
9. ✅ New image shows in dialog
10. ✅ Background chat unchanged
11. Post to LinkedIn
12. ✅ New image posted
1. Open dialog with image
2. Click X to remove
3. ✅ Image removed
4. ✅ "Add Image to Post" button appears
5. Click button, select new image
6. ✅ New image appears
7. Click X again
8. ✅ Image removed
9. Click button, select another image
10. ✅ Third image appears
11. Post to LinkedIn
12. ✅ Latest image posted
1. Upload image in dialog
2. ✅ Image shows in dialog
3. Type refinement: "Make it shorter"
4. Click "Refine"
5. ✅ AI refines post
6. ✅ Image still visible in dialog
7. ✅ Image context maintained
8. Post to LinkedIn
9. ✅ Refined post + image posted
1. Upload image in dialog
2. ✅ Image shows
3. Click "Cancel"
4. ✅ Dialog closes
5. ✅ Background chat unchanged
6. Open dialog again
7. ✅ No image (state cleared)
8. ✅ Can upload fresh
- ✅ Upload button works in dialog
- ✅ Image preview appears IN DIALOG
- ✅ Background chat not affected
- ✅ Can remove and re-upload
- ✅ Image maintained during refinements
- ✅ Separate state for dialog
- ✅ Separate file input for dialog
- ✅ No interference with main chat
- ✅ Clean state on dialog close
- ✅ Clean state after posting
- ✅ Clear visual feedback
- ✅ Intuitive upload process
- ✅ Can see image before posting
- ✅ Easy to change image
- ✅ Smooth workflow
The dialog image upload now works perfectly:
- ✅ Images stay in the dialog
- ✅ Background chat unaffected
- ✅ Can upload, remove, re-upload
- ✅ Image maintained during refinements
- ✅ Posts correctly to LinkedIn
- ✅ Clean state management
Ready to use! 🚀