| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  | import { UsersIcon } from "@heroicons/react/outline"; | 
					
						
							| 
									
										
										
										
											2022-02-07 23:35:26 +00:00
										 |  |  | import { useRef, useState } from "react"; | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  | import { useLocale } from "@calcom/lib/hooks/useLocale"; | 
					
						
							|  |  |  | import { Button } from "@calcom/ui"; | 
					
						
							| 
									
										
										
										
											2022-03-16 23:36:43 +00:00
										 |  |  | import { Alert } from "@calcom/ui/Alert"; | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  | import { Dialog, DialogContent, DialogFooter } from "@calcom/ui/Dialog"; | 
					
						
							| 
									
										
										
										
											2022-03-16 23:36:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  | import { trpc } from "@lib/trpc"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | interface Props { | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |   isOpen: boolean; | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |   onClose: () => void; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default function TeamCreate(props: Props) { | 
					
						
							|  |  |  |   const { t } = useLocale(); | 
					
						
							|  |  |  |   const utils = trpc.useContext(); | 
					
						
							| 
									
										
										
										
											2022-02-07 23:35:26 +00:00
										 |  |  |   const [errorMessage, setErrorMessage] = useState<null | string>(null); | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |   const nameRef = useRef<HTMLInputElement>() as React.MutableRefObject<HTMLInputElement>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const createTeamMutation = trpc.useMutation("viewer.teams.create", { | 
					
						
							|  |  |  |     onSuccess: () => { | 
					
						
							|  |  |  |       utils.invalidateQueries(["viewer.teams.list"]); | 
					
						
							|  |  |  |       props.onClose(); | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2022-02-07 23:35:26 +00:00
										 |  |  |     onError: (e) => { | 
					
						
							|  |  |  |       setErrorMessage(e?.message || t("something_went_wrong")); | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const createTeam = (e: React.FormEvent<HTMLFormElement>) => { | 
					
						
							|  |  |  |     e.preventDefault(); | 
					
						
							|  |  |  |     createTeamMutation.mutate({ name: nameRef?.current?.value }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |     <> | 
					
						
							|  |  |  |       <Dialog open={props.isOpen} onOpenChange={props.onClose}> | 
					
						
							|  |  |  |         <DialogContent> | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |           <div className="mb-4 sm:flex sm:items-start"> | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |             <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"> | 
					
						
							|  |  |  |               <UsersIcon className="text-brandcontrast h-6 w-6" /> | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |             </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("create_new_team")} | 
					
						
							|  |  |  |               </h3> | 
					
						
							|  |  |  |               <div> | 
					
						
							|  |  |  |                 <p className="text-sm text-gray-400">{t("create_new_team_description")}</p> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |           <form onSubmit={createTeam}> | 
					
						
							|  |  |  |             <div className="mb-4"> | 
					
						
							|  |  |  |               <label htmlFor="name" className="block text-sm font-medium text-gray-700"> | 
					
						
							|  |  |  |                 {t("name")} | 
					
						
							|  |  |  |               </label> | 
					
						
							|  |  |  |               <input | 
					
						
							|  |  |  |                 ref={nameRef} | 
					
						
							|  |  |  |                 type="text" | 
					
						
							|  |  |  |                 name="name" | 
					
						
							|  |  |  |                 id="name" | 
					
						
							|  |  |  |                 placeholder="Acme Inc." | 
					
						
							|  |  |  |                 required | 
					
						
							| 
									
										
										
										
											2022-02-09 00:05:13 +00:00
										 |  |  |                 className="mt-1 block w-full rounded-sm border border-gray-300 px-3 py-2 shadow-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm" | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |               /> | 
					
						
							|  |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2022-02-07 23:35:26 +00:00
										 |  |  |             {errorMessage && <Alert severity="error" title={errorMessage} />} | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |             <DialogFooter> | 
					
						
							|  |  |  |               <Button type="button" color="secondary" onClick={props.onClose}> | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |                 {t("cancel")} | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |               </Button> | 
					
						
							|  |  |  |               <Button | 
					
						
							|  |  |  |                 type="submit" | 
					
						
							|  |  |  |                 color="primary" | 
					
						
							|  |  |  |                 className="ltr:ml-2 rtl:mr-2" | 
					
						
							|  |  |  |                 data-testid="create-new-team-button"> | 
					
						
							|  |  |  |                 {t("create_team")} | 
					
						
							|  |  |  |               </Button> | 
					
						
							|  |  |  |             </DialogFooter> | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |           </form> | 
					
						
							| 
									
										
										
										
											2022-03-17 13:20:49 +00:00
										 |  |  |         </DialogContent> | 
					
						
							|  |  |  |       </Dialog> | 
					
						
							|  |  |  |     </> | 
					
						
							| 
									
										
										
										
											2021-12-09 23:51:30 +00:00
										 |  |  |   ); | 
					
						
							|  |  |  | } |