Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 6597 | Rev 11160 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 6597 Rev 11152
Línea 1... Línea 1...
1
import axios from 'axios';
1
import axios from 'axios'
2
import React, { useEffect, useState } from 'react'
2
import React, { useEffect, useState } from 'react'
3
import { Modal, Button } from 'react-bootstrap';
3
import { Modal, Button } from 'react-bootstrap'
4
import { useForm } from "react-hook-form";
4
import { useForm } from 'react-hook-form'
5
import { CKEditor } from "ckeditor4-react";
5
import { CKEditor } from 'ckeditor4-react'
6
import { getData } from '../../../helpers/fetchHelpers';
6
import { getData } from '../../../helpers/fetchHelpers'
Línea 7... Línea 7...
7
 
7
 
8
const OverviewModal = ({
8
const OverviewModal = ({
9
    isOpen = false,
9
	isOpen = false,
10
    closeModal = function () { },
10
	closeModal = function () { },
11
    overviewUrl,
11
	overviewUrl,
12
    action,
12
	action,
13
    overview
13
	overview
Línea 14... Línea 14...
14
}) => {
14
}) => {
15
 
15
 
Línea 16... Línea 16...
16
    const { register, handleSubmit, setValue, watch } = useForm();
16
	const { register, handleSubmit, setValue, watch } = useForm()
17
    const [error, setError] = useState(null);
17
	const [error, setError] = useState(null)
18
 
18
 
19
    const onSubmit = ({ description }) => {
19
	const onSubmit = ({ description }) => {
20
        const formData = new FormData
20
		const formData = new FormData
21
        formData.append("description", description)
21
		formData.append('description', description)
22
 
22
 
23
        axios.post(overviewUrl, formData)
23
		axios.post(overviewUrl, formData)
24
            .then(({ data }) => {
24
			.then(({ data }) => {
25
                if(!data.success){
25
				if (!data.success) {
26
                    return setError('Error')
26
					return setError('Error')
27
                }
27
				}
28
                action(data.data.description)
28
				action(data.data.description)
29
            })
29
			})
30
            .then(() => {
30
			.then(() => {
31
                setError(null)
31
				setError(null)
32
                closeModal()
32
				closeModal()
33
            })
33
			})
34
            .catch((err) => setError(err))
34
			.catch((err) => setError(err))
35
    };
35
	}
36
 
36
 
37
    useEffect(() => {
37
	useEffect(() => {
38
        register("description");
38
		register('description')
39
    }, []);
39
	}, [])
40
 
40
 
41
    return (
41
	return (
42
        <Modal
42
		<Modal
43
            size="md"
43
			size="md"
44
            show={isOpen}
44
			show={isOpen}
45
            onHide={closeModal}
45
			onHide={closeModal}
46
            autoFocus={false}
46
			autoFocus={false}
47
        >
47
		>
48
            <Modal.Header closeButton>
48
			<Modal.Header closeButton>
49
                <Modal.Title>Cambiar</Modal.Title>
49
				<Modal.Title>Cambiar</Modal.Title>
50
            </Modal.Header>
50
			</Modal.Header>
51
            <form onSubmit={handleSubmit(onSubmit)}>
51
			<form onSubmit={handleSubmit(onSubmit)}>
52
                <Modal.Body>
52
				<Modal.Body>
53
                    <div className="mb-3">
53
					<div className="mb-3">
54
                        <label className="form-label">Visión general</label>
54
						<label className="form-label">Visión general</label>
55
                        <CKEditor
55
						<CKEditor
56
                            data={watch("description")}
56
							data={watch('description')}
57
                            onChange={(e) => {
57
							onChange={(e) => {
58
                                const text = e.editor.getData();
58
								const text = e.editor.getData()
59
                                setValue("description", text);
59
								setValue('description', text)
60
                            }}
60
							}}
61
                            onInstanceReady={(e) => e.editor.setData(overview)}
61
							onInstanceReady={(e) => e.editor.setData(overview)}
62
                            config={{
62
							config={{
63
                                toolbar: [
63
								toolbar: [
64
                                    { name: 'editing', items: ['Scayt'] },
64
									{ name: 'editing', items: ['Scayt'] },
65
                                    { name: 'links', items: ['Link', 'Unlink'] },
65
									{ name: 'links', items: ['Link', 'Unlink'] },
66
                                    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
66
									{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
67
                                    { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
67
									{ name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
68
                                    '/',
68
									'/',
69
                                    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
69
									{ name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
70
                                    { name: 'styles', items: ['Styles', 'Format'] },
70
									{ name: 'styles', items: ['Styles', 'Format'] },
71
                                    { name: 'tools', items: ['Maximize'] }
71
									{ name: 'tools', items: ['Maximize'] }
72
                                ],
72
								],
73
                                removePlugins: 'elementspath,Anchor',
73
								removePlugins: 'elementspath,Anchor',
74
                                heigth: 100
74
								heigth: 100
75
                            }}
75
							}}
76
                            name="description"
76
							name="description"
77
                        />
77
						/>
78
                        {error && <p>{error}</p>}
78
						{error && <p>{error}</p>}
79
                    </div>
79
					</div>
80
                </Modal.Body>
80
				</Modal.Body>
81
                <Modal.Footer>
81
				<Modal.Footer>
82
                    <Button
82
					<Button
83
                        variant="primary"
83
						variant="primary"
84
                        type="submit"
84
						type="submit"
85
                    >
85
					>
86
                        Enviar
86
                        Enviar
87
                    </Button>
87
					</Button>
88
                    <Button variant="danger" onClick={closeModal}>
88
					<Button className='btn-tertiary' onClick={closeModal}>
89
                        Cancelar
89
                        Cancelar
90
                    </Button>
90
					</Button>
91
                </Modal.Footer>
91
				</Modal.Footer>
92
            </form>
92
			</form>
Línea 93... Línea 93...
93
        </Modal >
93
		</Modal >
94
    )
94
	)