Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor login form #1049

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/[channel]/(main)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Suspense } from "react";
import { Loader } from "@/ui/atoms/Loader";
import { LoginForm } from "@/ui/components/LoginForm";
import { LoginForm } from "@ui/components/LoginForm";
import { Loader } from "@ui/atoms/Loader";

export default function LoginPage() {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/app/[channel]/(main)/orders/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LoginForm } from "@ui/components/LoginForm";
import { CurrentUserOrderListDocument } from "@/gql/graphql";
import { executeGraphQL } from "@/lib/graphql";
import { LoginForm } from "@/ui/components/LoginForm";
import { OrderListItem } from "@/ui/components/OrderListItem";

export default async function OrderPage() {
Expand Down
1 change: 0 additions & 1 deletion src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
import { saleorAuthClient } from "@/app/config";

export async function logout() {
"use server";
saleorAuthClient.signOut();
}
16 changes: 16 additions & 0 deletions src/ui/atoms/LoginButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use client";

import { useFormStatus } from "react-dom";

export const LoginButton = () => {
const { pending } = useFormStatus();
return (
<button
className="mt-2 rounded bg-neutral-800 px-4 py-2 text-neutral-200 hover:bg-neutral-700 aria-disabled:opacity-80"
type="submit"
aria-disabled={pending}
>
{pending ? "Processing..." : "Log In"}
</button>
);
};
30 changes: 11 additions & 19 deletions src/ui/components/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { LoginButton } from "@ui/atoms/LoginButton";
import { saleorAuthClient } from "@/app/config";

export async function LoginForm() {
return (
<div className="mx-auto mt-16 w-full max-w-lg">
<form
className="rounded border p-8 shadow-md"
className="flex flex-col gap-y-2 rounded border p-8 shadow-md"
action={async (formData) => {
"use server";

Expand All @@ -23,39 +24,30 @@ export async function LoginForm() {
}
}}
>
<div className="mb-2">
<label className="sr-only" htmlFor="email">
Email
</label>
<label>
<span className="sr-only">Email</span>
<input
type="email"
name="email"
placeholder="Email"
className="w-full rounded border bg-neutral-50 px-4 py-2"
required
/>
</div>
<div className="mb-4">
<label className="sr-only" htmlFor="password">
Password
</label>
</label>
<label>
<span className="sr-only">Password</span>
<input
type="password"
name="password"
placeholder="Password"
autoCapitalize="off"
autoComplete="off"
className="w-full rounded border bg-neutral-50 px-4 py-2"
required
/>
</div>

<button
className="rounded bg-neutral-800 px-4 py-2 text-neutral-200 hover:bg-neutral-700"
type="submit"
>
Log In
</button>
</label>
<LoginButton />
</form>
<div></div>
</div>
);
}
4 changes: 2 additions & 2 deletions src/ui/components/nav/components/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ export function UserMenu({ user }: Props) {
<div className="flex flex-col px-1 py-1">
<Menu.Item>
{({ active }) => (
<form action={logout}>
<form action={logout} className="flex flex-col">
<button
type="submit"
className={clsx(
active && "bg-neutral-100",
"block px-4 py-2 text-start text-sm font-medium text-neutral-500 hover:text-neutral-700",
"px-4 py-2 text-start text-sm font-medium text-neutral-500 hover:text-neutral-700",
)}
>
Log Out
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"paths": {
"@/*": ["./src/*"],
"@ui/*": ["./src/components/*"]
"@ui/*": ["./src/ui/*"]
},
"types": ["react-dom/canary"]
},
Expand Down