| 
									
										
										
										
											2022-03-23 22:00:30 +00:00
										 |  |  | import { useState } from "react"; | 
					
						
							| 
									
										
										
										
											2021-10-12 09:35:44 +00:00
										 |  |  | import { useForm } from "react-hook-form"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-16 23:36:43 +00:00
										 |  |  | import { Alert } from "@calcom/ui/Alert"; | 
					
						
							|  |  |  | import Button from "@calcom/ui/Button"; | 
					
						
							| 
									
										
										
										
											2021-10-12 09:35:44 +00:00
										 |  |  | import { | 
					
						
							|  |  |  |   Dialog, | 
					
						
							|  |  |  |   DialogClose, | 
					
						
							| 
									
										
										
										
											2021-10-13 11:35:25 +00:00
										 |  |  |   DialogContent, | 
					
						
							| 
									
										
										
										
											2021-10-12 09:35:44 +00:00
										 |  |  |   DialogFooter, | 
					
						
							| 
									
										
										
										
											2021-10-13 11:35:25 +00:00
										 |  |  |   DialogHeader, | 
					
						
							|  |  |  |   DialogProps, | 
					
						
							| 
									
										
										
										
											2022-03-16 23:36:43 +00:00
										 |  |  | } from "@calcom/ui/Dialog"; | 
					
						
							|  |  |  | import { Form, TextField } from "@calcom/ui/form/fields"; | 
					
						
							| 
									
										
										
										
											2021-09-11 07:54:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-23 22:00:30 +00:00
										 |  |  | export const ADD_INTEGRATION_FORM_TITLE = "addAppleIntegration"; | 
					
						
							| 
									
										
										
										
											2021-09-11 07:54:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-23 22:00:30 +00:00
										 |  |  | function AddIntegrationModal(props: DialogProps) { | 
					
						
							| 
									
										
										
										
											2021-10-12 09:35:44 +00:00
										 |  |  |   const form = useForm({ | 
					
						
							|  |  |  |     defaultValues: { | 
					
						
							|  |  |  |       username: "", | 
					
						
							|  |  |  |       password: "", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   const [errorMessage, setErrorMessage] = useState(""); | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2022-03-23 22:00:30 +00:00
										 |  |  |     <Dialog name={ADD_INTEGRATION_FORM_TITLE} {...props}> | 
					
						
							| 
									
										
										
										
											2021-10-12 09:35:44 +00:00
										 |  |  |       <DialogContent> | 
					
						
							|  |  |  |         <DialogHeader | 
					
						
							|  |  |  |           title="Connect to Apple Server" | 
					
						
							|  |  |  |           subtitle={ | 
					
						
							|  |  |  |             <> | 
					
						
							|  |  |  |               Generate an app specific password to use with Cal.com at{" "} | 
					
						
							|  |  |  |               <a | 
					
						
							|  |  |  |                 className="text-indigo-400" | 
					
						
							|  |  |  |                 href="https://appleid.apple.com/account/manage" | 
					
						
							|  |  |  |                 target="_blank" | 
					
						
							|  |  |  |                 rel="noopener noreferrer"> | 
					
						
							|  |  |  |                 https://appleid.apple.com/account/manage
 | 
					
						
							|  |  |  |               </a> | 
					
						
							|  |  |  |               . Your credentials will be stored and encrypted. | 
					
						
							|  |  |  |             </> | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         <Form | 
					
						
							|  |  |  |           form={form} | 
					
						
							| 
									
										
										
										
											2022-01-06 17:28:31 +00:00
										 |  |  |           handleSubmit={async (values) => { | 
					
						
							| 
									
										
										
										
											2021-10-12 09:35:44 +00:00
										 |  |  |             setErrorMessage(""); | 
					
						
							| 
									
										
										
										
											2022-03-23 22:00:30 +00:00
										 |  |  |             const res = await fetch("/api/integrations/applecalendar/add", { | 
					
						
							| 
									
										
										
										
											2021-10-12 09:35:44 +00:00
										 |  |  |               method: "POST", | 
					
						
							|  |  |  |               body: JSON.stringify(values), | 
					
						
							|  |  |  |               headers: { | 
					
						
							|  |  |  |                 "Content-Type": "application/json", | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |             const json = await res.json(); | 
					
						
							|  |  |  |             if (!res.ok) { | 
					
						
							|  |  |  |               setErrorMessage(json?.message || "Something went wrong"); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |               props.onOpenChange?.(false); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-01-06 17:28:31 +00:00
										 |  |  |           }}> | 
					
						
							| 
									
										
										
										
											2021-10-12 09:35:44 +00:00
										 |  |  |           <fieldset className="space-y-2" disabled={form.formState.isSubmitting}> | 
					
						
							|  |  |  |             <TextField | 
					
						
							|  |  |  |               required | 
					
						
							|  |  |  |               type="text" | 
					
						
							|  |  |  |               {...form.register("username")} | 
					
						
							|  |  |  |               label="Username" | 
					
						
							|  |  |  |               placeholder="rickroll" | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |             <TextField | 
					
						
							|  |  |  |               required | 
					
						
							|  |  |  |               type="password" | 
					
						
							|  |  |  |               {...form.register("password")} | 
					
						
							|  |  |  |               label="Password" | 
					
						
							|  |  |  |               placeholder="•••••••••••••" | 
					
						
							|  |  |  |               autoComplete="password" | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           </fieldset> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           {errorMessage && <Alert severity="error" title={errorMessage} className="my-4" />} | 
					
						
							|  |  |  |           <DialogFooter> | 
					
						
							|  |  |  |             <DialogClose | 
					
						
							|  |  |  |               onClick={() => { | 
					
						
							|  |  |  |                 props.onOpenChange?.(false); | 
					
						
							|  |  |  |               }} | 
					
						
							|  |  |  |               asChild> | 
					
						
							|  |  |  |               <Button type="button" color="secondary" tabIndex={-1}> | 
					
						
							|  |  |  |                 Cancel | 
					
						
							|  |  |  |               </Button> | 
					
						
							|  |  |  |             </DialogClose> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             <Button type="submit" loading={form.formState.isSubmitting}> | 
					
						
							|  |  |  |               Save | 
					
						
							|  |  |  |             </Button> | 
					
						
							|  |  |  |           </DialogFooter> | 
					
						
							|  |  |  |         </Form> | 
					
						
							|  |  |  |       </DialogContent> | 
					
						
							|  |  |  |     </Dialog> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-23 22:00:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default AddIntegrationModal; |