|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useState } from "react"; |
| 4 | +import { UserType } from "@prisma/client"; |
| 5 | + |
| 6 | +interface InviteUserFormProps { |
| 7 | + closeModal: () => void; |
| 8 | + onSubmit: (role: UserType) => void; |
| 9 | +} |
| 10 | + |
| 11 | +export default function InviteUserForm({ closeModal, onSubmit }: InviteUserFormProps) { |
| 12 | + const [name, setName] = useState(""); |
| 13 | + const [email, setEmail] = useState(""); |
| 14 | + const [role, setRole] = useState<UserType | "">(""); |
| 15 | + const [step, setStep] = useState(1); |
| 16 | + |
| 17 | + const handleSubmit = (event: React.FormEvent) => { |
| 18 | + event.preventDefault(); |
| 19 | + |
| 20 | + if (!role) { |
| 21 | + console.error("Role is not selected"); |
| 22 | + return; |
| 23 | + } |
| 24 | + |
| 25 | + if (role === "SUPER_ADMIN" || role === "ADMIN" || role === "STAFF") { |
| 26 | + onSubmit(role as UserType); |
| 27 | + setStep(2); |
| 28 | + } else { |
| 29 | + onSubmit(role as UserType); |
| 30 | + } |
| 31 | + }; |
| 32 | + |
| 33 | + return ( |
| 34 | + <div className="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50"> |
| 35 | + <div className="bg-white p-6 rounded-lg shadow-lg w-96"> |
| 36 | + {step === 1 ? ( |
| 37 | + <> |
| 38 | + <h2 className="text-xl font-bold mb-4">Add new account</h2> |
| 39 | + <button className="absolute top-4 right-4" onClick={closeModal}>✕</button> |
| 40 | + <form onSubmit={handleSubmit}> |
| 41 | + <label className="block mb-2">Name</label> |
| 42 | + <input |
| 43 | + type="text" |
| 44 | + className="w-full p-2 border rounded mb-2" |
| 45 | + value={name} |
| 46 | + onChange={(e) => setName(e.target.value)} |
| 47 | + required |
| 48 | + /> |
| 49 | + |
| 50 | + <label className="block mb-2">Email</label> |
| 51 | + <input |
| 52 | + type="email" |
| 53 | + className="w-full p-2 border rounded mb-2" |
| 54 | + value={email} |
| 55 | + onChange={(e) => setEmail(e.target.value)} |
| 56 | + required |
| 57 | + /> |
| 58 | + |
| 59 | + <label className="block mb-2">Role</label> |
| 60 | + <select |
| 61 | + className="w-full p-2 border rounded mb-4" |
| 62 | + value={role} |
| 63 | + onChange={(e) => setRole(e.target.value as UserType)} |
| 64 | + required |
| 65 | + > |
| 66 | + <option value="" disabled>Select a role</option> |
| 67 | + {Object.values(UserType).map((roleOption) => ( |
| 68 | + <option key={roleOption} value={roleOption}>{roleOption}</option> |
| 69 | + ))} |
| 70 | + </select> |
| 71 | + |
| 72 | + <div className="flex justify-between"> |
| 73 | + <button |
| 74 | + type="button" |
| 75 | + className="border border-mainRed text-mainRed px-4 py-2 rounded" |
| 76 | + onClick={closeModal} |
| 77 | + > |
| 78 | + Cancel |
| 79 | + </button> |
| 80 | + <button |
| 81 | + type="submit" |
| 82 | + className="bg-mainRed text-white px-4 py-2 rounded" |
| 83 | + > |
| 84 | + {role === "PARTNER" ? "Next" : "Send invite link"} |
| 85 | + </button> |
| 86 | + </div> |
| 87 | + </form> |
| 88 | + </> |
| 89 | + ) : ( |
| 90 | + <> |
| 91 | + <h2 className="text-xl font-bold mb-4">Add new account</h2> |
| 92 | + <button className="absolute top-4 right-4" onClick={closeModal}>✕</button> |
| 93 | + <p className="mb-4">An email has been sent to finalize account creation. This account is currently pending.</p> |
| 94 | + <p className="mb-4">You can view the current status from the account management page.</p> |
| 95 | + <div className="flex justify-center mb-4"> |
| 96 | + <img src="/assets/blue_arrow.svg" alt="Blue Arrow" className="w-12 h-12" /> |
| 97 | + </div> |
| 98 | + <button |
| 99 | + className="bg-mainRed text-white px-4 py-2 rounded w-full" |
| 100 | + onClick={closeModal} |
| 101 | + > |
| 102 | + Back to account management |
| 103 | + </button> |
| 104 | + </> |
| 105 | + )} |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + ); |
| 109 | +} |
0 commit comments