Skip to content

Commit 02d771e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2c0afcb commit 02d771e

File tree

12 files changed

+363
-332
lines changed

12 files changed

+363
-332
lines changed

backend/api/serializers.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ class UserCreateSerializer(serializers.ModelSerializer):
8989

9090
class Meta:
9191
model = User
92-
fields = ["username", "email", "first_name", "last_name", "password", "password_retype"]
92+
fields = [
93+
"username",
94+
"email",
95+
"first_name",
96+
"last_name",
97+
"password",
98+
"password_retype",
99+
]
93100

94101
def validate(self, attrs):
95102
password_retype = attrs.pop("password_retype")
@@ -117,8 +124,12 @@ def create(self, validated_data):
117124
class UserCreateErrorSerializer(serializers.Serializer):
118125
username = serializers.ListSerializer(child=serializers.CharField(), required=False)
119126
email = serializers.ListSerializer(child=serializers.CharField(), required=False)
120-
first_name = serializers.ListSerializer(child=serializers.CharField(), required=False)
121-
last_name = serializers.ListSerializer(child=serializers.CharField(), required=False)
127+
first_name = serializers.ListSerializer(
128+
child=serializers.CharField(), required=False
129+
)
130+
last_name = serializers.ListSerializer(
131+
child=serializers.CharField(), required=False
132+
)
122133
password = serializers.ListSerializer(child=serializers.CharField(), required=False)
123134
password_retype = serializers.ListSerializer(
124135
child=serializers.CharField(), required=False
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ProfileForm } from "@/components/forms/profile-form";
2-
import type { Metadata } from "next";
1+
import { ProfileForm } from '@/components/forms/profile-form'
2+
import type { Metadata } from 'next'
33

44
export const metadata: Metadata = {
5-
title: "Profile - Turbo",
6-
};
5+
title: 'Profile - Turbo'
6+
}
77

88
export default function Profile() {
9-
return <ProfileForm />;
9+
return <ProfileForm />
1010
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { RegisterForm } from "@/components/forms/register-form";
2-
import type { Metadata } from "next";
1+
import { RegisterForm } from '@/components/forms/register-form'
2+
import type { Metadata } from 'next'
33

44
export const metadata: Metadata = {
5-
title: "Register - Turbo",
6-
};
5+
title: 'Register - Turbo'
6+
}
77

88
export default function Register() {
9-
return <RegisterForm />;
9+
return <RegisterForm />
1010
}

frontend/apps/web/app/layout.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
import { AuthProvider } from "@/providers/auth-provider";
2-
import { QueryProvider } from "@/providers/query-provider";
3-
import type { Metadata } from "next";
4-
import { Inter } from "next/font/google";
5-
import { twMerge } from "tailwind-merge";
1+
import { AuthProvider } from '@/providers/auth-provider'
2+
import { QueryProvider } from '@/providers/query-provider'
3+
import type { Metadata } from 'next'
4+
import { Inter } from 'next/font/google'
5+
import { twMerge } from 'tailwind-merge'
66

7-
import "@frontend/ui/styles/globals.css";
7+
import '@frontend/ui/styles/globals.css'
88

9-
const inter = Inter({ subsets: ["latin"] });
9+
const inter = Inter({ subsets: ['latin'] })
1010

1111
export const metadata: Metadata = {
12-
title: "Turbo - Django & Next.js Bootstrap Template",
13-
};
12+
title: 'Turbo - Django & Next.js Bootstrap Template'
13+
}
1414

1515
export default function RootLayout({
16-
children,
16+
children
1717
}: {
18-
children: React.ReactNode;
18+
children: React.ReactNode
1919
}) {
2020
return (
21-
<html lang='en'>
21+
<html lang="en">
2222
<body
2323
className={twMerge(
24-
"bg-gray-50 text-sm text-gray-700 antialiased",
24+
'bg-gray-50 text-sm text-gray-700 antialiased',
2525
inter.className
2626
)}
2727
>
2828
<QueryProvider>
2929
<AuthProvider>
30-
<div className='px-6'>
31-
<div className='container mx-auto my-12 max-w-6xl'>
30+
<div className="px-6">
31+
<div className="container mx-auto my-12 max-w-6xl">
3232
{children}
3333
</div>
3434
</div>
3535
</AuthProvider>
3636
</QueryProvider>
3737
</body>
3838
</html>
39-
);
39+
)
4040
}
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
1-
"use client";
1+
'use client'
22

