Skip to content
Snippets Groups Projects
Commit a4ff8eb9 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

Add editor service

parent ff951e87
No related branches found
No related tags found
Loading
...@@ -3,35 +3,16 @@ import 'react-datepicker/dist/react-datepicker.css' ...@@ -3,35 +3,16 @@ import 'react-datepicker/dist/react-datepicker.css'
import { Editor } from '@tinymce/tinymce-react' import { Editor } from '@tinymce/tinymce-react'
import DateSelector from '../DateSelector/DateSelector' import DateSelector from '../DateSelector/DateSelector'
import './editing.scss' import './editing.scss'
import { EditorService } from '../../services/editor.service'
const Editing: React.FC = () => { const Editing: React.FC = () => {
const [date, setDate] = useState<string>('') const [date, setDate] = useState<string>('')
const [header, setHeader] = useState<string>('') const [header, setHeader] = useState<string>('')
const [quote, setQuote] = useState<string>('') const [quote, setQuote] = useState<string>('')
async function handleSave() { const handleSave = async () => {
try { const editorService = new EditorService()
const response = await fetch( await editorService.sendQuotation(date, header, quote)
'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)
}
} }
useEffect(() => { useEffect(() => {
...@@ -48,14 +29,9 @@ const Editing: React.FC = () => { ...@@ -48,14 +29,9 @@ const Editing: React.FC = () => {
</div> </div>
<div className="content"> <div className="content">
<DateSelector date={date} setDate={setDate} /> <DateSelector date={date} setDate={setDate} />
<div className="subtitle">
<section className="hero is-small is-info"> <p className="title">Informations du mois</p>
<div className="hero-body"> </div>
<p className="title">Informations du mois</p>
<p className="subtitle"></p>
</div>
</section>
<div> <div>
<Editor <Editor
initialValue="" initialValue=""
...@@ -67,13 +43,9 @@ const Editing: React.FC = () => { ...@@ -67,13 +43,9 @@ const Editing: React.FC = () => {
value={header} value={header}
onEditorChange={(newHeader, editor) => setHeader(newHeader)} onEditorChange={(newHeader, editor) => setHeader(newHeader)}
/> />
<div className="subtitle">
<section className="hero is-small is-info"> <p className="title">Citation du mois</p>
<div className="hero-body"> </div>
<p className="title">Citation du mois</p>
<p className="subtitle"></p>
</div>
</section>
<Editor <Editor
initialValue="" initialValue=""
......
...@@ -12,3 +12,6 @@ ...@@ -12,3 +12,6 @@
.content { .content {
padding: 1rem; padding: 1rem;
} }
.subtitle {
margin: 1rem 0;
}
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)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment