@joelbarron/react-web-dev-kit 0.1.0
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 +236 -0
- package/dist/auth/client.d.ts +44 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/client.js +354 -0
- package/dist/auth/constants/countryCallingCodes.d.ts +9 -0
- package/dist/auth/constants/countryCallingCodes.d.ts.map +1 -0
- package/dist/auth/constants/countryCallingCodes.js +209 -0
- package/dist/auth/constants/gender.d.ts +9 -0
- package/dist/auth/constants/gender.d.ts.map +1 -0
- package/dist/auth/constants/gender.js +12 -0
- package/dist/auth/constants/index.d.ts +3 -0
- package/dist/auth/constants/index.d.ts.map +1 -0
- package/dist/auth/constants/index.js +2 -0
- package/dist/auth/forms/account/AuthAccountConfirmationForm.d.ts +18 -0
- package/dist/auth/forms/account/AuthAccountConfirmationForm.d.ts.map +1 -0
- package/dist/auth/forms/account/AuthAccountConfirmationForm.js +166 -0
- package/dist/auth/forms/account/index.d.ts +2 -0
- package/dist/auth/forms/account/index.d.ts.map +1 -0
- package/dist/auth/forms/account/index.js +1 -0
- package/dist/auth/forms/errorParser.d.ts +7 -0
- package/dist/auth/forms/errorParser.d.ts.map +1 -0
- package/dist/auth/forms/errorParser.js +65 -0
- package/dist/auth/forms/index.d.ts +6 -0
- package/dist/auth/forms/index.d.ts.map +1 -0
- package/dist/auth/forms/index.js +5 -0
- package/dist/auth/forms/password/AuthForgotPasswordForm.d.ts +12 -0
- package/dist/auth/forms/password/AuthForgotPasswordForm.d.ts.map +1 -0
- package/dist/auth/forms/password/AuthForgotPasswordForm.js +71 -0
- package/dist/auth/forms/password/AuthPasswordResetConfirmForm.d.ts +15 -0
- package/dist/auth/forms/password/AuthPasswordResetConfirmForm.d.ts.map +1 -0
- package/dist/auth/forms/password/AuthPasswordResetConfirmForm.js +88 -0
- package/dist/auth/forms/password/AuthResetPasswordForm.d.ts +12 -0
- package/dist/auth/forms/password/AuthResetPasswordForm.d.ts.map +1 -0
- package/dist/auth/forms/password/AuthResetPasswordForm.js +18 -0
- package/dist/auth/forms/password/index.d.ts +4 -0
- package/dist/auth/forms/password/index.d.ts.map +1 -0
- package/dist/auth/forms/password/index.js +3 -0
- package/dist/auth/forms/sign-in/AuthOtpSignInForm.d.ts +24 -0
- package/dist/auth/forms/sign-in/AuthOtpSignInForm.d.ts.map +1 -0
- package/dist/auth/forms/sign-in/AuthOtpSignInForm.js +226 -0
- package/dist/auth/forms/sign-in/AuthPasswordSignInForm.d.ts +21 -0
- package/dist/auth/forms/sign-in/AuthPasswordSignInForm.d.ts.map +1 -0
- package/dist/auth/forms/sign-in/AuthPasswordSignInForm.js +120 -0
- package/dist/auth/forms/sign-in/index.d.ts +3 -0
- package/dist/auth/forms/sign-in/index.d.ts.map +1 -0
- package/dist/auth/forms/sign-in/index.js +2 -0
- package/dist/auth/forms/sign-up/AuthSignUpForm.d.ts +36 -0
- package/dist/auth/forms/sign-up/AuthSignUpForm.d.ts.map +1 -0
- package/dist/auth/forms/sign-up/AuthSignUpForm.js +164 -0
- package/dist/auth/forms/sign-up/index.d.ts +2 -0
- package/dist/auth/forms/sign-up/index.d.ts.map +1 -0
- package/dist/auth/forms/sign-up/index.js +1 -0
- package/dist/auth/fuse/createFuseAuthViews.d.ts +24 -0
- package/dist/auth/fuse/createFuseAuthViews.d.ts.map +1 -0
- package/dist/auth/fuse/createFuseAuthViews.js +360 -0
- package/dist/auth/fuse/fuseAdapter.d.ts +40 -0
- package/dist/auth/fuse/fuseAdapter.d.ts.map +1 -0
- package/dist/auth/fuse/fuseAdapter.js +265 -0
- package/dist/auth/fuse/fuseIntegration.d.ts +59 -0
- package/dist/auth/fuse/fuseIntegration.d.ts.map +1 -0
- package/dist/auth/fuse/fuseIntegration.js +85 -0
- package/dist/auth/fuse/index.d.ts +4 -0
- package/dist/auth/fuse/index.d.ts.map +1 -0
- package/dist/auth/fuse/index.js +3 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +10 -0
- package/dist/auth/provider.d.ts +35 -0
- package/dist/auth/provider.d.ts.map +1 -0
- package/dist/auth/provider.js +133 -0
- package/dist/auth/query.d.ts +23 -0
- package/dist/auth/query.d.ts.map +1 -0
- package/dist/auth/query.js +103 -0
- package/dist/auth/routes.d.ts +37 -0
- package/dist/auth/routes.d.ts.map +1 -0
- package/dist/auth/routes.js +73 -0
- package/dist/auth/social/providerAuth.d.ts +76 -0
- package/dist/auth/social/providerAuth.d.ts.map +1 -0
- package/dist/auth/social/providerAuth.js +130 -0
- package/dist/auth/storage.d.ts +3 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +20 -0
- package/dist/auth/types.d.ts +208 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/auth/ui/AuthPagesMessageSection.d.ts +3 -0
- package/dist/auth/ui/AuthPagesMessageSection.d.ts.map +1 -0
- package/dist/auth/ui/AuthPagesMessageSection.js +39 -0
- package/dist/auth/ui/AuthPrimaryButton.d.ts +9 -0
- package/dist/auth/ui/AuthPrimaryButton.d.ts.map +1 -0
- package/dist/auth/ui/AuthPrimaryButton.js +19 -0
- package/dist/auth/ui/AuthRoleSelectionDialog.d.ts +14 -0
- package/dist/auth/ui/AuthRoleSelectionDialog.d.ts.map +1 -0
- package/dist/auth/ui/AuthRoleSelectionDialog.js +39 -0
- package/dist/auth/ui/AuthRoutePageWrapper.d.ts +12 -0
- package/dist/auth/ui/AuthRoutePageWrapper.d.ts.map +1 -0
- package/dist/auth/ui/AuthRoutePageWrapper.js +59 -0
- package/dist/auth/ui/AuthSecondaryButton.d.ts +7 -0
- package/dist/auth/ui/AuthSecondaryButton.d.ts.map +1 -0
- package/dist/auth/ui/AuthSecondaryButton.js +18 -0
- package/dist/auth/ui/AuthSocialProviderButton.d.ts +11 -0
- package/dist/auth/ui/AuthSocialProviderButton.d.ts.map +1 -0
- package/dist/auth/ui/AuthSocialProviderButton.js +30 -0
- package/dist/auth/ui/SignInPageTitle.d.ts +6 -0
- package/dist/auth/ui/SignInPageTitle.d.ts.map +1 -0
- package/dist/auth/ui/SignInPageTitle.js +7 -0
- package/dist/auth/ui/SignOutPageTitle.d.ts +6 -0
- package/dist/auth/ui/SignOutPageTitle.d.ts.map +1 -0
- package/dist/auth/ui/SignOutPageTitle.js +7 -0
- package/dist/auth/ui/SignUpPageTitle.d.ts +6 -0
- package/dist/auth/ui/SignUpPageTitle.d.ts.map +1 -0
- package/dist/auth/ui/SignUpPageTitle.js +7 -0
- package/dist/auth/ui/index.d.ts +11 -0
- package/dist/auth/ui/index.d.ts.map +1 -0
- package/dist/auth/ui/index.js +10 -0
- package/dist/auth/ui/types.d.ts +15 -0
- package/dist/auth/ui/types.d.ts.map +1 -0
- package/dist/auth/ui/types.js +1 -0
- package/dist/config/createConfig.d.ts +13 -0
- package/dist/config/createConfig.d.ts.map +1 -0
- package/dist/config/createConfig.js +104 -0
- package/dist/config/defaults.d.ts +3 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +38 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +4 -0
- package/dist/config/merge.d.ts +2 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/merge.js +18 -0
- package/dist/config/types.d.ts +46 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +1 -0
- package/dist/forms/JBCheckboxField.d.ts +12 -0
- package/dist/forms/JBCheckboxField.d.ts.map +1 -0
- package/dist/forms/JBCheckboxField.js +36 -0
- package/dist/forms/JBDatePickerField.d.ts +12 -0
- package/dist/forms/JBDatePickerField.d.ts.map +1 -0
- package/dist/forms/JBDatePickerField.js +14 -0
- package/dist/forms/JBRadioGroupField.d.ts +10 -0
- package/dist/forms/JBRadioGroupField.d.ts.map +1 -0
- package/dist/forms/JBRadioGroupField.js +8 -0
- package/dist/forms/JBSelectField.d.ts +9 -0
- package/dist/forms/JBSelectField.d.ts.map +1 -0
- package/dist/forms/JBSelectField.js +8 -0
- package/dist/forms/JBSwitchField.d.ts +11 -0
- package/dist/forms/JBSwitchField.d.ts.map +1 -0
- package/dist/forms/JBSwitchField.js +10 -0
- package/dist/forms/JBTextField.d.ts +6 -0
- package/dist/forms/JBTextField.d.ts.map +1 -0
- package/dist/forms/JBTextField.js +8 -0
- package/dist/forms/JBTimePickerField.d.ts +12 -0
- package/dist/forms/JBTimePickerField.d.ts.map +1 -0
- package/dist/forms/JBTimePickerField.js +14 -0
- package/dist/forms/index.d.ts +11 -0
- package/dist/forms/index.d.ts.map +1 -0
- package/dist/forms/index.js +10 -0
- package/dist/forms/rules.d.ts +16 -0
- package/dist/forms/rules.d.ts.map +1 -0
- package/dist/forms/rules.js +21 -0
- package/dist/forms/types.d.ts +12 -0
- package/dist/forms/types.d.ts.map +1 -0
- package/dist/forms/types.js +1 -0
- package/dist/forms/utils.d.ts +5 -0
- package/dist/forms/utils.d.ts.map +1 -0
- package/dist/forms/utils.js +7 -0
- package/dist/grid/JBGrid.d.ts +3 -0
- package/dist/grid/JBGrid.d.ts.map +1 -0
- package/dist/grid/JBGrid.js +89 -0
- package/dist/grid/JBGridHeader.d.ts +3 -0
- package/dist/grid/JBGridHeader.d.ts.map +1 -0
- package/dist/grid/JBGridHeader.js +22 -0
- package/dist/grid/JBGridProviders.d.ts +10 -0
- package/dist/grid/JBGridProviders.d.ts.map +1 -0
- package/dist/grid/JBGridProviders.js +31 -0
- package/dist/grid/index.d.ts +5 -0
- package/dist/grid/index.d.ts.map +1 -0
- package/dist/grid/index.js +4 -0
- package/dist/grid/types.d.ts +81 -0
- package/dist/grid/types.d.ts.map +1 -0
- package/dist/grid/types.js +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useJBDebouncedValue.d.ts +2 -0
- package/dist/hooks/useJBDebouncedValue.d.ts.map +1 -0
- package/dist/hooks/useJBDebouncedValue.js +11 -0
- package/dist/hooks/useJBRedirect.d.ts +10 -0
- package/dist/hooks/useJBRedirect.d.ts.map +1 -0
- package/dist/hooks/useJBRedirect.js +11 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/query/createQueryClient.d.ts +8 -0
- package/dist/query/createQueryClient.d.ts.map +1 -0
- package/dist/query/createQueryClient.js +25 -0
- package/dist/query/http.d.ts +3 -0
- package/dist/query/http.d.ts.map +1 -0
- package/dist/query/http.js +12 -0
- package/dist/query/index.d.ts +3 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +2 -0
- package/dist/utils/format.d.ts +4 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +28 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/query.d.ts +2 -0
- package/dist/utils/query.d.ts.map +1 -0
- package/dist/utils/query.js +4 -0
- package/dist/utils/regex.d.ts +7 -0
- package/dist/utils/regex.d.ts.map +1 -0
- package/dist/utils/regex.js +6 -0
- package/package.json +85 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { SelectOption } from '../../../forms';
|
|
3
|
+
import { RegisterPayload } from '../../types';
|
|
4
|
+
declare const signUpSchema: z.ZodObject<{
|
|
5
|
+
firstName: z.ZodString;
|
|
6
|
+
lastName1: z.ZodString;
|
|
7
|
+
lastName2: z.ZodOptional<z.ZodString>;
|
|
8
|
+
email: z.ZodString;
|
|
9
|
+
birthday: z.ZodOptional<z.ZodString>;
|
|
10
|
+
gender: z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
MALE: "MALE";
|
|
12
|
+
FEMALE: "FEMALE";
|
|
13
|
+
OTHER: "OTHER";
|
|
14
|
+
PREFER_NOT_TO_SAY: "PREFER_NOT_TO_SAY";
|
|
15
|
+
}>>;
|
|
16
|
+
role: z.ZodOptional<z.ZodString>;
|
|
17
|
+
password: z.ZodString;
|
|
18
|
+
passwordConfirm: z.ZodString;
|
|
19
|
+
acceptTermsConditions: z.ZodBoolean;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type AuthSignUpFormValues = z.infer<typeof signUpSchema>;
|
|
22
|
+
export type AuthSignUpFormProps = {
|
|
23
|
+
defaultValues?: Partial<AuthSignUpFormValues>;
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
submitLabel?: string;
|
|
26
|
+
fieldsScrollable?: boolean;
|
|
27
|
+
formMaxHeight?: string | number;
|
|
28
|
+
roleOptions?: Array<SelectOption<string> & {
|
|
29
|
+
allowSignup?: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
defaultRole?: string;
|
|
32
|
+
onSubmit: (values: RegisterPayload) => unknown | Promise<unknown>;
|
|
33
|
+
};
|
|
34
|
+
export declare function AuthSignUpForm(props: AuthSignUpFormProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=AuthSignUpForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthSignUpForm.d.ts","sourceRoot":"","sources":["../../../../src/auth/forms/sign-up/AuthSignUpForm.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAA+C,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3F,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9C,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;iBAmBd,CAAC;AAEL,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAEhE,MAAM,MAAM,mBAAmB,GAAG;IAChC,aAAa,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,WAAW,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG;QAAE,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnE,CAAC;AAeF,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,2CAiRxD"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
3
|
+
import Alert from '@mui/material/Alert';
|
|
4
|
+
import Box from '@mui/material/Box';
|
|
5
|
+
import _ from 'lodash';
|
|
6
|
+
import { useEffect } from 'react';
|
|
7
|
+
import { useForm, useWatch } from 'react-hook-form';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { JBCheckboxField, JBSelectField, JBTextField } from '../../../forms';
|
|
10
|
+
import { DEFAULT_GENDER, GENDERS, GENDER_SELECT_OPTIONS } from '../../constants';
|
|
11
|
+
import { AuthPrimaryButton } from '../../ui';
|
|
12
|
+
import { parseAuthError } from '../errorParser';
|
|
13
|
+
const signUpSchema = z
|
|
14
|
+
.object({
|
|
15
|
+
firstName: z.string().nonempty('Debes ingresar el nombre'),
|
|
16
|
+
lastName1: z.string().nonempty('Debes ingresar el primer apellido'),
|
|
17
|
+
lastName2: z.string().optional(),
|
|
18
|
+
email: z.string().email('Debes ingresar un correo válido').nonempty('Debes ingresar un correo'),
|
|
19
|
+
birthday: z.string().optional(),
|
|
20
|
+
gender: z.enum(GENDERS).optional(),
|
|
21
|
+
role: z.string().optional(),
|
|
22
|
+
password: z
|
|
23
|
+
.string()
|
|
24
|
+
.nonempty('Debes ingresar la contraseña.')
|
|
25
|
+
.min(8, 'La contraseña es muy corta - mínimo 8 caracteres.'),
|
|
26
|
+
passwordConfirm: z.string().nonempty('La confirmación de contraseña es obligatoria'),
|
|
27
|
+
acceptTermsConditions: z.boolean().refine((val) => val === true, 'Debes aceptar los términos y condiciones.')
|
|
28
|
+
})
|
|
29
|
+
.refine((data) => data.password === data.passwordConfirm, {
|
|
30
|
+
message: 'Las contraseñas deben coincidir',
|
|
31
|
+
path: ['passwordConfirm']
|
|
32
|
+
});
|
|
33
|
+
const defaultValues = {
|
|
34
|
+
firstName: '',
|
|
35
|
+
lastName1: '',
|
|
36
|
+
lastName2: '',
|
|
37
|
+
email: '',
|
|
38
|
+
birthday: '',
|
|
39
|
+
gender: DEFAULT_GENDER,
|
|
40
|
+
role: '',
|
|
41
|
+
password: '',
|
|
42
|
+
passwordConfirm: '',
|
|
43
|
+
acceptTermsConditions: false
|
|
44
|
+
};
|
|
45
|
+
export function AuthSignUpForm(props) {
|
|
46
|
+
const { defaultValues: valuesFromProps, loading = false, submitLabel = 'Crear cuenta', fieldsScrollable = false, formMaxHeight = 'min(72dvh, 620px)', roleOptions, defaultRole, onSubmit } = props;
|
|
47
|
+
const signupRoleOptions = (roleOptions ?? []).filter((roleOption) => roleOption.allowSignup !== false);
|
|
48
|
+
const resolvedDefaultRole = valuesFromProps?.role ??
|
|
49
|
+
defaultRole ??
|
|
50
|
+
signupRoleOptions[0]?.value ??
|
|
51
|
+
defaultValues.role;
|
|
52
|
+
const { control, formState, handleSubmit, setError, clearErrors, trigger, watch } = useForm({
|
|
53
|
+
mode: 'onChange',
|
|
54
|
+
defaultValues: {
|
|
55
|
+
...defaultValues,
|
|
56
|
+
role: resolvedDefaultRole,
|
|
57
|
+
...(valuesFromProps ?? {})
|
|
58
|
+
},
|
|
59
|
+
resolver: zodResolver(signUpSchema)
|
|
60
|
+
});
|
|
61
|
+
const { isValid, dirtyFields, errors, isSubmitting } = formState;
|
|
62
|
+
const isLoading = loading || isSubmitting;
|
|
63
|
+
const passwordValue = useWatch({ control, name: 'password' });
|
|
64
|
+
const passwordConfirmValue = useWatch({ control, name: 'passwordConfirm' });
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!passwordConfirmValue) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
void trigger('passwordConfirm');
|
|
70
|
+
}, [passwordValue, passwordConfirmValue, trigger]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const subscription = watch((_value, { name }) => {
|
|
73
|
+
if (name) {
|
|
74
|
+
clearErrors(name);
|
|
75
|
+
}
|
|
76
|
+
clearErrors('root');
|
|
77
|
+
});
|
|
78
|
+
return () => {
|
|
79
|
+
subscription.unsubscribe();
|
|
80
|
+
};
|
|
81
|
+
}, [watch, clearErrors]);
|
|
82
|
+
async function onSubmitForm(values) {
|
|
83
|
+
try {
|
|
84
|
+
await onSubmit({
|
|
85
|
+
firstName: values.firstName,
|
|
86
|
+
lastName1: values.lastName1,
|
|
87
|
+
lastName2: values.lastName2 || undefined,
|
|
88
|
+
username: null,
|
|
89
|
+
email: values.email,
|
|
90
|
+
birthday: values.birthday || undefined,
|
|
91
|
+
gender: values.gender || undefined,
|
|
92
|
+
password: values.password,
|
|
93
|
+
passwordConfirm: values.passwordConfirm,
|
|
94
|
+
role: values.role || defaultRole || undefined,
|
|
95
|
+
termsAndConditionsAccepted: values.acceptTermsConditions
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const parsed = parseAuthError(error, {
|
|
100
|
+
username: 'email'
|
|
101
|
+
});
|
|
102
|
+
const allowedFields = [
|
|
103
|
+
'firstName',
|
|
104
|
+
'lastName1',
|
|
105
|
+
'lastName2',
|
|
106
|
+
'email',
|
|
107
|
+
'birthday',
|
|
108
|
+
'gender',
|
|
109
|
+
'role',
|
|
110
|
+
'password',
|
|
111
|
+
'passwordConfirm',
|
|
112
|
+
'acceptTermsConditions'
|
|
113
|
+
];
|
|
114
|
+
Object.entries(parsed.fieldErrors).forEach(([field, message]) => {
|
|
115
|
+
if (allowedFields.includes(field)) {
|
|
116
|
+
setError(field, { type: 'manual', message });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
setError('root', {
|
|
120
|
+
type: 'manual',
|
|
121
|
+
message
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
if (parsed.rootMessage) {
|
|
125
|
+
setError('root', {
|
|
126
|
+
type: 'manual',
|
|
127
|
+
message: parsed.rootMessage
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
setError('root', {
|
|
132
|
+
type: 'manual',
|
|
133
|
+
message: 'No se pudo crear la cuenta. Inténtalo de nuevo.'
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return (_jsxs("form", { name: "registerForm", noValidate: true, style: {
|
|
138
|
+
display: 'flex',
|
|
139
|
+
width: '100%',
|
|
140
|
+
flexDirection: 'column',
|
|
141
|
+
justifyContent: 'flex-start',
|
|
142
|
+
paddingTop: 4,
|
|
143
|
+
...(fieldsScrollable
|
|
144
|
+
? {
|
|
145
|
+
height: '100%',
|
|
146
|
+
maxHeight: typeof formMaxHeight === 'number' ? `${formMaxHeight}px` : formMaxHeight,
|
|
147
|
+
minHeight: 0,
|
|
148
|
+
overflow: 'hidden'
|
|
149
|
+
}
|
|
150
|
+
: null)
|
|
151
|
+
}, onSubmit: handleSubmit(onSubmitForm), children: [_jsxs(Box, { sx: {
|
|
152
|
+
...(fieldsScrollable
|
|
153
|
+
? {
|
|
154
|
+
display: 'flex',
|
|
155
|
+
flexDirection: 'column',
|
|
156
|
+
flex: 1,
|
|
157
|
+
minHeight: 0,
|
|
158
|
+
overflowY: 'auto',
|
|
159
|
+
pr: 0.5,
|
|
160
|
+
pb: 1
|
|
161
|
+
}
|
|
162
|
+
: null)
|
|
163
|
+
}, children: [_jsx(JBTextField, { control: control, name: "firstName", sx: { mb: 3 }, label: "Nombre(s)", autoFocus: true, type: "text", variant: "outlined", required: true, fullWidth: true }), _jsx(JBTextField, { control: control, name: "lastName1", sx: { mb: 3 }, label: "Primer apellido", type: "text", variant: "outlined", required: true, fullWidth: true }), _jsx(JBTextField, { control: control, name: "lastName2", sx: { mb: 3 }, label: "Segundo apellido", type: "text", variant: "outlined", fullWidth: true }), _jsx(JBTextField, { control: control, name: "email", sx: { mb: 3 }, label: "Correo electr\u00F3nico", type: "email", variant: "outlined", required: true, fullWidth: true }), _jsx(JBTextField, { control: control, name: "birthday", sx: { mb: 3 }, label: "Fecha de nacimiento", type: "date", InputLabelProps: { shrink: true }, variant: "outlined", fullWidth: true }), _jsx(JBSelectField, { control: control, name: "gender", sx: { mb: 3 }, label: "G\u00E9nero", variant: "outlined", fullWidth: true, options: GENDER_SELECT_OPTIONS }), signupRoleOptions.length > 0 ? (_jsx(JBSelectField, { control: control, name: "role", sx: { mb: 3 }, label: "Rol de perfil", variant: "outlined", fullWidth: true, options: signupRoleOptions, required: true })) : null, _jsx(JBTextField, { control: control, name: "password", sx: { mb: 3 }, label: "Contrase\u00F1a", type: "password", variant: "outlined", required: true, fullWidth: true }), _jsx(JBTextField, { control: control, name: "passwordConfirm", sx: { mb: 3 }, label: "Confirmar contrase\u00F1a", type: "password", variant: "outlined", required: true, fullWidth: true }), _jsx(JBCheckboxField, { control: control, name: "acceptTermsConditions", size: "small", label: "Acepto t\u00E9rminos y pol\u00EDticas de privacidad" })] }), errors.root?.message ? (_jsx(Alert, { sx: { mt: 2 }, severity: "error", children: errors.root.message })) : null, _jsx(AuthPrimaryButton, { sx: { mt: 3 }, "aria-label": submitLabel, disabled: isLoading || _.isEmpty(dirtyFields) || !isValid, loading: isLoading, loadingLabel: "Creando cuenta...", type: "submit", size: "large", children: submitLabel })] }));
|
|
164
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/auth/forms/sign-up/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AuthSignUpForm';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JBAuthProfileRoleOption, JBAuthSocialConfig } from "../../config";
|
|
2
|
+
import { AuthLinkComponent } from "../ui";
|
|
3
|
+
type CreateFuseAuthViewsOptions = {
|
|
4
|
+
LinkComponent: AuthLinkComponent;
|
|
5
|
+
accountConfirmationPath?: string;
|
|
6
|
+
signUpRoleOptions?: JBAuthProfileRoleOption[];
|
|
7
|
+
defaultSignUpRole?: string;
|
|
8
|
+
socialConfig?: JBAuthSocialConfig;
|
|
9
|
+
onSignUpSuccess?: (values: {
|
|
10
|
+
email: string;
|
|
11
|
+
detail?: string;
|
|
12
|
+
response: Record<string, unknown>;
|
|
13
|
+
}) => void;
|
|
14
|
+
};
|
|
15
|
+
export declare function createFuseAuthViews(options: CreateFuseAuthViewsOptions): {
|
|
16
|
+
SignInPageView: () => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
SignUpPageView: () => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
ForgotPasswordPageView: () => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
ResetPasswordPageView: () => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
SignOutPageView: () => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
AccountConfirmationPageView: () => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=createFuseAuthViews.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFuseAuthViews.d.ts","sourceRoot":"","sources":["../../../src/auth/fuse/createFuseAuthViews.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAG3E,OAAO,EACL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AAqaf,KAAK,0BAA0B,GAAG;IAChC,aAAa,EAAE,iBAAiB,CAAC;IACjC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,iBAAiB,CAAC,EAAE,uBAAuB,EAAE,CAAC;IAC9C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE;QACzB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,KAAK,IAAI,CAAC;CACZ,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B;;;;;;;EAwYtE"}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import Box from "@mui/material/Box";
|
|
3
|
+
import Alert from "@mui/material/Alert";
|
|
4
|
+
import Typography from "@mui/material/Typography";
|
|
5
|
+
import PhoneIphoneIcon from "@mui/icons-material/PhoneIphone";
|
|
6
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
7
|
+
import { useNavigate, useSearchParams } from "react-router";
|
|
8
|
+
import { AuthAccountConfirmationForm, AuthForgotPasswordForm, AuthOtpSignInForm, AuthPasswordResetConfirmForm, AuthPasswordSignInForm, AuthSignUpForm, } from "../forms";
|
|
9
|
+
import { authenticateWithSocialProvider } from "../social/providerAuth";
|
|
10
|
+
import { useFuseJwtAuth } from "./fuseAdapter";
|
|
11
|
+
import { AuthRoleSelectionDialog, AuthSocialProviderButton, AuthSecondaryButton, SignInPageTitle, SignOutPageTitle, SignUpPageTitle, } from "../ui";
|
|
12
|
+
import { parseAuthError } from "../forms/errorParser";
|
|
13
|
+
const IS_DEV = typeof window !== "undefined" && window.location.hostname === "localhost";
|
|
14
|
+
const DEV_LOGIN_DEFAULT_VALUES = IS_DEV
|
|
15
|
+
? {
|
|
16
|
+
login: "admin",
|
|
17
|
+
password: "Test123_",
|
|
18
|
+
remember: true,
|
|
19
|
+
}
|
|
20
|
+
: undefined;
|
|
21
|
+
const DEV_SIGN_UP_DEFAULT_VALUES = IS_DEV
|
|
22
|
+
? {
|
|
23
|
+
firstName: "Joel",
|
|
24
|
+
lastName1: "Barron",
|
|
25
|
+
lastName2: "Hernandez",
|
|
26
|
+
email: "joel.test+1@example.com",
|
|
27
|
+
birthday: "1995-12-16",
|
|
28
|
+
gender: "MALE",
|
|
29
|
+
password: "Test123_",
|
|
30
|
+
passwordConfirm: "Test123_",
|
|
31
|
+
acceptTermsConditions: true,
|
|
32
|
+
}
|
|
33
|
+
: undefined;
|
|
34
|
+
const DEV_OTP_DEFAULT_VALUES = IS_DEV
|
|
35
|
+
? {
|
|
36
|
+
countryCode: "+52",
|
|
37
|
+
phone: "5512345678",
|
|
38
|
+
code: "",
|
|
39
|
+
}
|
|
40
|
+
: undefined;
|
|
41
|
+
const SOCIAL_PROVIDER_ORDER = ["google", "facebook", "apple"];
|
|
42
|
+
function getEnabledSocialProviders(socialConfig) {
|
|
43
|
+
if (!socialConfig) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
return SOCIAL_PROVIDER_ORDER.flatMap((provider) => {
|
|
47
|
+
const providerConfig = socialConfig[provider];
|
|
48
|
+
if (!providerConfig?.enabled || !providerConfig.clientId?.trim()) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
provider,
|
|
54
|
+
clientId: providerConfig.clientId.trim(),
|
|
55
|
+
redirectUri: providerConfig.redirectUri?.trim() || undefined,
|
|
56
|
+
scope: providerConfig.scope?.trim() || undefined
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function FuseSignInController(props) {
|
|
62
|
+
const { LinkComponent, mode = "password", onBackToPassword, requestRoleSelection } = props;
|
|
63
|
+
const { signIn, requestOtp, signInOtp } = useFuseJwtAuth();
|
|
64
|
+
if (mode === "otp") {
|
|
65
|
+
return (_jsx(AuthOtpSignInForm, { defaultValues: DEV_OTP_DEFAULT_VALUES, requestRoleSelection: requestRoleSelection, onBackToPassword: onBackToPassword, onRequestOtp: ({ phone }) => requestOtp({
|
|
66
|
+
channel: "sms",
|
|
67
|
+
phone,
|
|
68
|
+
}), onVerifyOtp: ({ phone, code, role }) => signInOtp({
|
|
69
|
+
channel: "sms",
|
|
70
|
+
phone,
|
|
71
|
+
code,
|
|
72
|
+
role,
|
|
73
|
+
}) }));
|
|
74
|
+
}
|
|
75
|
+
return (_jsx(AuthPasswordSignInForm, { defaultValues: DEV_LOGIN_DEFAULT_VALUES, LinkComponent: LinkComponent, onSubmit: (values) => signIn({
|
|
76
|
+
login: values.login,
|
|
77
|
+
password: values.password,
|
|
78
|
+
}) }));
|
|
79
|
+
}
|
|
80
|
+
function FuseSignUpController(props) {
|
|
81
|
+
const { onSuccess, requestRoleSelection, requiresRoleSelection = false } = props;
|
|
82
|
+
const { signUp } = useFuseJwtAuth();
|
|
83
|
+
return (_jsx(AuthSignUpForm, { defaultValues: DEV_SIGN_UP_DEFAULT_VALUES, onSubmit: async (values) => {
|
|
84
|
+
const selectedRole = requestRoleSelection
|
|
85
|
+
? await requestRoleSelection()
|
|
86
|
+
: values.role;
|
|
87
|
+
if (requiresRoleSelection && !selectedRole) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const response = await signUp({
|
|
91
|
+
...values,
|
|
92
|
+
role: selectedRole ?? values.role,
|
|
93
|
+
});
|
|
94
|
+
onSuccess?.({
|
|
95
|
+
email: values.email,
|
|
96
|
+
detail: response.detail ?? undefined,
|
|
97
|
+
response
|
|
98
|
+
});
|
|
99
|
+
} }));
|
|
100
|
+
}
|
|
101
|
+
function FuseOtpSignUpForm(props) {
|
|
102
|
+
const { onBackToPassword, requestRoleSelection } = props;
|
|
103
|
+
const { requestOtp, signInOtp } = useFuseJwtAuth();
|
|
104
|
+
return (_jsx(AuthOtpSignInForm, { defaultValues: DEV_OTP_DEFAULT_VALUES, requestRoleSelection: requestRoleSelection, onBackToPassword: onBackToPassword, onRequestOtp: ({ phone }) => requestOtp({
|
|
105
|
+
channel: "sms",
|
|
106
|
+
phone,
|
|
107
|
+
}), onVerifyOtp: ({ phone, code, role }) => signInOtp({
|
|
108
|
+
channel: "sms",
|
|
109
|
+
phone,
|
|
110
|
+
code,
|
|
111
|
+
role,
|
|
112
|
+
}) }));
|
|
113
|
+
}
|
|
114
|
+
function FuseAuthAlternativesSection(props) {
|
|
115
|
+
const { onSmsClick, socialProviders = [], onSocialClick, socialLoadingProvider, socialError } = props;
|
|
116
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Box, { sx: { mt: 4, display: "flex", alignItems: "center" }, children: [_jsx(Box, { sx: { mt: "1px", flex: 1, borderTop: 1, borderColor: "divider" } }), _jsx(Typography, { sx: { mx: 1 }, color: "text.secondary", children: "O contin\u00FAa con" }), _jsx(Box, { sx: { mt: "1px", flex: 1, borderTop: 1, borderColor: "divider" } })] }), _jsxs(Box, { sx: {
|
|
117
|
+
mt: 4,
|
|
118
|
+
display: "grid",
|
|
119
|
+
gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
|
|
120
|
+
gap: 1.5
|
|
121
|
+
}, children: [socialProviders.map((socialProvider) => (_jsx(AuthSocialProviderButton, { provider: socialProvider.provider, loading: socialLoadingProvider === socialProvider.provider, disabled: Boolean(socialLoadingProvider && socialLoadingProvider !== socialProvider.provider), onClick: () => onSocialClick?.(socialProvider.provider) }, socialProvider.provider))), _jsx(AuthSecondaryButton, { sx: { minWidth: 0 }, "aria-label": "SMS", onClick: onSmsClick, startIcon: _jsx(PhoneIphoneIcon, { fontSize: "small" }), children: "SMS" })] }), socialError ? (_jsx(Alert, { severity: "error", sx: { mt: 2 }, children: socialError })) : null] }));
|
|
122
|
+
}
|
|
123
|
+
function FuseSignUpCtaSection(props) {
|
|
124
|
+
const { LinkComponent, signUpPath = "/sign-up" } = props;
|
|
125
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Box, { sx: { mt: 6, display: "flex", alignItems: "center" }, children: [_jsx(Box, { sx: { mt: "1px", flex: 1, borderTop: 1, borderColor: "divider" } }), _jsx(Typography, { sx: { mx: 1 }, color: "text.secondary", children: "\u00BFNo tienes una cuenta?" }), _jsx(Box, { sx: { mt: "1px", flex: 1, borderTop: 1, borderColor: "divider" } })] }), _jsx(Box, { sx: { mt: 2, display: "flex", alignItems: "center", gap: 2 }, children: _jsx(AuthSecondaryButton, { component: LinkComponent, to: signUpPath, sx: { flex: 1 }, "aria-label": "Crear cuenta", children: "Crear cuenta" }) })] }));
|
|
126
|
+
}
|
|
127
|
+
function FuseSignInCtaSection(props) {
|
|
128
|
+
const { LinkComponent, signInPath = "/sign-in" } = props;
|
|
129
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Box, { sx: { mt: 6, display: "flex", alignItems: "center" }, children: [_jsx(Box, { sx: { mt: "1px", flex: 1, borderTop: 1, borderColor: "divider" } }), _jsx(Typography, { sx: { mx: 1 }, color: "text.secondary", children: "\u00BFYa tienes una cuenta?" }), _jsx(Box, { sx: { mt: "1px", flex: 1, borderTop: 1, borderColor: "divider" } })] }), _jsx(Box, { sx: { mt: 2, display: "flex", alignItems: "center", gap: 2 }, children: _jsx(AuthSecondaryButton, { component: LinkComponent, to: signInPath, sx: { flex: 1 }, "aria-label": "Iniciar sesi\u00F3n", children: "Iniciar sesi\u00F3n" }) })] }));
|
|
130
|
+
}
|
|
131
|
+
function FuseForgotPasswordPageForm() {
|
|
132
|
+
const { requestPasswordReset } = useFuseJwtAuth();
|
|
133
|
+
return (_jsx(AuthForgotPasswordForm, { onSubmit: (values) => requestPasswordReset({ email: values.email }) }));
|
|
134
|
+
}
|
|
135
|
+
function FuseResetPasswordPageForm(props) {
|
|
136
|
+
const { initialUid = "", initialToken = "" } = props;
|
|
137
|
+
const { confirmPasswordReset } = useFuseJwtAuth();
|
|
138
|
+
return (_jsx(AuthPasswordResetConfirmForm, { defaultValues: {
|
|
139
|
+
uid: initialUid,
|
|
140
|
+
token: initialToken,
|
|
141
|
+
}, onSubmit: (values) => confirmPasswordReset(values) }));
|
|
142
|
+
}
|
|
143
|
+
function FuseAccountConfirmationPageForm(props) {
|
|
144
|
+
const { initialUid = "", initialToken = "" } = props;
|
|
145
|
+
const [searchParams] = useSearchParams();
|
|
146
|
+
const navigate = useNavigate();
|
|
147
|
+
const initialEmail = useMemo(() => searchParams.get("email") || "", [searchParams]);
|
|
148
|
+
const { confirmAccountEmail, resendAccountConfirmation } = useFuseJwtAuth();
|
|
149
|
+
return (_jsx(AuthAccountConfirmationForm, { defaultValues: {
|
|
150
|
+
uid: initialUid,
|
|
151
|
+
token: initialToken,
|
|
152
|
+
}, defaultEmail: initialEmail, onGoToSignIn: () => navigate('/sign-in'), onSubmit: (values) => confirmAccountEmail(values), onResend: (values) => resendAccountConfirmation(values) }));
|
|
153
|
+
}
|
|
154
|
+
function useRoleSelectionDialog(options, defaultRole) {
|
|
155
|
+
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
|
156
|
+
const [selectedRole, setSelectedRole] = useState(defaultRole ?? options[0]?.value ?? "");
|
|
157
|
+
const roleSelectionResolverRef = useRef(null);
|
|
158
|
+
const requestRoleSelection = useCallback(() => {
|
|
159
|
+
if (!options.length) {
|
|
160
|
+
return Promise.resolve(undefined);
|
|
161
|
+
}
|
|
162
|
+
if (options.length === 1) {
|
|
163
|
+
return Promise.resolve(options[0].value);
|
|
164
|
+
}
|
|
165
|
+
return new Promise((resolve) => {
|
|
166
|
+
roleSelectionResolverRef.current = resolve;
|
|
167
|
+
setIsDialogOpen(true);
|
|
168
|
+
});
|
|
169
|
+
}, [options]);
|
|
170
|
+
const closeRoleDialog = useCallback((role) => {
|
|
171
|
+
const resolver = roleSelectionResolverRef.current;
|
|
172
|
+
roleSelectionResolverRef.current = null;
|
|
173
|
+
setIsDialogOpen(false);
|
|
174
|
+
resolver?.(role);
|
|
175
|
+
}, []);
|
|
176
|
+
const dialog = (_jsx(AuthRoleSelectionDialog, { open: isDialogOpen, options: options, initialRole: selectedRole, onCancel: () => closeRoleDialog(undefined), onConfirm: (role) => {
|
|
177
|
+
setSelectedRole(role);
|
|
178
|
+
closeRoleDialog(role);
|
|
179
|
+
} }));
|
|
180
|
+
return { requestRoleSelection, dialog, hasRoleOptions: options.length > 0 };
|
|
181
|
+
}
|
|
182
|
+
export function createFuseAuthViews(options) {
|
|
183
|
+
const { LinkComponent, accountConfirmationPath = "/verify-email", signUpRoleOptions, defaultSignUpRole, socialConfig, onSignUpSuccess, } = options;
|
|
184
|
+
function SignInPageView() {
|
|
185
|
+
const [mode, setMode] = useState("password");
|
|
186
|
+
const { signInSocial } = useFuseJwtAuth();
|
|
187
|
+
const [socialLoadingProvider, setSocialLoadingProvider] = useState(null);
|
|
188
|
+
const [socialError, setSocialError] = useState(null);
|
|
189
|
+
const signupRoleOptions = (signUpRoleOptions ?? [])
|
|
190
|
+
.filter((roleOption) => roleOption.allowSignup === true)
|
|
191
|
+
.map((roleOption) => ({
|
|
192
|
+
value: roleOption.value,
|
|
193
|
+
label: roleOption.label,
|
|
194
|
+
}));
|
|
195
|
+
const { requestRoleSelection, dialog, hasRoleOptions } = useRoleSelectionDialog(signupRoleOptions, defaultSignUpRole);
|
|
196
|
+
const enabledSocialProviders = useMemo(() => getEnabledSocialProviders(socialConfig), [socialConfig]);
|
|
197
|
+
const onSocialClick = useCallback(async (provider) => {
|
|
198
|
+
const providerConfig = enabledSocialProviders.find((item) => item.provider === provider);
|
|
199
|
+
if (!providerConfig) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
setSocialError(null);
|
|
204
|
+
setSocialLoadingProvider(provider);
|
|
205
|
+
const tokenPayload = await authenticateWithSocialProvider(provider, providerConfig);
|
|
206
|
+
const selectedRole = hasRoleOptions ? await requestRoleSelection() : undefined;
|
|
207
|
+
if (hasRoleOptions && !selectedRole) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
await signInSocial({
|
|
211
|
+
...tokenPayload,
|
|
212
|
+
provider,
|
|
213
|
+
role: selectedRole,
|
|
214
|
+
client: "web",
|
|
215
|
+
termsAndConditionsAccepted: true,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
const parsed = parseAuthError(error);
|
|
220
|
+
setSocialError(parsed.rootMessage || "No se pudo continuar con el proveedor social.");
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
setSocialLoadingProvider(null);
|
|
224
|
+
}
|
|
225
|
+
}, [enabledSocialProviders, hasRoleOptions, requestRoleSelection, signInSocial]);
|
|
226
|
+
return (_jsxs(Box, { sx: {
|
|
227
|
+
mx: { xs: "auto", sm: 0 },
|
|
228
|
+
width: { xs: "100%", sm: 320 },
|
|
229
|
+
maxWidth: 320,
|
|
230
|
+
display: "flex",
|
|
231
|
+
flexDirection: "column",
|
|
232
|
+
gap: 4,
|
|
233
|
+
}, children: [_jsx(SignInPageTitle, {}), _jsxs(Box, { sx: { width: "100%" }, children: [_jsx(FuseSignInController, { LinkComponent: LinkComponent, mode: mode, requestRoleSelection: requestRoleSelection, onBackToPassword: () => setMode("password") }), mode === "password" && (_jsxs(_Fragment, { children: [_jsx(FuseSignUpCtaSection, { LinkComponent: LinkComponent }), _jsx(FuseAuthAlternativesSection, { onSmsClick: () => setMode("otp"), socialProviders: enabledSocialProviders, onSocialClick: onSocialClick, socialLoadingProvider: socialLoadingProvider, socialError: socialError })] }))] }), dialog] }));
|
|
234
|
+
}
|
|
235
|
+
function SignUpPageView() {
|
|
236
|
+
const [mode, setMode] = useState("password");
|
|
237
|
+
const { signInSocial } = useFuseJwtAuth();
|
|
238
|
+
const [socialLoadingProvider, setSocialLoadingProvider] = useState(null);
|
|
239
|
+
const [socialError, setSocialError] = useState(null);
|
|
240
|
+
const navigate = useNavigate();
|
|
241
|
+
const signupRoleOptions = (signUpRoleOptions ?? [])
|
|
242
|
+
.filter((roleOption) => roleOption.allowSignup === true)
|
|
243
|
+
.map((roleOption) => ({
|
|
244
|
+
value: roleOption.value,
|
|
245
|
+
label: roleOption.label,
|
|
246
|
+
}));
|
|
247
|
+
const { requestRoleSelection, dialog, hasRoleOptions } = useRoleSelectionDialog(signupRoleOptions, defaultSignUpRole);
|
|
248
|
+
const enabledSocialProviders = useMemo(() => getEnabledSocialProviders(socialConfig), [socialConfig]);
|
|
249
|
+
const onSocialClick = useCallback(async (provider) => {
|
|
250
|
+
const providerConfig = enabledSocialProviders.find((item) => item.provider === provider);
|
|
251
|
+
if (!providerConfig) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
setSocialError(null);
|
|
256
|
+
setSocialLoadingProvider(provider);
|
|
257
|
+
const tokenPayload = await authenticateWithSocialProvider(provider, providerConfig);
|
|
258
|
+
const selectedRole = hasRoleOptions ? await requestRoleSelection() : undefined;
|
|
259
|
+
if (hasRoleOptions && !selectedRole) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
await signInSocial({
|
|
263
|
+
...tokenPayload,
|
|
264
|
+
provider,
|
|
265
|
+
role: selectedRole,
|
|
266
|
+
client: "web",
|
|
267
|
+
termsAndConditionsAccepted: true,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
const parsed = parseAuthError(error);
|
|
272
|
+
setSocialError(parsed.rootMessage || "No se pudo continuar con el proveedor social.");
|
|
273
|
+
}
|
|
274
|
+
finally {
|
|
275
|
+
setSocialLoadingProvider(null);
|
|
276
|
+
}
|
|
277
|
+
}, [enabledSocialProviders, hasRoleOptions, requestRoleSelection, signInSocial]);
|
|
278
|
+
return (_jsxs(Box, { sx: {
|
|
279
|
+
mx: { xs: "auto", sm: 0 },
|
|
280
|
+
width: { xs: "100%", sm: 320 },
|
|
281
|
+
maxWidth: 320,
|
|
282
|
+
display: "flex",
|
|
283
|
+
flexDirection: "column",
|
|
284
|
+
gap: 4,
|
|
285
|
+
}, children: [_jsx(SignUpPageTitle, {}), _jsx(Box, { sx: { width: "100%" }, children: mode === "password" ? (_jsxs(_Fragment, { children: [_jsx(FuseSignUpController, { requiresRoleSelection: hasRoleOptions, requestRoleSelection: requestRoleSelection, onSuccess: (payload) => {
|
|
286
|
+
const { email } = payload;
|
|
287
|
+
onSignUpSuccess?.(payload);
|
|
288
|
+
navigate(`${accountConfirmationPath}?email=${encodeURIComponent(email)}`);
|
|
289
|
+
} }), _jsx(FuseSignInCtaSection, { LinkComponent: LinkComponent }), _jsx(FuseAuthAlternativesSection, { onSmsClick: () => setMode("otp"), socialProviders: enabledSocialProviders, onSocialClick: onSocialClick, socialLoadingProvider: socialLoadingProvider, socialError: socialError })] })) : (_jsx(FuseOtpSignUpForm, { requestRoleSelection: requestRoleSelection, onBackToPassword: () => setMode("password") })) }), dialog] }));
|
|
290
|
+
}
|
|
291
|
+
function ForgotPasswordPageView() {
|
|
292
|
+
return (_jsxs(Box, { sx: {
|
|
293
|
+
mx: { xs: "auto", sm: 0 },
|
|
294
|
+
width: { xs: "100%", sm: 320 },
|
|
295
|
+
maxWidth: 320,
|
|
296
|
+
display: "flex",
|
|
297
|
+
flexDirection: "column",
|
|
298
|
+
gap: 4,
|
|
299
|
+
}, children: [_jsxs(Box, { sx: { width: "100%" }, children: [_jsx("img", { style: { width: 48 }, src: "/assets/images/logo/logo.svg", alt: "logo" }), _jsx(Typography, { sx: {
|
|
300
|
+
mt: 4,
|
|
301
|
+
fontSize: 36,
|
|
302
|
+
lineHeight: 1.25,
|
|
303
|
+
fontWeight: 800,
|
|
304
|
+
letterSpacing: "-0.02em",
|
|
305
|
+
}, children: "Olvid\u00E9 mi contrase\u00F1a" }), _jsx(Typography, { sx: { mt: 1.5, fontSize: 16 }, color: "text.secondary", children: "Ingresa tu correo y te enviaremos un enlace para restablecer tu contrase\u00F1a." })] }), _jsx(FuseForgotPasswordPageForm, {}), _jsxs(Typography, { sx: { fontSize: 16, fontWeight: 500 }, color: "text.secondary", children: ["Volver a ", _jsx(LinkComponent, { to: "/sign-in", children: "Iniciar sesi\u00F3n" })] })] }));
|
|
306
|
+
}
|
|
307
|
+
function ResetPasswordPageView() {
|
|
308
|
+
const [searchParams] = useSearchParams();
|
|
309
|
+
const initialUid = useMemo(() => searchParams.get("uid") || "", [searchParams]);
|
|
310
|
+
const initialToken = useMemo(() => searchParams.get("token") || "", [searchParams]);
|
|
311
|
+
return (_jsxs(Box, { sx: {
|
|
312
|
+
mx: { xs: "auto", sm: 0 },
|
|
313
|
+
width: { xs: "100%", sm: 320 },
|
|
314
|
+
maxWidth: 320,
|
|
315
|
+
display: "flex",
|
|
316
|
+
flexDirection: "column",
|
|
317
|
+
gap: 4,
|
|
318
|
+
}, children: [_jsxs(Box, { sx: { width: "100%" }, children: [_jsx("img", { style: { width: 48 }, src: "/assets/images/logo/logo.svg", alt: "logo" }), _jsx(Typography, { sx: {
|
|
319
|
+
mt: 4,
|
|
320
|
+
fontSize: 36,
|
|
321
|
+
lineHeight: 1.25,
|
|
322
|
+
fontWeight: 800,
|
|
323
|
+
letterSpacing: "-0.02em",
|
|
324
|
+
}, children: "Restablecer contrase\u00F1a" }), _jsx(Typography, { sx: { mt: 1.5, fontSize: 16 }, color: "text.secondary", children: "Define una nueva contrase\u00F1a para volver a acceder a tu cuenta." })] }), _jsx(FuseResetPasswordPageForm, { initialUid: initialUid, initialToken: initialToken }), _jsxs(Typography, { sx: { fontSize: 16, fontWeight: 500 }, color: "text.secondary", children: ["Volver a ", _jsx(LinkComponent, { to: "/sign-in", children: "Iniciar sesi\u00F3n" })] })] }));
|
|
325
|
+
}
|
|
326
|
+
function SignOutPageView() {
|
|
327
|
+
return (_jsxs(Box, { sx: {
|
|
328
|
+
mx: { xs: "auto", sm: 0 },
|
|
329
|
+
width: { xs: "100%", sm: 320 },
|
|
330
|
+
maxWidth: 320,
|
|
331
|
+
}, children: [_jsx(SignOutPageTitle, {}), _jsxs(Typography, { sx: { mt: 2, textAlign: "center", fontSize: 16, fontWeight: 500 }, color: "text.secondary", children: ["Ir a ", _jsx(LinkComponent, { to: "/sign-in", children: "iniciar sesi\u00F3n" })] })] }));
|
|
332
|
+
}
|
|
333
|
+
function AccountConfirmationPageView() {
|
|
334
|
+
const [searchParams] = useSearchParams();
|
|
335
|
+
const initialUid = useMemo(() => searchParams.get("uid") || "", [searchParams]);
|
|
336
|
+
const initialToken = useMemo(() => searchParams.get("token") || "", [searchParams]);
|
|
337
|
+
return (_jsxs(Box, { sx: {
|
|
338
|
+
mx: { xs: "auto", sm: 0 },
|
|
339
|
+
width: { xs: "100%", sm: 320 },
|
|
340
|
+
maxWidth: 320,
|
|
341
|
+
display: "flex",
|
|
342
|
+
flexDirection: "column",
|
|
343
|
+
gap: 4,
|
|
344
|
+
}, children: [_jsxs(Box, { sx: { width: "100%" }, children: [_jsx("img", { style: { width: 48 }, src: "/assets/images/logo/logo.svg", alt: "logo" }), _jsx(Typography, { sx: {
|
|
345
|
+
mt: 4,
|
|
346
|
+
fontSize: 36,
|
|
347
|
+
lineHeight: 1.25,
|
|
348
|
+
fontWeight: 800,
|
|
349
|
+
letterSpacing: "-0.02em",
|
|
350
|
+
}, children: "Verificar cuenta" }), _jsx(Typography, { sx: { mt: 1.5, fontSize: 16 }, color: "text.secondary", children: "Estamos validando tu enlace de confirmaci\u00F3n." })] }), _jsx(FuseAccountConfirmationPageForm, { initialUid: initialUid, initialToken: initialToken })] }));
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
SignInPageView,
|
|
354
|
+
SignUpPageView,
|
|
355
|
+
ForgotPasswordPageView,
|
|
356
|
+
ResetPasswordPageView,
|
|
357
|
+
SignOutPageView,
|
|
358
|
+
AccountConfirmationPageView,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AuthClient } from '../client';
|
|
3
|
+
import { AccountConfirmationPayload, AccountConfirmationResendPayload, LoginSocialPayload, PasswordChangePayload, PasswordResetConfirmPayload, PasswordResetRequestPayload, RegisterPayload, RequestOtpPayload, VerifyOtpPayload } from '../types';
|
|
4
|
+
type JsonRecord = Record<string, unknown>;
|
|
5
|
+
type FuseAuthState<TUser = JsonRecord> = {
|
|
6
|
+
authStatus: 'configuring' | 'authenticated' | 'unauthenticated';
|
|
7
|
+
isAuthenticated: boolean;
|
|
8
|
+
user: TUser | null;
|
|
9
|
+
};
|
|
10
|
+
export type FuseJwtAuthContextType<TUser = JsonRecord> = FuseAuthState<TUser> & {
|
|
11
|
+
signIn: (credentials: {
|
|
12
|
+
login: string;
|
|
13
|
+
password: string;
|
|
14
|
+
username?: string;
|
|
15
|
+
}) => Promise<JsonRecord>;
|
|
16
|
+
signInSocial: (payload: LoginSocialPayload) => Promise<JsonRecord>;
|
|
17
|
+
requestOtp: (payload: RequestOtpPayload) => Promise<Record<string, unknown>>;
|
|
18
|
+
signInOtp: (payload: VerifyOtpPayload) => Promise<JsonRecord>;
|
|
19
|
+
signUp: (payload: RegisterPayload) => Promise<JsonRecord>;
|
|
20
|
+
confirmAccountEmail: (payload: AccountConfirmationPayload) => Promise<Record<string, unknown>>;
|
|
21
|
+
resendAccountConfirmation: (payload: AccountConfirmationResendPayload) => Promise<Record<string, unknown>>;
|
|
22
|
+
requestPasswordReset: (payload: PasswordResetRequestPayload) => Promise<Record<string, unknown>>;
|
|
23
|
+
confirmPasswordReset: (payload: PasswordResetConfirmPayload) => Promise<Record<string, unknown>>;
|
|
24
|
+
changePassword: (payload: PasswordChangePayload) => Promise<Record<string, unknown>>;
|
|
25
|
+
switchProfile: (profileId: number) => Promise<JsonRecord>;
|
|
26
|
+
getProfiles: () => Promise<Record<string, unknown>[]>;
|
|
27
|
+
signOut: () => void;
|
|
28
|
+
refreshToken: () => Promise<string | null>;
|
|
29
|
+
};
|
|
30
|
+
type FuseAuthProviderComponentProps = {
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
onAuthStateChanged?: (state: FuseAuthState) => void;
|
|
33
|
+
ref?: React.Ref<{
|
|
34
|
+
signOut: () => void;
|
|
35
|
+
}>;
|
|
36
|
+
};
|
|
37
|
+
export declare const createFuseJwtAuthProvider: (authClient: AuthClient) => (props: FuseAuthProviderComponentProps) => import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export declare const useFuseJwtAuth: () => FuseJwtAuthContextType<JsonRecord>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=fuseAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fuseAdapter.d.ts","sourceRoot":"","sources":["../../../src/auth/fuse/fuseAdapter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAOV,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,EAC3B,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAElB,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,KAAK,aAAa,CAAC,KAAK,GAAG,UAAU,IAAI;IACvC,UAAU,EAAE,aAAa,GAAG,eAAe,GAAG,iBAAiB,CAAC;IAChE,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,KAAK,GAAG,UAAU,IAAI,aAAa,CAAC,KAAK,CAAC,GAAG;IAC9E,MAAM,EAAE,CAAC,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACrG,YAAY,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACnE,UAAU,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7E,SAAS,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9D,MAAM,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1D,mBAAmB,EAAE,CAAC,OAAO,EAAE,0BAA0B,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/F,yBAAyB,EAAE,CAAC,OAAO,EAAE,gCAAgC,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3G,oBAAoB,EAAE,CAAC,OAAO,EAAE,2BAA2B,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjG,oBAAoB,EAAE,CAAC,OAAO,EAAE,2BAA2B,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjG,cAAc,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACrF,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1D,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACtD,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC5C,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACpD,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC;QACd,OAAO,EAAE,MAAM,IAAI,CAAC;KACrB,CAAC,CAAC;CACJ,CAAC;AAsEF,eAAO,MAAM,yBAAyB,GAAI,YAAY,UAAU,aAC1B,8BAA8B,4CAgQnE,CAAC;AAEF,eAAO,MAAM,cAAc,0CAM1B,CAAC"}
|