Skip to content

Commit c022841

Browse files
authored
Merge pull request #72 from leonardoOluz/favorite
façanha: adicionar o fluxo de trabalho do GitHub Actions para compila…
2 parents 952abe9 + 86404e8 commit c022841

32 files changed

Lines changed: 490 additions & 235 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build on Push
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
- name: Set up Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: '20'
18+
- name: Install dependencies
19+
run: npm install
20+
- name: Build project
21+
run: npm run build

src/components/RequireAuth/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import useCheckLogin from "@/hooks/useCheckLogin";
1+
import useCheckRotas from "@/hooks/useCheckRotas";
22
import { Outlet } from "react-router-dom";
33

44
const RequireAuth = () => {
5-
useCheckLogin();
5+
useCheckRotas();
66
return <Outlet />;
77
};
88

src/hooks/useCheckAddress.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { RootState } from "@/types/store";
2+
import { showWrongToast } from "@/utils/showWrongToast";
23
import { useEffect, useRef } from "react";
34
import { useSelector } from "react-redux";
45
import { useNavigate } from "react-router-dom";
5-
import { toast } from "react-toastify";
66

77
const useCheckAddress = () => {
88
const { addressChecked } = useSelector((state: RootState) => state.address);
@@ -12,11 +12,7 @@ const useCheckAddress = () => {
1212
useEffect(() => {
1313
if (!addressChecked && !toastShown.current) {
1414
toastShown.current = true;
15-
toast.error("Você precisa informar o endereço para continuar", {
16-
hideProgressBar: true,
17-
autoClose: 2500,
18-
theme: "colored",
19-
});
15+
showWrongToast("Você precisa informar o endereço para continuar");
2016
navigate("/checkout/address");
2117
}
2218
}, [addressChecked, navigate]);

src/hooks/useCheckLogin.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
11
import { AppDispatch } from "@/store";
2-
import { isCheckLogin } from "@/store/reducers/usuario";
3-
import { CheckoutSteps, RootState } from "@/types/store";
2+
import { checkAuthenticatedUser } from "@/store/reducers/usuario";
3+
import { RootState } from "@/types/store";
44
import { useEffect } from "react";
55
import { useSelector } from "react-redux";
66
import { useDispatch } from "react-redux";
7-
import { useLocation, useNavigate } from "react-router-dom";
7+
import { useNavigate } from "react-router-dom";
88

99
const useCheckLogin = () => {
1010
const isLogado = useSelector((state: RootState) => state.usuario).isLogado;
1111
const dispatch = useDispatch<AppDispatch>();
1212
const navigate = useNavigate();
13-
const location = useLocation();
1413

1514
useEffect(() => {
1615
if (!isLogado) {
17-
dispatch(isCheckLogin());
16+
dispatch(checkAuthenticatedUser());
1817
}
19-
}, [dispatch, isLogado]);
20-
21-
useEffect(() => {
22-
const privatePrefixes = [
23-
`/${CheckoutSteps.CHECKOUT}`,
24-
`/${CheckoutSteps.PEDIDOS}`,
25-
`/${CheckoutSteps.FAVORITOS}`,
26-
];
27-
if (
28-
!isLogado &&
29-
privatePrefixes.some((prefix) => location.pathname.startsWith(prefix))
30-
) {
31-
navigate("/login");
32-
}
33-
}, [isLogado, navigate, location.pathname]);
18+
}, [dispatch, isLogado, navigate]);
3419
};
3520

3621
export default useCheckLogin;

src/hooks/useCheckRotas.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { AppDispatch } from "@/store";
2+
import { checkAuthenticatedUser } from "@/store/reducers/usuario";
3+
import { CheckoutSteps, RootState } from "@/types/store";
4+
import { useEffect } from "react";
5+
import { useSelector } from "react-redux";
6+
import { useDispatch } from "react-redux";
7+
import { useLocation, useNavigate } from "react-router-dom";
8+
9+
const useCheckRotas = () => {
10+
const isLogado = useSelector((state: RootState) => state.usuario).isLogado;
11+
const dispatch = useDispatch<AppDispatch>();
12+
const navigate = useNavigate();
13+
const location = useLocation();
14+
15+
useEffect(() => {
16+
if (!isLogado) {
17+
navigate("/login");
18+
}
19+
}, [dispatch, isLogado , navigate]);
20+
21+
useEffect(() => {
22+
const privatePrefixes = [
23+
`/${CheckoutSteps.CHECKOUT}`,
24+
`/${CheckoutSteps.PEDIDOS}`,
25+
`/${CheckoutSteps.FAVORITOS}`,
26+
];
27+
if (
28+
privatePrefixes.some((prefix) => location.pathname.startsWith(prefix))
29+
) {
30+
dispatch(checkAuthenticatedUser());
31+
}
32+
}, [isLogado, navigate, location.pathname , dispatch]);
33+
};
34+
35+
export default useCheckRotas;

src/hooks/usePaymentConfirmed.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import { RootState } from "@/types/store";
2-
import { useEffect } from "react";
2+
import { showWrongToast } from "@/utils/showWrongToast";
3+
import { useEffect, useRef } from "react";
34
import { useSelector } from "react-redux";
45
import { useNavigate } from "react-router-dom";
5-
import { toast } from "react-toastify";
66

