Pārlūkot izejas kodu

api

cart-api-guide
azri 5 dienas atpakaļ
vecāks
revīzija
290995658f

+ 32
- 0
package-lock.json Parādīt failu

@@ -18,6 +18,7 @@
18 18
         "@testing-library/jest-dom": "^5.17.0",
19 19
         "@testing-library/react": "^13.4.0",
20 20
         "@testing-library/user-event": "^13.5.0",
21
+        "axios": "^1.7.9",
21 22
         "dotenv": "^16.4.7",
22 23
         "react": "^18.3.1",
23 24
         "react-dom": "^18.3.1",
@@ -5749,6 +5750,31 @@
5749 5750
         "node": ">=4"
5750 5751
       }
5751 5752
     },
5753
+    "node_modules/axios": {
5754
+      "version": "1.7.9",
5755
+      "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
5756
+      "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
5757
+      "license": "MIT",
5758
+      "dependencies": {
5759
+        "follow-redirects": "^1.15.6",
5760
+        "form-data": "^4.0.0",
5761
+        "proxy-from-env": "^1.1.0"
5762
+      }
5763
+    },
5764
+    "node_modules/axios/node_modules/form-data": {
5765
+      "version": "4.0.1",
5766
+      "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz",
5767
+      "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==",
5768
+      "license": "MIT",
5769
+      "dependencies": {
5770
+        "asynckit": "^0.4.0",
5771
+        "combined-stream": "^1.0.8",
5772
+        "mime-types": "^2.1.12"
5773
+      },
5774
+      "engines": {
5775
+        "node": ">= 6"
5776
+      }
5777
+    },
5752 5778
     "node_modules/axobject-query": {
5753 5779
       "version": "4.1.0",
5754 5780
       "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz",
@@ -14808,6 +14834,12 @@
14808 14834
         "node": ">= 0.10"
14809 14835
       }
14810 14836
     },
