diff --git a/app/components/modal/addUserModal.tsx b/app/components/modal/addUserModal.tsx new file mode 100644 index 00000000..6a7835e1 --- /dev/null +++ b/app/components/modal/addUserModal.tsx @@ -0,0 +1,127 @@ +import { ChangeEvent, FormEvent, useState } from "react"; + +interface AddUserContentProperties { + toggleShow: (show: boolean) => void; +} + +const AddUserContent: React.FC = ({ toggleShow }) => { + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [phoneNumber, setPhoneNumber] = useState(""); + const [errors, setErrors] = useState({ + name: "", + email: "", + phoneNumber: "", + }); + + const handleChange = (event: ChangeEvent) => { + const { id, value } = event.target; + if (id === "name") setName(value); + if (id === "email") setEmail(value); + if (id === "phoneNumber") setPhoneNumber(value); + }; + + const handleSubmit = (event: FormEvent) => { + event.preventDefault(); + const newErrors = { + name: "", + email: "", + phoneNumber: "", + }; + + if (!name.trim()) { + newErrors.name = "Name is required"; + } + if (!email.trim()) { + newErrors.email = "Email is required"; + } else if (!/\S+@\S+\.\S+/.test(email)) { + newErrors.email = "Email address is invalid"; + } + if (!phoneNumber.trim()) { + newErrors.phoneNumber = "Phone number is required"; + } + if (newErrors.name || newErrors.email || newErrors.phoneNumber) { + setErrors(newErrors); + } else { + setName(""); + setEmail(""); + setPhoneNumber(""); + setErrors({ + name: "", + email: "", + phoneNumber: "", + }); + toggleShow(false); + } + }; + + return ( +
+

Add new user

+

Create a new user

+
+
+ +
+
+

Upload Picture

+
+

Click to upload

+ +
+
+
+
+
+ + + {errors.name &&

{errors.name}

} +
+
+ + + {errors.email &&

{errors.email}

} +
+
+ + + {errors.phoneNumber && ( +

{errors.phoneNumber}

+ )} +
+
+
+ +
+
+ ); +}; + +export default AddUserContent; diff --git a/app/components/modal/deleteUser.tsx b/app/components/modal/deleteUser.tsx new file mode 100644 index 00000000..ccd34046 --- /dev/null +++ b/app/components/modal/deleteUser.tsx @@ -0,0 +1,39 @@ +import { Button } from "../ui/button"; + +interface DeleteUserContentProperties { + toggleShow: (show: boolean) => void; +} + +const DeleteUserContent: React.FC = ({ + toggleShow, +}) => { + return ( +
+

+ {" "} + Are you sure you want to delete?{" "} +

+

+ {" "} + This action cannot be undone. This will permanently delete this user + from the database.{" "} +

+
+ + +
+
+ ); +}; + +export default DeleteUserContent; diff --git a/app/components/modal/modal.tsx b/app/components/modal/modal.tsx new file mode 100644 index 00000000..878f3890 --- /dev/null +++ b/app/components/modal/modal.tsx @@ -0,0 +1,49 @@ +import React, { ReactNode, useEffect, useRef } from "react"; + +import { Card } from "../ui/card"; + +interface ModalProperties { + className?: string; + show: boolean; + toggleShow: (show: boolean) => void; + children: ReactNode; +} + +const Modal: React.FC = ({ + className, + show, + toggleShow, + children, +}) => { + const modal = useRef(null); + + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (modal.current && !modal.current.contains(event.target as Node)) { + toggleShow(false); + } + }; + + document.addEventListener("click", handleClickOutside); + return () => { + document.removeEventListener("click", handleClickOutside); + }; + }, [toggleShow]); + + return ( + + {show && ( +
+
+
{children}
+
+
+ )} +
+ ); +}; + +export default Modal;