import { Button, FocusModal, Heading, Hint, OtpInput, Text } from "@medusajs/ui" import type { AuthTypes } from "@medusajs/types" import { useState } from "react" import { useTranslation } from "react-i18next" import { useDisableAuthMfa } from "../../../../../hooks/api" type MfaDisableModalProps = { factor: AuthTypes.AuthMfaDTO onClose: () => void onSuccess: () => void } export const MfaDisableModal = ({ factor, onClose, onSuccess, }: MfaDisableModalProps) => { const { t } = useTranslation() const [code, setCode] = useState("") const [error, setError] = useState(null) const { mutateAsync, isPending } = useDisableAuthMfa(factor.id) const handleDisable = async (nextCode = code) => { if (nextCode.length !== 6) { return } setError(null) try { await mutateAsync({ method: factor.provider, code: nextCode, }) onSuccess() } catch (e) { setError(e instanceof Error ? e.message : t("profile.mfa.disableError")) setCode("") } } const handleOtpChange = (value: string) => { setCode(value) } return ( !open && onClose()}> {t("profile.mfa.disableTitle")}
{t("profile.mfa.disableTitle")} {t("profile.mfa.disableChallengeDescription")}
{error && ( {error} )}
) }