Skip to content

Commit

Permalink
chore: bump atoms 1.0.35 and wrap context (#14744)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThyMinimalDev committed Apr 25, 2024
1 parent d8adc8e commit 8fbb1ed
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
77 changes: 47 additions & 30 deletions packages/platform/atoms/cal-provider/BaseCalProvider.tsx
Expand Up @@ -62,6 +62,35 @@ export function BaseCalProvider({
clientId,
});

const translations = {
t: (key: string, values: Record<string, string | number | null | undefined>) => {
let translation = String(enTranslations[key as translationKeys] ?? "");
if (!translation) {
return "";
}
if (values) {
const valueKeys = Object.keys(values) as (keyof typeof values)[];
if (valueKeys.length) {
valueKeys.forEach((valueKey) => {
if (translation)
translation = translation.replace(
`{{${String(valueKey)}}}`,
values[valueKey]?.toString() ?? `{{${String(valueKey)}}}`
);
});
}
}

return replaceOccurrences(translation, enTranslations) ?? "";
},
i18n: {
language: "en",
defaultLocale: "en",
locales: ["en"],
exists: (key: translationKeys | string) => Boolean(enTranslations[key as translationKeys]),
},
};

return isInit ? (
<AtomsContext.Provider
value={{
Expand All @@ -74,41 +103,29 @@ export function BaseCalProvider({
isInit: isInit,
isValidClient: Boolean(!error && clientId && isInit),
isAuth: Boolean(isInit && !error && clientId && currentAccessToken && http.getAuthorizationHeader()),
t: (key, values) => {
let translation = String(enTranslations[key as translationKeys] ?? "");
if (!translation) {
return "";
}
if (values) {
const valueKeys = Object.keys(values) as (keyof typeof values)[];
if (valueKeys.length) {
valueKeys.forEach((valueKey) => {
if (translation)
translation = translation.replace(
`{{${String(valueKey)}}}`,
values[valueKey]?.toString() ?? `{{${String(valueKey)}}}`
);
});
}
}

return replaceOccurrences(translation, enTranslations) ?? "";
},
i18n: {
language: "en",
defaultLocale: "en",
locales: ["en"],
exists: (key: translationKeys | string) => Boolean(enTranslations[key as translationKeys]),
},
...translations,
}}>
<TooltipProvider>{children}</TooltipProvider>
<Toaster />
</AtomsContext.Provider>
) : (
<>
{children}
<Toaster />
</>
<AtomsContext.Provider
value={{
clientId,
options,
error,
getClient: () => http,
isAuth: false,
isValidClient: Boolean(!error && clientId),
isInit: false,
isRefreshing: false,
...translations,
}}>
<>
<TooltipProvider>{children}</TooltipProvider>
<Toaster />
</>
</AtomsContext.Provider>
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/platform/atoms/hooks/useAtomsContext.ts
Expand Up @@ -25,7 +25,7 @@ export interface IAtomsContext {
i18n: {
language: string;
defaultLocale: string;
locales: [string];
locales: string[];
exists: (key: translationKeys | string) => boolean;
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/atoms/package.json
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"description": "Customizable UI components to integrate scheduling into your product.",
"authors": "Cal.com, Inc.",
"version": "1.0.30",
"version": "1.0.35",
"scripts": {
"dev": "yarn vite build --watch & npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify --watch",
"build": "yarn vite build && npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify",
Expand Down

0 comments on commit 8fbb1ed

Please sign in to comment.