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

158 lines (157 loc) 5.41 kB
import { jsx as e, jsxs as m } from "react/jsx-runtime"; 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 { validatePassword as U } from "../../utils/functions/StringUtils.js"; import "../../utils/SynapseConstants.js"; import "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "@tanstack/react-query"; import "../../utils/PermissionLevelToAccessType.js"; import { useState as s, useEffect as k } from "react"; import { useSynapseContext as q } from "../../utils/context/SynapseContext.js"; import "use-deep-compare-effect"; import { Alert as w, TextField as i, Button as R, Link as D } 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 '../../style/components/_spinner.css';/* empty css */ import "@tanstack/query-core"; import "lodash-es/isEmpty"; import "lodash-es/isEqual"; import "lodash-es/xorWith"; import { Navigate as G, Link as _ } from "react-router"; import "@sage-bionetworks/synapse-client"; import "../../utils/types/IsType.js"; import { useGetCurrentUserProfile as j } from "../../synapse-queries/user/useUserBundle.js"; import { displayToast as f } from "../ToastMessage/ToastMessage.js"; import O from "./useChangePasswordFormState.js"; const h = "Your password was successfully changed."; function yr(g) { const { redirectToRoute: l, hideReset2FA: P = !1 } = g, [n, C] = s(""), [a, v] = s(""), [y, x] = s( void 0 ), [d, S] = s(""), [o, u] = s(""), { isAuthenticated: p } = q(), { data: t, isLoading: b } = j({ enabled: p }); k(() => { t && o == "" && u(t.userName ?? t.emails[0]); }, [o, t, t?.userName]); const { promptForTwoFactorAuth: A, TwoFactorAuthPrompt: N, successfullyChangedPassword: E, isPending: F, handleChangePasswordWithCurrentPassword: T, error: c } = O({ hideReset2FA: P }), L = (r) => { r.preventDefault(), a !== d ? f("Passwords do not match.", "danger") : T( o, n, a ); }; return E ? l ? (f(h, "success"), /* @__PURE__ */ e(G, { to: l })) : /* @__PURE__ */ e(w, { severity: "success", children: h }) : /* @__PURE__ */ m("div", { children: [ A ? /* @__PURE__ */ e(N, {}) : /* @__PURE__ */ m( "form", { onSubmit: (r) => { L(r); }, children: [ !p && /* @__PURE__ */ e( i, { required: !0, fullWidth: !0, autoFocus: !0, autoComplete: "username", label: "Username or Email Address", id: "username", type: "text", value: o, onChange: (r) => u(r.target.value) } ), /* @__PURE__ */ e( i, { fullWidth: !0, required: !0, margin: "normal", type: "password", id: "currentPassword", label: "Current password", onChange: (r) => C(r.target.value), value: n } ), /* @__PURE__ */ e( i, { fullWidth: !0, required: !0, helperText: y, margin: "normal", type: "password", id: "newPassword", label: "New password", onChange: (r) => { const W = U(r.target.value); x(W), v(r.target.value); }, value: a } ), /* @__PURE__ */ e( i, { fullWidth: !0, required: !0, margin: "normal", type: "password", id: "confirmPassword", label: "Confirm password", onChange: (r) => S(r.target.value), value: d } ), /* @__PURE__ */ m("div", { style: { marginTop: "30px" }, children: [ /* @__PURE__ */ e( R, { sx: { marginRight: "26px" }, disabled: !n || !a || !d || !o || b || F, variant: "contained", type: "submit", children: "Change Password" } ), /* @__PURE__ */ e( D, { component: _, to: "/resetPassword", sx: { display: "block", marginTop: "1em", marginLeft: "5px" }, children: "Forgot password?" } ) ] }) ] } ), c && /* @__PURE__ */ e(w, { severity: "error", sx: { my: 2 }, children: c.reason }) ] }); } export { h as PASSWORD_CHANGED_SUCCESS_MESSAGE, yr as default }; //# sourceMappingURL=ChangePassword.js.map