| 
									
										
										
										
											2021-09-21 09:29:20 +00:00
										 |  |  | import { useState } from "react"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-16 23:36:43 +00:00
										 |  |  | import Button from "@calcom/ui/Button"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-08 11:43:48 +00:00
										 |  |  | import { useLocale } from "@lib/hooks/useLocale"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 09:29:20 +00:00
										 |  |  | import Badge from "@components/ui/Badge"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 09:29:20 +00:00
										 |  |  | import DisableTwoFactorModal from "./DisableTwoFactorModal"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | import EnableTwoFactorModal from "./EnableTwoFactorModal"; | 
					
						
							| 
									
										
										
										
											2021-09-21 09:29:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 13:11:33 +00:00
										 |  |  | const TwoFactorAuthSection = ({ twoFactorEnabled }: { twoFactorEnabled: boolean }) => { | 
					
						
							| 
									
										
										
										
											2021-09-21 09:29:20 +00:00
										 |  |  |   const [enabled, setEnabled] = useState(twoFactorEnabled); | 
					
						
							|  |  |  |   const [enableModalOpen, setEnableModalOpen] = useState(false); | 
					
						
							|  |  |  |   const [disableModalOpen, setDisableModalOpen] = useState(false); | 
					
						
							| 
									
										
										
										
											2021-10-12 13:11:33 +00:00
										 |  |  |   const { t } = useLocale(); | 
					
						
							| 
									
										
										
										
											2021-09-21 09:29:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <div className="flex flex-row items-center"> | 
					
						
							| 
									
										
										
										
											2022-02-09 00:05:13 +00:00
										 |  |  |         <h2 className="font-cal text-lg font-medium leading-6 text-gray-900">{t("2fa")}</h2> | 
					
						
							|  |  |  |         <Badge className="ml-2 text-xs" variant={enabled ? "success" : "gray"}> | 
					
						
							| 
									
										
										
										
											2021-10-13 09:34:55 +00:00
										 |  |  |           {enabled ? t("enabled") : t("disabled")} | 
					
						
							| 
									
										
										
										
											2021-09-21 09:29:20 +00:00
										 |  |  |         </Badge> | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2021-10-08 11:43:48 +00:00
										 |  |  |       <p className="mt-1 text-sm text-gray-500">{t("add_an_extra_layer_of_security")}</p> | 
					
						
							| 
									
										
										
										
											2021-09-21 09:29:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       <Button | 
					
						
							|  |  |  |         className="mt-6" | 
					
						
							|  |  |  |         type="submit" | 
					
						
							|  |  |  |         onClick={() => (enabled ? setDisableModalOpen(true) : setEnableModalOpen(true))}> | 
					
						
							| 
									
										
										
										
											2021-10-13 09:34:55 +00:00
										 |  |  |         {enabled ? t("disable") : t("enable")} {t("2fa")} | 
					
						
							| 
									
										
										
										
											2021-09-21 09:29:20 +00:00
										 |  |  |       </Button> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       {enableModalOpen && ( | 
					
						
							|  |  |  |         <EnableTwoFactorModal | 
					
						
							|  |  |  |           onEnable={() => { | 
					
						
							|  |  |  |             setEnabled(true); | 
					
						
							|  |  |  |             setEnableModalOpen(false); | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |           onCancel={() => setEnableModalOpen(false)} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       {disableModalOpen && ( | 
					
						
							|  |  |  |         <DisableTwoFactorModal | 
					
						
							|  |  |  |           onDisable={() => { | 
					
						
							|  |  |  |             setEnabled(false); | 
					
						
							|  |  |  |             setDisableModalOpen(false); | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |           onCancel={() => setDisableModalOpen(false)} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |     </> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default TwoFactorAuthSection; |