Skip to content
Snippets Groups Projects
MonthlyNews.tsx 3.93 KiB
Newer Older
  • Learn to ignore specific revisions
  • Guilhem CARRON's avatar
    Guilhem CARRON committed
    import { Editor } from '@tinymce/tinymce-react'
    import React from 'react'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import { ContentItems } from '../Editing/Editing'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    interface MonthlyNewsProps {
    
      onSave: () => Promise<void>
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      onCancel: () => void
      header: string
      quote: string
      handleChange: (
        value: string,
        type: 'header' | 'quote' | 'question' | 'link'
      ) => void
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      onDelete: (target: ContentItems) => void
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    }
    const MonthlyNews: React.FC<MonthlyNewsProps> = ({
      onSave,
      onCancel,
      header,
      quote,
      handleChange,
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    }: MonthlyNewsProps) => {
      return (
        <>
          <div className="subtitle">
            <p className="title">Informations du mois</p>
          </div>
          <div>
            <Editor
              init={{
                menubar: false,
                toolbar:
                  'undo redo | bold italic underline | alignleft aligncenter alignright | code | ecolyoLink',
              }}
              value={header}
    
              onEditorChange={(newHeader: string) =>
                handleChange(newHeader, 'header')
              }
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            />
            <div className="subtitle">
              <p className="title">Citation du mois</p>
            </div>
    
            <Editor
              init={{
                menubar: false,
                toolbar:
                  'undo redo | bold italic underline | alignleft aligncenter alignright | code | ecolyoLink',
                setup: function (editor) {
                  editor.ui.registry.addMenuButton('ecolyoLink', {
                    text: 'Lien Ecolyo',
                    fetch: function (callback) {
                      var items: any = [
                        {
                          type: 'menuitem',
                          text: 'consumption',
                          onAction: function () {
                            editor.insertContent(
                              '&nbsp;<a href="https://ecolyo.{cozyUrl}/consumption">Page de consommation</a>'
                            )
                          },
                        },
                        {
                          type: 'menuitem',
                          text: 'challenges',
                          onAction: function () {
                            editor.insertContent(
                              '&nbsp;<a href="https://ecolyo.{cozyUrl}/challenges">Page challenges</a>'
                            )
                          },
                        },
                        {
                          type: 'menuitem',
                          text: 'ecogestures',
                          onAction: function () {
                            editor.insertContent(
                              '&nbsp;<a href="https://ecolyo.{cozyUrl}/ecogestures">Page ecogestures</a>'
                            )
                          },
                        },
                        {
                          type: 'menuitem',
                          text: 'analysis',
                          onAction: function () {
                            editor.insertContent(
                              '&nbsp;<a href="https://ecolyo.{cozyUrl}/analysis">Page analyse</a>'
                            )
                          },
                        },
                        {
                          type: 'menuitem',
                          text: 'options',
                          onAction: function () {
                            editor.insertContent(
                              '&nbsp;<a href="https://ecolyo.{cozyUrl}/options">Page options</a>'
                            )
                          },
                        },
                      ]
                      callback(items)
                    },
                  })
                },
              }}
              value={quote}
    
              onEditorChange={(newQuote: string) => handleChange(newQuote, 'quote')}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            />
    
            <div className="buttons">
              <button className="btnCancel" onClick={onCancel}>
                Annuler
              </button>
              <button className="btnValid" onClick={onSave}>
                Sauvegarder
              </button>
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
              <button className="btnDelete" onClick={() => onDelete('monthlyNews')}>
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          </div>
        </>
      )
    }
    
    export default MonthlyNews