116 lines
3.0 KiB
TypeScript
116 lines
3.0 KiB
TypeScript
|
|
import { useState } from 'react'
|
||
|
|
import StyleSelector from './StyleSelector'
|
||
|
|
import CustomTagsEditor from './CustomTagsEditor'
|
||
|
|
|
||
|
|
interface CreateProjectModalProps {
|
||
|
|
open: boolean
|
||
|
|
onClose: () => void
|
||
|
|
onSubmit: (name: string, style: Record<string, string>) => Promise<void>
|
||
|
|
}
|
||
|
|
|
||
|
|
export default function CreateProjectModal({
|
||
|
|
open,
|
||
|
|
onClose,
|
||
|
|
onSubmit,
|
||
|
|
}: CreateProjectModalProps) {
|
||
|
|
const [name, setName] = useState('')
|
||
|
|
const [style, setStyle] = useState<Record<string, string>>({})
|
||
|
|
const [submitting, setSubmitting] = useState(false)
|
||
|
|
|
||
|
|
if (!open) return null
|
||
|
|
|
||
|
|
const handleStyleChange = (key: string, value: string) => {
|
||
|
|
setStyle(prev =>
|
||
|
|
prev[key] === value
|
||
|
|
? (() => {
|
||
|
|
const { [key]: _, ...rest } = prev
|
||
|
|
return rest
|
||
|
|
})()
|
||
|
|
: { ...prev, [key]: value }
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
const handleSubmit = async () => {
|
||
|
|
if (!name.trim()) return
|
||
|
|
setSubmitting(true)
|
||
|
|
try {
|
||
|
|
await onSubmit(name.trim(), style)
|
||
|
|
setName('')
|
||
|
|
setStyle({})
|
||
|
|
onClose()
|
||
|
|
} finally {
|
||
|
|
setSubmitting(false)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div
|
||
|
|
style={{
|
||
|
|
position: 'fixed',
|
||
|
|
inset: 0,
|
||
|
|
zIndex: 1000,
|
||
|
|
display: 'flex',
|
||
|
|
alignItems: 'center',
|
||
|
|
justifyContent: 'center',
|
||
|
|
}}
|
||
|
|
onClick={onClose}
|
||
|
|
>
|
||
|
|
<div
|
||
|
|
style={{
|
||
|
|
position: 'absolute',
|
||
|
|
inset: 0,
|
||
|
|
background: 'rgba(0, 0, 0, 0.5)',
|
||
|
|
}}
|
||
|
|
/>
|
||
|
|
<div
|
||
|
|
className="card"
|
||
|
|
style={{
|
||
|
|
position: 'relative',
|
||
|
|
width: '100%',
|
||
|
|
maxWidth: 520,
|
||
|
|
maxHeight: '80vh',
|
||
|
|
overflow: 'auto',
|
||
|
|
zIndex: 1,
|
||
|
|
}}
|
||
|
|
onClick={e => e.stopPropagation()}
|
||
|
|
>
|
||
|
|
<h2 style={{ fontSize: 18, marginBottom: 20 }}>新建工程</h2>
|
||
|
|
|
||
|
|
<label style={{ display: 'block', marginBottom: 16 }}>
|
||
|
|
<span style={{ display: 'block', fontSize: 13, fontWeight: 600, marginBottom: 6, color: 'var(--text-secondary)' }}>
|
||
|
|
工程名称
|
||
|
|
</span>
|
||
|
|
<input
|
||
|
|
type="text"
|
||
|
|
value={name}
|
||
|
|
onChange={e => setName(e.target.value)}
|
||
|
|
placeholder="输入工程名称"
|
||
|
|
style={{ width: '100%' }}
|
||
|
|
/>
|
||
|
|
</label>
|
||
|
|
|
||
|
|
<div style={{ marginBottom: 16 }}>
|
||
|
|
<span style={{ display: 'block', fontSize: 13, fontWeight: 600, marginBottom: 8, color: 'var(--text-secondary)' }}>
|
||
|
|
风格配置
|
||
|
|
</span>
|
||
|
|
<StyleSelector value={style} onChange={handleStyleChange} compact />
|
||
|
|
<CustomTagsEditor style={style} onChange={setStyle} />
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 12 }}>
|
||
|
|
<button className="btn-secondary" onClick={onClose} disabled={submitting}>
|
||
|
|
取消
|
||
|
|
</button>
|
||
|
|
<button
|
||
|
|
className="btn-primary"
|
||
|
|
onClick={handleSubmit}
|
||
|
|
disabled={!name.trim() || submitting}
|
||
|
|
>
|
||
|
|
{submitting ? '创建中...' : '创建'}
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
)
|
||
|
|
}
|