Newer
Older
import React, { useState } from 'react'
import DatePicker from 'react-datepicker'
import 'react-datepicker/dist/react-datepicker.css'
import { Editor } from '@tinymce/tinymce-react'
const Editing: React.FC = () => {
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const [date, setDate] = useState<Date>(new Date())
const [header, setHeader] = useState<string>('')
const [quote, setQuote] = useState<string>('')
const months = [
'Janvier',
'Février',
'Mars',
'Avril',
'Mai',
'Juin',
'Juillet',
'Août',
'Septembre',
'Octobre',
'Novembre',
'Décembre',
]
const locale = {
localize: {
month: (n: number) => months[n],
},
formatLong: {},
}
async function handleSave() {
try {
const response = await fetch(
'https://localhost:1443/api/admin/monthlyNews',
{
method: 'POST',
body: JSON.stringify({
month: date.getMonth(),
year: date.getFullYear(),
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)
}
}
return (
<>
<DatePicker
selected={date}
onChange={(date: React.SetStateAction<Date>) => setDate(date)}
dateFormat="MM/yyyy"
showMonthYearPicker
showFullMonthYearPicker
locale={locale}
/>
<section className="hero is-link">
<div className="hero-body">
<p className="title">Partie Marion</p>
<p className="subtitle">
Édition des informations et de la citation du mois
</p>
</div>
</section>
<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>
<Editor
initialValue=""
init={{
menubar: false,
toolbar:
'undo redo | bold italic underline | alignleft aligncenter alignright | code',
}}
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>
<Editor
initialValue=""
init={{
menubar: false,
toolbar:
'undo redo | bold italic underline | alignleft aligncenter alignright | code',
}}
onEditorChange={(newQuote, editor) => setQuote(newQuote)}
/>
<button className="button is-link" onClick={handleSave}>
Sauvegarder
</button>
</div>
</>
)
}
export default Editing