Spaces:
Running
Running
Create components/CustomModal.tsx
Browse files
src/components/components/CustomModal.tsx
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// src/components/CustomModal.tsx
|
2 |
+
import React, { useState, useEffect, FC } from 'react';
|
3 |
+
import './CustomModal.scss'; // استایلها را در فایل جداگانه قرار میدهیم
|
4 |
+
|
5 |
+
interface CustomModalProps {
|
6 |
+
isOpen: boolean;
|
7 |
+
onClose: () => void;
|
8 |
+
onSave: (name: string, instructions: string) => void;
|
9 |
+
initialName: string;
|
10 |
+
initialInstructions: string;
|
11 |
+
}
|
12 |
+
|
13 |
+
export const CustomModal: FC<CustomModalProps> = ({ isOpen, onClose, onSave, initialName, initialInstructions }) => {
|
14 |
+
const [name, setName] = useState(initialName);
|
15 |
+
const [instructions, setInstructions] = useState(initialInstructions);
|
16 |
+
|
17 |
+
useEffect(() => {
|
18 |
+
if (isOpen) {
|
19 |
+
setName(initialName);
|
20 |
+
setInstructions(initialInstructions);
|
21 |
+
}
|
22 |
+
}, [isOpen, initialName, initialInstructions]);
|
23 |
+
|
24 |
+
if (!isOpen) return null;
|
25 |
+
|
26 |
+
const handleSave = () => {
|
27 |
+
if (name.trim() && instructions.trim()) {
|
28 |
+
onSave(name.trim(), instructions.trim());
|
29 |
+
onClose();
|
30 |
+
} else {
|
31 |
+
alert("لطفا نام و دستورالعملها را وارد کنید.");
|
32 |
+
}
|
33 |
+
};
|
34 |
+
|
35 |
+
return (
|
36 |
+
<div className="modal-overlay" onClick={onClose}>
|
37 |
+
<div className="modal-content" onClick={(e) => e.stopPropagation()}>
|
38 |
+
<div className="modal-header">
|
39 |
+
<h3>ساخت شخصیت اختصاصی</h3>
|
40 |
+
<button className="close-button" onClick={onClose}>×</button>
|
41 |
+
</div>
|
42 |
+
<div className="modal-body">
|
43 |
+
<div className="form-group">
|
44 |
+
<label htmlFor="name">نام شما (برای صدا زدن)</label>
|
45 |
+
<input id="name" type="text" placeholder="مثلا: علی" value={name} onChange={(e) => setName(e.target.value)} />
|
46 |
+
</div>
|
47 |
+
<div className="form-group">
|
48 |
+
<label htmlFor="instructions">دستورالعملهای شخصیت</label>
|
49 |
+
<textarea id="instructions" placeholder="مثلا: خیلی خودمونی و بامزه صحبت کن..." value={instructions} onChange={(e) => setInstructions(e.target.value)} rows={6} />
|
50 |
+
<small>اینجا فقط رفتار و سبک صحبت کردن دستیار را مشخص کنید.</small>
|
51 |
+
</div>
|
52 |
+
</div>
|
53 |
+
<div className="modal-footer">
|
54 |
+
<button className="save-button" onClick={handleSave}>ذخیره و فعالسازی</button>
|
55 |
+
</div>
|
56 |
+
</div>
|
57 |
+
</div>
|
58 |
+
);
|
59 |
+
};
|