| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  | import { UserIcon } from "@heroicons/react/outline"; | 
					
						
							| 
									
										
										
										
											2022-02-07 23:35:26 +00:00
										 |  |  | import { InformationCircleIcon } from "@heroicons/react/solid"; | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  | import { MembershipRole } from "@prisma/client"; | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:00 +00:00
										 |  |  | import { useState } from "react"; | 
					
						
							| 
									
										
										
										
											2021-10-25 13:05:21 +00:00
										 |  |  | import React, { SyntheticEvent } from "react"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-16 23:36:43 +00:00
										 |  |  | import Button from "@calcom/ui/Button"; | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  | import { Dialog, DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/Dialog"; | 
					
						
							| 
									
										
										
										
											2022-03-16 23:36:43 +00:00
										 |  |  | import { TextField } from "@calcom/ui/form/fields"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 11:43:48 +00:00
										 |  |  | import { useLocale } from "@lib/hooks/useLocale"; | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  | import { TeamWithMembers } from "@lib/queries/teams"; | 
					
						
							|  |  |  | import { trpc } from "@lib/trpc"; | 
					
						
							| 
									
										
										
										
											2021-06-05 22:53:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  | type MemberInvitationModalProps = { | 
					
						
							|  |  |  |   isOpen: boolean; | 
					
						
							|  |  |  |   team: TeamWithMembers | null; | 
					
						
							|  |  |  |   onExit: () => void; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default function MemberInvitationModal(props: MemberInvitationModalProps) { | 
					
						
							| 
									
										
										
										
											2021-08-02 20:51:57 +00:00
										 |  |  |   const [errorMessage, setErrorMessage] = useState(""); | 
					
						
							| 
									
										
										
										
											2021-10-25 13:05:21 +00:00
										 |  |  |   const { t, i18n } = useLocale(); | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |   const utils = trpc.useContext(); | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |   const inviteMemberMutation = trpc.useMutation("viewer.teams.inviteMember", { | 
					
						
							|  |  |  |     async onSuccess() { | 
					
						
							|  |  |  |       await utils.invalidateQueries(["viewer.teams.get"]); | 
					
						
							|  |  |  |       props.onExit(); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     async onError(err) { | 
					
						
							|  |  |  |       setErrorMessage(err.message); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |   function inviteMember(e: SyntheticEvent) { | 
					
						
							| 
									
										
										
										
											2021-06-05 22:53:33 +00:00
										 |  |  |     e.preventDefault(); | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |     if (!props.team) return; | 
					
						
							| 
									
										
										
										
											2021-06-05 22:53:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-25 13:05:21 +00:00
										 |  |  |     const target = e.target as typeof e.target & { | 
					
						
							|  |  |  |       elements: { | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |         role: { value: MembershipRole }; | 
					
						
							| 
									
										
										
										
											2021-10-25 13:05:21 +00:00
										 |  |  |         inviteUser: { value: string }; | 
					
						
							|  |  |  |         sendInviteEmail: { checked: boolean }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |     inviteMemberMutation.mutate({ | 
					
						
							|  |  |  |       teamId: props.team.id, | 
					
						
							| 
									
										
										
										
											2021-10-25 13:05:21 +00:00
										 |  |  |       language: i18n.language, | 
					
						
							|  |  |  |       role: target.elements["role"].value, | 
					
						
							|  |  |  |       usernameOrEmail: target.elements["inviteUser"].value, | 
					
						
							|  |  |  |       sendEmailInvitation: target.elements["sendInviteEmail"].checked, | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-06-05 22:53:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-02 15:36:28 +00:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |     <Dialog open={props.isOpen} onOpenChange={props.onExit}> | 
					
						
							|  |  |  |       <DialogContent> | 
					
						
							|  |  |  |         <div className="mb-4 sm:flex sm:items-start"> | 
					
						
							|  |  |  |           <div className="bg-brand text-brandcontrast dark:bg-darkmodebrand dark:text-darkmodebrandcontrast mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-opacity-5 sm:mx-0 sm:h-10 sm:w-10"> | 
					
						
							|  |  |  |             <UserIcon className="text-brandcontrast h-6 w-6" /> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |           <div className="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left"> | 
					
						
							|  |  |  |             <h3 className="text-lg font-medium leading-6 text-gray-900" id="modal-title"> | 
					
						
							|  |  |  |               {t("invite_new_member")} | 
					
						
							|  |  |  |             </h3> | 
					
						
							|  |  |  |             <div> | 
					
						
							|  |  |  |               <p className="text-sm text-gray-400">{t("invite_new_team_member")}</p> | 
					
						
							| 
									
										
										
										
											2021-08-02 15:36:28 +00:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2021-06-05 22:53:33 +00:00
										 |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |         </div> | 
					
						
							|  |  |  |         <form onSubmit={inviteMember}> | 
					
						
							|  |  |  |           <div className="space-y-4"> | 
					
						
							|  |  |  |             <TextField | 
					
						
							|  |  |  |               label={t("email_or_username")} | 
					
						
							|  |  |  |               id="inviteUser" | 
					
						
							|  |  |  |               name="inviteUser" | 
					
						
							|  |  |  |               placeholder="email@example.com" | 
					
						
							|  |  |  |               required | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |             <div> | 
					
						
							|  |  |  |               <label className="mb-1 block text-sm font-medium tracking-wide text-gray-700" htmlFor="role"> | 
					
						
							|  |  |  |                 {t("role")} | 
					
						
							|  |  |  |               </label> | 
					
						
							|  |  |  |               <select | 
					
						
							|  |  |  |                 id="role" | 
					
						
							|  |  |  |                 className="focus:border-brand mt-1 block w-full rounded-sm border-gray-300 shadow-sm focus:ring-black sm:text-sm"> | 
					
						
							|  |  |  |                 <option value="MEMBER">{t("member")}</option> | 
					
						
							|  |  |  |                 <option value="ADMIN">{t("admin")}</option> | 
					
						
							|  |  |  |               </select> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |             <div className="relative flex items-start"> | 
					
						
							|  |  |  |               <div className="flex h-5 items-center"> | 
					
						
							|  |  |  |                 <input | 
					
						
							|  |  |  |                   type="checkbox" | 
					
						
							|  |  |  |                   name="sendInviteEmail" | 
					
						
							|  |  |  |                   defaultChecked | 
					
						
							|  |  |  |                   id="sendInviteEmail" | 
					
						
							|  |  |  |                   className="focus:border-brand rounded-sm border-gray-300 text-black shadow-sm focus:ring-black sm:text-sm" | 
					
						
							|  |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2021-08-02 15:36:28 +00:00
										 |  |  |               </div> | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |               <div className="text-sm ltr:ml-2 rtl:mr-2"> | 
					
						
							|  |  |  |                 <label htmlFor="sendInviteEmail" className="font-medium text-gray-700"> | 
					
						
							|  |  |  |                   {t("send_invite_email")} | 
					
						
							|  |  |  |                 </label> | 
					
						
							| 
									
										
										
										
											2022-02-07 23:35:26 +00:00
										 |  |  |               </div> | 
					
						
							| 
									
										
										
										
											2021-08-02 15:36:28 +00:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |             <div className="flex flex-row rounded-sm bg-gray-50 px-3 py-2"> | 
					
						
							|  |  |  |               <InformationCircleIcon className="h-5 w-5 flex-shrink-0 fill-gray-400" aria-hidden="true" /> | 
					
						
							|  |  |  |               <span className="ml-2 text-sm leading-tight text-gray-500"> | 
					
						
							|  |  |  |                 Note: This will cost an extra seat ($12/m) on your subscription if this invitee does not have | 
					
						
							|  |  |  |                 a pro account.{" "} | 
					
						
							|  |  |  |                 <a href="#" className="underline"> | 
					
						
							|  |  |  |                   Learn More | 
					
						
							|  |  |  |                 </a> | 
					
						
							|  |  |  |               </span> | 
					
						
							| 
									
										
										
										
											2021-06-08 16:00:06 +00:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |           </div> | 
					
						
							|  |  |  |           {errorMessage && ( | 
					
						
							|  |  |  |             <p className="text-sm text-red-700"> | 
					
						
							|  |  |  |               <span className="font-bold">Error: </span> | 
					
						
							|  |  |  |               {errorMessage} | 
					
						
							|  |  |  |             </p> | 
					
						
							|  |  |  |           )} | 
					
						
							|  |  |  |           <DialogFooter> | 
					
						
							|  |  |  |             <Button type="button" color="secondary" onClick={props.onExit}> | 
					
						
							|  |  |  |               {t("cancel")} | 
					
						
							|  |  |  |             </Button> | 
					
						
							|  |  |  |             <Button | 
					
						
							|  |  |  |               type="submit" | 
					
						
							|  |  |  |               color="primary" | 
					
						
							|  |  |  |               className="ltr:ml-2 rtl:mr-2" | 
					
						
							|  |  |  |               data-testid="invite-new-member-button"> | 
					
						
							|  |  |  |               {t("invite")} | 
					
						
							|  |  |  |             </Button> | 
					
						
							|  |  |  |           </DialogFooter> | 
					
						
							|  |  |  |         </form> | 
					
						
							|  |  |  |       </DialogContent> | 
					
						
							|  |  |  |     </Dialog> | 
					
						
							| 
									
										
										
										
											2021-08-02 15:36:28 +00:00
										 |  |  |   ); | 
					
						
							| 
									
										
										
										
											2021-08-02 20:51:57 +00:00
										 |  |  | } |