3-
import { loginFormSchema } from "@/lib/validation";
4-
import { FormFooter } from "@frontend/ui/forms/form-footer";
5-
import { FormHeader } from "@frontend/ui/forms/form-header";
6-
import { SubmitField } from "@frontend/ui/forms/submit-field";
7-
import { TextField } from "@frontend/ui/forms/text-field";
8-
import { ErrorMessage } from "@frontend/ui/messages/error-message";
9-
import { zodResolver } from "@hookform/resolvers/zod";
10-
import { signIn } from "next-auth/react";
11-
import { useSearchParams } from "next/navigation";
12-
import { useForm } from "react-hook-form";
13-
import type { z } from "zod";
3+
import { loginFormSchema } from '@/lib/validation'
4+
import { FormFooter } from '@frontend/ui/forms/form-footer'
5+
import { FormHeader } from '@frontend/ui/forms/form-header'
6+
import { SubmitField } from '@frontend/ui/forms/submit-field'
7+
import { TextField } from '@frontend/ui/forms/text-field'
8+
import { ErrorMessage } from '@frontend/ui/messages/error-message'
9+
import { zodResolver } from '@hookform/resolvers/zod'
10+
import { signIn } from 'next-auth/react'
11+
import { useSearchParams } from 'next/navigation'
12+
import { useForm } from 'react-hook-form'
13+
import type { z } from 'zod'
1414

15-
type LoginFormSchema = z.infer<typeof loginFormSchema>;
15+
type LoginFormSchema = z.infer<typeof loginFormSchema>
1616

1717
export function LoginForm() {
18-
const search = useSearchParams();
18+
const search = useSearchParams()
1919

2020
const { register, handleSubmit, formState } = useForm<LoginFormSchema>({
21-
resolver: zodResolver(loginFormSchema),
22-
});
21+
resolver: zodResolver(loginFormSchema)
22+
})
2323

2424
const onSubmitHandler = handleSubmit((data) => {
25-
signIn("credentials", {
25+
signIn('credentials', {
2626
username: data.username,
2727
password: data.password,
28-
callbackUrl: "/",
29-
});
30-
});
28+
callbackUrl: '/'
29+
})
30+
})
3131

3232
return (
3333
<>
3434
<FormHeader
35-
title='Welcome back to Turbo'
36-
description='Get an access to internal application'
35+
title="Welcome back to Turbo"
36+
description="Get an access to internal application"
3737
/>
3838

39-
{search.has("error") && search.get("error") === "CredentialsSignin" && (
39+
{search.has('error') && search.get('error') === 'CredentialsSignin' && (
4040
<ErrorMessage>Provided account does not exists.</ErrorMessage>
4141
)}
4242

4343
<form
44-
method='post'
45-
action='/api/auth/callback/credentials'
44+
method="post"
45+
action="/api/auth/callback/credentials"
4646
onSubmit={onSubmitHandler}
4747
>
4848
<TextField
49-
type='text'
50-
register={register("username")}
49+
type="text"
50+
register={register('username')}
5151
formState={formState}
52-
label='Username'
53-
placeholder='Enter your username'
52+
label="Username"
53+
placeholder="Enter your username"
5454
/>
5555

5656
<TextField
57-
type='password'
58-
register={register("password", { required: true })}
57+
type="password"
58+
register={register('password', { required: true })}
5959
formState={formState}
60-
label='Password'
61-
placeholder='Enter your password'
60+
label="Password"
61+
placeholder="Enter your password"
6262
/>
6363

6464
<SubmitField>Sign in</SubmitField>
6565
</form>
6666

6767
<FormFooter
6868
cta="Don't have an account?"
69-
link='/register'
70-
title='Sign up'
69+
link="/register"
70+
title="Sign up"
7171
/>
7272
</>
73-
);
73+
)
7474
}
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
1-
"use client";
1+
'use client'
22

