Skip to content

Commit a7fc482

Browse files
authored
Merge pull request #298 from brionmario/refactor-thunder-flows
Stop resolving `i18n` keys in render props
2 parents c7c8864 + c68d138 commit a7fc482

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

.changeset/moody-pens-look.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@asgardeo/react': patch
3+
---
4+
5+
Stop resolving `i18n` for render props

packages/react/src/components/presentation/auth/SignIn/v2/SignIn.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,9 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
396396
return;
397397
}
398398

399-
const {flowId, components} = normalizeFlowResponse(response, t);
399+
const {flowId, components} = normalizeFlowResponse(response, t, {
400+
resolveTranslations: !children,
401+
});
400402

401403
if (flowId && components) {
402404
setFlowId(flowId);
@@ -448,7 +450,9 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
448450
return;
449451
}
450452

451-
const {flowId, components} = normalizeFlowResponse(response, t);
453+
const {flowId, components} = normalizeFlowResponse(response, t, {
454+
resolveTranslations: !children,
455+
});
452456

453457
// Handle Error flow status - flow has failed and is invalidated
454458
if (response.flowStatus === EmbeddedSignInFlowStatusV2.Error) {

packages/react/src/components/presentation/auth/SignUp/v2/BaseSignUp.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ const BaseSignUpContent: FC<BaseSignUpProps> = ({
302302
try {
303303
const {components} = normalizeFlowResponse(response, t, {
304304
defaultErrorKey: 'components.signUp.errors.generic',
305+
resolveTranslations: !children,
305306
});
306307

307308
return {
@@ -320,7 +321,7 @@ const BaseSignUpContent: FC<BaseSignUpProps> = ({
320321
// Return as-is if no transformation needed
321322
return response;
322323
},
323-
[t],
324+
[t, children],
324325
);
325326

326327
/**

packages/react/src/utils/v2/flowTransformer.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,35 @@ export interface FlowTransformOptions {
7272
* @default 'errors.flow.generic'
7373
*/
7474
defaultErrorKey?: string;
75+
/**
76+
* Whether to resolve translation strings or keep them as i18n keys
77+
* @default true
78+
*/
79+
resolveTranslations?: boolean;
7580
}
7681

7782
/**
7883
* Transform and resolve translations in components from flow response.
79-
* This function extracts components from the response meta structure and resolves
84+
* This function extracts components from the response meta structure and optionally resolves
8085
* any translation strings within them.
8186
*
8287
* @param response - The flow response object containing components in meta structure
8388
* @param t - Translation function from useTranslation hook
84-
* @returns Array of flow components with resolved translations
89+
* @param resolveTranslations - Whether to resolve translation strings or keep them as i18n keys (default: true)
90+
* @returns Array of flow components with resolved or unresolved translations
8591
*/
86-
export const transformComponents = (response: any, t: UseTranslation['t']): EmbeddedFlowComponent[] => {
92+
export const transformComponents = (
93+
response: any,
94+
t: UseTranslation['t'],
95+
resolveTranslations: boolean = true,
96+
): EmbeddedFlowComponent[] => {
8797
if (!response?.data?.meta?.components) {
8898
return [];
8999
}
90100

91101
const components: EmbeddedFlowComponent[] = response.data.meta.components;
92102

93-
return resolveTranslationsInArray(components, t);
103+
return resolveTranslations ? resolveTranslationsInArray(components, t) : components;
94104
};
95105

96106
/**
@@ -154,7 +164,7 @@ export const normalizeFlowResponse = (
154164
flowId: string;
155165
components: EmbeddedFlowComponent[];
156166
} => {
157-
const {throwOnError = true, defaultErrorKey = 'errors.flow.generic'} = options;
167+
const {throwOnError = true, defaultErrorKey = 'errors.flow.generic', resolveTranslations = true} = options;
158168

159169
// Check if this is an error response
160170
const errorMessage: string | null = checkForErrorResponse(response, t, defaultErrorKey);
@@ -166,6 +176,6 @@ export const normalizeFlowResponse = (
166176

167177
return {
168178
flowId: response.flowId,
169-
components: transformComponents(response, t),
179+
components: transformComponents(response, t, resolveTranslations),
170180
};
171181
};

0 commit comments

Comments
 (0)