blob: 0ffe1f371e9fda7702a0e6953d85fb7cfe93113e (
plain) (
blame)
1
2
3
4
5
6
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
|
import styles from '../styles/Notes.module.scss'
import React from 'react'
import usePopup from 'hooks/usePopup'
import useSettings from 'hooks/useSettings'
import useNotes from '../hooks/useNotes'
import { addNote, updateNote } from '../helpers/noteActions.js'
const NoteEdit = ({ setAction, fetchedNote }) => {
const { t } = useSettings()
const { setPopup } = usePopup()
const { mutateNotes } = useNotes()
const handleSubmit = e => {
e.preventDefault()
fetchedNote
? updateNote(e, fetchedNote, mutateNotes, setAction, t, setPopup)
: addNote(e, mutateNotes, setAction, t, setPopup)
}
return (
<div className={styles.noteEdit}>
<h2>{fetchedNote ? t('notes_edit') : t('notes_add_new')}</h2>
<form onSubmit={handleSubmit}>
<input
name='title'
type='text'
maxLength={1000}
placeholder='Title'
defaultValue={fetchedNote ? fetchedNote.title : ''}
/>
<textarea
required
placeholder='Note'
name='content'
defaultValue={fetchedNote ? fetchedNote.content : ''}
/>
<div className='note__buttons'>
<span
className='window__button'
onClick={() => { setAction(fetchedNote ? 'showNote' : '') }}
>
{t('cancel')}
</span>
<input
className='window__button'
type='submit'
value={fetchedNote ? t('notes_save') : t('notes_add')}
/>
</div>
</form>
</div>
)
}
export default NoteEdit
|