2024-11-14 18:50:58 +07:00
|
|
|
import { Text, ScrollView, Card, Separator, XStack } from "tamagui";
|
2024-11-10 18:49:18 +07:00
|
|
|
import React from "react";
|
|
|
|
import FormField from "@/components/ui/form";
|
|
|
|
import { InputField } from "@/components/ui/input";
|
|
|
|
import { useZForm } from "@/hooks/useZForm";
|
2024-11-14 18:50:58 +07:00
|
|
|
import { Link, router, Stack } from "expo-router";
|
2024-11-10 18:49:18 +07:00
|
|
|
import Button from "@/components/ui/button";
|
|
|
|
import ThemeSwitcher from "@/components/containers/theme-switcher";
|
2024-11-17 17:54:41 +07:00
|
|
|
import * as WebBrowser from "expo-web-browser";
|
2024-11-10 18:49:18 +07:00
|
|
|
import { ErrorAlert } from "@/components/ui/alert";
|
2024-11-14 18:50:58 +07:00
|
|
|
import { loginSchema } from "./schema";
|
2024-11-10 18:49:18 +07:00
|
|
|
import Icons from "@/components/ui/icons";
|
2024-11-12 19:15:13 +07:00
|
|
|
import tamaguiConfig from "@/tamagui.config";
|
2024-11-14 18:50:58 +07:00
|
|
|
import { useLoginMutation } from "./hooks";
|
2024-11-17 17:54:41 +07:00
|
|
|
import LoginGithubButton from "./components/login-github";
|
|
|
|
import { useServerConfig } from "@/hooks/useServerConfig";
|
2024-11-17 19:49:42 +07:00
|
|
|
import LoginGitlabButton from "./components/login-gitlab";
|
2024-11-17 17:54:41 +07:00
|
|
|
|
|
|
|
WebBrowser.maybeCompleteAuthSession();
|
2024-11-10 18:49:18 +07:00
|
|
|
|
|
|
|
export default function LoginPage() {
|
|
|
|
const form = useZForm(loginSchema);
|
2024-11-14 18:50:58 +07:00
|
|
|
const login = useLoginMutation();
|
2024-11-17 17:54:41 +07:00
|
|
|
const { data: oauthList } = useServerConfig("oauth");
|
2024-11-10 18:49:18 +07:00
|
|
|
|
|
|
|
const onSubmit = form.handleSubmit((values) => {
|
|
|
|
login.mutate(values);
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Stack.Screen
|
|
|
|
options={{
|
|
|
|
contentStyle: {
|
|
|
|
width: "100%",
|
2024-11-12 19:15:13 +07:00
|
|
|
maxWidth: tamaguiConfig.media.xs.maxWidth,
|
2024-11-10 18:49:18 +07:00
|
|
|
marginHorizontal: "auto",
|
|
|
|
},
|
|
|
|
title: "Login",
|
2024-11-12 17:17:10 +00:00
|
|
|
headerTitle: "",
|
2024-11-15 09:39:35 +00:00
|
|
|
headerRight: () => <ThemeSwitcher $gtSm={{ mr: "$3" }} />,
|
2024-11-10 18:49:18 +07:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ScrollView
|
|
|
|
contentContainerStyle={{
|
|
|
|
padding: "$4",
|
|
|
|
pb: "$12",
|
|
|
|
justifyContent: "center",
|
|
|
|
flexGrow: 1,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Card bordered p="$4" gap="$4">
|
2024-11-14 18:50:58 +07:00
|
|
|
<Text fontSize="$9" mt="$4">
|
|
|
|
Login
|
|
|
|
</Text>
|
2024-11-10 18:49:18 +07:00
|
|
|
|
|
|
|
<ErrorAlert error={login.error} />
|
|
|
|
|
|
|
|
<FormField vertical label="Username/Email">
|
2024-11-12 04:43:59 +07:00
|
|
|
<InputField
|
|
|
|
form={form}
|
|
|
|
name="username"
|
2024-11-15 04:08:37 +07:00
|
|
|
autoCapitalize="none"
|
2024-11-12 04:43:59 +07:00
|
|
|
onSubmitEditing={onSubmit}
|
2024-11-16 23:50:02 +07:00
|
|
|
autoFocus
|
2024-11-12 04:43:59 +07:00
|
|
|
/>
|
2024-11-10 18:49:18 +07:00
|
|
|
</FormField>
|
|
|
|
<FormField vertical label="Password">
|
2024-11-12 04:43:59 +07:00
|
|
|
<InputField
|
|
|
|
form={form}
|
|
|
|
name="password"
|
2024-11-15 04:08:37 +07:00
|
|
|
autoCapitalize="none"
|
2024-11-12 04:43:59 +07:00
|
|
|
secureTextEntry
|
|
|
|
onSubmitEditing={onSubmit}
|
|
|
|
/>
|
2024-11-10 18:49:18 +07:00
|
|
|
</FormField>
|
|
|
|
|
|
|
|
<Separator />
|
|
|
|
|
|
|
|
<Button
|
2024-11-14 18:50:58 +07:00
|
|
|
icon={<Icons name="login" size={16} />}
|
2024-11-10 18:49:18 +07:00
|
|
|
onPress={onSubmit}
|
|
|
|
isLoading={login.isPending}
|
|
|
|
>
|
2024-11-14 18:50:58 +07:00
|
|
|
Login
|
2024-11-10 18:49:18 +07:00
|
|
|
</Button>
|
|
|
|
|
2024-11-14 18:50:58 +07:00
|
|
|
<XStack justifyContent="space-between">
|
|
|
|
<Text textAlign="center" fontSize="$4">
|
|
|
|
Not registered yet?{" "}
|
|
|
|
<Link href="/auth/register" asChild>
|
|
|
|
<Text cursor="pointer" fontWeight="600">
|
|
|
|
Register Now.
|
|
|
|
</Text>
|
|
|
|
</Link>
|
|
|
|
</Text>
|
|
|
|
|
|
|
|
<Link href="/auth/reset-password" asChild>
|
|
|
|
<Text cursor="pointer" fontWeight="600" fontSize="$4">
|
|
|
|
Reset Password
|
|
|
|
</Text>
|
|
|
|
</Link>
|
|
|
|
</XStack>
|
|
|
|
|
2024-11-17 17:54:41 +07:00
|
|
|
{oauthList?.length > 0 && (
|
|
|
|
<>
|
|
|
|
<Text textAlign="center" fontSize="$3">
|
|
|
|
or
|
|
|
|
</Text>
|
|
|
|
|
|
|
|
{oauthList.includes("github") && <LoginGithubButton />}
|
2024-11-17 19:49:42 +07:00
|
|
|
{oauthList.includes("gitlab") && <LoginGitlabButton />}
|
2024-11-17 17:54:41 +07:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
2024-11-14 18:50:58 +07:00
|
|
|
<Separator w="100%" />
|
|
|
|
|
|
|
|
<Button
|
|
|
|
onPress={() => router.push("/server")}
|
|
|
|
bg="$colorTransparent"
|
|
|
|
icon={<Icons name="desktop-classic" size={16} />}
|
|
|
|
>
|
2024-11-10 18:49:18 +07:00
|
|
|
Change Server
|
|
|
|
</Button>
|
|
|
|
</Card>
|
|
|
|
</ScrollView>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|