Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7116 | Rev 7138 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React, { useEffect, useState } from 'react';
import { getData } from '../../../helpers/fetchHelpers';
import SubmitModal from './SubmitModal';

const StatusModal = ({
    modalData = '',
    dataLink = '',
    closeModal = function () { }
}) => {

    const defaultValues = [{ label: "Activo", value: "a" }, { label: "Inactivo", value: "i" }]
    const [data, setData] = useState(defaultValues.find((el) => el.label === modalData && el.value));
    const [error, setError] = useState('');
    const [values, setValues] = useState('');


    useEffect(() => {
        getData(dataLink)
            .then(results => setValues(results))
            .catch(err => setError(err))
    }, []);

    return (
        <SubmitModal
            closeModal={closeModal}
            postLink={dataLink}
            submitData={{ status: data }}
            title="Estatus"
        >
            <select
                className='form-control'
                name="status"
                onChange={(e) => setData(e.target.value)}
                defaultValue={modalData}
            >
                {
                    defaultValues.map(({ value, label }) => (
                        <option value={value}>{label}</option>
                    ))
                }
            </select>
            {error && <p>{error}</p>}
        </SubmitModal >
    )
}

export default StatusModal