Skip to content

Commit b710170

Browse files
committed
🌟 disabled btn when stusLogin be invalid
1 parent 1bf2206 commit b710170

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

src/components/Form/Buttons/Buttons.module.scss

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@
3030

3131
outline: none;
3232

33-
a {
34-
color: var(--grayDarkPrimary90opacity);
35-
text-decoration: none;
36-
font-weight: 600;
37-
font-family: Poppins;
38-
width: 100%;
39-
height: 100%;
40-
padding: 8px;
41-
42-
cursor: default;
43-
user-select: none;
44-
pointer-events: none;
33+
color: var(--grayDarkPrimary90opacity);
34+
text-decoration: none;
35+
font-weight: 600;
36+
font-family: Poppins;
37+
width: 100%;
38+
height: 100%;
39+
padding: 8px;
40+
41+
cursor: default;
42+
user-select: none;
43+
pointer-events: none;
44+
4545

46-
}
4746

4847
&.active {
4948
background-color: var(--yellowPrimary);

src/components/Form/Buttons/Buttons.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Link from "next/link"
22
import { useEffect, useRef, useState } from "react"
33
import styles from "./Buttons.module.scss"
44

5-
function Buttons({ statusLogin }) {
5+
function Buttons({ statusLogin, typeForm, setTypeForm }) {
66

77
const c_btn = useRef<any>(null)
88

@@ -11,22 +11,31 @@ function Buttons({ statusLogin }) {
1111

1212
const [hrefLinkByStateLogin, setHrefLinkByStateLogin] = useState<string>('/')
1313

14+
1415
useEffect(() => {
1516
changeBtn()
1617
verifyLoginStateByPathname()
1718
})
1819

20+
console.log(typeForm)
1921

2022
function verifyLoginStateByPathname() {
2123
const pathname = window.location.pathname
2224
if (pathname == '/signUp') {
2325
c_btn_span.current.innerText = 'Create now'
2426
c_btn_create_span.current.innerText = 'Login here'
2527
setHrefLinkByStateLogin('/')
28+
setTypeForm('signUp')
2629
} else {
2730
c_btn_span.current.innerText = 'Login'
2831
c_btn_create_span.current.innerText = 'Create your account here'
2932
setHrefLinkByStateLogin('/signUp')
33+
setTypeForm('/signIn')
34+
35+
if (statusLogin) {
36+
} else {
37+
c_btn.current.disable
38+
}
3039
}
3140
}
3241

@@ -40,11 +49,14 @@ function Buttons({ statusLogin }) {
4049

4150
return (
4251
<div className={styles.c_buttons}>
43-
<button className={`${styles.c_btn}`} ref={c_btn}>
44-
<Link href={'/logged'}>
45-
<span ref={c_btn_span} />
46-
</Link>
52+
53+
<button
54+
ref={c_btn}
55+
className={`${styles.c_btn}`}
56+
disabled={!statusLogin}>
57+
<span ref={c_btn_span} />
4758
</button>
59+
4860
<button className={styles.c_btn_create}>
4961
<span>
5062
<Link href={hrefLinkByStateLogin}>

src/components/Form/Form.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ function Form({ state }) {
1111
const [statusLogin, setStatusLogin] = useState<Boolean>(false)
1212
const [path, setPath] = useState<String>('/')
1313

14-
function verifyIfCanSubmit(e){
15-
if(statusLogin){
16-
setPath('/logged')
17-
}
18-
else {
19-
setPath('/')
14+
const [typeForm, setTypeForm] = useState<String>('/')
15+
16+
console.log(typeForm)
17+
18+
function verifyIfCanSubmit(e) {
19+
// se dados estiverem ok
20+
if (statusLogin) {
21+
console.log('ok')
22+
if (typeForm == 'signUp') {
23+
// se o formulario for do tipo cadastro, va para o login
24+
setPath('/')
25+
} else {
26+
// se o formulario for do tipo login, va para home
27+
setPath('/logged')
28+
}
29+
} else {
30+
console.log('Not yet')
2031
e.preventDefault()
2132
}
2233
}
@@ -29,7 +40,7 @@ function Form({ state }) {
2940
<SignIn setStatusLogin={setStatusLogin} />
3041
:
3142
<SignUp setStatusLogin={setStatusLogin} />}
32-
<Buttons statusLogin={statusLogin} />
43+
<Buttons statusLogin={statusLogin} typeForm={typeForm} setTypeForm={setTypeForm} />
3344
<Footer />
3445
</form>
3546
)

0 commit comments

Comments
 (0)