diff --git a/src/components/Editing/Editing.tsx b/src/components/Editing/Editing.tsx index 03528b3e559ff67e137ac476d37841933315fa31..22a098db33e377b0e1c3a4a8266e7233f0c5f2ea 100644 --- a/src/components/Editing/Editing.tsx +++ b/src/components/Editing/Editing.tsx @@ -3,35 +3,16 @@ import 'react-datepicker/dist/react-datepicker.css' import { Editor } from '@tinymce/tinymce-react' import DateSelector from '../DateSelector/DateSelector' import './editing.scss' +import { EditorService } from '../../services/editor.service' const Editing: React.FC = () => { const [date, setDate] = useState<string>('') const [header, setHeader] = useState<string>('') const [quote, setQuote] = useState<string>('') - async function handleSave() { - try { - const response = await fetch( - 'https://localhost:1443/api/admin/monthlyNews', - { - method: 'POST', - body: JSON.stringify({ - month: date.split('-')[0], - year: date.split('-')[1], - header: header, - quote: quote, - }), - } - ) - if (response.status !== 201) { - throw new Error( - `Le post n'a pas pu être créé (code ${response.status})` - ) - } - console.log('Le post a été créé avec succès') - } catch (e) { - console.log(e) - } + const handleSave = async () => { + const editorService = new EditorService() + await editorService.sendQuotation(date, header, quote) } useEffect(() => { @@ -48,14 +29,9 @@ const Editing: React.FC = () => { </div> <div className="content"> <DateSelector date={date} setDate={setDate} /> - - <section className="hero is-small is-info"> - <div className="hero-body"> - <p className="title">Informations du mois</p> - <p className="subtitle"></p> - </div> - </section> - + <div className="subtitle"> + <p className="title">Informations du mois</p> + </div> <div> <Editor initialValue="" @@ -67,13 +43,9 @@ const Editing: React.FC = () => { value={header} onEditorChange={(newHeader, editor) => setHeader(newHeader)} /> - - <section className="hero is-small is-info"> - <div className="hero-body"> - <p className="title">Citation du mois</p> - <p className="subtitle"></p> - </div> - </section> + <div className="subtitle"> + <p className="title">Citation du mois</p> + </div> <Editor initialValue="" diff --git a/src/components/Editing/editing.scss b/src/components/Editing/editing.scss index ea763643b8a42bff837e56f05b60709e9b605043..1bebdaa739d7ad0a105922c5a6ac48e8fc2d3ccf 100644 --- a/src/components/Editing/editing.scss +++ b/src/components/Editing/editing.scss @@ -12,3 +12,6 @@ .content { padding: 1rem; } +.subtitle { + margin: 1rem 0; +} diff --git a/src/services/editor.service.ts b/src/services/editor.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..dbf75c2c412b6cab1bdce554fed31e9c8c14a934 --- /dev/null +++ b/src/services/editor.service.ts @@ -0,0 +1,36 @@ +export class EditorService { + /** + * Createsa quotation and header for selected month + * @param date + * @param header + * @param quote + */ + public sendQuotation = async ( + date: string, + header: string, + quote: string + ): Promise<void> => { + try { + const response = await fetch( + 'https://localhost:1443/api/admin/monthlyNews', + { + method: 'POST', + body: JSON.stringify({ + month: date.split('-')[0], + year: date.split('-')[1], + header: header, + quote: quote, + }), + } + ) + if (response.status !== 201) { + throw new Error( + `Le post n'a pas pu être créé (code ${response.status})` + ) + } + console.log('Le post a été créé avec succès') + } catch (e) { + console.log(e) + } + } +}