Skip to content

Commit 929c08e

Browse files
authored
refactor(console): add i18n context to cloud tenant api (#8018)
1 parent 43e1789 commit 929c08e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/console/src/cloud/hooks/use-cloud-api.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const useCloudApi = ({ hideErrorToast = false }: UseCloudApiProps = {}):
6060
...conditional(!hideErrorToast && { error: toastResponseError }),
6161
},
6262
}),
63-
[getAccessToken, hideErrorToast, isAuthenticated]
63+
[getAccessToken, hideErrorToast, i18n.language, isAuthenticated]
6464
);
6565

6666
return api;
@@ -69,14 +69,16 @@ export const useCloudApi = ({ hideErrorToast = false }: UseCloudApiProps = {}):
6969
type CreateTenantOptions = UseCloudApiProps &
7070
Pick<ReturnType<typeof useLogto>, 'isAuthenticated' | 'getOrganizationToken'> & {
7171
tenantId: string;
72+
language: string;
7273
};
7374

7475
export const createTenantApi = ({
7576
hideErrorToast = false,
7677
isAuthenticated,
7778
getOrganizationToken,
7879
tenantId,
79-
}: CreateTenantOptions) =>
80+
language,
81+
}: CreateTenantOptions): Client<typeof tenantAuthRouter> =>
8082
new Client<typeof tenantAuthRouter>({
8183
baseUrl: window.location.origin,
8284
headers: async () => {
@@ -85,6 +87,7 @@ export const createTenantApi = ({
8587
Authorization: `Bearer ${
8688
(await getOrganizationToken(getTenantOrganizationId(tenantId))) ?? ''
8789
}`,
90+
'Accept-Language': language,
8891
};
8992
}
9093
},
@@ -99,6 +102,7 @@ export const createTenantApi = ({
99102
export const useAuthedCloudApi = ({ hideErrorToast = false }: UseCloudApiProps = {}): Client<
100103
typeof tenantAuthRouter
101104
> => {
105+
const { i18n } = useTranslation();
102106
const { currentTenantId } = useContext(TenantsContext);
103107
const { isAuthenticated, getOrganizationToken } = useLogto();
104108
const api = useMemo(
@@ -108,8 +112,9 @@ export const useAuthedCloudApi = ({ hideErrorToast = false }: UseCloudApiProps =
108112
isAuthenticated,
109113
getOrganizationToken,
110114
tenantId: currentTenantId,
115+
language: i18n.language,
111116
}),
112-
[currentTenantId, getOrganizationToken, hideErrorToast, isAuthenticated]
117+
[currentTenantId, getOrganizationToken, hideErrorToast, isAuthenticated, i18n.language]
113118
);
114119

115120
return api;

packages/console/src/onboarding/pages/CreateTenant/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function CreateTenant() {
5252
} = methods;
5353
const { prependTenant } = useContext(TenantsContext);
5454
const theme = useTheme();
55-
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
55+
const { t, i18n } = useTranslation(undefined, { keyPrefix: 'admin_console' });
5656
const { update } = useUserOnboardingData();
5757
const parseEmailOptions = useCallback(
5858
(values: InviteeEmailItem[]) => {
@@ -93,6 +93,7 @@ function CreateTenant() {
9393
isAuthenticated,
9494
getOrganizationToken,
9595
tenantId: newTenant.id,
96+
language: i18n.language,
9697
});
9798

9899
if (collaboratorEmails.length > 0) {

0 commit comments

Comments
 (0)