feat(ui): integrate RichTextEditor for product full description and add click-outside handlers for dropdowns
This commit is contained in:
1 parent
1651a593bd
commit
bfb7f42065
18 files changed
+150012
-5970
No files matched your search
@@ -87,6 +87,22 @@ export default function RichTextEditor({
|
||||
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||
const [showColorPicker, setShowColorPicker] = useState(false);
|
||||
const [showBgColorPicker, setShowBgColorPicker] = useState(false);
|
||||
const colorPickerRef = useRef<HTMLDivElement>(null);
|
||||
const bgColorPickerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (colorPickerRef.current && !colorPickerRef.current.contains(event.target as Node)) {
|
||||
setShowColorPicker(false);
|
||||
}
|
||||
if (bgColorPickerRef.current && !bgColorPickerRef.current.contains(event.target as Node)) {
|
||||
setShowBgColorPicker(false);
|
||||
}
|
||||
};
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
||||
}, []);
|
||||
|
||||
const [customColor, setCustomColor] = useState('#111827');
|
||||
const [customBgColor, setCustomBgColor] = useState('#fef08a');
|
||||
|
||||
@@ -608,7 +624,7 @@ export default function RichTextEditor({
|
||||
</div>
|
||||
|
||||
{/* Text Color Picker */}
|
||||
<div className="relative">
|
||||
<div ref={colorPickerRef} className="relative">
|
||||
<button
|
||||
type="button"
|
||||
disabled={isCodeMode}
|
||||
@@ -674,7 +690,7 @@ export default function RichTextEditor({
|
||||
</div>
|
||||
|
||||
{/* Background Color Picker */}
|
||||
<div className="relative">
|
||||
<div ref={bgColorPickerRef} className="relative">
|
||||
<button
|
||||
type="button"
|
||||
disabled={isCodeMode}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { Search, Filter, Box, Plus, Edit2, Trash2, Image as ImageIcon, X, HelpCircle, ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
@@ -9,6 +9,7 @@ import MediaSelector from '../components/ui/MediaSelector';
|
||||
import ConfirmModal from '../components/ui/ConfirmModal';
|
||||
import PriceInput from '../components/ui/PriceInput';
|
||||
import Button from '../components/ui/Button';
|
||||
import RichTextEditor from '../components/ui/RichTextEditor';
|
||||
|
||||
|
||||
|
||||
@@ -127,6 +128,18 @@ export default function Products() {
|
||||
]);
|
||||
const [symptomInput, setSymptomInput] = useState('');
|
||||
const [showSymptomSuggestions, setShowSymptomSuggestions] = useState(false);
|
||||
const symptomContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (symptomContainerRef.current && !symptomContainerRef.current.contains(event.target as Node)) {
|
||||
setShowSymptomSuggestions(false);
|
||||
}
|
||||
};
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
||||
}, []);
|
||||
|
||||
const limit = 10;
|
||||
|
||||
// Sync state changes to URL search params
|
||||
@@ -858,7 +871,12 @@ export default function Products() {
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
<textarea rows={5} value={formData.description} onChange={(e) => setFormData({ ...formData, description: e.target.value })} className="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-purple-500 outline-none"></textarea>
|
||||
<RichTextEditor
|
||||
value={formData.description || ''}
|
||||
onChange={(val) => setFormData({ ...formData, description: val })}
|
||||
placeholder="توضیحات کامل علمی، نحوه عملکرد مکمل و جزئیات ترکیبات محصول را وارد کنید..."
|
||||
minHeight="min-h-[250px]"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<label className="text-sm font-bold text-gray-700 flex items-center gap-1.5">
|
||||
@@ -898,7 +916,7 @@ export default function Products() {
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
<div className="relative flex-1 min-w-[200px]">
|
||||
<div ref={symptomContainerRef} className="relative flex-1 min-w-[200px]">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="جستجو یا تایپ علامت جدید..."
|
||||
|
||||
Reference in new issue
Block a user