Skip to content

Commit a04d073

Browse files
committed
fix login loding
1 parent ccfdd32 commit a04d073

1 file changed

Lines changed: 53 additions & 10 deletions

File tree

src/components/shared/sidebar/LoginMenuModule.tsx

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default function LoginMenuModule({ isClosed, tabsMenu, params }: any) {
1111
const [dropDown, setDropDown] = useState(false);
1212
const [cookies, setCookie, removeCookie] = useCookies(["auth"]);
1313
const [isMounted, setIsMounted] = useState(false);
14+
const [isLoading, setIsLoading] = useState(false);
1415
const [loggedInUserData, setLoggedInUserData] = useState({
1516
token: "",
1617
code: "",
@@ -118,6 +119,9 @@ export default function LoginMenuModule({ isClosed, tabsMenu, params }: any) {
118119
}, [isMounted, cookies.auth]);
119120

120121
const handleLogin = async () => {
122+
if (isLoading) return;
123+
124+
setIsLoading(true);
121125
const token = parsAuthCookieByName("token");
122126
if (token) {
123127
// console.log("[ALREADY LOGGED IN]");
@@ -176,6 +180,7 @@ export default function LoginMenuModule({ isClosed, tabsMenu, params }: any) {
176180
}
177181
} catch (err) {
178182
// console.error("[LOGIN/REGISTER ERROR]", err);
183+
setIsLoading(false);
179184
}
180185
};
181186

@@ -308,17 +313,55 @@ export default function LoginMenuModule({ isClosed, tabsMenu, params }: any) {
308313
</div>
309314
) : (
310315
<button
311-
className={`${isClosed ? "justify-center" : "justify-center"
312-
} w-full bg-blueLink cursor-pointer dark:bg-dark-yellow rounded-[15px]
313-
h-[40px] flex flex-row xs:px-2 px-4 gap-5 items-center
314-
text-white dark:text-dark-background font-azarMehr font-medium text-center text-[15px] m-auto`}
315-
onClick={handleLogin}
316+
disabled={isLoading}
317+
onClick={handleLogin}
318+
className={`
319+
w-full
320+
rounded-[15px]
321+
h-[40px]
322+
flex
323+
items-center
324+
justify-center
325+
px-4
326+
bg-blueLink
327+
dark:bg-dark-yellow
328+
text-white
329+
dark:text-dark-background
330+
font-azarMehr
331+
font-medium
332+
text-[15px]
333+
transition-all
334+
${
335+
isLoading
336+
? "opacity-60 cursor-not-allowed pointer-events-none"
337+
: "cursor-pointer"
338+
}
339+
`}
316340
>
317-
{localFind("login") == ""
318-
? ""
319-
: params.lang == "fa"
320-
? "ورود"
321-
: "Login"}
341+
{isLoading ? (
342+
<svg
343+
className="h-5 w-5 animate-spin"
344+
viewBox="0 0 24 24"
345+
fill="none"
346+
>
347+
<circle
348+
cx="12"
349+
cy="12"
350+
r="10"
351+
stroke="currentColor"
352+
strokeWidth="3"
353+
opacity=".2"
354+
/>
355+
<path
356+
d="M22 12a10 10 0 0 1-10 10"
357+
stroke="currentColor"
358+
strokeWidth="3"
359+
strokeLinecap="round"
360+
/>
361+
</svg>
362+
) : (
363+
params.lang === "fa" ? "ورود" : "Login"
364+
)}
322365
</button>
323366
)}
324367
</>

0 commit comments

Comments
 (0)