14837
+    "node_modules/proxy-from-env": {
14838
+      "version": "1.1.0",
14839
+      "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
14840
+      "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
14841
+      "license": "MIT"
14842
+    },
14811 14843
     "node_modules/psl": {
14812 14844
       "version": "1.15.0",
14813 14845
       "resolved": "https://registry.npmjs.org/psl/-/psl-1.15.0.tgz",

+ 1
- 0
package.json Parādīt failu

@@ -13,6 +13,7 @@
13 13
     "@testing-library/jest-dom": "^5.17.0",
14 14
     "@testing-library/react": "^13.4.0",
15 15
     "@testing-library/user-event": "^13.5.0",
16
+    "axios": "^1.7.9",
16 17
     "dotenv": "^16.4.7",
17 18
     "react": "^18.3.1",
18 19
     "react-dom": "^18.3.1",

+ 0
- 1
src/components/BillingForm/BillingForm.jsx Parādīt failu

@@ -21,7 +21,6 @@ import Grid from '@mui/material/Grid2';
21 21
 import CreditCardIcon from '@mui/icons-material/CreditCard';
22 22
 import AccountBalanceWalletIcon from '@mui/icons-material/AccountBalanceWallet';
23 23
 
24
-
25 24
 const BillingForm = () => {
26 25
 
27 26
   const rows = [

+ 0
- 6
src/components/Navbar/Navbar.jsx Parādīt failu

@@ -1,12 +1,10 @@
1 1
 import React, { useState, useEffect } from "react";
2 2
 import AppBar from "@mui/material/AppBar";
3 3
 import Toolbar from "@mui/material/Toolbar";
4
-import Typography from "@mui/material/Typography";
5 4
 import Button from "@mui/material/Button";
6 5
 import IconButton from "@mui/material/IconButton";
7 6
 import Box from "@mui/material/Box";
8 7
 import Header from "../Header";
9
-import InputBase from "@mui/material/InputBase";
10 8
 import SearchIcon from "@mui/icons-material/Search";
11 9
 import LocalMallIcon from '@mui/icons-material/LocalMall';
12 10
 import AccountCircleIcon from "@mui/icons-material/AccountCircle";
@@ -60,10 +58,6 @@ const Navbar = () => {
60 58
 
61 59
   const [open, setOpen] = React.useState(false);
62 60
 
63
-  const toggleDrawer = (newOpen) => () => {
64
-    setOpen(newOpen);
65
-  };
66
-
67 61
   const navItem = [
68 62
     {
69 63
       title: "DISCOVER",

+ 2
- 1
src/components/Navbar/components/MobileNav/MobileNav.jsx Parādīt failu

@@ -1,5 +1,5 @@
1 1
 import React from "react";
2
-import { Drawer, Box, List, ListItem, ListItemButton, ListItemIcon, ListItemText, Divider } from "@mui/material";
2
+import { Drawer, Box, List, ListItem, ListItemButton, ListItemText } from "@mui/material";
3 3
 import logoSrc from "../../../../assets/svg/logo.svg";
4 4
 
5 5
 const MobileNav = ({ open, onClose, menu = [] }) => {
@@ -40,6 +40,7 @@ const MobileNav = ({ open, onClose, menu = [] }) => {
40 40
           {menu.map(({title, link, icon}) => (
41 41
             <ListItem key={title} disablePadding>
42 42
               <ListItemButton
43
+                onClick={()=>{window.location.href = link }}
43 44
                 sx={{
44 45
                   color: "white",
45 46
                   "&:hover": {

+ 6
- 0
src/pages/Home.jsx Parādīt failu

@@ -12,8 +12,14 @@ import KeyboardArrowLeftIcon from '@mui/icons-material/KeyboardArrowLeft';
12 12
 import ProductType from '../components/ProductType';
13 13
 import NewsLetter from '../components/NewsLetter';
14 14
 
15
+import ProductService from "../services/ProductService"
16
+
15 17
 const Home = () => {
16 18
 
19
+  React.useEffect(()=>{
20
+    ProductService.getProducts();
21
+  },[])
22
+
17 23
   return (
18 24
     <>
19 25
       <Carousel />

+ 49
- 0
src/services/ProductService.js Parādīt failu

@@ -0,0 +1,49 @@
1
+import axios from 'axios'
2
+import { createStorefrontApiClient } from '@shopify/storefront-api-client';
3
+import { API_URL, REACT_APP_API_KEY, REACT_APP_API_SECRET, REACT_APP_ACCESS_TOKEN, REACT_APP_SHOP_NAME } from '../utils/httpCommon'
4
+
5
+const shopUrl = REACT_APP_SHOP_NAME;
6
+const accessToken = REACT_APP_ACCESS_TOKEN;
7
+
8
+
9
+const getProducts = async () => {
10
+
11
+  console.log(shopUrl)
12
+  console.log(accessToken)
13
+  console.log(createStorefrontApiClient)
14
+
15
+  const client = createStorefrontApiClient({
16
+    storeDomain: `https://${shopUrl}/api/2024-10/graphql.json`,
17
+    apiVersion: '2024-10',
18
+    publicAccessToken: accessToken,
19
+  });
20
+
21
+  const productQuery = `
22
+    {
23
+      products(first: 99) {
24
+        nodes {
25
+          id
26
+          title
27
+          totalInventory
28
+        }
29
+      }
30
+    }
31
+  `;
32
+
33
+  const { data, errors, extensions } = await client.request(productQuery, {
34
+    variables: {
35
+      handle: 'sample-product',
36
+    },
37
+  });
38
+
39
+  console.log(data)
40
+
41
+  return
42
+
43
+}
44
+
45
+const ProductService = {
46
+  getProducts
47
+}
48
+
49
+export default ProductService

+ 6
- 0
src/utils/httpCommon.js Parādīt failu

@@ -0,0 +1,6 @@
1
+export const API_URL = process.env.REACT_APP_API_URL
2
+export const REACT_APP_API_KEY = process.env.REACT_APP_API_KEY
3
+export const REACT_APP_API_SECRET = process.env.REACT_APP_API_SECRET
4
+export const REACT_APP_ACCESS_TOKEN = process.env.REACT_APP_ACCESS_TOKEN
5
+export const REACT_APP_SHOP_NAME = process.env.REACT_APP_SHOP_NAME
6
+

Notiek ielāde…
Atcelt
Saglabāt