diff --git a/package-lock.json b/package-lock.json index 40e9e5e..f2fcfb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,9 @@ "styled-components": "^5.3.6", "typescript": "^4.9.5", "web-vitals": "^2.1.4" + }, + "devDependencies": { + "gh-pages": "^5.0.0" } }, "node_modules/@adobe/css-tools": { @@ -5117,6 +5120,15 @@ "node": ">=8" } }, + "node_modules/array-uniq": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", + "integrity": "sha512-MNha4BWQ6JbwhFhj03YK552f7cb3AzoE8SzeljgChvL1dl3IcvggXVz1DilzySZkCja+CXuZbdW7yATchWn8/Q==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/array.prototype.flat": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.1.tgz", @@ -7107,6 +7119,12 @@ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.295.tgz", "integrity": "sha512-lEO94zqf1bDA3aepxwnWoHUjA8sZ+2owgcSZjYQy0+uOSEclJX0VieZC+r+wLpSxUHRd6gG32znTWmr+5iGzFw==" }, + "node_modules/email-addresses": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/email-addresses/-/email-addresses-5.0.0.tgz", + "integrity": "sha512-4OIPYlA6JXqtVn8zpHpGiI7vE6EQOAg16aGnDMIAlZVinnoZ8208tW1hAbjWydgN/4PLTT9q+O1K6AH/vALJGw==", + "dev": true + }, "node_modules/emittery": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.8.1.tgz", @@ -8318,6 +8336,32 @@ "node": ">=10" } }, + "node_modules/filename-reserved-regex": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz", + "integrity": "sha512-lc1bnsSr4L4Bdif8Xb/qrtokGbq5zlsms/CYH8PP+WtCkGNF65DPiQY8vG3SakEdRn8Dlnm+gW/qWKKjS5sZzQ==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/filenamify": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-4.3.0.tgz", + "integrity": "sha512-hcFKyUG57yWGAzu1CMt/dPzYZuv+jAJUT85bL8mrXvNe6hWj6yEHEc4EdcgiA6Z3oi1/9wXJdZPXF2dZNgwgOg==", + "dev": true, + "dependencies": { + "filename-reserved-regex": "^2.0.0", + "strip-outer": "^1.0.1", + "trim-repeated": "^1.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/filesize": { "version": "8.0.7", "resolved": "https://registry.npmjs.org/filesize/-/filesize-8.0.7.tgz", @@ -8778,6 +8822,94 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/gh-pages": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/gh-pages/-/gh-pages-5.0.0.tgz", + "integrity": "sha512-Nqp1SjkPIB94Xw/3yYNTUL+G2dxlhjvv1zeN/4kMC1jfViTEqhtVz/Ba1zSXHuvXCN9ADNS1dN4r5/J/nZWEQQ==", + "dev": true, + "dependencies": { + "async": "^3.2.4", + "commander": "^2.18.0", + "email-addresses": "^5.0.0", + "filenamify": "^4.3.0", + "find-cache-dir": "^3.3.1", + "fs-extra": "^8.1.0", + "globby": "^6.1.0" + }, + "bin": { + "gh-pages": "bin/gh-pages.js", + "gh-pages-clean": "bin/gh-pages-clean.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/gh-pages/node_modules/array-union": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", + "integrity": "sha512-Dxr6QJj/RdU/hCaBjOfxW+q6lyuVE6JFWIrAUpuOOhoJJoQ99cUn3igRaHVB5P9WrgFVN0FfArM3x0cueOU8ng==", + "dev": true, + "dependencies": { + "array-uniq": "^1.0.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/gh-pages/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, + "node_modules/gh-pages/node_modules/fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + }, + "engines": { + "node": ">=6 <7 || >=8" + } + }, + "node_modules/gh-pages/node_modules/globby": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz", + "integrity": "sha512-KVbFv2TQtbzCoxAnfD6JcHZTYCzyliEaaeM/gH8qQdkKr5s0OP9scEgvdcngyk7AVdY6YVW/TJHd+lQ/Df3Daw==", + "dev": true, + "dependencies": { + "array-union": "^1.0.1", + "glob": "^7.0.3", + "object-assign": "^4.0.1", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/gh-pages/node_modules/jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", + "dev": true, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/gh-pages/node_modules/universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true, + "engines": { + "node": ">= 4.0.0" + } + }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -13007,6 +13139,27 @@ "node": ">=0.10.0" } }, + "node_modules/pinkie": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/pinkie-promise": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha512-0Gni6D4UcLTbv9c57DfxDGdr41XfgUjqWZu492f0cIGr16zDU06BWP/RAEvOuo7CQ0CNjHaLlM59YJJFm3NWlw==", + "dev": true, + "dependencies": { + "pinkie": "^2.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/pirates": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.5.tgz", @@ -16048,6 +16201,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/strip-outer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/strip-outer/-/strip-outer-1.0.1.tgz", + "integrity": "sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==", + "dev": true, + "dependencies": { + "escape-string-regexp": "^1.0.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/style-loader": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/style-loader/-/style-loader-3.3.1.tgz", @@ -16513,6 +16678,18 @@ "node": ">=8" } }, + "node_modules/trim-repeated": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz", + "integrity": "sha512-pkonvlKk8/ZuR0D5tLW8ljt5I8kmxp2XKymhepUeOdCEfKpZaktSArkLHZt76OB1ZvO9bssUsDty4SWhLvZpLg==", + "dev": true, + "dependencies": { + "escape-string-regexp": "^1.0.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/tryer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz", diff --git a/package.json b/package.json index 40d5e2c..04fec28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "ivy-inventorymanager", "version": "0.1.0", + "homepage": "https://lemeow125.github.io/Ivy", "private": true, "dependencies": { "@emotion/react": "^11.10.5", @@ -38,7 +39,9 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "predeploy": "npm run build", + "deploy": "gh-pages -d build" }, "eslintConfig": { "extends": [ @@ -57,5 +60,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "devDependencies": { + "gh-pages": "^5.0.0" } } diff --git a/src/Components/Api/Api.tsx b/src/Components/Api/Api.tsx index efa6b73..94fa33e 100644 --- a/src/Components/Api/Api.tsx +++ b/src/Components/Api/Api.tsx @@ -9,106 +9,123 @@ import { // Product APIs // Local Testing "http://localhost:8000" -// Remote Deploy "http://keannu125.pythonanywhere.com" -export const baseurl = "http://localhost:8000"; - +// Remote Deploy "https://keannu125.pythonanywhere.com" +axios.defaults.baseURL = "https://keannu125.pythonanywhere.com"; +const token = JSON.parse(localStorage.getItem("token") || "{}"); export function GetProducts() { - const token = JSON.parse(localStorage.getItem("token") || "{}"); return axios - .get(baseurl + "/api/v1/products/", { + .get("/api/v1/products/", { headers: { Authorization: "Token " + token, }, }) .then((response) => { + console.log("Queried products successfully"); return response.data; + }) + .catch((error) => { + console.log("Error querying products"); + return error; }); } export function GetProduct(id: number) { - const token = JSON.parse(localStorage.getItem("token") || "{}"); return axios - .get(baseurl + "/api/v1/products/" + id + "/", { + .get("/api/v1/products/" + id + "/", { headers: { Authorization: "Token " + token, }, }) .then((response) => { + console.log("Queried product successfully"); return response.data; + }) + .catch((error) => { + console.log("Error querying product"); + return error; }); } export function UpdateProduct(product: UpdateProductParams) { - const token = JSON.parse(localStorage.getItem("token") || "{}"); return axios - .patch(baseurl + "/api/v1/products/" + product.id + "/", product, { + .patch("/api/v1/products/" + product.id + "/", product, { headers: { Authorization: "Token " + token, }, }) .then((response) => { - console.log("Product update successful", response.data); + console.log("Product update successful"); return response.data; }) .catch((error) => { - console.log("Error updating product", error.response); + console.log("Error updating product"); return error; }); } export function GetLowestStockedProduct() { - const token = JSON.parse(localStorage.getItem("token") || "{}"); return axios - .get(baseurl + "/api/v1/lowest_stock_product/", { + .get("/api/v1/lowest_stock_product/", { headers: { Authorization: "Token " + token, }, }) .then((response) => { + console.log("Queried lowest stocekd product successfully"); return response.data; + }) + .catch((error) => { + console.log("Error querying lowest stocked product"); }); } export function GetLogs() { - const token = JSON.parse(localStorage.getItem("token") || "{}"); return axios - .get(baseurl + "/api/v1/logs/", { + .get("/api/v1/logs/", { headers: { Authorization: "Token " + token, }, }) .then((response) => { + console.log("Queried logs successfully"); return response.data; + }) + .catch((error) => { + console.log("Error querying logs"); + return error; }); } export function AddProduct(note: AddProductParams) { - const token = JSON.parse(localStorage.getItem("token") || "{}"); return axios - .post(baseurl + "/api/v1/products/", note, { + .post("/api/v1/products/", note, { headers: { Authorization: "Token " + token, }, }) .then((response) => { + console.log("Added product successfully"); return response.data; }) .catch((error) => { - console.log("Error adding product", error.response); + console.log("Error adding product"); return error; }); } export function DeleteProduct(id: number) { - const token = JSON.parse(localStorage.getItem("token") || "{}"); return axios - .delete(baseurl + "/api/v1/products/" + id + "/", { + .delete("/api/v1/products/" + id + "/", { headers: { Authorization: "Token " + token, }, }) + .then((response) => { + console.log("Deleted product successfully"); + return response; + }) .catch((error) => { - console.log("Error deleting product", error.response); + console.log("Error deleting product"); return error; }); } @@ -117,79 +134,74 @@ export function DeleteProduct(id: number) { export function UserRegister(register: RegistrationParams) { return axios - .post(baseurl + "/api/v1/accounts/users/", register) + .post("/api/v1/accounts/users/", register) .then(async (response) => { - console.log(response.data); + console.log("Registration success"); return true; }) .catch((error) => { - console.log("Registration failed: " + error.response); + console.log("Registration failed"); return false; }); } export function UserLogin(user: LoginParams) { return axios - .post(baseurl + "/api/v1/accounts/token/login/", user) + .post("/api/v1/accounts/token/login/", user) .then(async (response) => { localStorage.setItem("token", JSON.stringify(response.data.auth_token)); - console.log( - "Login Success! Stored Token: ", - JSON.parse(localStorage.getItem("token") || "{}") - ); + console.log("Login Success!"); return true; }) .catch((error) => { - console.log("Login Failed: " + error.response); + console.log("Login Failed"); return false; }); } export function UserInfo() { - const token = JSON.parse(localStorage.getItem("token") || "{}"); return axios - .get(baseurl + "/api/v1/accounts/users/me/", { + .get("/api/v1/accounts/users/me/", { headers: { Authorization: "Token " + token, }, }) .then((response) => { - console.log(response.data); + console.log("Success querying self info"); return response.data; }) .catch((error) => { - console.log("Error retrieving user data", error.response); + console.log("Error querying self info"); return false; }); } export function QueryUser(id: number) { - const token = JSON.parse(localStorage.getItem("token") || "{}"); return axios - .get(baseurl + "/api/v1/user_list/" + id, { + .get("/api/v1/user_list/" + id, { headers: { Authorization: "Token " + token, }, }) .then((response) => { - console.log("Querying one user...", response.data); + console.log("Success querying user"); return response.data; }) .catch((error) => { - console.log("Error retrieving single user data", error.response); + console.log("Error querying user"); return false; }); } export function UserActivate(activation: ActivationParams) { return axios - .post(baseurl + "/api/v1/accounts/users/activation/", activation) + .post("/api/v1/accounts/users/activation/", activation) .then(async (response) => { console.log("Activation Success"); return true; }) .catch((error) => { - console.log("Activation failed: " + error.response); + console.log("Activation failed"); return false; }); }