UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

185 lines (184 loc) 6.7 kB
import { jsx as i, Fragment as O, jsxs as f } from "react/jsx-runtime"; import { useChangePassword as V } from "../../synapse-queries/auth/useChangePassword.js"; import "../../synapse-client/SynapseClient.js"; import "@sage-bionetworks/synapse-client/generated/models/ErrorResponseCode"; import "@sage-bionetworks/synapse-client/generated/models/TwoFactorAuthErrorResponse"; import "@sage-bionetworks/synapse-client/util/SynapseClientError"; import "@sage-bionetworks/synapse-types"; import "../../utils/functions/EntityTypeUtils.js"; import "../../utils/SynapseConstants.js"; import "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "../../utils/PermissionLevelToAccessType.js"; import { useState as a, useCallback as m } from "react"; import { useOneSageURL as W } from "../../utils/hooks/useOneSageURL.js"; import "use-deep-compare-effect"; import "../../utils/context/SynapseContext.js"; import "@tanstack/react-query"; import { Typography as I, Alert as y } from "@mui/material"; import "../../utils/hooks/useCookiePreferences.js"; import "../../utils/hooks/useSourceAppConfigs.js"; import "universal-cookie"; import "../../utils/AppUtils/session/ApplicationSessionContext.js"; import "../../utils/context/FullContextProvider.js"; import "../../utils/context/DocumentMetadataContext.js"; import '../FullWidthAlert/FullWidthAlert.css';import '../../style/components/_spinner.css';/* empty css */ import { useResetTwoFactorAuth as x } from "../../synapse-queries/auth/useTwoFactorEnrollment.js"; import "react-router"; import "@sage-bionetworks/synapse-client"; import "../../utils/types/IsType.js"; import "@tanstack/query-core"; import "lodash-es/isEmpty"; import "lodash-es/isEqual"; import "lodash-es/xorWith"; import Y from "../../utils/appendFinalQueryParamKey.js"; import "../../utils/functions/DateFormatter.js"; import "@mui/icons-material"; import "@react-hookz/web"; import "dayjs"; import "../styled/StyledFormControl.js"; import { TOTP_GUIDANCE_TEXT as v, RECOVERY_CODE_GUIDANCE_TEXT_SHORT as B } from "../Authentication/Constants.js"; import "../../assets/ArcusBioIcon.svg.js"; import "@mui/material/SvgIcon"; import "../../assets/icons/AccessPending.svg.js"; import "../../assets/icons/AccessPendingCloud.svg.js"; import "../../assets/icons/FileWithShield.svg.js"; import "../../assets/icons/MultiFile.svg.js"; import "../../assets/icons/UnpackagableFile.svg.js"; import "../../assets/icons/bioChemicalPhysical.svg.js"; import "../../assets/icons/computationalTool.svg.js"; import "../../assets/icons/dataReuse.svg.js"; import "../../assets/icons/inSilicoModel.svg.js"; import "../../assets/icons/modelSystem.svg.js"; import "../../assets/mui_components/PackagableFile.svg.js"; import "../../assets/icons/spatialProfiling.svg.js"; /* empty css */ import "../Authentication/AuthenticationMethodSelection.js"; import G from "../Authentication/OneTimePasswordForm.js"; import "../Authentication/TwoFactorEnrollmentForm.js"; import "../styled/LeftRightPanel.js"; import "react-hot-toast"; import "react-transition-group"; import "../Authentication/RecoveryCodeGrid.js"; const H = "Two-factor authentication is required to change your password. Your password has not yet been changed."; function $o(p) { const _ = W("/reset2FA"), w = Y( _, "twoFAResetToken" ), [C, k] = a(""), [g, T] = a(""), [e, R] = a(), [r, c] = a("VERIFICATION_CODE"), [S, D] = a(!1), { mutate: s, isPending: u, error: b } = V({ onSuccess: (o) => { o ? R(o) : (D(!0), R(void 0), p?.onChangePasswordSuccess && p.onChangePasswordSuccess()); } }), q = m( (o, t, n) => { k(t), T(n), s({ username: o, currentPassword: t, newPassword: n, concreteType: "org.sagebionetworks.repo.model.auth.ChangePasswordWithCurrentPassword" }); }, [s] ), N = m( (o, t) => { T(o), s({ newPassword: o, concreteType: "org.sagebionetworks.repo.model.auth.ChangePasswordWithToken", passwordChangeToken: t }); }, [s] ), l = m( (o, t, n) => { if (e) { const E = { newPassword: o, concreteType: "org.sagebionetworks.repo.model.auth.ChangePasswordWithTwoFactorAuthToken", userId: e.userId, twoFaToken: e.twoFaToken, otpType: n, otpCode: t }; s(E); } }, [s, e] ), d = !!e, { mutate: P, isSuccess: h, isPending: A } = x(), F = m( (o) => { if (e) { const t = { userId: e.userId, twoFaResetEndpoint: o, // When attempting to reset 2FA while resetting a password, the current password must be used to request 2FA reset password: C }; P(t); } }, [C, P, e] ), U = m(() => d ? /* @__PURE__ */ f(O, { children: [ r === "VERIFICATION_CODE" && /* @__PURE__ */ i(I, { variant: "body1", sx: { my: 2 }, align: "center", children: v }), r === "RECOVERY_CODE" && /* @__PURE__ */ i(I, { variant: "body1", sx: { my: 2 }, align: "center", children: B }), /* @__PURE__ */ i( G, { step: r, onClickUseTOTP: () => { c("VERIFICATION_CODE"); }, onClickUseBackupCode: () => { c("RECOVERY_CODE"); }, loginIsPending: u, onSubmit: (o, t) => l(g, o, t), hideReset2FA: p?.hideReset2FA, onClickPromptReset2FA: () => { c("DISABLE_2FA_PROMPT"); }, onClickReset2FA: () => { F(w); }, twoFactorAuthResetIsPending: A, twoFactorAuthResetIsSuccess: h } ), (r === "RECOVERY_CODE" || r === "VERIFICATION_CODE") && /* @__PURE__ */ i(y, { severity: "info", sx: { my: 2 }, children: H }), r === "DISABLE_2FA_PROMPT" && h && /* @__PURE__ */ f(y, { severity: "warning", sx: { my: 2 }, children: [ /* @__PURE__ */ i("strong", { children: "Your password has not been changed." }), " To disable two-factor authentication, you may be required to enter your current password after clicking the link sent to your email address." ] }) ] }) : /* @__PURE__ */ i(O, {}), [ F, l, u, g, p?.hideReset2FA, r, d, A, h, w ]); return { successfullyChangedPassword: S, isPending: u, error: b, promptForTwoFactorAuth: d, TwoFactorAuthPrompt: U, handleChangePasswordWithCurrentPassword: q, handleChangePasswordWithResetToken: N }; } export { H as TWO_FACTOR_AUTH_CHANGE_PASSWORD_PROMPT, $o as default }; //# sourceMappingURL=useChangePasswordFormState.js.map