mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-17 10:11:03 +10:00
cleanups
This commit is contained in:
@ -29,7 +29,9 @@ export function InviteSignUpForm() {
|
||||
const params = useParams();
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const { data: invitation } = useGetInvitationQuery(params?.invitationId);
|
||||
const { data: invitation, isError } = useGetInvitationQuery(
|
||||
params?.invitationId,
|
||||
);
|
||||
const { invitationSignup, isLoading } = useAuth();
|
||||
useRedirectIfAuthenticated();
|
||||
|
||||
@ -52,6 +54,10 @@ export function InviteSignUpForm() {
|
||||
});
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return <div>invalid invitation link</div>;
|
||||
}
|
||||
|
||||
if (!invitation) {
|
||||
return <div></div>;
|
||||
}
|
||||
|
||||
@ -71,13 +71,6 @@ export function LoginForm() {
|
||||
Sign In
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<Text c="dimmed" size="sm" ta="center" mt="sm">
|
||||
Don't have an account yet?{" "}
|
||||
<Anchor size="sm" component={Link} to="/signup">
|
||||
Create account
|
||||
</Anchor>
|
||||
</Text>
|
||||
</Box>
|
||||
</Container>
|
||||
);
|
||||
|
||||
@ -1,83 +0,0 @@
|
||||
import * as React from "react";
|
||||
import * as z from "zod";
|
||||
|
||||
import { useForm, zodResolver } from "@mantine/form";
|
||||
import {
|
||||
Container,
|
||||
Title,
|
||||
Anchor,
|
||||
TextInput,
|
||||
Button,
|
||||
Text,
|
||||
PasswordInput,
|
||||
Box,
|
||||
} from "@mantine/core";
|
||||
import { Link } from "react-router-dom";
|
||||
import { IRegister } from "@/features/auth/types/auth.types";
|
||||
import useAuth from "@/features/auth/hooks/use-auth";
|
||||
import classes from "@/features/auth/components/auth.module.css";
|
||||
import { useRedirectIfAuthenticated } from "@/features/auth/hooks/use-redirect-if-authenticated.ts";
|
||||
|
||||
const formSchema = z.object({
|
||||
email: z
|
||||
.string()
|
||||
.min(1, { message: "email is required" })
|
||||
.email({ message: "Invalid email address" }),
|
||||
password: z.string().min(1, { message: "Password is required" }),
|
||||
});
|
||||
|
||||
export function SignUpForm() {
|
||||
const { signUp, isLoading } = useAuth();
|
||||
useRedirectIfAuthenticated();
|
||||
|
||||
const form = useForm<IRegister>({
|
||||
validate: zodResolver(formSchema),
|
||||
initialValues: {
|
||||
email: "",
|
||||
password: "",
|
||||
},
|
||||
});
|
||||
|
||||
async function onSubmit(data: IRegister) {
|
||||
await signUp(data);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container size={420} my={40} className={classes.container}>
|
||||
<Box p="xl" mt={200}>
|
||||
<Title order={2} ta="center" fw={500} mb="md">
|
||||
Create an account
|
||||
</Title>
|
||||
|
||||
<form onSubmit={form.onSubmit(onSubmit)}>
|
||||
<TextInput
|
||||
id="email"
|
||||
type="email"
|
||||
label="Email"
|
||||
placeholder="email@example.com"
|
||||
variant="filled"
|
||||
{...form.getInputProps("email")}
|
||||
/>
|
||||
|
||||
<PasswordInput
|
||||
label="Password"
|
||||
placeholder="Your password"
|
||||
variant="filled"
|
||||
mt="md"
|
||||
{...form.getInputProps("password")}
|
||||
/>
|
||||
<Button type="submit" fullWidth mt="xl" loading={isLoading}>
|
||||
Sign Up
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<Text c="dimmed" size="sm" ta="center" mt="sm">
|
||||
Already have an account?{" "}
|
||||
<Anchor size="sm" component={Link} to="/login">
|
||||
Login
|
||||
</Anchor>
|
||||
</Text>
|
||||
</Box>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@ -1,9 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import {
|
||||
login,
|
||||
register,
|
||||
setupWorkspace,
|
||||
} from "@/features/auth/services/auth-service";
|
||||
import { login, setupWorkspace } from "@/features/auth/services/auth-service";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useAtom } from "jotai";
|
||||
import { authTokensAtom } from "@/features/auth/atoms/auth-tokens-atom";
|
||||
@ -46,25 +42,6 @@ export default function useAuth() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSignUp = async (data: IRegister) => {
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
const res = await register(data);
|
||||
setIsLoading(false);
|
||||
|
||||
setAuthToken(res.tokens);
|
||||
|
||||
navigate(APP_ROUTE.HOME);
|
||||
} catch (err) {
|
||||
setIsLoading(false);
|
||||
notifications.show({
|
||||
message: err.response?.data.message,
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleInvitationSignUp = async (data: IAcceptInvite) => {
|
||||
setIsLoading(true);
|
||||
|
||||
@ -135,7 +112,6 @@ export default function useAuth() {
|
||||
|
||||
return {
|
||||
signIn: handleSignIn,
|
||||
signUp: handleSignUp,
|
||||
invitationSignup: handleInvitationSignUp,
|
||||
setupWorkspace: handleSetupWorkspace,
|
||||
isAuthenticated: handleIsAuthenticated,
|
||||
|
||||
@ -12,10 +12,11 @@ export async function login(data: ILogin): Promise<ITokenResponse> {
|
||||
return req.data;
|
||||
}
|
||||
|
||||
/*
|
||||
export async function register(data: IRegister): Promise<ITokenResponse> {
|
||||
const req = await api.post<ITokenResponse>("/auth/register", data);
|
||||
return req.data;
|
||||
}
|
||||
}*/
|
||||
|
||||
export async function changePassword(
|
||||
data: IChangePassword,
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import api from "@/lib/api-client";
|
||||
import { ICurrentUser, IUser } from "@/features/user/types/user.types";
|
||||
import { IAttachment } from "@/lib/types.ts";
|
||||
|
||||
export async function getMyInfo(): Promise<ICurrentUser> {
|
||||
const req = await api.post<ICurrentUser>("/users/me");
|
||||
@ -22,6 +21,5 @@ export async function uploadAvatar(file: File): Promise<any> {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
});
|
||||
console.log(req);
|
||||
return req;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user