UNPKG

test-crud

Version:

es una prueba acerca de como publicar un package name

94 lines (90 loc) 2.51 kB
import { useFormikContext } from 'formik' import CloudIcon from '@mui/icons-material/Cloud' import DoneIcon from '@mui/icons-material/Done' import CloseIcon from '@mui/icons-material/Close' import SaveIcon from '@mui/icons-material/Save' import SendIcon from '@mui/icons-material/Send' import Button from '../inputs/button' import { IconButton, Tooltip } from '@mui/material' const AppSubmit = ({ label, alignSelf = 'flex-end', icono = 'cloud', btnClose = false, onClose = () => {}, isHeaderMenuRTT = false, isSubmitting = false, // Agregar prop para manejar el estado de envío ...rest }) => { const { handleSubmit, errors, touched, initialValues } = useFormikContext() return ( <div style={{ alignSelf: alignSelf, }} > {btnClose && ( <Button type="button" label="Cerrar" variant="outlined" startIcon={<CloseIcon />} color="secondary" style={{ marginRight: 20 }} onClick={onClose} ></Button> )} {isHeaderMenuRTT ? ( <> <Tooltip title="Guardar Tarjeta" placement="top"> <IconButton aria-label="guardar" onClick={handleSubmit} disabled={ !( Object.keys(errors).length === 0 && (Object.keys(initialValues).length > 0 || Object.keys(touched).length > 0) ) } {...rest} > <SaveIcon fontSize="large" /> </IconButton> </Tooltip> </> ) : ( <Button type="submit" variant="contained" startIcon={ icono === 'check' ? ( <DoneIcon /> ) : icono === 'send' ? ( <SendIcon /> ) : ( <CloudIcon /> ) } label={label} onClick={handleSubmit} disabled={ isSubmitting || // Deshabilitar el botón si se está enviando !( Object.keys(errors).length === 0 && (Object.keys(initialValues).length > 0 || Object.keys(touched).length > 0) ) } // disabled={ // Object.keys(errors).length > 0 || Object.keys(touched).length === 0 // } {...rest} > {label} </Button> )} </div> ) } export default AppSubmit