Rev 2093 | Rev 2861 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'import { useForm } from 'react-hook-form'import { connect, useSelector } from 'react-redux'import { axios } from '@app/utils'import { addNotification } from '@app/redux/notification/notification.actions'import Modal from '../UI/modal/Modal'import Input from '../UI/inputs/Input'const AddProfileModal = ({show = '',onHide = () => null,getProfiles = () => null,addNotification // redux action}) => {const labels = useSelector(({ intl }) => intl.labels)const {register,handleSubmit,formState: { errors }} = useForm()const onSubmitHandler = handleSubmit(async (data) => {const formData = new FormData()Object.entries(data).map(([key, value]) => formData.append(key, value))axios.post('/profile/my-profiles/add', formData).then(({ data: response }) => {const { data, success } = responseif (!success) {const errorMessage =typeof data === 'string'? data: 'Ha ocurrido un error, por favor intente más tarde'addNotification({ style: 'success', msg: errorMessage })return}getProfiles()addNotification({ style: 'success', msg: data })onHide()}).catch((err) => {addNotification({ style: 'danger', msg: err.message })})})return (<Modaltitle={labels.new_profile}show={show}onHide={onHide}onAccept={onSubmitHandler}onClose={onHide}><Inputname='name'placeholder={labels.create_profile}inputRef={register({ required: 'Este campo es requerido' })}error={errors.name?.message}/></Modal>)}const mapDispatchToProps = {addNotification: (notification) => addNotification(notification)}export default connect(null, mapDispatchToProps)(AddProfileModal)