feat: move to locale

This commit is contained in:
tresabhi committed 2024-12-27 12:38:38 -06:00
1 parent 60ab845326
commit 1843eb3bcf
44 files changed
+234 -223

No files matched your search

@@ -0,0 +1,61 @@
import { useEffect } from 'react';
import { App } from '../../../../stores/app';
export const AUTH_PROVIDERS = ['wargaming'] as const;
type AuthProvider = (typeof AUTH_PROVIDERS)[number];
export const AUTH_PROVIDER_NAMES: Record<AuthProvider, string> = {
wargaming: 'Wargaming',
};
interface AuthorizeProps {
provider: AuthProvider;
}
export function Authorize(props: AuthorizeProps) {
return (
<App.Provider>
<Content {...props} />
</App.Provider>
);
}
function Content({ provider }: AuthorizeProps) {
const mutateApp = App.useMutation();
useEffect(() => {
(async () => {
const searchParams = new URLSearchParams(window.location.search);
switch (provider) {
case 'wargaming': {
if (
!searchParams.has('expires_at') ||
!searchParams.has('access_token') ||
!searchParams.has('account_id')
) {
break;
}
mutateApp((draft) => {
draft.logins.wargaming = {
expires: Number(searchParams.get('expires_at')) * 1000,
token: searchParams.get('access_token')!,
id: Number(searchParams.get('account_id'))!,
};
});
break;
}
default:
throw new Error(`Unknown provider: ${provider}`);
}
window.location.href = searchParams.get('return') ?? '/';
})();
}, []);
return null;
}
@@ -0,0 +1,32 @@
---
import { Flex, Heading, Text } from '@radix-ui/themes';
import type { GetStaticPaths } from 'astro';
import { PageWrapper } from '../../../../components/PageWrapper';
import BaseLayout from '../../../layouts/BaseLayout.astro';
import { AUTH_PROVIDERS, AUTH_PROVIDER_NAMES, Authorize } from './_index';
export const getStaticPaths = (() => {
return AUTH_PROVIDERS.map((provider) => ({ params: { provider } }));
}) satisfies GetStaticPaths;
const { provider } = Astro.params;
---
<BaseLayout>
<PageWrapper>
<Flex
style={{ flex: 1 }}
align="center"
justify="center"
direction="column"
gap="2"
>
<Heading align="center"
>Authorizing you with {AUTH_PROVIDER_NAMES[provider]}...</Heading
>
<Text color="gray" align="center">You'll be on your way shortly.</Text>
</Flex>
</PageWrapper>
<Authorize client:only="react" {provider} />
</BaseLayout>