Skip to content

Commit c04e432

Browse files
committed
[UPDATE]:API DEMO ADDED AND SOME MINOR CHANGES DONE
1 parent 58c98b9 commit c04e432

File tree

4 files changed

+110
-4
lines changed

4 files changed

+110
-4
lines changed

src/App.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import NotFound from "pages/dashboard/pages/NotFound";
1616
import LayoutVertical from "pages/dashboard/LayoutVertical";
1717
import Documentation from "pages/dashboard/Documentation";
1818
import ChangeLog from "pages/dashboard/Changelog";
19+
import ApiDemo from "./pages/dashboard/pages/ApiDemo";
1920

2021
// import bootstrap components
2122
import Accordion from "bootstrap-components/Accordions";
@@ -76,6 +77,10 @@ const App = () => {
7677
path: "pricing",
7778
Component: Pricing,
7879
},
80+
{
81+
path: "api-demo",
82+
Component: ApiDemo,
83+
},
7984
],
8085
},
8186
{

src/pages/dashboard/Documentation.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ const Documentation = () => {
100100
<li>
101101
<h4 className="mb-0 fw-bold">Start</h4>
102102
<p>
103-
Run <code>npm run dev</code> or <code>yarn dev</code> or{" "}
104-
<code>pnpm dev</code> to start the development server on
103+
Run <code>npm run dev</code> or <code>yarn run dev</code> or{" "}
104+
<code>pnpm run dev</code> to start the development server on
105105
http://localhost:5173
106106
</p>
107107
<p>
108108
Visit{" "}
109109
<code>
110110
<Link
111-
to="http://localhost:3000"
111+
to="http://localhost:5173"
112112
target="_blank"
113113
rel="noreferrer"
114114
>

src/pages/dashboard/pages/ApiDemo.tsx

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Import node module libraries
2+
import React, { Fragment, useEffect, useState } from "react";
3+
import { Card } from "react-bootstrap";
4+
5+
// Define types
6+
interface Dimensions {
7+
width: number;
8+
height: number;
9+
depth: number;
10+
}
11+
12+
interface Product {
13+
id: number;
14+
title: string;
15+
description: string;
16+
category: string;
17+
price: number;
18+
discountPercentage: number;
19+
rating: number;
20+
stock: number;
21+
tags: string[];
22+
brand: string;
23+
sku: string;
24+
weight: number;
25+
dimensions: Dimensions;
26+
}
27+
28+
interface ErrorState {
29+
status_code: string;
30+
message: string;
31+
}
32+
33+
const ApiDemo: React.FC = () => {
34+
const [product, setProduct] = useState<Product | null>(null);
35+
const [isLoading, setIsLoading] = useState<boolean>(false);
36+
const [error, setError] = useState<ErrorState | null>(null);
37+
38+
useEffect(() => {
39+
const fetchProduct = async () => {
40+
try {
41+
setIsLoading(true);
42+
const response = await fetch("https://dummyjson.com/products/1");
43+
44+
if (!response.ok) {
45+
setError({
46+
status_code: "400",
47+
message: "Something went wrong, please try again.",
48+
});
49+
throw new Error("Unable to fetch product, Please try again later");
50+
}
51+
52+
const data: Product = await response.json();
53+
setProduct(data);
54+
} catch (error) {
55+
if (error instanceof Error) {
56+
setError({
57+
status_code: "500",
58+
message: error.message,
59+
});
60+
}
61+
} finally {
62+
setIsLoading(false);
63+
}
64+
};
65+
66+
fetchProduct();
67+
}, []);
68+
69+
return (
70+
<Fragment>
71+
{isLoading && (
72+
<Card className="m-5">
73+
<Card.Body>
74+
<div className="d-flex justify-content-center align-items-center">
75+
<p className="fs-4">Loading...</p>
76+
</div>
77+
</Card.Body>
78+
</Card>
79+
)}
80+
81+
{error && (
82+
<Card className="m-5">
83+
<Card.Body>
84+
<h4>Error: {error.status_code}</h4>
85+
<p>{error.message}</p>
86+
</Card.Body>
87+
</Card>
88+
)}
89+
90+
{product && !isLoading && !error && (
91+
<Card className="m-5">
92+
<Card.Body>
93+
<pre>{JSON.stringify(product, null, 2)}</pre>
94+
</Card.Body>
95+
</Card>
96+
)}
97+
</Fragment>
98+
);
99+
};
100+
101+
export default ApiDemo;

tsconfig.app.tsbuildinfo

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"root":["./src/app.tsx","./src/main.tsx","./src/types.ts","./src/vite-env.d.ts","./src/bootstrap-components/accordions.tsx","./src/bootstrap-components/alerts.tsx","./src/bootstrap-components/badges.tsx","./src/bootstrap-components/breadcrumbs.tsx","./src/bootstrap-components/buttongroup.tsx","./src/bootstrap-components/buttons.tsx","./src/bootstrap-components/cards.tsx","./src/bootstrap-components/carousels.tsx","./src/bootstrap-components/closebutton.tsx","./src/bootstrap-components/collapse.tsx","./src/bootstrap-components/dropdowns.tsx","./src/bootstrap-components/listgroup.tsx","./src/bootstrap-components/modals.tsx","./src/bootstrap-components/navbars.tsx","./src/bootstrap-components/navs.tsx","./src/bootstrap-components/offcanvas.tsx","./src/bootstrap-components/overlays.tsx","./src/bootstrap-components/paginations.tsx","./src/bootstrap-components/popovers.tsx","./src/bootstrap-components/progress.tsx","./src/bootstrap-components/spinners.tsx","./src/bootstrap-components/tables.tsx","./src/bootstrap-components/toasts.tsx","./src/bootstrap-components/tooltips.tsx","./src/components/bootstrap/dotbadge.tsx","./src/components/navbars/sidebar/customtoggle.tsx","./src/components/navbars/sidebar/customtoggleleveltwo.tsx","./src/components/navbars/sidebar/sidebar.tsx","./src/components/navbars/topbar/desktopnotifications.tsx","./src/components/navbars/topbar/header.tsx","./src/components/navbars/topbar/mobilenotifications.tsx","./src/components/navbars/topbar/notificationlist.tsx","./src/components/navbars/topbar/notifications.tsx","./src/data/notification.ts","./src/data/code/accordioncode.ts","./src/data/code/alertscode.ts","./src/data/code/badgescode.ts","./src/data/code/breadcrumbcode.ts","./src/data/code/buttongroupcode.ts","./src/data/code/buttonscode.ts","./src/data/code/cardscode.ts","./src/data/code/carouselscode.ts","./src/data/code/closecode.ts","./src/data/code/collapsescode.ts","./src/data/code/dropdownscode.ts","./src/data/code/listgroupscode.ts","./src/data/code/modalscode.ts","./src/data/code/navbarscode.ts","./src/data/code/navscode.ts","./src/data/code/offcanvascode.ts","./src/data/code/overlayscode.ts","./src/data/code/paginationscode.ts","./src/data/code/popoverscode.ts","./src/data/code/progresscode.ts","./src/data/code/spinnerscode.ts","./src/data/code/tablescode.ts","./src/data/code/toastscode.ts","./src/data/code/tooltipscode.ts","./src/data/dashboard/activeprojectsdata.ts","./src/data/dashboard/projectsstatsdata.tsx","./src/data/dashboard/teamsdata.ts","./src/data/pricing/faqsdata.ts","./src/data/pricing/featuresdata.ts","./src/data/pricing/pricingplansdata.ts","./src/data/profile/projectscontributionsdata.ts","./src/hooks/usemounted.tsx","./src/hooks/usetoggle.tsx","./src/layouts/authenticationlayout.tsx","./src/layouts/rootlayout.tsx","./src/pages/auth/forgetpassword.tsx","./src/pages/auth/signin.tsx","./src/pages/auth/signup.tsx","./src/pages/dashboard/changelog.tsx","./src/pages/dashboard/documentation.tsx","./src/pages/dashboard/index.tsx","./src/pages/dashboard/layoutvertical.tsx","./src/pages/dashboard/pages/billing.tsx","./src/pages/dashboard/pages/notfound.tsx","./src/pages/dashboard/pages/pricing.tsx","./src/pages/dashboard/pages/profile.tsx","./src/pages/dashboard/pages/settings.tsx","./src/routes/dashboardroutes.ts","./src/sub-components/index.tsx","./src/sub-components/billing/billingaddress.tsx","./src/sub-components/billing/currentplan.tsx","./src/sub-components/changelog/version_01_00_00.tsx","./src/sub-components/dashboard/activeprojects.tsx","./src/sub-components/dashboard/tasksperformance.tsx","./src/sub-components/dashboard/teams.tsx","./src/sub-components/profile/aboutme.tsx","./src/sub-components/profile/activityfeed.tsx","./src/sub-components/profile/myteam.tsx","./src/sub-components/profile/profileheader.tsx","./src/sub-components/profile/projectscontributions.tsx","./src/sub-components/profile/recentfromblog.tsx","./src/sub-components/settings/deleteaccount.tsx","./src/sub-components/settings/emailsetting.tsx","./src/sub-components/settings/generalsetting.tsx","./src/sub-components/settings/notifications.tsx","./src/sub-components/settings/preferences.tsx","./src/widgets/pageheading.tsx","./src/widgets/index.tsx","./src/widgets/cards/pricingcard.tsx","./src/widgets/dropfiles/dropfiles.tsx","./src/widgets/features/featurelefttopicon.tsx","./src/widgets/form-select/formselect.tsx","./src/widgets/highlight-code/highlightcode.tsx","./src/widgets/stats/statrighttopicon.tsx"],"version":"5.6.3"}
1+
{"root":["./src/app.tsx","./src/main.tsx","./src/types.ts","./src/vite-env.d.ts","./src/bootstrap-components/accordions.tsx","./src/bootstrap-components/alerts.tsx","./src/bootstrap-components/badges.tsx","./src/bootstrap-components/breadcrumbs.tsx","./src/bootstrap-components/buttongroup.tsx","./src/bootstrap-components/buttons.tsx","./src/bootstrap-components/cards.tsx","./src/bootstrap-components/carousels.tsx","./src/bootstrap-components/closebutton.tsx","./src/bootstrap-components/collapse.tsx","./src/bootstrap-components/dropdowns.tsx","./src/bootstrap-components/listgroup.tsx","./src/bootstrap-components/modals.tsx","./src/bootstrap-components/navbars.tsx","./src/bootstrap-components/navs.tsx","./src/bootstrap-components/offcanvas.tsx","./src/bootstrap-components/overlays.tsx","./src/bootstrap-components/paginations.tsx","./src/bootstrap-components/popovers.tsx","./src/bootstrap-components/progress.tsx","./src/bootstrap-components/spinners.tsx","./src/bootstrap-components/tables.tsx","./src/bootstrap-components/toasts.tsx","./src/bootstrap-components/tooltips.tsx","./src/components/bootstrap/dotbadge.tsx","./src/components/navbars/sidebar/customtoggle.tsx","./src/components/navbars/sidebar/customtoggleleveltwo.tsx","./src/components/navbars/sidebar/sidebar.tsx","./src/components/navbars/topbar/desktopnotifications.tsx","./src/components/navbars/topbar/header.tsx","./src/components/navbars/topbar/mobilenotifications.tsx","./src/components/navbars/topbar/notificationlist.tsx","./src/components/navbars/topbar/notifications.tsx","./src/data/notification.ts","./src/data/code/accordioncode.ts","./src/data/code/alertscode.ts","./src/data/code/badgescode.ts","./src/data/code/breadcrumbcode.ts","./src/data/code/buttongroupcode.ts","./src/data/code/buttonscode.ts","./src/data/code/cardscode.ts","./src/data/code/carouselscode.ts","./src/data/code/closecode.ts","./src/data/code/collapsescode.ts","./src/data/code/dropdownscode.ts","./src/data/code/listgroupscode.ts","./src/data/code/modalscode.ts","./src/data/code/navbarscode.ts","./src/data/code/navscode.ts","./src/data/code/offcanvascode.ts","./src/data/code/overlayscode.ts","./src/data/code/paginationscode.ts","./src/data/code/popoverscode.ts","./src/data/code/progresscode.ts","./src/data/code/spinnerscode.ts","./src/data/code/tablescode.ts","./src/data/code/toastscode.ts","./src/data/code/tooltipscode.ts","./src/data/dashboard/activeprojectsdata.ts","./src/data/dashboard/projectsstatsdata.tsx","./src/data/dashboard/teamsdata.ts","./src/data/pricing/faqsdata.ts","./src/data/pricing/featuresdata.ts","./src/data/pricing/pricingplansdata.ts","./src/data/profile/projectscontributionsdata.ts","./src/hooks/usemounted.tsx","./src/hooks/usetoggle.tsx","./src/layouts/authenticationlayout.tsx","./src/layouts/rootlayout.tsx","./src/pages/auth/forgetpassword.tsx","./src/pages/auth/signin.tsx","./src/pages/auth/signup.tsx","./src/pages/dashboard/changelog.tsx","./src/pages/dashboard/documentation.tsx","./src/pages/dashboard/index.tsx","./src/pages/dashboard/layoutvertical.tsx","./src/pages/dashboard/pages/apidemo.tsx","./src/pages/dashboard/pages/billing.tsx","./src/pages/dashboard/pages/notfound.tsx","./src/pages/dashboard/pages/pricing.tsx","./src/pages/dashboard/pages/profile.tsx","./src/pages/dashboard/pages/settings.tsx","./src/routes/dashboardroutes.ts","./src/sub-components/index.tsx","./src/sub-components/billing/billingaddress.tsx","./src/sub-components/billing/currentplan.tsx","./src/sub-components/changelog/version_01_00_00.tsx","./src/sub-components/dashboard/activeprojects.tsx","./src/sub-components/dashboard/tasksperformance.tsx","./src/sub-components/dashboard/teams.tsx","./src/sub-components/profile/aboutme.tsx","./src/sub-components/profile/activityfeed.tsx","./src/sub-components/profile/myteam.tsx","./src/sub-components/profile/profileheader.tsx","./src/sub-components/profile/projectscontributions.tsx","./src/sub-components/profile/recentfromblog.tsx","./src/sub-components/settings/deleteaccount.tsx","./src/sub-components/settings/emailsetting.tsx","./src/sub-components/settings/generalsetting.tsx","./src/sub-components/settings/notifications.tsx","./src/sub-components/settings/preferences.tsx","./src/widgets/pageheading.tsx","./src/widgets/index.tsx","./src/widgets/cards/pricingcard.tsx","./src/widgets/dropfiles/dropfiles.tsx","./src/widgets/features/featurelefttopicon.tsx","./src/widgets/form-select/formselect.tsx","./src/widgets/highlight-code/highlightcode.tsx","./src/widgets/stats/statrighttopicon.tsx"],"version":"5.6.3"}

0 commit comments

Comments
 (0)