generated from Kenzie-Academy-Brasil-Developers/react-entrega-kenzie-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dashboard add/edit/delete technologies
- Loading branch information
Showing
39 changed files
with
977 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,33 @@ | ||
import { useState } from "react"; | ||
import { toast } from "react-toastify"; | ||
import { RoutesComponent } from "./routes"; | ||
import { api } from "./services/api"; | ||
import "react-toastify/dist/ReactToastify.css"; | ||
import { MessageToast } from "./styles/messageToast"; | ||
import { StyledContainer } from "./styles/toastTheme"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { AuthContext } from "./contexts/AuthContext"; | ||
import { useContext } from "react"; | ||
|
||
export const App = () => { | ||
const localStorageToken = localStorage.getItem("@TOKEN"); | ||
const localStorageUserId = localStorage.getItem("@USERID"); | ||
const [user, setUser] = useState(null); | ||
const navigate = useNavigate(); | ||
|
||
const userLogin = async (data, setLoading) => { | ||
try { | ||
setLoading(true); | ||
const request = await toast.promise(api.post("sessions", data), { | ||
pending: { | ||
render() { | ||
return <MessageToast message="Carregando..." />; | ||
}, | ||
icon: true, | ||
theme: "dark", | ||
}, | ||
success: { | ||
render({ data }) { | ||
return ( | ||
<MessageToast message={`Bem-vindo ${data.data.user.name}`} /> | ||
); | ||
}, | ||
icon: true, | ||
theme: "dark", | ||
}, | ||
error: { | ||
render({ data }) { | ||
return <MessageToast message={data.response.data.message} />; | ||
}, | ||
icon: true, | ||
theme: "dark", | ||
}, | ||
}); | ||
if (request.statusText === "OK") { | ||
console.log(request.data); | ||
setUser(request.data); | ||
localStorage.setItem("@TOKEN", request.data.token); | ||
localStorage.setItem("@USERID", request.data.user.id); | ||
navigate("user"); | ||
return request.data; | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const userLogout = () => { | ||
localStorage.clear(); | ||
setUser(null); | ||
navigate(""); | ||
}; | ||
|
||
const userRegister = async (data, setLoading) => { | ||
try { | ||
setLoading(true); | ||
const request = await toast.promise(api.post("users", data), { | ||
pending: { | ||
render() { | ||
return <MessageToast message="Carregando..." />; | ||
}, | ||
icon: true, | ||
theme: "dark", | ||
}, | ||
success: { | ||
render() { | ||
return <MessageToast message="Conta criada com sucesso!" />; | ||
}, | ||
icon: true, | ||
theme: "dark", | ||
}, | ||
error: { | ||
render({ data }) { | ||
return <MessageToast message={data.response.data.message} />; | ||
}, | ||
icon: true, | ||
theme: "dark", | ||
}, | ||
}); | ||
navigate(""); | ||
return request.data; | ||
} catch (error) { | ||
console.log(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const { globalLoading } = useContext(AuthContext); | ||
return ( | ||
<div className="App"> | ||
<RoutesComponent | ||
navigate={navigate} | ||
userLogin={userLogin} | ||
user={user} | ||
userLogout={userLogout} | ||
userRegister={userRegister} | ||
/> | ||
<StyledContainer | ||
position="top-right" | ||
autoClose={1000} | ||
hideProgressBar={false} | ||
newestOnTop={false} | ||
closeOnClick | ||
rtl={false} | ||
pauseOnFocusLoss | ||
draggable | ||
pauseOnHover | ||
theme="dark" | ||
/> | ||
<StyledContainer /> | ||
</div> | ||
<> | ||
{globalLoading ? ( | ||
<h1>Loading</h1> | ||
) : ( | ||
<> | ||
<RoutesComponent /> | ||
<StyledContainer | ||
position="top-right" | ||
autoClose={1000} | ||
hideProgressBar={false} | ||
newestOnTop={false} | ||
closeOnClick | ||
rtl={false} | ||
pauseOnFocusLoss | ||
draggable | ||
pauseOnHover | ||
theme="dark" | ||
/> | ||
<StyledContainer /> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as yup from "yup"; | ||
|
||
export const LoginSchema = yup.object().shape({ | ||
email: yup.string().required("Insira um email válido."), | ||
password: yup.string().required("Insira uma senha válida."), | ||
email: yup.string().required("Enter valid email"), | ||
password: yup.string().required("Enter valid password"), | ||
}); |
2 changes: 1 addition & 1 deletion
2
...Form/RegisterForm/Select/Option/index.jsx → src/components/Form/Option/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { OptionStyled } from "./style"; | ||
|
||
export const OptionSelectModule = ({ value, children }) => { | ||
export const OptionSelect = ({ value, children }) => { | ||
return <OptionStyled value={value}>{children}</OptionStyled>; | ||
}; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.