Skip to content

Commit

Permalink
[Penify]: Documentation for commit - f8e2402 (#266)
Browse files Browse the repository at this point in the history
* [Penify]: Documentation for commit - f8e2402

* [Penify]: Documentation for commit - f8e2402

* [Penify]: Documentation for commit - f8e2402

---------

Co-authored-by: penify-dev[bot] <146478655+penify-dev[bot]@users.noreply.github.com>
  • Loading branch information
penify-dev[bot] authored Sep 1, 2024
1 parent f8e2402 commit 97797d5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Components/Layout/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ import logo from "../../ApiBRLogo.png";
import classnames from "classnames";
import useMetadata from "../../Hooks/useMetadata";

/**
* A functional component that renders a navigation bar for the application.
* The navigation bar includes links to various sections of the application
* and displays API metadata such as version and date.
*
* @component
* @returns {JSX.Element} The rendered navigation bar component.
*
* @example
* // Usage in a React application
* import NavBar from './NavBar';
*
* function App() {
* return (
* <div>
* <NavBar />
* {/* Other components */
const NavBar = () => {

let ApiMetadata = useMetadata();
Expand Down
17 changes: 17 additions & 0 deletions src/Hooks/useFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ function reducer(state, action) {

const BASE_URL = "https://apibr.com/vagas/api/v2/";

/**
* Custom hook that fetches data from a specified API endpoint using the provided entity and parameters.
* It manages the loading state and the fetched items, along with pagination information.
*
* @param {string} entity - The API endpoint to fetch data from.
* @param {Object} params - Additional parameters to be sent with the request.
* @param {number} page - The current page number for pagination.
* @returns {[Object, function]} An array containing the current state and a function to load the page.
*
* @example
* const [state, loadPage] = useFetch('users', { active: true }, 1);
*
* // To load the data
* loadPage();
*
* @throws {Error} Throws an error if the request fails, which can be handled in the calling component.
*/
export default function useFetch(entity, params, page) {
const [state, dispatch] = useReducer(reducer, {
loading: false,
Expand Down
18 changes: 18 additions & 0 deletions src/Hooks/useMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ import FormatDate from "../Helpers/FormatDate";

const BASE_URL = "https://apibr.com/vagas/api/v2/";

/**
* A custom React hook that retrieves and manages metadata from an API.
*
* This hook uses the `useState` and `useEffect` hooks to fetch API metadata,
* including the version and date, when the component mounts. It handles the
* API request using Axios and provides error handling through toastr notifications.
*
* @returns {Object} An object containing the API metadata:
* - {string} version - The version of the API.
* - {string} date - The date associated with the API version.
*
* @example
* const { version, date } = useMetadata();
* console.log(`API Version: ${version}, Date: ${date}`);
*
* @throws {Error} Throws an error if the API request fails, which is handled
* by displaying a toastr error notification.
*/
export default function useMetadata() {
const [metadata, setMetadata] = useState({
version: "0.0.0",
Expand Down

0 comments on commit 97797d5

Please sign in to comment.