3-
import { useCurrentUser, usePartialUpdateUser } from "@/lib/hooks/useAuth";
4-
import { fieldApiError } from "@/lib/forms";
5-
import { profileFormSchema } from "@/lib/validation";
6-
import { ApiError } from "@/lib/api-client";
7-
import { FormHeader } from "@frontend/ui/forms/form-header";
8-
import { SubmitField } from "@frontend/ui/forms/submit-field";
9-
import { TextField } from "@frontend/ui/forms/text-field";
10-
import { SuccessMessage } from "@frontend/ui/messages/success-message";
11-
import { zodResolver } from "@hookform/resolvers/zod";
12-
import React, { useState } from "react";
13-
import { useForm } from "react-hook-form";
14-
import type { z } from "zod";
3+
import { ApiError } from '@/lib/api-client'
4+
import { fieldApiError } from '@/lib/forms'
5+
import { useCurrentUser, usePartialUpdateUser } from '@/lib/hooks/useAuth'
6+
import { profileFormSchema } from '@/lib/validation'
7+
import { FormHeader } from '@frontend/ui/forms/form-header'
8+
import { SubmitField } from '@frontend/ui/forms/submit-field'
9+
import { TextField } from '@frontend/ui/forms/text-field'
10+
import { SuccessMessage } from '@frontend/ui/messages/success-message'
11+
import { zodResolver } from '@hookform/resolvers/zod'
12+
import React, { useState } from 'react'
13+
import { useForm } from 'react-hook-form'
14+
import type { z } from 'zod'
1515

16-
export type ProfileFormSchema = z.infer<typeof profileFormSchema>;
16+
export type ProfileFormSchema = z.infer<typeof profileFormSchema>
1717

1818
export function ProfileForm() {
19-
const [success, setSuccess] = useState<boolean>(false);
20-
const { data: currentUser, isLoading: userLoading } = useCurrentUser();
21-
const updateUserMutation = usePartialUpdateUser();
19+
const [success, setSuccess] = useState<boolean>(false)
20+
const { data: currentUser, isLoading: userLoading } = useCurrentUser()
21+
const updateUserMutation = usePartialUpdateUser()
2222

2323
const { formState, handleSubmit, register, setError, reset } =
2424
useForm<ProfileFormSchema>({
2525
resolver: zodResolver(profileFormSchema),
2626
defaultValues: {
27-
firstName: currentUser?.first_name || "",
28-
lastName: currentUser?.last_name || "",
29-
},
30-
});
27+
firstName: currentUser?.first_name || '',
28+
lastName: currentUser?.last_name || ''
29+
}
30+
})
3131

3232
// 当用户数据加载完成后,重置表单
3333
React.useEffect(() => {
3434
if (currentUser) {
3535
reset({
36-
firstName: currentUser.first_name || "",
37-
lastName: currentUser.last_name || "",
38-
});
36+
firstName: currentUser.first_name || '',
37+
lastName: currentUser.last_name || ''
38+
})
3939
}
40-
}, [currentUser, reset]);
40+
}, [currentUser, reset])
4141

4242
if (userLoading) {
43-
return <div>Loading...</div>;
43+
return <div>Loading...</div>
4444
}
4545

4646
return (
4747
<>
4848
<FormHeader
49-
title='Update you profile information'
50-
description='Change your account data'
49+
title="Update you profile information"
50+
description="Change your account data"
5151
/>
5252

5353
<form
5454
onSubmit={handleSubmit(async (data) => {
5555
try {
5656
await updateUserMutation.mutateAsync({
5757
first_name: data.firstName,
58-
last_name: data.lastName,
59-
});
58+
last_name: data.lastName
59+
})
6060

61-
setSuccess(true);
61+
setSuccess(true)
6262
} catch (error: any) {
63-
setSuccess(false);
63+
setSuccess(false)
6464

6565
if (error instanceof ApiError && error.data) {
66-
const errorData = error.data;
67-
fieldApiError("first_name", "firstName", errorData, setError);
68-
fieldApiError("last_name", "lastName", errorData, setError);
66+
const errorData = error.data
67+
fieldApiError('first_name', 'firstName', errorData, setError)
68+
fieldApiError('last_name', 'lastName', errorData, setError)
6969
}
7070
}
7171
})}
@@ -75,23 +75,23 @@ export function ProfileForm() {
7575
)}
7676

7777
<TextField
78-
type='text'
79-
register={register("firstName")}
80-
label='First name'
78+
type="text"
79+
register={register('firstName')}
80+
label="First name"
8181
formState={formState}
8282
/>
8383

8484
<TextField
85-
type='text'
86-
register={register("lastName")}
87-
label='Last name'
85+
type="text"
86+
register={register('lastName')}
87+
label="Last name"
8888
formState={formState}
8989
/>
9090

9191
<SubmitField disabled={updateUserMutation.isPending}>
92-
{updateUserMutation.isPending ? "Updating..." : "Update profile"}
92+
{updateUserMutation.isPending ? 'Updating...' : 'Update profile'}
9393
</SubmitField>
9494
</form>
9595
</>
96-
);
96+
)
9797
}

0 commit comments

Comments
 (0)