芝麻web文件管理V1.00
编辑当前文件:/home/freeclou/app.optimyar.com/backend/.cache/admin/src/containers/Users/ListPage/ModalForm.js
import React, { useRef, useState } from 'react'; import PropTypes from 'prop-types'; import { Button } from '@buffetjs/core'; import { Modal, ModalFooter, ModalHeader, useGlobalContext } from 'strapi-helper-plugin'; import stepper from './stepper'; const ModalForm = ({ isOpen, onClosed, onToggle }) => { const [currentStep, setStep] = useState('create'); // Little trick to focus the first input // Without this the focus is lost const [showBody, setShowBody] = useState(false); const [isSubmiting, setIsSubmiting] = useState(false); const [registrationToken, setRegistrationToken] = useState(null); const { formatMessage } = useGlobalContext(); const ref = useRef(null); const { buttonSubmitLabel, Component, isDisabled, next } = stepper[currentStep]; const goNext = () => { if (next) { setStep(next); } else { onToggle(); } }; const handleClick = () => { if (ref.current) { ref.current.submit(); } else { goNext(); } }; const handleClosed = () => { // Fetch data only if the user has submitted a new entry // We can use the registrationToken to know this if (registrationToken || currentStep === 'magic-link') { onClosed(); } // Reset the state so we know that the user has created a new entry when there is a registrationToken setStep('create'); setShowBody(false); setRegistrationToken(null); }; const handleSubmit = (e, data) => { const { registrationToken } = data; setRegistrationToken(registrationToken); goNext(); }; const handleOpened = () => { setShowBody(true); }; return (
{showBody && (
)}
{formatMessage({ id: 'app.components.Button.cancel' })}
{formatMessage({ id: buttonSubmitLabel })}
); }; ModalForm.defaultProps = { onClosed: () => {}, }; ModalForm.propTypes = { isOpen: PropTypes.bool.isRequired, onClosed: PropTypes.func, onToggle: PropTypes.func.isRequired, }; export default ModalForm;