-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21b104c
commit 8ae944d
Showing
5 changed files
with
109 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,12 @@ import { useAddUser } from "../hooks/useAddUser"; | |
import { useGetUserData } from "../hooks/useGetUserData"; | ||
import { useUpdateUserData } from "../hooks/useUpdateUserData"; | ||
import InputComponent from "./InputComponent"; | ||
import { | ||
UserOutlined, | ||
MailOutlined, | ||
FontColorsOutlined, | ||
PhoneOutlined | ||
} from "@ant-design/icons"; | ||
|
||
interface Props { | ||
id: string | null; | ||
|
@@ -15,15 +21,15 @@ interface Props { | |
type FieldStatus = "" | "error" | "warning" | undefined; | ||
|
||
const UserForm: React.FC<Props> = ({ isModalOpen, onClose, id }) => { | ||
const [formData, setFormData] = useState({ | ||
const [formData, setFormData] = useState<any>({ | ||
name: "", | ||
username: "", | ||
email: "", | ||
phone: "" | ||
}); | ||
const [filedStatus, setFieldStatus] = useState<FieldStatus>(""); | ||
const [messageApi, contextHolder] = message.useMessage(); | ||
|
||
|
||
const error = () => { | ||
messageApi.open({ | ||
type: "error", | ||
|
@@ -42,11 +48,17 @@ const UserForm: React.FC<Props> = ({ isModalOpen, onClose, id }) => { | |
}, [userData]); | ||
|
||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const { name, value } = e.target; | ||
setFormData({ | ||
...formData, | ||
[e.target.name]: e.target.value, | ||
[name]: value, | ||
}); | ||
|
||
if ((name === 'name' || name === 'username') && value.trim().length > 0) { | ||
setFieldStatus(''); | ||
} | ||
}; | ||
|
||
|
||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
|
@@ -83,28 +95,52 @@ const UserForm: React.FC<Props> = ({ isModalOpen, onClose, id }) => { | |
</div> | ||
) : ( | ||
<form onSubmit={handleSubmit}> | ||
<div> | ||
<InputComponent | ||
label="Name" | ||
name= "name" | ||
value={formData.name} | ||
onChange={(e) => handleInputChange(e)} | ||
status={filedStatus} | ||
/> | ||
<InputComponent | ||
label="Username" | ||
name="username" | ||
value={formData.username} | ||
onChange={handleInputChange} | ||
status={filedStatus} | ||
/> | ||
<InputComponent | ||
label="Email" | ||
name="email" | ||
value={formData.email} | ||
onChange={handleInputChange} | ||
/> | ||
</div> | ||
<section> | ||
<div className="mb-3"> | ||
<InputComponent | ||
label="Name" | ||
name="name" | ||
placeholder="Mehrdad Karami" | ||
value={formData.name} | ||
onChange={handleInputChange} | ||
status={filedStatus} | ||
prefix={<UserOutlined />} | ||
/> | ||
</div> | ||
<div className="mb-3"> | ||
<InputComponent | ||
label="Username" | ||
name="username" | ||
placeholder="Ash Mehr" | ||
value={formData.username} | ||
onChange={handleInputChange} | ||
status={filedStatus} | ||
prefix={<FontColorsOutlined />} | ||
/> | ||
</div> | ||
<div className="mb-3"> | ||
<InputComponent | ||
label="Email" | ||
name="email" | ||
type="email" | ||
placeholder="[email protected]" | ||
value={formData.email} | ||
onChange={handleInputChange} | ||
prefix={<MailOutlined />} | ||
/> | ||
</div> | ||
<div className="mb-3"> | ||
<InputComponent | ||
label="Phone" | ||
name="phone" | ||
type="phone" | ||
placeholder="+98912..." | ||
value={formData.phone} | ||
onChange={handleInputChange} | ||
prefix={<PhoneOutlined />} | ||
/> | ||
</div> | ||
</section> | ||
<div className="flex gap-2 justify-end mt-5"> | ||
<Button type="primary" danger onClick={onClose}> | ||
Cancel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
@layer base { | ||
html { | ||
@apply font-light bg-gray-400 m-3 | ||
@apply font-light bg-gray-300 m-3 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters