芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/www/wp-content/plugins/envato-elements/src/js/react/components/Forms/ProjectName.jsx
import React, { useEffect, useState } from 'react' import InputWithButton from './InputWithButton' import ButtonActionProvider from '../Actions/ButtonActionProvider' import setProjectName from '../../api/setProjectName' import useGlobalConfig from '../Contexts/useGlobalConfig' import Button from '../Buttons/Button' import styles from './ProjectName.module.scss' const ProjectButton = ({ text, disabled = false, onClick = null }) => { return (
) } /** * Generates a form allowing the user to set their project name * * @param customActionHook * @param completedCallback * @returns {*} * @constructor */ const ProjectName = ({ customActionHook = null, completedCallback = null }) => { const { getConfigProjectName, setConfigProjectName } = useGlobalConfig() const [stateProjectName, setStateProjectName] = useState(getConfigProjectName()) const [error, setError] = useState(null) const [saved, setSaved] = useState(false) // Call our completedCallback() after our "saved" state variable is set to true: useEffect(() => { if (saved) { setConfigProjectName(stateProjectName) if (completedCallback) { completedCallback() } } }, [saved]) useEffect(() => { // each time our local project name changes we update our saved state to false. setSaved(false) setError(null) }, [stateProjectName]) return (
{ // Update local project name state value: setStateProjectName(e.target.value) }} className={styles.input} spellCheck='false' autoComplete='false' placeholder='My New Project' /> )} Button={(
} LoadingButton={
} ErrorButton={
} SuccessButton={
} CompletedButton={
} actionHook={customActionHook || (() => setProjectName({ projectName: stateProjectName }))} isAlreadyCompleted={saved} completedCallback={(data) => { setSaved(true) }} errorCallback={(data) => { setError(data && data.error ? data.error : { code: 'unknown_error', message: 'Sorry something went wrong, please try again.' }) }} /> )} instructions={null} errorMessage={error ? error.message : null} /> ) } export default ProjectName