@joelbarron/react-web-dev-kit 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -160
- package/package.json +9 -2
- package/dist/auth/client.d.ts +0 -46
- package/dist/auth/client.d.ts.map +0 -1
- package/dist/auth/client.js +0 -379
- package/dist/auth/constants/countryCallingCodes.d.ts +0 -9
- package/dist/auth/constants/countryCallingCodes.d.ts.map +0 -1
- package/dist/auth/constants/countryCallingCodes.js +0 -209
- package/dist/auth/constants/gender.d.ts +0 -9
- package/dist/auth/constants/gender.d.ts.map +0 -1
- package/dist/auth/constants/gender.js +0 -12
- package/dist/auth/constants/index.d.ts +0 -3
- package/dist/auth/constants/index.d.ts.map +0 -1
- package/dist/auth/constants/index.js +0 -2
- package/dist/auth/forms/account/AuthAccountConfirmationForm.d.ts +0 -18
- package/dist/auth/forms/account/AuthAccountConfirmationForm.d.ts.map +0 -1
- package/dist/auth/forms/account/AuthAccountConfirmationForm.js +0 -167
- package/dist/auth/forms/account/index.d.ts +0 -2
- package/dist/auth/forms/account/index.d.ts.map +0 -1
- package/dist/auth/forms/account/index.js +0 -1
- package/dist/auth/forms/errorParser.d.ts +0 -7
- package/dist/auth/forms/errorParser.d.ts.map +0 -1
- package/dist/auth/forms/errorParser.js +0 -65
- package/dist/auth/forms/index.d.ts +0 -6
- package/dist/auth/forms/index.d.ts.map +0 -1
- package/dist/auth/forms/index.js +0 -5
- package/dist/auth/forms/password/AuthForgotPasswordForm.d.ts +0 -16
- package/dist/auth/forms/password/AuthForgotPasswordForm.d.ts.map +0 -1
- package/dist/auth/forms/password/AuthForgotPasswordForm.js +0 -109
- package/dist/auth/forms/password/AuthPasswordResetConfirmForm.d.ts +0 -17
- package/dist/auth/forms/password/AuthPasswordResetConfirmForm.d.ts.map +0 -1
- package/dist/auth/forms/password/AuthPasswordResetConfirmForm.js +0 -163
- package/dist/auth/forms/password/AuthResetPasswordForm.d.ts +0 -12
- package/dist/auth/forms/password/AuthResetPasswordForm.d.ts.map +0 -1
- package/dist/auth/forms/password/AuthResetPasswordForm.js +0 -22
- package/dist/auth/forms/password/index.d.ts +0 -4
- package/dist/auth/forms/password/index.d.ts.map +0 -1
- package/dist/auth/forms/password/index.js +0 -3
- package/dist/auth/forms/password/passwordValidation.d.ts +0 -3
- package/dist/auth/forms/password/passwordValidation.d.ts.map +0 -1
- package/dist/auth/forms/password/passwordValidation.js +0 -45
- package/dist/auth/forms/sign-in/AuthOtpSignInForm.d.ts +0 -24
- package/dist/auth/forms/sign-in/AuthOtpSignInForm.d.ts.map +0 -1
- package/dist/auth/forms/sign-in/AuthOtpSignInForm.js +0 -227
- package/dist/auth/forms/sign-in/AuthPasswordSignInForm.d.ts +0 -22
- package/dist/auth/forms/sign-in/AuthPasswordSignInForm.d.ts.map +0 -1
- package/dist/auth/forms/sign-in/AuthPasswordSignInForm.js +0 -148
- package/dist/auth/forms/sign-in/index.d.ts +0 -3
- package/dist/auth/forms/sign-in/index.d.ts.map +0 -1
- package/dist/auth/forms/sign-in/index.js +0 -2
- package/dist/auth/forms/sign-up/AuthSignUpForm.d.ts +0 -37
- package/dist/auth/forms/sign-up/AuthSignUpForm.d.ts.map +0 -1
- package/dist/auth/forms/sign-up/AuthSignUpForm.js +0 -193
- package/dist/auth/forms/sign-up/index.d.ts +0 -2
- package/dist/auth/forms/sign-up/index.d.ts.map +0 -1
- package/dist/auth/forms/sign-up/index.js +0 -1
- package/dist/auth/fuse/createFuseAuthViews.d.ts +0 -25
- package/dist/auth/fuse/createFuseAuthViews.d.ts.map +0 -1
- package/dist/auth/fuse/createFuseAuthViews.js +0 -510
- package/dist/auth/fuse/fuseAdapter.d.ts +0 -42
- package/dist/auth/fuse/fuseAdapter.d.ts.map +0 -1
- package/dist/auth/fuse/fuseAdapter.js +0 -291
- package/dist/auth/fuse/fuseIntegration.d.ts +0 -61
- package/dist/auth/fuse/fuseIntegration.d.ts.map +0 -1
- package/dist/auth/fuse/fuseIntegration.js +0 -103
- package/dist/auth/fuse/index.d.ts +0 -4
- package/dist/auth/fuse/index.d.ts.map +0 -1
- package/dist/auth/fuse/index.js +0 -3
- package/dist/auth/index.d.ts +0 -11
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -10
- package/dist/auth/provider.d.ts +0 -35
- package/dist/auth/provider.d.ts.map +0 -1
- package/dist/auth/provider.js +0 -133
- package/dist/auth/query.d.ts +0 -23
- package/dist/auth/query.d.ts.map +0 -1
- package/dist/auth/query.js +0 -103
- package/dist/auth/routes.d.ts +0 -37
- package/dist/auth/routes.d.ts.map +0 -1
- package/dist/auth/routes.js +0 -75
- package/dist/auth/social/providerAuth.d.ts +0 -101
- package/dist/auth/social/providerAuth.d.ts.map +0 -1
- package/dist/auth/social/providerAuth.js +0 -207
- package/dist/auth/storage.d.ts +0 -3
- package/dist/auth/storage.d.ts.map +0 -1
- package/dist/auth/storage.js +0 -20
- package/dist/auth/types.d.ts +0 -238
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -1
- package/dist/auth/ui/AuthPageTitle.d.ts +0 -7
- package/dist/auth/ui/AuthPageTitle.d.ts.map +0 -1
- package/dist/auth/ui/AuthPageTitle.js +0 -7
- package/dist/auth/ui/AuthPagesMessageSection.d.ts +0 -3
- package/dist/auth/ui/AuthPagesMessageSection.d.ts.map +0 -1
- package/dist/auth/ui/AuthPagesMessageSection.js +0 -39
- package/dist/auth/ui/AuthPrimaryButton.d.ts +0 -9
- package/dist/auth/ui/AuthPrimaryButton.d.ts.map +0 -1
- package/dist/auth/ui/AuthPrimaryButton.js +0 -19
- package/dist/auth/ui/AuthRoleSelectionDialog.d.ts +0 -14
- package/dist/auth/ui/AuthRoleSelectionDialog.d.ts.map +0 -1
- package/dist/auth/ui/AuthRoleSelectionDialog.js +0 -39
- package/dist/auth/ui/AuthRoutePageWrapper.d.ts +0 -12
- package/dist/auth/ui/AuthRoutePageWrapper.d.ts.map +0 -1
- package/dist/auth/ui/AuthRoutePageWrapper.js +0 -61
- package/dist/auth/ui/AuthSecondaryButton.d.ts +0 -7
- package/dist/auth/ui/AuthSecondaryButton.d.ts.map +0 -1
- package/dist/auth/ui/AuthSecondaryButton.js +0 -18
- package/dist/auth/ui/AuthSocialProviderButton.d.ts +0 -11
- package/dist/auth/ui/AuthSocialProviderButton.d.ts.map +0 -1
- package/dist/auth/ui/AuthSocialProviderButton.js +0 -33
- package/dist/auth/ui/index.d.ts +0 -9
- package/dist/auth/ui/index.d.ts.map +0 -1
- package/dist/auth/ui/index.js +0 -8
- package/dist/auth/ui/types.d.ts +0 -15
- package/dist/auth/ui/types.d.ts.map +0 -1
- package/dist/auth/ui/types.js +0 -1
- package/dist/config/createConfig.d.ts +0 -14
- package/dist/config/createConfig.d.ts.map +0 -1
- package/dist/config/createConfig.js +0 -179
- package/dist/config/defaults.d.ts +0 -3
- package/dist/config/defaults.d.ts.map +0 -1
- package/dist/config/defaults.js +0 -39
- package/dist/config/index.d.ts +0 -5
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -4
- package/dist/config/merge.d.ts +0 -2
- package/dist/config/merge.d.ts.map +0 -1
- package/dist/config/merge.js +0 -18
- package/dist/config/types.d.ts +0 -53
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -1
- package/dist/core/buttons/JBButton.d.ts +0 -8
- package/dist/core/buttons/JBButton.d.ts.map +0 -1
- package/dist/core/buttons/JBButton.js +0 -55
- package/dist/core/buttons/index.d.ts +0 -2
- package/dist/core/buttons/index.d.ts.map +0 -1
- package/dist/core/buttons/index.js +0 -1
- package/dist/core/dialogs/JBConfirmDialog.d.ts +0 -15
- package/dist/core/dialogs/JBConfirmDialog.d.ts.map +0 -1
- package/dist/core/dialogs/JBConfirmDialog.js +0 -6
- package/dist/core/dialogs/index.d.ts +0 -2
- package/dist/core/dialogs/index.d.ts.map +0 -1
- package/dist/core/dialogs/index.js +0 -1
- package/dist/core/index.d.ts +0 -5
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -4
- package/dist/core/layout/JBContentContainer.d.ts +0 -31
- package/dist/core/layout/JBContentContainer.d.ts.map +0 -1
- package/dist/core/layout/JBContentContainer.js +0 -50
- package/dist/core/layout/JBFormHeader.d.ts +0 -3
- package/dist/core/layout/JBFormHeader.d.ts.map +0 -1
- package/dist/core/layout/JBFormHeader.js +0 -131
- package/dist/core/layout/index.d.ts +0 -3
- package/dist/core/layout/index.d.ts.map +0 -1
- package/dist/core/layout/index.js +0 -2
- package/dist/core/skeletons/JBFormContentSkeleton.d.ts +0 -5
- package/dist/core/skeletons/JBFormContentSkeleton.d.ts.map +0 -1
- package/dist/core/skeletons/JBFormContentSkeleton.js +0 -12
- package/dist/core/skeletons/JBFormHeaderSkeleton.d.ts +0 -6
- package/dist/core/skeletons/JBFormHeaderSkeleton.d.ts.map +0 -1
- package/dist/core/skeletons/JBFormHeaderSkeleton.js +0 -19
- package/dist/core/skeletons/index.d.ts +0 -3
- package/dist/core/skeletons/index.d.ts.map +0 -1
- package/dist/core/skeletons/index.js +0 -2
- package/dist/forms/JBAutocompleteField.d.ts +0 -12
- package/dist/forms/JBAutocompleteField.d.ts.map +0 -1
- package/dist/forms/JBAutocompleteField.js +0 -20
- package/dist/forms/JBCheckboxField.d.ts +0 -12
- package/dist/forms/JBCheckboxField.d.ts.map +0 -1
- package/dist/forms/JBCheckboxField.js +0 -36
- package/dist/forms/JBDatePickerField.d.ts +0 -13
- package/dist/forms/JBDatePickerField.d.ts.map +0 -1
- package/dist/forms/JBDatePickerField.js +0 -49
- package/dist/forms/JBRadioGroupField.d.ts +0 -10
- package/dist/forms/JBRadioGroupField.d.ts.map +0 -1
- package/dist/forms/JBRadioGroupField.js +0 -8
- package/dist/forms/JBSelectField.d.ts +0 -9
- package/dist/forms/JBSelectField.d.ts.map +0 -1
- package/dist/forms/JBSelectField.js +0 -8
- package/dist/forms/JBSwitchField.d.ts +0 -11
- package/dist/forms/JBSwitchField.d.ts.map +0 -1
- package/dist/forms/JBSwitchField.js +0 -10
- package/dist/forms/JBTextField.d.ts +0 -6
- package/dist/forms/JBTextField.d.ts.map +0 -1
- package/dist/forms/JBTextField.js +0 -8
- package/dist/forms/JBTimePickerField.d.ts +0 -12
- package/dist/forms/JBTimePickerField.d.ts.map +0 -1
- package/dist/forms/JBTimePickerField.js +0 -17
- package/dist/forms/index.d.ts +0 -13
- package/dist/forms/index.d.ts.map +0 -1
- package/dist/forms/index.js +0 -12
- package/dist/forms/rules.d.ts +0 -16
- package/dist/forms/rules.d.ts.map +0 -1
- package/dist/forms/rules.js +0 -21
- package/dist/forms/types.d.ts +0 -12
- package/dist/forms/types.d.ts.map +0 -1
- package/dist/forms/types.js +0 -1
- package/dist/forms/utils.d.ts +0 -5
- package/dist/forms/utils.d.ts.map +0 -1
- package/dist/forms/utils.js +0 -7
- package/dist/forms/zod.d.ts +0 -4
- package/dist/forms/zod.d.ts.map +0 -1
- package/dist/forms/zod.js +0 -9
- package/dist/grid/JBGrid.d.ts +0 -3
- package/dist/grid/JBGrid.d.ts.map +0 -1
- package/dist/grid/JBGrid.js +0 -338
- package/dist/grid/JBGridHeader.d.ts +0 -3
- package/dist/grid/JBGridHeader.d.ts.map +0 -1
- package/dist/grid/JBGridHeader.js +0 -93
- package/dist/grid/JBGridLoading.d.ts +0 -9
- package/dist/grid/JBGridLoading.d.ts.map +0 -1
- package/dist/grid/JBGridLoading.js +0 -14
- package/dist/grid/JBGridProviders.d.ts +0 -13
- package/dist/grid/JBGridProviders.d.ts.map +0 -1
- package/dist/grid/JBGridProviders.js +0 -54
- package/dist/grid/JBGridSkeleton.d.ts +0 -7
- package/dist/grid/JBGridSkeleton.d.ts.map +0 -1
- package/dist/grid/JBGridSkeleton.js +0 -6
- package/dist/grid/defaults.d.ts +0 -4
- package/dist/grid/defaults.d.ts.map +0 -1
- package/dist/grid/defaults.js +0 -29
- package/dist/grid/index.d.ts +0 -8
- package/dist/grid/index.d.ts.map +0 -1
- package/dist/grid/index.js +0 -7
- package/dist/grid/types.d.ts +0 -197
- package/dist/grid/types.d.ts.map +0 -1
- package/dist/grid/types.js +0 -1
- package/dist/hooks/index.d.ts +0 -4
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -3
- package/dist/hooks/useJBDebouncedValue.d.ts +0 -2
- package/dist/hooks/useJBDebouncedValue.d.ts.map +0 -1
- package/dist/hooks/useJBDebouncedValue.js +0 -11
- package/dist/hooks/useJBEntityFormController.d.ts +0 -54
- package/dist/hooks/useJBEntityFormController.d.ts.map +0 -1
- package/dist/hooks/useJBEntityFormController.js +0 -156
- package/dist/hooks/useJBRedirect.d.ts +0 -10
- package/dist/hooks/useJBRedirect.d.ts.map +0 -1
- package/dist/hooks/useJBRedirect.js +0 -11
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -8
- package/dist/query/createQueryClient.d.ts +0 -8
- package/dist/query/createQueryClient.d.ts.map +0 -1
- package/dist/query/createQueryClient.js +0 -25
- package/dist/query/http.d.ts +0 -3
- package/dist/query/http.d.ts.map +0 -1
- package/dist/query/http.js +0 -12
- package/dist/query/index.d.ts +0 -4
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -3
- package/dist/query/types.d.ts +0 -7
- package/dist/query/types.d.ts.map +0 -1
- package/dist/query/types.js +0 -1
- package/dist/utils/errors.d.ts +0 -10
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js +0 -55
- package/dist/utils/format.d.ts +0 -4
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js +0 -28
- package/dist/utils/geo.d.ts +0 -9
- package/dist/utils/geo.d.ts.map +0 -1
- package/dist/utils/geo.js +0 -186
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -5
- package/dist/utils/query.d.ts +0 -2
- package/dist/utils/query.d.ts.map +0 -1
- package/dist/utils/query.js +0 -4
- package/dist/utils/regex.d.ts +0 -7
- package/dist/utils/regex.d.ts.map +0 -1
- package/dist/utils/regex.js +0 -6
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const GENDERS = ['MALE', 'FEMALE', 'OTHER', 'PREFER_NOT_TO_SAY'];
|
|
2
|
-
export const DEFAULT_GENDER = 'OTHER';
|
|
3
|
-
export const GENDER_LABELS = {
|
|
4
|
-
MALE: 'Masculino',
|
|
5
|
-
FEMALE: 'Femenino',
|
|
6
|
-
OTHER: 'Otro',
|
|
7
|
-
PREFER_NOT_TO_SAY: 'Prefiero no decirlo'
|
|
8
|
-
};
|
|
9
|
-
export const GENDER_SELECT_OPTIONS = GENDERS.map((value) => ({
|
|
10
|
-
value,
|
|
11
|
-
label: GENDER_LABELS[value]
|
|
12
|
-
}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type AuthAccountConfirmationFormValues = {
|
|
2
|
-
uid: string;
|
|
3
|
-
token: string;
|
|
4
|
-
};
|
|
5
|
-
export type AuthAccountConfirmationFormProps = {
|
|
6
|
-
defaultValues?: Partial<AuthAccountConfirmationFormValues>;
|
|
7
|
-
defaultEmail?: string;
|
|
8
|
-
onGoToSignIn?: () => void;
|
|
9
|
-
resendCooldownSeconds?: number;
|
|
10
|
-
signInRedirectSeconds?: number;
|
|
11
|
-
autoSubmit?: boolean;
|
|
12
|
-
onSubmit: (values: AuthAccountConfirmationFormValues) => unknown | Promise<unknown>;
|
|
13
|
-
onResend?: (values: {
|
|
14
|
-
email: string;
|
|
15
|
-
}) => unknown | Promise<unknown>;
|
|
16
|
-
};
|
|
17
|
-
export declare function AuthAccountConfirmationForm(props: AuthAccountConfirmationFormProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
-
//# sourceMappingURL=AuthAccountConfirmationForm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthAccountConfirmationForm.d.ts","sourceRoot":"","sources":["../../../../src/auth/forms/account/AuthAccountConfirmationForm.tsx"],"names":[],"mappings":"AAUA,MAAM,MAAM,iCAAiC,GAAG;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,aAAa,CAAC,EAAE,OAAO,CAAC,iCAAiC,CAAC,CAAC;IAC3D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,CAAC,MAAM,EAAE,iCAAiC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpF,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtE,CAAC;AAEF,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,gCAAgC,2CA8QlF"}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import Alert from '@mui/material/Alert';
|
|
3
|
-
import Button from '@mui/material/Button';
|
|
4
|
-
import CircularProgress from '@mui/material/CircularProgress';
|
|
5
|
-
import Stack from '@mui/material/Stack';
|
|
6
|
-
import Typography from '@mui/material/Typography';
|
|
7
|
-
import EmailOutlinedIcon from '@mui/icons-material/EmailOutlined';
|
|
8
|
-
import { useEffect, useRef, useState } from 'react';
|
|
9
|
-
import { AuthPrimaryButton, AuthSecondaryButton } from '../../ui';
|
|
10
|
-
import { parseAuthError } from '../errorParser';
|
|
11
|
-
export function AuthAccountConfirmationForm(props) {
|
|
12
|
-
const { defaultValues, defaultEmail, onGoToSignIn, resendCooldownSeconds = 30, signInRedirectSeconds = 5, autoSubmit = true, onSubmit, onResend } = props;
|
|
13
|
-
const uid = defaultValues?.uid ?? '';
|
|
14
|
-
const token = defaultValues?.token ?? '';
|
|
15
|
-
const email = defaultEmail?.trim() ?? '';
|
|
16
|
-
const hasValues = Boolean(uid && token);
|
|
17
|
-
const canResendFromSignup = !hasValues && Boolean(email) && Boolean(onResend);
|
|
18
|
-
const hasAutoSubmittedRef = useRef(false);
|
|
19
|
-
const hasInitializedCooldownRef = useRef(false);
|
|
20
|
-
const [loading, setLoading] = useState(false);
|
|
21
|
-
const [resending, setResending] = useState(false);
|
|
22
|
-
const [isSuccess, setIsSuccess] = useState(false);
|
|
23
|
-
const [isExpiredVerificationError, setIsExpiredVerificationError] = useState(false);
|
|
24
|
-
const [errorMessage, setErrorMessage] = useState(null);
|
|
25
|
-
const [resendMessage, setResendMessage] = useState(null);
|
|
26
|
-
const [resendCooldown, setResendCooldown] = useState(0);
|
|
27
|
-
const [signInRedirectCountdown, setSignInRedirectCountdown] = useState(null);
|
|
28
|
-
const shouldAutoRedirectToSignIn = Boolean(isSuccess && hasValues);
|
|
29
|
-
const canResendFromExpiredLink = hasValues && isExpiredVerificationError && Boolean(email) && Boolean(onResend);
|
|
30
|
-
const isExpiredMessage = (message) => {
|
|
31
|
-
const normalized = message
|
|
32
|
-
.normalize('NFD')
|
|
33
|
-
.replace(/[\u0300-\u036f]/g, '')
|
|
34
|
-
.toLowerCase();
|
|
35
|
-
return normalized.includes('expir') || normalized.includes('invalid') || normalized.includes('invalido');
|
|
36
|
-
};
|
|
37
|
-
const submit = async () => {
|
|
38
|
-
if (!hasValues) {
|
|
39
|
-
setErrorMessage('El enlace no es válido o está incompleto.');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
setLoading(true);
|
|
44
|
-
setErrorMessage(null);
|
|
45
|
-
setIsExpiredVerificationError(false);
|
|
46
|
-
await onSubmit({ uid, token });
|
|
47
|
-
setIsSuccess(true);
|
|
48
|
-
setSignInRedirectCountdown(signInRedirectSeconds);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
setIsSuccess(false);
|
|
52
|
-
const parsed = parseAuthError(error);
|
|
53
|
-
const resolvedMessage = parsed.rootMessage || 'No se pudo verificar la cuenta. El enlace puede haber expirado.';
|
|
54
|
-
setErrorMessage(resolvedMessage);
|
|
55
|
-
setIsExpiredVerificationError(isExpiredMessage(resolvedMessage));
|
|
56
|
-
}
|
|
57
|
-
finally {
|
|
58
|
-
setLoading(false);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const resend = async () => {
|
|
62
|
-
if (!onResend || !email || resendCooldown > 0) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
setResendMessage(null);
|
|
67
|
-
setErrorMessage(null);
|
|
68
|
-
setResending(true);
|
|
69
|
-
await onResend({ email });
|
|
70
|
-
setResendMessage('Correo de verificación reenviado.');
|
|
71
|
-
setResendCooldown(resendCooldownSeconds);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
setErrorMessage('No se pudo reenviar el correo de verificación.');
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
setResending(false);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
if (!canResendFromSignup || hasInitializedCooldownRef.current) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
hasInitializedCooldownRef.current = true;
|
|
85
|
-
setResendCooldown(resendCooldownSeconds);
|
|
86
|
-
}, [canResendFromSignup, resendCooldownSeconds]);
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
if (resendCooldown <= 0) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const timeoutId = window.setTimeout(() => {
|
|
92
|
-
setResendCooldown((currentValue) => Math.max(0, currentValue - 1));
|
|
93
|
-
}, 1000);
|
|
94
|
-
return () => window.clearTimeout(timeoutId);
|
|
95
|
-
}, [resendCooldown]);
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
if (!shouldAutoRedirectToSignIn || !onGoToSignIn || !signInRedirectCountdown || signInRedirectCountdown <= 0) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const timeoutId = window.setTimeout(() => {
|
|
101
|
-
setSignInRedirectCountdown((currentValue) => {
|
|
102
|
-
if (!currentValue) {
|
|
103
|
-
return 0;
|
|
104
|
-
}
|
|
105
|
-
return currentValue - 1;
|
|
106
|
-
});
|
|
107
|
-
}, 1000);
|
|
108
|
-
return () => window.clearTimeout(timeoutId);
|
|
109
|
-
}, [shouldAutoRedirectToSignIn, onGoToSignIn, signInRedirectCountdown]);
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
if (!shouldAutoRedirectToSignIn || !onGoToSignIn || signInRedirectCountdown !== 0) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
onGoToSignIn();
|
|
115
|
-
}, [shouldAutoRedirectToSignIn, onGoToSignIn, signInRedirectCountdown]);
|
|
116
|
-
const formatCooldown = (seconds) => {
|
|
117
|
-
const minutes = Math.floor(seconds / 60)
|
|
118
|
-
.toString()
|
|
119
|
-
.padStart(2, '0');
|
|
120
|
-
const remainingSeconds = (seconds % 60).toString().padStart(2, '0');
|
|
121
|
-
return `${minutes}:${remainingSeconds}`;
|
|
122
|
-
};
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
if (!autoSubmit || !hasValues || hasAutoSubmittedRef.current) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
hasAutoSubmittedRef.current = true;
|
|
128
|
-
void submit();
|
|
129
|
-
}, [autoSubmit, hasValues, uid, token]);
|
|
130
|
-
useEffect(() => {
|
|
131
|
-
hasAutoSubmittedRef.current = false;
|
|
132
|
-
setLoading(false);
|
|
133
|
-
setResending(false);
|
|
134
|
-
setErrorMessage(null);
|
|
135
|
-
setResendMessage(null);
|
|
136
|
-
setIsExpiredVerificationError(false);
|
|
137
|
-
if (canResendFromSignup) {
|
|
138
|
-
hasInitializedCooldownRef.current = true;
|
|
139
|
-
setResendCooldown(resendCooldownSeconds);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
hasInitializedCooldownRef.current = false;
|
|
143
|
-
setResendCooldown(0);
|
|
144
|
-
}
|
|
145
|
-
if (!hasValues) {
|
|
146
|
-
setIsSuccess(false);
|
|
147
|
-
setSignInRedirectCountdown(null);
|
|
148
|
-
}
|
|
149
|
-
}, [uid, token, email, hasValues, canResendFromSignup, resendCooldownSeconds]);
|
|
150
|
-
return (_jsxs(Stack, { spacing: 2, children: [!hasValues && email ? (_jsx(Alert, { severity: "info", children: "Tu cuenta fue creada. Revisa tu correo para verificar tu cuenta." })) : null, !hasValues && !email ? (_jsx(Alert, { severity: "warning", children: "Falta informaci\u00F3n del enlace de verificaci\u00F3n." })) : null, loading ? (_jsx(Alert, { severity: "info", children: _jsxs(Stack, { direction: "row", spacing: 1, alignItems: "center", children: [_jsx(CircularProgress, { size: 16, color: "inherit" }), _jsx(Typography, { variant: "body2", children: "Verificando tu cuenta..." })] }) })) : null, isSuccess ? _jsx(Alert, { severity: "success", children: "Tu cuenta fue verificada correctamente." }) : null, resendMessage ? _jsx(Alert, { severity: "success", children: resendMessage }) : null, errorMessage ? _jsx(Alert, { severity: "error", children: errorMessage }) : null, !isSuccess && hasValues && !canResendFromExpiredLink ? (_jsx(Button, { variant: "contained", onClick: () => {
|
|
151
|
-
void submit();
|
|
152
|
-
}, disabled: loading, children: "Reintentar verificaci\u00F3n" })) : null, canResendFromSignup ? (_jsxs(Stack, { sx: { mt: 1.5 }, children: [_jsx(AuthPrimaryButton, { type: "button", startIcon: _jsx(EmailOutlinedIcon, { fontSize: "small" }), onClick: onGoToSignIn, children: "Ir a iniciar sesi\u00F3n" }), _jsx(AuthSecondaryButton, { sx: { mt: 1.5 }, type: "button", onClick: () => {
|
|
153
|
-
void resend();
|
|
154
|
-
}, disabled: resending || resendCooldown > 0, children: resending
|
|
155
|
-
? 'Reenviando...'
|
|
156
|
-
: resendCooldown > 0
|
|
157
|
-
? `Reenviar verificación (${formatCooldown(resendCooldown)})`
|
|
158
|
-
: 'Reenviar verificación' })] })) : null, canResendFromExpiredLink ? (_jsx(Stack, { sx: { mt: 1.5 }, children: _jsx(AuthSecondaryButton, { type: "button", onClick: () => {
|
|
159
|
-
void resend();
|
|
160
|
-
}, disabled: resending || resendCooldown > 0, children: resending
|
|
161
|
-
? 'Reenviando...'
|
|
162
|
-
: resendCooldown > 0
|
|
163
|
-
? `Reenviar verificación (${formatCooldown(resendCooldown)})`
|
|
164
|
-
: 'Reenviar verificación' }) })) : null, isSuccess && !canResendFromSignup && !canResendFromExpiredLink ? (_jsx(Stack, { sx: { mt: 1.5 }, children: _jsx(AuthPrimaryButton, { type: "button", startIcon: _jsx(EmailOutlinedIcon, { fontSize: "small" }), onClick: onGoToSignIn, children: `Ir a iniciar sesión${typeof signInRedirectCountdown === 'number' && signInRedirectCountdown > 0
|
|
165
|
-
? ` (${signInRedirectCountdown}s)`
|
|
166
|
-
: ''}` }) })) : null] }));
|
|
167
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/auth/forms/account/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './AuthAccountConfirmationForm';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errorParser.d.ts","sourceRoot":"","sources":["../../../src/auth/forms/errorParser.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAoBF,eAAO,MAAM,cAAc,GACzB,OAAO,OAAO,EACd,eAAe,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACpC,eAwDF,CAAC"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const toCamelCase = (value) => value.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
2
|
-
const readMessage = (value) => {
|
|
3
|
-
if (!value)
|
|
4
|
-
return undefined;
|
|
5
|
-
if (typeof value === 'string')
|
|
6
|
-
return value;
|
|
7
|
-
if (Array.isArray(value)) {
|
|
8
|
-
const first = value.find((item) => typeof item === 'string');
|
|
9
|
-
return typeof first === 'string' ? first : undefined;
|
|
10
|
-
}
|
|
11
|
-
if (typeof value === 'object') {
|
|
12
|
-
const record = value;
|
|
13
|
-
if (typeof record.message === 'string')
|
|
14
|
-
return record.message;
|
|
15
|
-
if (typeof record.detail === 'string')
|
|
16
|
-
return record.detail;
|
|
17
|
-
}
|
|
18
|
-
return undefined;
|
|
19
|
-
};
|
|
20
|
-
export const parseAuthError = (error, fieldAliases) => {
|
|
21
|
-
const raw = error;
|
|
22
|
-
const responseData = (raw.response?.data ?? raw.data);
|
|
23
|
-
const parsed = { fieldErrors: {} };
|
|
24
|
-
const normalizeField = (key) => {
|
|
25
|
-
const camelKey = toCamelCase(key);
|
|
26
|
-
return fieldAliases?.[camelKey] ?? camelKey;
|
|
27
|
-
};
|
|
28
|
-
const legacyErrors = responseData?.data;
|
|
29
|
-
if (Array.isArray(legacyErrors)) {
|
|
30
|
-
legacyErrors.forEach((entry) => {
|
|
31
|
-
const item = entry;
|
|
32
|
-
if (!item?.type || !item?.message)
|
|
33
|
-
return;
|
|
34
|
-
const field = normalizeField(item.type);
|
|
35
|
-
if (field === 'root') {
|
|
36
|
-
parsed.rootMessage = item.message;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
parsed.fieldErrors[field] = item.message;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
if (typeof responseData === 'string' && !parsed.rootMessage) {
|
|
43
|
-
parsed.rootMessage = responseData;
|
|
44
|
-
}
|
|
45
|
-
if (responseData && typeof responseData === 'object' && !Array.isArray(responseData)) {
|
|
46
|
-
const data = responseData;
|
|
47
|
-
const detailMessage = readMessage(data.detail);
|
|
48
|
-
const nonFieldMessage = readMessage(data.non_field_errors);
|
|
49
|
-
const message = readMessage(data.message);
|
|
50
|
-
parsed.rootMessage = parsed.rootMessage ?? detailMessage ?? nonFieldMessage ?? message;
|
|
51
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
52
|
-
if (['detail', 'non_field_errors', 'message', 'code', 'status'].includes(key)) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const fieldMessage = readMessage(value);
|
|
56
|
-
if (!fieldMessage)
|
|
57
|
-
return;
|
|
58
|
-
parsed.fieldErrors[normalizeField(key)] = fieldMessage;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (!parsed.rootMessage && Object.keys(parsed.fieldErrors).length === 0 && raw.message) {
|
|
62
|
-
parsed.rootMessage = raw.message;
|
|
63
|
-
}
|
|
64
|
-
return parsed;
|
|
65
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/forms/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
|
package/dist/auth/forms/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type AuthForgotPasswordFormValues = {
|
|
2
|
-
email: string;
|
|
3
|
-
};
|
|
4
|
-
export type AuthForgotPasswordFormProps = {
|
|
5
|
-
defaultValues?: Partial<AuthForgotPasswordFormValues>;
|
|
6
|
-
loading?: boolean;
|
|
7
|
-
submitLabel?: string;
|
|
8
|
-
resendLabel?: string;
|
|
9
|
-
successMessage?: string;
|
|
10
|
-
notSentMessage?: string;
|
|
11
|
-
resendCooldownSeconds?: number;
|
|
12
|
-
onEmailSentSuccess?: () => void;
|
|
13
|
-
onSubmit: (values: AuthForgotPasswordFormValues) => unknown | Promise<unknown>;
|
|
14
|
-
};
|
|
15
|
-
export declare function AuthForgotPasswordForm(props: AuthForgotPasswordFormProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
//# sourceMappingURL=AuthForgotPasswordForm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthForgotPasswordForm.d.ts","sourceRoot":"","sources":["../../../../src/auth/forms/password/AuthForgotPasswordForm.tsx"],"names":[],"mappings":"AAYA,MAAM,MAAM,4BAA4B,GAAG;IACzC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,CAAC,EAAE,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACtD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,QAAQ,EAAE,CAAC,MAAM,EAAE,4BAA4B,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChF,CAAC;AAgBF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,2CA+JxE"}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { zodResolver } from '@hookform/resolvers/zod';
|
|
3
|
-
import LinkOutlinedIcon from '@mui/icons-material/LinkOutlined';
|
|
4
|
-
import Alert from '@mui/material/Alert';
|
|
5
|
-
import _ from 'lodash';
|
|
6
|
-
import { useEffect, useState } from 'react';
|
|
7
|
-
import { useForm } from 'react-hook-form';
|
|
8
|
-
import { z } from 'zod';
|
|
9
|
-
import { JBTextField } from '../../../forms';
|
|
10
|
-
import { AuthPrimaryButton } from '../../ui';
|
|
11
|
-
import { parseAuthError } from '../errorParser';
|
|
12
|
-
function getEmailSentFlag(response) {
|
|
13
|
-
if (!response || typeof response !== 'object') {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
const data = response;
|
|
17
|
-
const emailSent = data.emailSent ?? data.email_sent;
|
|
18
|
-
return typeof emailSent === 'boolean' ? emailSent : undefined;
|
|
19
|
-
}
|
|
20
|
-
const forgotSchema = z.object({
|
|
21
|
-
email: z.string().email('Debes ingresar un correo válido').nonempty('Debes ingresar un correo')
|
|
22
|
-
});
|
|
23
|
-
export function AuthForgotPasswordForm(props) {
|
|
24
|
-
const { defaultValues, loading = false, submitLabel = 'Enviar enlace de recuperación', resendLabel = 'Reenviar enlace de recuperación', successMessage = 'Si la cuenta existe, enviamos un enlace de recuperación a tu correo.', notSentMessage = 'Solicitud recibida, pero no se pudo enviar el correo de recuperación.', resendCooldownSeconds = 30, onEmailSentSuccess, onSubmit } = props;
|
|
25
|
-
const [success, setSuccess] = useState(null);
|
|
26
|
-
const [successSeverity, setSuccessSeverity] = useState('success');
|
|
27
|
-
const [isEmailSentSuccessfully, setIsEmailSentSuccessfully] = useState(false);
|
|
28
|
-
const [resendSecondsLeft, setResendSecondsLeft] = useState(0);
|
|
29
|
-
const { control, formState, handleSubmit, setError, clearErrors, watch } = useForm({
|
|
30
|
-
mode: 'onChange',
|
|
31
|
-
defaultValues: {
|
|
32
|
-
email: defaultValues?.email ?? ''
|
|
33
|
-
},
|
|
34
|
-
resolver: zodResolver(forgotSchema)
|
|
35
|
-
});
|
|
36
|
-
const { errors, dirtyFields, isSubmitting, isValid } = formState;
|
|
37
|
-
const emailValue = watch('email');
|
|
38
|
-
const isResendCooldownActive = isEmailSentSuccessfully && resendSecondsLeft > 0;
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (!isResendCooldownActive) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const timer = window.setInterval(() => {
|
|
44
|
-
setResendSecondsLeft((current) => {
|
|
45
|
-
if (current <= 1) {
|
|
46
|
-
window.clearInterval(timer);
|
|
47
|
-
return 0;
|
|
48
|
-
}
|
|
49
|
-
return current - 1;
|
|
50
|
-
});
|
|
51
|
-
}, 1000);
|
|
52
|
-
return () => {
|
|
53
|
-
window.clearInterval(timer);
|
|
54
|
-
};
|
|
55
|
-
}, [isResendCooldownActive]);
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
const subscription = watch((_value, { name }) => {
|
|
58
|
-
if (name) {
|
|
59
|
-
clearErrors(name);
|
|
60
|
-
}
|
|
61
|
-
clearErrors('root');
|
|
62
|
-
});
|
|
63
|
-
return () => {
|
|
64
|
-
subscription.unsubscribe();
|
|
65
|
-
};
|
|
66
|
-
}, [watch, clearErrors]);
|
|
67
|
-
async function onSubmitForm(values) {
|
|
68
|
-
try {
|
|
69
|
-
setSuccess(null);
|
|
70
|
-
const response = await onSubmit(values);
|
|
71
|
-
const emailSent = getEmailSentFlag(response);
|
|
72
|
-
setSuccessSeverity(emailSent === false ? 'warning' : 'success');
|
|
73
|
-
setSuccess(emailSent === false ? notSentMessage : successMessage);
|
|
74
|
-
setIsEmailSentSuccessfully(emailSent === true);
|
|
75
|
-
if (emailSent === true) {
|
|
76
|
-
setResendSecondsLeft(resendCooldownSeconds);
|
|
77
|
-
onEmailSentSuccess?.();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
const parsed = parseAuthError(error);
|
|
82
|
-
Object.entries(parsed.fieldErrors).forEach(([field, message]) => {
|
|
83
|
-
if (field === 'email') {
|
|
84
|
-
setError('email', {
|
|
85
|
-
type: 'manual',
|
|
86
|
-
message
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
setError('root', {
|
|
91
|
-
type: 'manual',
|
|
92
|
-
message
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
if (parsed.rootMessage) {
|
|
96
|
-
setError('root', {
|
|
97
|
-
type: 'manual',
|
|
98
|
-
message: parsed.rootMessage
|
|
99
|
-
});
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
setError('root', {
|
|
103
|
-
type: 'manual',
|
|
104
|
-
message: 'No se pudo enviar el correo de recuperación. Inténtalo de nuevo.'
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return (_jsxs("form", { name: "forgotPasswordForm", noValidate: true, style: { display: 'flex', width: '100%', flexDirection: 'column', justifyContent: 'center', paddingTop: 4 }, onSubmit: handleSubmit(onSubmitForm), children: [!isEmailSentSuccessfully ? (_jsx(JBTextField, { control: control, name: "email", sx: { mb: 3 }, label: "Correo electr\u00F3nico", autoFocus: true, type: "email", variant: "outlined", required: true, fullWidth: true })) : null, errors.root?.message && (_jsx(Alert, { sx: { mb: 2 }, severity: "error", children: errors.root.message })), success && (_jsx(Alert, { sx: { mb: 2 }, severity: successSeverity, children: success })), !isEmailSentSuccessfully ? (_jsx(AuthPrimaryButton, { "aria-label": submitLabel, type: "submit", startIcon: _jsx(LinkOutlinedIcon, { fontSize: "small" }), disabled: loading || isSubmitting || _.isEmpty(dirtyFields) || !isValid, children: submitLabel })) : (_jsx(AuthPrimaryButton, { "aria-label": resendLabel, type: "submit", startIcon: _jsx(LinkOutlinedIcon, { fontSize: "small" }), disabled: loading || isSubmitting || isResendCooldownActive || !isValid || !emailValue?.trim(), children: isResendCooldownActive ? `${resendLabel} (${resendSecondsLeft}s)` : resendLabel }))] }));
|
|
109
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type AuthPasswordResetConfirmFormValues = {
|
|
2
|
-
uid: string;
|
|
3
|
-
token: string;
|
|
4
|
-
newPassword: string;
|
|
5
|
-
newPasswordConfirm: string;
|
|
6
|
-
};
|
|
7
|
-
export type AuthPasswordResetConfirmFormProps = {
|
|
8
|
-
defaultValues?: Partial<AuthPasswordResetConfirmFormValues>;
|
|
9
|
-
loading?: boolean;
|
|
10
|
-
submitLabel?: string;
|
|
11
|
-
successMessage?: string;
|
|
12
|
-
successRedirectSeconds?: number;
|
|
13
|
-
onGoToSignIn?: () => void;
|
|
14
|
-
onSubmit: (values: AuthPasswordResetConfirmFormValues) => unknown | Promise<unknown>;
|
|
15
|
-
};
|
|
16
|
-
export declare function AuthPasswordResetConfirmForm(props: AuthPasswordResetConfirmFormProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
-
//# sourceMappingURL=AuthPasswordResetConfirmForm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthPasswordResetConfirmForm.d.ts","sourceRoot":"","sources":["../../../../src/auth/forms/password/AuthPasswordResetConfirmForm.tsx"],"names":[],"mappings":"AAkBA,MAAM,MAAM,kCAAkC,GAAG;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,aAAa,CAAC,EAAE,OAAO,CAAC,kCAAkC,CAAC,CAAC;IAC5D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,QAAQ,EAAE,CAAC,MAAM,EAAE,kCAAkC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtF,CAAC;AA8BF,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,iCAAiC,2CA6OpF"}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { zodResolver } from '@hookform/resolvers/zod';
|
|
3
|
-
import ArrowBackOutlinedIcon from '@mui/icons-material/ArrowBackOutlined';
|
|
4
|
-
import LockResetOutlinedIcon from '@mui/icons-material/LockResetOutlined';
|
|
5
|
-
import VisibilityOffOutlinedIcon from '@mui/icons-material/VisibilityOffOutlined';
|
|
6
|
-
import VisibilityOutlinedIcon from '@mui/icons-material/VisibilityOutlined';
|
|
7
|
-
import Alert from '@mui/material/Alert';
|
|
8
|
-
import IconButton from '@mui/material/IconButton';
|
|
9
|
-
import InputAdornment from '@mui/material/InputAdornment';
|
|
10
|
-
import _ from 'lodash';
|
|
11
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
12
|
-
import { useForm } from 'react-hook-form';
|
|
13
|
-
import { z } from 'zod';
|
|
14
|
-
import { JBTextField } from '../../../forms';
|
|
15
|
-
import { AuthPrimaryButton, AuthSecondaryButton } from '../../ui';
|
|
16
|
-
import { parseAuthError } from '../errorParser';
|
|
17
|
-
import { getDjangoLikePasswordError } from './passwordValidation';
|
|
18
|
-
const resetSchema = z
|
|
19
|
-
.object({
|
|
20
|
-
uid: z.string().nonempty('El uid es obligatorio'),
|
|
21
|
-
token: z.string().nonempty('El token es obligatorio'),
|
|
22
|
-
newPassword: z.string().superRefine((value, ctx) => {
|
|
23
|
-
if (!value) {
|
|
24
|
-
ctx.addIssue({
|
|
25
|
-
code: z.ZodIssueCode.custom,
|
|
26
|
-
message: 'Debes ingresar tu nueva contraseña'
|
|
27
|
-
});
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const passwordError = getDjangoLikePasswordError(value);
|
|
31
|
-
if (passwordError) {
|
|
32
|
-
ctx.addIssue({
|
|
33
|
-
code: z.ZodIssueCode.custom,
|
|
34
|
-
message: passwordError
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}),
|
|
38
|
-
newPasswordConfirm: z.string().nonempty('La confirmación de contraseña es obligatoria')
|
|
39
|
-
})
|
|
40
|
-
.refine((data) => data.newPassword === data.newPasswordConfirm, {
|
|
41
|
-
message: 'Las contraseñas deben coincidir',
|
|
42
|
-
path: ['newPasswordConfirm']
|
|
43
|
-
});
|
|
44
|
-
export function AuthPasswordResetConfirmForm(props) {
|
|
45
|
-
const { defaultValues, loading = false, submitLabel = 'Restablecer contraseña', successMessage = 'Contraseña restablecida correctamente. Ya puedes iniciar sesión.', successRedirectSeconds = 5, onGoToSignIn, onSubmit } = props;
|
|
46
|
-
const [redirectSecondsLeft, setRedirectSecondsLeft] = useState(null);
|
|
47
|
-
const [showNewPassword, setShowNewPassword] = useState(false);
|
|
48
|
-
const [showNewPasswordConfirm, setShowNewPasswordConfirm] = useState(false);
|
|
49
|
-
const { control, formState, handleSubmit, setError, clearErrors, watch } = useForm({
|
|
50
|
-
mode: 'onChange',
|
|
51
|
-
defaultValues: {
|
|
52
|
-
uid: defaultValues?.uid ?? '',
|
|
53
|
-
token: defaultValues?.token ?? '',
|
|
54
|
-
newPassword: defaultValues?.newPassword ?? '',
|
|
55
|
-
newPasswordConfirm: defaultValues?.newPasswordConfirm ?? ''
|
|
56
|
-
},
|
|
57
|
-
resolver: zodResolver(resetSchema)
|
|
58
|
-
});
|
|
59
|
-
const { errors, dirtyFields, isSubmitting, isValid, isSubmitSuccessful } = formState;
|
|
60
|
-
const uidValue = watch('uid');
|
|
61
|
-
const tokenValue = watch('token');
|
|
62
|
-
const hasValidRecoveryLink = Boolean(uidValue?.trim() && tokenValue?.trim());
|
|
63
|
-
const goToSignInLabel = useMemo(() => {
|
|
64
|
-
if (!isSubmitSuccessful) {
|
|
65
|
-
return 'Ir a iniciar sesión';
|
|
66
|
-
}
|
|
67
|
-
if (!redirectSecondsLeft || redirectSecondsLeft <= 0) {
|
|
68
|
-
return 'Ir a iniciar sesión';
|
|
69
|
-
}
|
|
70
|
-
return `Ir a iniciar sesión (${redirectSecondsLeft}s)`;
|
|
71
|
-
}, [isSubmitSuccessful, redirectSecondsLeft]);
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
const subscription = watch((_value, { name }) => {
|
|
74
|
-
if (name) {
|
|
75
|
-
clearErrors(name);
|
|
76
|
-
}
|
|
77
|
-
clearErrors('root');
|
|
78
|
-
});
|
|
79
|
-
return () => {
|
|
80
|
-
subscription.unsubscribe();
|
|
81
|
-
};
|
|
82
|
-
}, [watch, clearErrors]);
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
if (!isSubmitSuccessful || !onGoToSignIn) {
|
|
85
|
-
setRedirectSecondsLeft(null);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
setRedirectSecondsLeft(successRedirectSeconds);
|
|
89
|
-
const timer = window.setInterval(() => {
|
|
90
|
-
setRedirectSecondsLeft((current) => {
|
|
91
|
-
if (!current || current <= 1) {
|
|
92
|
-
window.clearInterval(timer);
|
|
93
|
-
onGoToSignIn();
|
|
94
|
-
return 0;
|
|
95
|
-
}
|
|
96
|
-
return current - 1;
|
|
97
|
-
});
|
|
98
|
-
}, 1000);
|
|
99
|
-
return () => {
|
|
100
|
-
window.clearInterval(timer);
|
|
101
|
-
};
|
|
102
|
-
}, [isSubmitSuccessful, onGoToSignIn, successRedirectSeconds]);
|
|
103
|
-
async function onSubmitForm(values) {
|
|
104
|
-
try {
|
|
105
|
-
await onSubmit(values);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
const parsed = parseAuthError(error);
|
|
109
|
-
const allowedFields = [
|
|
110
|
-
'uid',
|
|
111
|
-
'token',
|
|
112
|
-
'newPassword',
|
|
113
|
-
'newPasswordConfirm'
|
|
114
|
-
];
|
|
115
|
-
Object.entries(parsed.fieldErrors).forEach(([field, message]) => {
|
|
116
|
-
if (field === 'uid' || field === 'token') {
|
|
117
|
-
setError('root', {
|
|
118
|
-
type: 'manual',
|
|
119
|
-
message
|
|
120
|
-
});
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (allowedFields.includes(field)) {
|
|
124
|
-
setError(field, {
|
|
125
|
-
type: 'manual',
|
|
126
|
-
message
|
|
127
|
-
});
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
setError('root', {
|
|
131
|
-
type: 'manual',
|
|
132
|
-
message
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
if (parsed.rootMessage) {
|
|
136
|
-
setError('root', {
|
|
137
|
-
type: 'manual',
|
|
138
|
-
message: parsed.rootMessage
|
|
139
|
-
});
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (Object.keys(parsed.fieldErrors).length > 0) {
|
|
143
|
-
const firstFieldError = Object.values(parsed.fieldErrors)[0];
|
|
144
|
-
if (firstFieldError) {
|
|
145
|
-
setError('root', {
|
|
146
|
-
type: 'manual',
|
|
147
|
-
message: firstFieldError
|
|
148
|
-
});
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
setError('root', {
|
|
153
|
-
type: 'manual',
|
|
154
|
-
message: 'No se pudo restablecer la contraseña. Inténtalo de nuevo.'
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return (_jsxs("form", { name: "resetPasswordForm", noValidate: true, style: { display: 'flex', width: '100%', flexDirection: 'column', justifyContent: 'center', paddingTop: 4 }, onSubmit: handleSubmit(onSubmitForm), children: [!isSubmitSuccessful && !hasValidRecoveryLink ? (_jsx(Alert, { sx: { mb: 3 }, severity: "warning", children: "El enlace de recuperaci\u00F3n es inv\u00E1lido o incompleto." })) : null, !isSubmitSuccessful ? (_jsxs(_Fragment, { children: [_jsx(JBTextField, { control: control, name: "newPassword", sx: { mb: 3 }, label: "Nueva contrase\u00F1a", type: showNewPassword ? 'text' : 'password', InputProps: {
|
|
159
|
-
endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(IconButton, { edge: "end", "aria-label": showNewPassword ? 'Ocultar contraseña' : 'Mostrar contraseña', onClick: () => setShowNewPassword((prev) => !prev), children: showNewPassword ? _jsx(VisibilityOffOutlinedIcon, {}) : _jsx(VisibilityOutlinedIcon, {}) }) }))
|
|
160
|
-
}, variant: "outlined", required: true, fullWidth: true }), _jsx(JBTextField, { control: control, name: "newPasswordConfirm", sx: { mb: 3 }, label: "Confirmar nueva contrase\u00F1a", type: showNewPasswordConfirm ? 'text' : 'password', InputProps: {
|
|
161
|
-
endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(IconButton, { edge: "end", "aria-label": showNewPasswordConfirm ? 'Ocultar confirmación de contraseña' : 'Mostrar confirmación de contraseña', onClick: () => setShowNewPasswordConfirm((prev) => !prev), children: showNewPasswordConfirm ? _jsx(VisibilityOffOutlinedIcon, {}) : _jsx(VisibilityOutlinedIcon, {}) }) }))
|
|
162
|
-
}, variant: "outlined", required: true, fullWidth: true })] })) : null, errors.root?.message && (_jsx(Alert, { sx: { mb: 2 }, severity: "error", children: errors.root.message })), isSubmitSuccessful && (_jsx(Alert, { sx: { mb: 2 }, severity: "success", children: successMessage })), !isSubmitSuccessful ? (_jsx(AuthPrimaryButton, { "aria-label": submitLabel, startIcon: _jsx(LockResetOutlinedIcon, { fontSize: "small" }), disabled: loading || isSubmitting || _.isEmpty(dirtyFields) || !isValid || !hasValidRecoveryLink, type: "submit", size: "large", children: submitLabel })) : null, isSubmitSuccessful && onGoToSignIn ? (_jsx(AuthSecondaryButton, { sx: { mt: 2 }, startIcon: _jsx(ArrowBackOutlinedIcon, { fontSize: "small" }), onClick: onGoToSignIn, children: goToSignInLabel })) : null] }));
|
|
163
|
-
}
|