Skip to content

Commit 9a87693

Browse files
authored
Loading state for auth (#104)
1 parent 723724c commit 9a87693

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/modules/account/components/login/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { medusaClient } from "@lib/config"
22
import { LOGIN_VIEW, useAccount } from "@lib/context/account-context"
33
import Button from "@modules/common/components/button"
44
import Input from "@modules/common/components/input"
5+
import Spinner from "@modules/common/icons/spinner"
56
import { useRouter } from "next/router"
67
import { useState } from "react"
78
import { FieldValues, useForm } from "react-hook-form"
@@ -24,11 +25,11 @@ const Login = () => {
2425
const {
2526
register,
2627
handleSubmit,
27-
formState: { errors },
28+
formState: { errors, isSubmitting },
2829
} = useForm<SignInCredentials>()
2930

3031
const onSubmit = handleSubmit(async (credentials) => {
31-
medusaClient.auth
32+
await medusaClient.auth
3233
.authenticate(credentials)
3334
.then(() => {
3435
refetchCustomer()
@@ -39,6 +40,11 @@ const Login = () => {
3940

4041
return (
4142
<div className="max-w-sm w-full flex flex-col items-center">
43+
{isSubmitting && (
44+
<div className="z-10 fixed inset-0 bg-white bg-opacity-50 flex items-center justify-center">
45+
<Spinner size={24} />
46+
</div>
47+
)}
4248
<h1 className="text-large-semi uppercase mb-6">Welcome back</h1>
4349
<p className="text-center text-base-regular text-gray-700 mb-8">
4450
Sign in to access an enhanced shopping experience.

src/modules/account/components/register/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { medusaClient } from "@lib/config"
22
import { LOGIN_VIEW, useAccount } from "@lib/context/account-context"
33
import Button from "@modules/common/components/button"
44
import Input from "@modules/common/components/input"
5+
import Spinner from "@modules/common/icons/spinner"
56
import Link from "next/link"
67
import { useRouter } from "next/router"
78
import { useState } from "react"
@@ -28,11 +29,11 @@ const Register = () => {
2829
const {
2930
register,
3031
handleSubmit,
31-
formState: { errors },
32+
formState: { errors, isSubmitting },
3233
} = useForm<RegisterCredentials>()
3334

3435
const onSubmit = handleSubmit(async (credentials) => {
35-
medusaClient.customers
36+
await medusaClient.customers
3637
.create(credentials)
3738
.then(() => {
3839
refetchCustomer()
@@ -43,6 +44,11 @@ const Register = () => {
4344

4445
return (
4546
<div className="max-w-sm flex flex-col items-center mt-12">
47+
{isSubmitting && (
48+
<div className="z-10 fixed inset-0 bg-white bg-opacity-50 flex items-center justify-center">
49+
<Spinner size={24} />
50+
</div>
51+
)}
4652
<h1 className="text-large-semi uppercase mb-6">Become a Acme Member</h1>
4753
<p className="text-center text-base-regular text-gray-700 mb-4">
4854
Create your Acme Member profile, and get access to an enhanced shopping

0 commit comments

Comments
 (0)