77
const usePaymentConfirmed = () => {
88
const { checkedPay } = useSelector((state: RootState) => state.pay);
99
const navigate = useNavigate();
10+
const toastShown = useRef(false);
1011

1112
// Redireciona e mostra toast conforme status do pagamento
1213
useEffect(() => {
1314
if (checkedPay) {
1415
navigate("/checkout/address/pay/summary");
1516
} else {
16-
if (!toast.isActive("pay-toast")) {
17-
toast.error("Verifique seu pagamento! ", {
18-
toastId: "pay-toast",
19-
hideProgressBar: true,
20-
autoClose: 2500,
21-
theme: "colored",
22-
});
17+
if (!toastShown.current) {
18+
toastShown.current = true;
19+
showWrongToast("Você precisa confirmar o pagamento para continuar");
2320
}
2421
navigate("/checkout/address/pay");
2522
}

src/main.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StrictMode } from "react";
1+
// import { StrictMode } from "react";
22
import { createRoot } from "react-dom/client";
33
import "normalize.css";
44
import "./index.css";
@@ -11,12 +11,12 @@ import { RouterProvider } from "react-router-dom";
1111
import { ToastContainer } from "react-toastify";
1212

1313
createRoot(document.getElementById("root")!).render(
14-
<StrictMode>
14+
// <StrictMode>
1515
<Provider store={store}>
1616
<ThemeProvider theme={thema}>
1717
<RouterProvider router={router} />
1818
<ToastContainer position="top-center"/>
1919
</ThemeProvider>
2020
</Provider>
21-
</StrictMode>
21+
// </StrictMode>
2222
);

src/pages/cadastro/FormRegister/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import Botao from "@/components/Botao";
22
import FieldInput from "@/components/FieldInput";
33
import Form from "@/components/Form";
44
import { MessageError } from "@/components/MessageError";
5-
import { createUser } from "@/store/reducers/usuario";
5+
import { AppDispatch } from "@/store";
6+
import { addNewUser } from "@/store/reducers/usuario";
67
import { ContainerForm, FieldsetForm, LegendForm } from "@/styles/forms";
78
import { RootState } from "@/types/store";
89
import { Usuario } from "@/types/usuarios";
9-
import { getStorage } from "@/utils/starage";
1010
import { useEffect } from "react";
1111
import { useForm } from "react-hook-form";
1212
import { useDispatch, useSelector } from "react-redux";
@@ -31,22 +31,19 @@ const FormRegister = () => {
3131
const user = useSelector((state: RootState) => state.usuario);
3232
const cart = useSelector((state: RootState) => state.carrinho);
3333
const navigate = useNavigate();
34-
const dispatch = useDispatch();
34+
const dispatch = useDispatch<AppDispatch>();
3535
const password = watch("password");
3636

3737
const checkPassword = {
3838
minLength: (val: string | undefined) =>
39-
(val?.length ?? 0) >= 6 || "O campo senha deve ter pelo menos 6 caracteres",
40-
checkEmpty: (val: string | undefined) => !!val || "O campo senha deve ser preenchido",
39+
(val?.length ?? 0) >= 6 ||
40+
"O campo senha deve ter pelo menos 6 caracteres",
41+
checkEmpty: (val: string | undefined) =>
42+
!!val || "O campo senha deve ser preenchido",
4143
validatePassword: (val: string | undefined) =>
4244
val === password || "As senhas devem ser iguais",
4345
};
4446
const checkEmail = {
45-
emailUsed: (val: string) => {
46-
const usuarios: Usuario[] = JSON.parse(getStorage("user") || "[]");
47-
const user = usuarios.find((use) => use.email === val);
48-
return !user || "Email ja cadastrado";
49-
},
5047
emailEmpty: (val: string) => !!val || "Verifique seu email",
5148
isEmailValid: (val: string) => {
5249
return (
@@ -69,7 +66,13 @@ const FormRegister = () => {
6966
}, [isSubmitSuccessful, reset, user, cart, navigate]);
7067

7168
const submit = (data: Usuario) => {
72-
dispatch(createUser(data));
69+
dispatch(
70+
addNewUser({
71+
email: data.email,
72+
nome: data.nome,
73+
password: data.password,
74+
})
75+
);
7376
};
7477

7578
return (

src/pages/checkout/PayForm/components/PayForTicket.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import { useNavigate } from "react-router-dom";
1313
const BoletoSimulado = () => {
1414
const { totValue } = useSelector((state: RootState) => state.carrinho);
1515
const { price } = useSelector((state: RootState) => state.frete);
16-
const {
17-
usuario: { nome },
18-
} = useSelector((state: RootState) => state.usuario);
16+
const { nome } = useSelector((state: RootState) => state.usuario);
1917
const [status, setStatus] = useState("Aberto");
2018
const [dataPagamento, setDataPagamento] = useState<string>("");
2119
const dispatch = useDispatch<AppDispatch>();

src/pages/login/FormLogin/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { MessageError } from "@/components/MessageError";
77
import { useEffect } from "react";
88
import { ILogin } from "@/types/usuarios";
99
import { useDispatch } from "react-redux";
10-
import { authenticateUser } from "@/store/reducers/usuario";
10+
import { loginUser } from "@/store/reducers/usuario";
1111
import { useSelector } from "react-redux";
1212
import { RootState } from "@/types/store";
1313
import { useNavigate } from "react-router-dom";
14+
import { AppDispatch } from "@/store";
1415

1516
const FormLogin = () => {
16-
const dispatch = useDispatch();
17+
const dispatch = useDispatch<AppDispatch>();
1718
const navigate = useNavigate();
1819
const user = useSelector((state: RootState) => state.usuario);
1920
const cart = useSelector((state: RootState) => state.carrinho);
@@ -42,7 +43,7 @@ const FormLogin = () => {
4243
}
4344
}, [isSubmitSuccessful, reset, user, cart, navigate]);
4445
const submit = (data: ILogin) => {
45-
dispatch(authenticateUser(data));
46+
dispatch(loginUser(data));
4647
};
4748

4849
return (

0 commit comments

Comments
 (0)