@consilioweb/payload-support 0.9.10 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -136,7 +136,9 @@ export const TicketDetailClient: React.FC = () => {
136
136
  // Inline message edit
137
137
  const [editingMsgId, setEditingMsgId] = useState<string | number | null>(null)
138
138
  const [editingBody, setEditingBody] = useState('')
139
+ const [editingHtml, setEditingHtml] = useState('')
139
140
  const [editSaving, setEditSaving] = useState(false)
141
+ const editEditorRef = useRef<RichTextEditorHandle>(null)
140
142
  const [sending, setSending] = useState(false)
141
143
 
142
144
  const [showMenu, setShowMenu] = useState(false)
@@ -449,11 +451,14 @@ const [clientTyping, setClientTyping] = useState(false)
449
451
  const startEditMessage = (msg: Message) => {
450
452
  setEditingMsgId(msg.id)
451
453
  setEditingBody(msg.body || '')
454
+ // Prefer existing bodyHtml for WYSIWYG edit, fallback to body with <br/> conversion
455
+ setEditingHtml(msg.bodyHtml || (msg.body || '').replace(/\n/g, '<br/>'))
452
456
  }
453
457
 
454
458
  const cancelEditMessage = () => {
455
459
  setEditingMsgId(null)
456
460
  setEditingBody('')
461
+ setEditingHtml('')
457
462
  }
458
463
 
459
464
  const saveEditMessage = async () => {
@@ -464,11 +469,12 @@ const [clientTyping, setClientTyping] = useState(false)
464
469
  method: 'PATCH',
465
470
  headers: { 'Content-Type': 'application/json' },
466
471
  credentials: 'include',
467
- body: JSON.stringify({ body: editingBody, bodyHtml: null, skipNotification: true }),
472
+ body: JSON.stringify({ body: editingBody, bodyHtml: editingHtml || null, skipNotification: true }),
468
473
  })
469
474
  if (res.ok) {
470
475
  setEditingMsgId(null)
471
476
  setEditingBody('')
477
+ setEditingHtml('')
472
478
  fetchAll()
473
479
  }
474
480
  } catch { /* silent */ } finally {
@@ -654,11 +660,23 @@ const [clientTyping, setClientTyping] = useState(false)
654
660
  </div>
655
661
  {editingMsgId === msg.id ? (
656
662
  <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
657
- <textarea
658
- value={editingBody}
659
- onChange={(e) => setEditingBody(e.target.value)}
660
- style={{ width: '100%', minHeight: 120, padding: 10, fontSize: 13, lineHeight: 1.5, fontFamily: 'inherit', border: '1px solid var(--theme-elevation-200)', borderRadius: 6, background: 'var(--theme-elevation-0)', color: 'var(--theme-text)' }}
661
- autoFocus
663
+ <RichTextEditor
664
+ ref={editEditorRef}
665
+ initialValue={editingHtml}
666
+ onChange={(html, text) => { setEditingHtml(html); setEditingBody(text) }}
667
+ placeholder="Éditer le message..."
668
+ minHeight={120}
669
+ onFileUpload={async (file) => {
670
+ try {
671
+ const formData = new FormData()
672
+ formData.append('file', file)
673
+ formData.append('_payload', JSON.stringify({ alt: file.name }))
674
+ const ur = await fetch('/api/media', { method: 'POST', credentials: 'include', body: formData })
675
+ if (!ur.ok) return null
676
+ const ud = await ur.json()
677
+ return ud.doc?.url || null
678
+ } catch { return null }
679
+ }}
662
680
  />
663
681
  <div style={{ display: 'flex', gap: 6, justifyContent: 'flex-end' }}>
664
682
  <button onClick={cancelEditMessage} disabled={editSaving} style={{ padding: '5px 12px', fontSize: 12, borderRadius: 5, border: '1px solid var(--theme-elevation-200)', background: 'var(--theme-elevation-0)', color: 'var(--theme-text)', cursor: 'pointer' }}>Annuler</button>