Skip to content

Commit c1b90fa

Browse files
committed
feat: update error handling in SignIn, SignOut, and SignUp buttons; enhance AsgardeoLoading and SignedIn components with CSR remarks; clean up FieldFactory and BaseCreateOrganization components
1 parent 4d10de8 commit c1b90fa

File tree

9 files changed

+17
-79
lines changed

9 files changed

+17
-79
lines changed

packages/react/src/components/actions/SignInButton/SignInButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const SignInButton: ForwardRefExoticComponent<SignInButtonProps & RefAttributes<
9595
} catch (error) {
9696
throw new AsgardeoRuntimeError(
9797
`Sign in failed: ${error instanceof Error ? error.message : String(error)}`,
98-
'handleSignIn-RuntimeError-001',
98+
'SignInButton-handleSignIn-RuntimeError-001',
9999
'react',
100100
'Something went wrong while trying to sign in. Please try again later.',
101101
);

packages/react/src/components/actions/SignOutButton/SignOutButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const SignOutButton: ForwardRefExoticComponent<SignOutButtonProps & RefAttribute
7979
const handleSignOut = async (e?: MouseEvent<HTMLButtonElement>): Promise<void> => {
8080
try {
8181
setIsLoading(true);
82+
8283
await signOut();
8384

8485
if (onClick) {
@@ -87,7 +88,7 @@ const SignOutButton: ForwardRefExoticComponent<SignOutButtonProps & RefAttribute
8788
} catch (error) {
8889
throw new AsgardeoRuntimeError(
8990
`Sign out failed: ${error instanceof Error ? error.message : String(error)}`,
90-
'handleSignOut-RuntimeError-001',
91+
'SignOutButton-handleSignOut-RuntimeError-001',
9192
'react',
9293
'Something went wrong while trying to sign out. Please try again later.',
9394
);

packages/react/src/components/actions/SignUpButton/SignUpButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const SignUpButton: ForwardRefExoticComponent<SignUpButtonProps & RefAttributes<
8080
const handleSignUp = async (e?: MouseEvent<HTMLButtonElement>): Promise<void> => {
8181
try {
8282
setIsLoading(true);
83+
8384
await signUp();
8485

8586
if (onClick) {
@@ -88,7 +89,7 @@ const SignUpButton: ForwardRefExoticComponent<SignUpButtonProps & RefAttributes<
8889
} catch (error) {
8990
throw new AsgardeoRuntimeError(
9091
`Sign up failed: ${error instanceof Error ? error.message : String(error)}`,
91-
'handleSignUp-RuntimeError-001',
92+
'SignUpButton-handleSignUp-RuntimeError-001',
9293
'react',
9394
'Something went wrong while trying to sign up. Please try again later.',
9495
);

packages/react/src/components/control/AsgardeoLoading.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export interface AsgardeoLoadingProps {
3232
/**
3333
* A component that only renders its children when the Asgardeo is loading.
3434
*
35+
* @remarks This component is only supported in browser based React applications (CSR).
36+
*
3537
* @example
3638
* ```tsx
3739
* import { AsgardeoLoading } from '@asgardeo/auth-react';
@@ -58,6 +60,6 @@ const AsgardeoLoading: FC<PropsWithChildren<AsgardeoLoadingProps>> = ({
5860
return <>{children}</>;
5961
};
6062

61-
AsgardeoLoading.displayName = 'Loading';
63+
AsgardeoLoading.displayName = 'AsgardeoLoading';
6264

6365
export default AsgardeoLoading;

packages/react/src/components/control/SignedIn.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export interface SignedInProps {
3232
/**
3333
* A component that only renders its children when the user is signed in.
3434
*
35+
* @remarks This component is only supported in browser based React applications (CSR).
36+
*
3537
* @example
3638
* ```tsx
3739
* import { SignedIn } from '@asgardeo/auth-react';

packages/react/src/components/control/SignedOut.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export interface SignedOutProps {
3232
/**
3333
* A component that only renders its children when the user is signed out.
3434
*
35+
* @remarks This component is only supported in browser based React applications (CSR).
36+
*
3537
* @example
3638
* ```tsx
3739
* import { SignedOut } from '@asgardeo/auth-react';

packages/react/src/components/factories/FieldFactory.tsx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ import {FieldType} from '@asgardeo/browser';
3030
* Interface for field configuration.
3131
*/
3232
export interface FieldConfig {
33+
/**
34+
* The name of the field.
35+
*/
3336
name: string;
3437
/**
35-
* The field type based on EmbeddedSignInFlowAuthenticatorParamType.
38+
* The field type.
3639
*/
3740
type: FieldType;
3841
/**
@@ -77,24 +80,6 @@ export interface FieldConfig {
7780
placeholder?: string;
7881
}
7982

80-
/**
81-
* Utility function to parse multi-valued string into array
82-
*/
83-
export const parseMultiValuedString = (value: string): string[] => {
84-
if (!value || value.trim() === '') return [];
85-
return value
86-
.split(',')
87-
.map(item => item.trim())
88-
.filter(item => item.length > 0);
89-
};
90-
91-
/**
92-
* Utility function to format array into multi-valued string
93-
*/
94-
export const formatMultiValuedString = (values: string[]): string => {
95-
return values.join(', ');
96-
};
97-
9883
/**
9984
* Utility function to validate field values based on type
10085
*/
@@ -104,12 +89,10 @@ export const validateFieldValue = (
10489
required: boolean = false,
10590
touched: boolean = false,
10691
): string | null => {
107-
// Only show required field errors if the field has been touched
10892
if (required && touched && (!value || value.trim() === '')) {
10993
return 'This field is required';
11094
}
11195

112-
// If not required and empty, no validation needed
11396
if (!value || value.trim() === '') {
11497
return null;
11598
}
@@ -161,7 +144,6 @@ export const createField = (config: FieldConfig): ReactElement => {
161144
placeholder,
162145
} = config;
163146

164-
// Auto-validate the field value
165147
const validationError = error || validateFieldValue(value, type, required, touched);
166148

167149
const commonProps = {
@@ -237,7 +219,7 @@ export const createField = (config: FieldConfig): ReactElement => {
237219
/**
238220
* React component wrapper for the field factory.
239221
*/
240-
export const FieldFactory: FC<FieldConfig> = props => {
222+
export const FieldFactory: FC<FieldConfig> = (props: FieldConfig): ReactElement => {
241223
return createField(props);
242224
};
243225

packages/react/src/components/presentation/CreateOrganization/BaseCreateOrganization.tsx

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
import {withVendorCSSClassPrefix} from '@asgardeo/browser';
2020
import clsx from 'clsx';
2121
import {ChangeEvent, CSSProperties, FC, ReactElement, ReactNode, useMemo, useState} from 'react';
22-
2322
import {CreateOrganizationPayload} from '../../../api/scim2/createOrganization';
2423
import useTheme from '../../../contexts/Theme/useTheme';
2524
import useTranslation from '../../../hooks/useTranslation';
26-
import {Avatar} from '../../primitives/Avatar/Avatar';
2725
import Button from '../../primitives/Button/Button';
2826
import {Dialog, DialogContent, DialogHeading} from '../../primitives/Popover/Popover';
2927
import FormControl from '../../primitives/FormControl/FormControl';
@@ -181,8 +179,6 @@ export const BaseCreateOrganization: FC<BaseCreateOrganizationProps> = ({
181179
const styles = useStyles();
182180
const {theme} = useTheme();
183181
const {t} = useTranslation();
184-
const [avatarUrl, setAvatarUrl] = useState<string>('');
185-
const [avatarFile, setAvatarFile] = useState<File | null>(null);
186182
const [formData, setFormData] = useState<OrganizationFormData>({
187183
description: '',
188184
handle: '',
@@ -227,44 +223,6 @@ export const BaseCreateOrganization: FC<BaseCreateOrganizationProps> = ({
227223
}
228224
};
229225

230-
const handleAvatarUpload = (event: ChangeEvent<HTMLInputElement>): void => {
231-
const file = event.target.files?.[0];
232-
if (file) {
233-
// Validate file type
234-
if (!file.type.startsWith('image/')) {
235-
setFormErrors(prev => ({
236-
...prev,
237-
avatar: 'Please select a valid image file',
238-
}));
239-
return;
240-
}
241-
242-
// Validate file size (max 2MB)
243-
if (file.size > 2 * 1024 * 1024) {
244-
setFormErrors(prev => ({
245-
...prev,
246-
avatar: 'Image size must be less than 2MB',
247-
}));
248-
return;
249-
}
250-
251-
setAvatarFile(file);
252-
253-
// Create preview URL
254-
const reader = new FileReader();
255-
reader.onload = e => {
256-
setAvatarUrl(e.target?.result as string);
257-
};
258-
reader.readAsDataURL(file);
259-
260-
// Clear any previous avatar errors
261-
setFormErrors(prev => ({
262-
...prev,
263-
avatar: undefined,
264-
}));
265-
}
266-
};
267-
268226
const handleNameChange = (value: string): void => {
269227
handleInputChange('name', value);
270228

@@ -310,14 +268,6 @@ export const BaseCreateOrganization: FC<BaseCreateOrganizationProps> = ({
310268
}
311269
};
312270

313-
const defaultRenderHeader = (): ReactElement => (
314-
<div className={withVendorCSSClassPrefix('create-organization__header')} style={styles.header}>
315-
<Typography variant="h6" component="h2">
316-
{t('organization.create.title')}
317-
</Typography>
318-
</div>
319-
);
320-
321271
const containerStyle = {
322272
...styles.root,
323273
...(cardLayout ? styles.card : {}),

packages/react/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ export {default as LogOut} from './components/primitives/Icons/LogOut';
239239
export {
240240
createField,
241241
FieldFactory,
242-
parseMultiValuedString,
243-
formatMultiValuedString,
244242
validateFieldValue,
245243
} from './components/factories/FieldFactory';
246244
export * from './components/factories/FieldFactory';

0 commit comments

Comments
 (0)