diff --git a/Frontend/package-lock.json b/Frontend/package-lock.json index 1cf32a8..d7152d4 100644 --- a/Frontend/package-lock.json +++ b/Frontend/package-lock.json @@ -55,6 +55,9 @@ "@babel/plugin-proposal-private-property-in-object": "^7.16.7", "@babel/preset-env": "^7.25.3", "@babel/preset-react": "^7.24.7", + "@types/node": "^22.5.5", + "@types/react": "^18.3.8", + "@types/react-native": "^0.73.0", "babel-plugin-inline-dotenv": "^1.7.0", "babel-plugin-module-resolver": "^5.0.2", "babel-plugin-transform-inline-environment-variables": "^0.4.4", @@ -62,6 +65,8 @@ "eslint": "^8.56.0", "eslint-config-react-app": "^7.0.1", "jest": "^29.7.0", + "tsc-alias": "^1.8.10", + "typescript": "^4.9.5", "webpack": "^5.92.1" } }, @@ -6787,6 +6792,14 @@ "node": ">=14.15" } }, + "node_modules/@rnx-kit/chromium-edge-launcher/node_modules/@types/node": { + "version": "18.19.50", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.50.tgz", + "integrity": "sha512-xonK+NRrMBRtkL1hVCc3G+uXtjh1Al4opBLjqVmipe5ZAaBYWW6cNAiBVZ1BvmkBhep698rP3UM3aRAdSALuhg==", + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/@rnx-kit/chromium-edge-launcher/node_modules/escape-string-regexp": { "version": "4.0.0", "license": "MIT", @@ -6807,6 +6820,11 @@ "node": ">=10" } }, + "node_modules/@rnx-kit/chromium-edge-launcher/node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "node_modules/@rollup/plugin-babel": { "version": "5.3.1", "license": "MIT", @@ -7606,10 +7624,11 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "18.19.50", - "license": "MIT", + "version": "22.5.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", + "integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", "dependencies": { - "undici-types": "~5.26.4" + "undici-types": "~6.19.2" } }, "node_modules/@types/node-forge": { @@ -7644,8 +7663,9 @@ "license": "MIT" }, "node_modules/@types/react": { - "version": "18.3.5", - "license": "MIT", + "version": "18.3.8", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.8.tgz", + "integrity": "sha512-syBUrW3/XpnW4WJ41Pft+I+aPoDVbrBVQGEnbD7NijDGlVC+8gV/XKRY+7vMDlfPpbwYt0l1vd/Sj8bJGMbs9Q==", "dependencies": { "@types/prop-types": "*", "csstype": "^3.0.2" @@ -7658,6 +7678,16 @@ "@types/react": "*" } }, + "node_modules/@types/react-native": { + "version": "0.73.0", + "resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.73.0.tgz", + "integrity": "sha512-6ZRPQrYM72qYKGWidEttRe6M5DZBEV5F+MHMHqd4TTYx0tfkcdrUFGdef6CCxY0jXU7wldvd/zA/b0A/kTeJmA==", + "deprecated": "This is a stub types definition. react-native provides its own type definitions, so you do not need this installed.", + "dev": true, + "dependencies": { + "react-native": "*" + } + }, "node_modules/@types/resolve": { "version": "1.17.1", "license": "MIT", @@ -11116,7 +11146,8 @@ }, "node_modules/dotenv": { "version": "16.4.5", - "license": "BSD-2-Clause", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", "engines": { "node": ">=12" }, @@ -13188,6 +13219,19 @@ "version": "1.0.0", "license": "ISC" }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "license": "MIT", @@ -19076,6 +19120,19 @@ "multicast-dns": "cli.js" } }, + "node_modules/mylas": { + "version": "2.1.13", + "resolved": "https://registry.npmjs.org/mylas/-/mylas-2.1.13.tgz", + "integrity": "sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==", + "dev": true, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/raouldeheer" + } + }, "node_modules/mz": { "version": "2.7.0", "license": "MIT", @@ -19944,6 +20001,18 @@ "node": ">=4" } }, + "node_modules/plimit-lit": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/plimit-lit/-/plimit-lit-1.6.1.tgz", + "integrity": "sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==", + "dev": true, + "dependencies": { + "queue-lit": "^1.5.1" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/plist": { "version": "3.1.0", "license": "MIT", @@ -21311,6 +21380,15 @@ "inherits": "~2.0.3" } }, + "node_modules/queue-lit": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/queue-lit/-/queue-lit-1.5.2.tgz", + "integrity": "sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==", + "dev": true, + "engines": { + "node": ">=12" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "funding": [ @@ -25430,6 +25508,32 @@ "version": "0.1.13", "license": "Apache-2.0" }, + "node_modules/tsc-alias": { + "version": "1.8.10", + "resolved": "https://registry.npmjs.org/tsc-alias/-/tsc-alias-1.8.10.tgz", + "integrity": "sha512-Ibv4KAWfFkFdKJxnWfVtdOmB0Zi1RJVxcbPGiCDsFpCQSsmpWyuzHG3rQyI5YkobWwxFPEyQfu1hdo4qLG2zPw==", + "dev": true, + "dependencies": { + "chokidar": "^3.5.3", + "commander": "^9.0.0", + "globby": "^11.0.4", + "mylas": "^2.1.9", + "normalize-path": "^3.0.0", + "plimit-lit": "^1.2.6" + }, + "bin": { + "tsc-alias": "dist/bin/index.js" + } + }, + "node_modules/tsc-alias/node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "dev": true, + "engines": { + "node": "^12.20.0 || >=14" + } + }, "node_modules/tsconfig-paths": { "version": "3.15.0", "license": "MIT", @@ -25608,8 +25712,8 @@ }, "node_modules/typescript": { "version": "4.9.5", - "license": "Apache-2.0", - "peer": true, + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -25661,8 +25765,9 @@ "license": "MIT" }, "node_modules/undici-types": { - "version": "5.26.5", - "license": "MIT" + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==" }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", diff --git a/Frontend/package.json b/Frontend/package.json index 473ec34..432e98e 100644 --- a/Frontend/package.json +++ b/Frontend/package.json @@ -53,6 +53,9 @@ "@babel/plugin-proposal-private-property-in-object": "^7.16.7", "@babel/preset-env": "^7.25.3", "@babel/preset-react": "^7.24.7", + "@types/node": "^22.5.5", + "@types/react": "^18.3.8", + "@types/react-native": "^0.73.0", "babel-plugin-inline-dotenv": "^1.7.0", "babel-plugin-module-resolver": "^5.0.2", "babel-plugin-transform-inline-environment-variables": "^0.4.4", @@ -60,6 +63,8 @@ "eslint": "^8.56.0", "eslint-config-react-app": "^7.0.1", "jest": "^29.7.0", + "tsc-alias": "^1.8.10", + "typescript": "^4.9.5", "webpack": "^5.92.1" }, "version": "1.0.0", diff --git a/Frontend/shared/.babelrc b/Frontend/shared/.babelrc deleted file mode 100644 index 96addf5..0000000 --- a/Frontend/shared/.babelrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "presets": ["@babel/preset-env", "@babel/preset-react"], - "plugins": [ - "inline-dotenv", - [ - "module-resolver", - { - "alias": { - "@constants": "./src/constants" - } - } - ] - ] - } - \ No newline at end of file diff --git a/Frontend/shared/.env b/Frontend/shared/.env index e5fe75f..2f01cf9 100644 --- a/Frontend/shared/.env +++ b/Frontend/shared/.env @@ -1,2 +1,2 @@ -REACT_APP_API_DOMAIN=api.speedcartapp.com -REACT_APP_API_PORT=8443 \ No newline at end of file +API_DOMAIN=api.speedcartapp.com +API_PORT=8443 \ No newline at end of file diff --git a/Frontend/shared/.gitignore b/Frontend/shared/.gitignore index b947077..c228cbe 100644 --- a/Frontend/shared/.gitignore +++ b/Frontend/shared/.gitignore @@ -1,2 +1,3 @@ node_modules/ dist/ +src/constants/config.json \ No newline at end of file diff --git a/Frontend/shared/generate-config.js b/Frontend/shared/generate-config.js new file mode 100644 index 0000000..0632042 --- /dev/null +++ b/Frontend/shared/generate-config.js @@ -0,0 +1,15 @@ +const fs = require('fs'); +const path = require('path'); +const dotenv = require('dotenv'); + +// Load environment variables from the .env file +dotenv.config(); + +const config = { + API_DOMAIN: process.env.API_DOMAIN, + API_PORT: process.env.API_PORT, +}; + +// Write the config to a file in the shared directory +fs.writeFileSync(path.resolve(__dirname, './src/constants/config.json'), JSON.stringify(config, null, 2)); +console.log('Config file generated successfully.'); diff --git a/Frontend/shared/package.json b/Frontend/shared/package.json index 2e9dcc5..f2e6cd4 100644 --- a/Frontend/shared/package.json +++ b/Frontend/shared/package.json @@ -4,7 +4,7 @@ "description": "", "main": "./dist/index.js", "scripts": { - "build": "babel src --out-dir dist && echo Success" + "build": "node generate-config.js && tsc && tsc-alias && echo Success" }, "keywords": [], "author": "", diff --git a/Frontend/shared/src/constants/BaseUrl.ts b/Frontend/shared/src/constants/BaseUrl.ts new file mode 100644 index 0000000..c1c0a0d --- /dev/null +++ b/Frontend/shared/src/constants/BaseUrl.ts @@ -0,0 +1,8 @@ +// src/constants/config/config.ts +import config from './config.json'; + +const API_DOMAIN = config.API_DOMAIN; +const API_PORT = config.API_PORT; + +// This can be reused for all backend interactions +export const BASE_URL: string = `https://${API_DOMAIN}:${API_PORT}`; diff --git a/Frontend/shared/src/constants/config/config.js b/Frontend/shared/src/constants/config/config.js deleted file mode 100644 index b94fd32..0000000 --- a/Frontend/shared/src/constants/config/config.js +++ /dev/null @@ -1,2 +0,0 @@ -// This can be reused for all backend interactions -export const BASE_URL = `https://${process.env.REACT_APP_API_DOMAIN}:${process.env.REACT_APP_API_PORT}`; \ No newline at end of file diff --git a/Frontend/shared/src/constants/config/index.js b/Frontend/shared/src/constants/config/index.js deleted file mode 100644 index ff87ad7..0000000 --- a/Frontend/shared/src/constants/config/index.js +++ /dev/null @@ -1 +0,0 @@ -export { BASE_URL } from './config'; \ No newline at end of file diff --git a/Frontend/shared/src/constants/index.d.ts b/Frontend/shared/src/constants/index.d.ts new file mode 100644 index 0000000..db7c382 --- /dev/null +++ b/Frontend/shared/src/constants/index.d.ts @@ -0,0 +1,5 @@ +// src/constants/index.d.ts + +declare module '@constants' { + export const BASE_URL; +} \ No newline at end of file diff --git a/Frontend/shared/src/constants/index.js b/Frontend/shared/src/constants/index.js deleted file mode 100644 index ff87ad7..0000000 --- a/Frontend/shared/src/constants/index.js +++ /dev/null @@ -1 +0,0 @@ -export { BASE_URL } from './config'; \ No newline at end of file diff --git a/Frontend/shared/src/constants/index.ts b/Frontend/shared/src/constants/index.ts new file mode 100644 index 0000000..d5c8cd9 --- /dev/null +++ b/Frontend/shared/src/constants/index.ts @@ -0,0 +1 @@ +export * from './BaseUrl'; \ No newline at end of file diff --git a/Frontend/shared/src/functions/createGroceryItem/createGroceryItem.js b/Frontend/shared/src/functions/createGroceryItem/createGroceryItem.js deleted file mode 100644 index 80bb3fa..0000000 --- a/Frontend/shared/src/functions/createGroceryItem/createGroceryItem.js +++ /dev/null @@ -1,21 +0,0 @@ -import { BASE_URL } from '@constants/config'; -/* -This is what item must look like: -{ - id: number; - name: string; - is_food: boolean; - quantity: number; - list_id: uuid (or Number, one of these?) -} -*/ -export const createGroceryItem = async (item) => { - return fetch(`${BASE_URL}/grocery-items`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - credentials: 'include', - body: JSON.stringify(item) - }); -}; \ No newline at end of file diff --git a/Frontend/shared/src/functions/createGroceryItem/createGroceryItem.ts b/Frontend/shared/src/functions/createGroceryItem/createGroceryItem.ts new file mode 100644 index 0000000..fd287ea --- /dev/null +++ b/Frontend/shared/src/functions/createGroceryItem/createGroceryItem.ts @@ -0,0 +1,13 @@ +import { BASE_URL } from '@constants'; +import { GroceryItem } from '@types'; + +export const createGroceryItem = async (item: GroceryItem) => { + return fetch(`${BASE_URL}/grocery-items`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include', + body: JSON.stringify(item) + }); +}; \ No newline at end of file diff --git a/Frontend/shared/src/functions/createGroceryItem/index.js b/Frontend/shared/src/functions/createGroceryItem/index.ts similarity index 100% rename from Frontend/shared/src/functions/createGroceryItem/index.js rename to Frontend/shared/src/functions/createGroceryItem/index.ts diff --git a/Frontend/shared/src/functions/createShareLink/createShareLink.js b/Frontend/shared/src/functions/createShareLink/createShareLink.ts similarity index 68% rename from Frontend/shared/src/functions/createShareLink/createShareLink.js rename to Frontend/shared/src/functions/createShareLink/createShareLink.ts index 39fd68f..f097aa5 100644 --- a/Frontend/shared/src/functions/createShareLink/createShareLink.js +++ b/Frontend/shared/src/functions/createShareLink/createShareLink.ts @@ -1,6 +1,6 @@ -import { BASE_URL } from '@constants/config'; +import { BASE_URL } from '@constants'; -export const createShareLink = async (shareListId, permissions) => { +export const createShareLink = async (shareListId: string, permissions: any) => { return fetch(`${BASE_URL}/share/${shareListId}`, { method: 'POST', headers: { diff --git a/Frontend/shared/src/functions/createShareLink/index.js b/Frontend/shared/src/functions/createShareLink/index.ts similarity index 100% rename from Frontend/shared/src/functions/createShareLink/index.js rename to Frontend/shared/src/functions/createShareLink/index.ts diff --git a/Frontend/shared/src/functions/createSharingPermissions/createSharingPermissions.js b/Frontend/shared/src/functions/createSharingPermissions/createSharingPermissions.ts similarity index 64% rename from Frontend/shared/src/functions/createSharingPermissions/createSharingPermissions.js rename to Frontend/shared/src/functions/createSharingPermissions/createSharingPermissions.ts index 82655ad..7ce2526 100644 --- a/Frontend/shared/src/functions/createSharingPermissions/createSharingPermissions.js +++ b/Frontend/shared/src/functions/createSharingPermissions/createSharingPermissions.ts @@ -1,6 +1,6 @@ -import { BASE_URL } from "@constants/config"; +import { BASE_URL } from '@constants'; -export const createSharingPermissions = async (token) => { +export const createSharingPermissions = async (token: string) => { return fetch(`${BASE_URL}/share/${token}`, { method: 'GET', headers: { diff --git a/Frontend/shared/src/functions/createSharingPermissions/index.js b/Frontend/shared/src/functions/createSharingPermissions/index.ts similarity index 100% rename from Frontend/shared/src/functions/createSharingPermissions/index.js rename to Frontend/shared/src/functions/createSharingPermissions/index.ts diff --git a/Frontend/shared/src/functions/createShoppingList/createShoppingList.js b/Frontend/shared/src/functions/createShoppingList/createShoppingList.js deleted file mode 100644 index ea1271c..0000000 --- a/Frontend/shared/src/functions/createShoppingList/createShoppingList.js +++ /dev/null @@ -1,25 +0,0 @@ -import { BASE_URL } from '@constants/config'; - -export const createShoppingList = async (name, routeId = null) => { - const url = `${BASE_URL}/shopping-lists`; - - const body = JSON.stringify({ - name: name, - route_id: routeId - }); - - const response = await fetch(url, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - credentials: 'include', - body - }); - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - return response.json(); -}; \ No newline at end of file diff --git a/Frontend/shared/src/functions/createShoppingList/createShoppingList.ts b/Frontend/shared/src/functions/createShoppingList/createShoppingList.ts new file mode 100644 index 0000000..e060fb6 --- /dev/null +++ b/Frontend/shared/src/functions/createShoppingList/createShoppingList.ts @@ -0,0 +1,15 @@ +import { BASE_URL } from '@constants'; + +export const createShoppingList = async (name: string, routeId: any = null) => { + return fetch(`${BASE_URL}/shopping-lists`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include', + body: JSON.stringify({ + name: name, + route_id: routeId + }) + }); +}; \ No newline at end of file diff --git a/Frontend/shared/src/functions/createShoppingList/index.js b/Frontend/shared/src/functions/createShoppingList/index.ts similarity index 100% rename from Frontend/shared/src/functions/createShoppingList/index.js rename to Frontend/shared/src/functions/createShoppingList/index.ts diff --git a/Frontend/shared/src/functions/deleteGroceryItem/deleteGroceryItem.js b/Frontend/shared/src/functions/deleteGroceryItem/deleteGroceryItem.ts similarity index 58% rename from Frontend/shared/src/functions/deleteGroceryItem/deleteGroceryItem.js rename to Frontend/shared/src/functions/deleteGroceryItem/deleteGroceryItem.ts index 9607e8b..eefd6b5 100644 --- a/Frontend/shared/src/functions/deleteGroceryItem/deleteGroceryItem.js +++ b/Frontend/shared/src/functions/deleteGroceryItem/deleteGroceryItem.ts @@ -1,6 +1,7 @@ -import { BASE_URL } from '@constants/config'; +import { BASE_URL } from '@constants'; +import { GroceryItem } from '@types'; -export const deleteGroceryItem = async (item) => { +export const deleteGroceryItem = async (item: GroceryItem) => { fetch(`${BASE_URL}/grocery-items/${item.item_id}`, { method: 'DELETE', headers: { diff --git a/Frontend/shared/src/functions/deleteGroceryItem/index.js b/Frontend/shared/src/functions/deleteGroceryItem/index.ts similarity index 100% rename from Frontend/shared/src/functions/deleteGroceryItem/index.js rename to Frontend/shared/src/functions/deleteGroceryItem/index.ts diff --git a/Frontend/shared/src/functions/deleteShoppingList/deleteShoppingList.js b/Frontend/shared/src/functions/deleteShoppingList/deleteShoppingList.js deleted file mode 100644 index f32fa8b..0000000 --- a/Frontend/shared/src/functions/deleteShoppingList/deleteShoppingList.js +++ /dev/null @@ -1,20 +0,0 @@ -import { BASE_URL } from '@constants/config'; -/* -This is what item must look like: -{ - id: number; - name: string; - is_food: boolean; - quantity: number; - list_id: uuid (or Number, one of these?) -} -*/ -export const deleteShoppingList = async (listId) => { - return fetch(`${BASE_URL}/shopping-lists/${listId}`, { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - }, - credentials: 'include' // Include cookies in the request - }) -}; \ No newline at end of file diff --git a/Frontend/shared/src/functions/deleteShoppingList/deleteShoppingList.ts b/Frontend/shared/src/functions/deleteShoppingList/deleteShoppingList.ts new file mode 100644 index 0000000..1076c88 --- /dev/null +++ b/Frontend/shared/src/functions/deleteShoppingList/deleteShoppingList.ts @@ -0,0 +1,11 @@ +import { BASE_URL } from '@constants'; + +export const deleteShoppingList = async (listId: string) => { + return fetch(`${BASE_URL}/shopping-lists/${listId}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include' // Include cookies in the request + }) +}; \ No newline at end of file diff --git a/Frontend/shared/src/functions/deleteShoppingList/index.js b/Frontend/shared/src/functions/deleteShoppingList/index.ts similarity index 100% rename from Frontend/shared/src/functions/deleteShoppingList/index.js rename to Frontend/shared/src/functions/deleteShoppingList/index.ts diff --git a/Frontend/shared/src/functions/fetchGroceryItems/fetchGroceryItems.js b/Frontend/shared/src/functions/fetchGroceryItems/fetchGroceryItems.js deleted file mode 100644 index 05b7bc1..0000000 --- a/Frontend/shared/src/functions/fetchGroceryItems/fetchGroceryItems.js +++ /dev/null @@ -1,26 +0,0 @@ -import { BASE_URL } from '@constants/config'; - -export const fetchGroceryItems = async (listId) => { - const url = `${BASE_URL}/grocery-items/${listId}`; - - const response = await fetch(url, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - // Add any authorization headers if needed - }, - credentials: "include" - }); - - if (!response.ok) { - throw new Error(`Failed to fetch grocery items for shopping list with ID ${listId}`); - } - - // Clone the response before reading it as text - //const clonedResponse = response.clone(); - // Log the response body as text (debugging use only) - //console.log('fetchGroceryItems response:', await clonedResponse.text()); - - // Return JSON response - return response.json(); -}; \ No newline at end of file diff --git a/Frontend/shared/src/functions/fetchGroceryItems/fetchGroceryItems.ts b/Frontend/shared/src/functions/fetchGroceryItems/fetchGroceryItems.ts new file mode 100644 index 0000000..87d7d03 --- /dev/null +++ b/Frontend/shared/src/functions/fetchGroceryItems/fetchGroceryItems.ts @@ -0,0 +1,12 @@ +import { BASE_URL } from '@constants'; + +export const fetchGroceryItems = async (listId: string) => { + + return fetch(`${BASE_URL}/grocery-items/${listId}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include', + }); +}; diff --git a/Frontend/shared/src/functions/fetchGroceryItems/index.js b/Frontend/shared/src/functions/fetchGroceryItems/index.ts similarity index 100% rename from Frontend/shared/src/functions/fetchGroceryItems/index.js rename to Frontend/shared/src/functions/fetchGroceryItems/index.ts diff --git a/Frontend/shared/src/functions/fetchOwnedShoppingLists/fetchOwnedShoppingLists.js b/Frontend/shared/src/functions/fetchOwnedShoppingLists/fetchOwnedShoppingLists.ts similarity index 85% rename from Frontend/shared/src/functions/fetchOwnedShoppingLists/fetchOwnedShoppingLists.js rename to Frontend/shared/src/functions/fetchOwnedShoppingLists/fetchOwnedShoppingLists.ts index cb62d22..dc1baba 100644 --- a/Frontend/shared/src/functions/fetchOwnedShoppingLists/fetchOwnedShoppingLists.js +++ b/Frontend/shared/src/functions/fetchOwnedShoppingLists/fetchOwnedShoppingLists.ts @@ -1,4 +1,4 @@ -import { BASE_URL } from '@constants/config'; +import { BASE_URL } from '@constants'; export const fetchOwnedShoppingLists = () => { return fetch(`${BASE_URL}/shopping-lists`, { diff --git a/Frontend/shared/src/functions/fetchOwnedShoppingLists/index.js b/Frontend/shared/src/functions/fetchOwnedShoppingLists/index.ts similarity index 100% rename from Frontend/shared/src/functions/fetchOwnedShoppingLists/index.js rename to Frontend/shared/src/functions/fetchOwnedShoppingLists/index.ts diff --git a/Frontend/shared/src/functions/fetchSharedShoppingLists/fetchSharedShoppingLists.js b/Frontend/shared/src/functions/fetchSharedShoppingLists/fetchSharedShoppingLists.ts similarity index 85% rename from Frontend/shared/src/functions/fetchSharedShoppingLists/fetchSharedShoppingLists.js rename to Frontend/shared/src/functions/fetchSharedShoppingLists/fetchSharedShoppingLists.ts index a660a6a..4eac7c5 100644 --- a/Frontend/shared/src/functions/fetchSharedShoppingLists/fetchSharedShoppingLists.js +++ b/Frontend/shared/src/functions/fetchSharedShoppingLists/fetchSharedShoppingLists.ts @@ -1,4 +1,4 @@ -import { BASE_URL } from '@constants/config'; +import { BASE_URL } from '@constants'; export const fetchSharedShoppingLists = () => { return fetch(`${BASE_URL}/shopping-lists/shared`, { diff --git a/Frontend/shared/src/functions/fetchSharedShoppingLists/index.js b/Frontend/shared/src/functions/fetchSharedShoppingLists/index.ts similarity index 100% rename from Frontend/shared/src/functions/fetchSharedShoppingLists/index.js rename to Frontend/shared/src/functions/fetchSharedShoppingLists/index.ts diff --git a/Frontend/shared/src/functions/fetchShoppingList/fetchShoppingList.js b/Frontend/shared/src/functions/fetchShoppingList/fetchShoppingList.ts similarity index 81% rename from Frontend/shared/src/functions/fetchShoppingList/fetchShoppingList.js rename to Frontend/shared/src/functions/fetchShoppingList/fetchShoppingList.ts index ecd19f3..8610659 100644 --- a/Frontend/shared/src/functions/fetchShoppingList/fetchShoppingList.js +++ b/Frontend/shared/src/functions/fetchShoppingList/fetchShoppingList.ts @@ -1,6 +1,6 @@ -import { BASE_URL } from '@constants/config'; +import { BASE_URL } from '@constants'; -export const fetchShoppingList = async (listId) => { +export const fetchShoppingList = async (listId: string) => { const url = `${BASE_URL}/shopping-lists/${listId}`; const response = await fetch(url, { diff --git a/Frontend/shared/src/functions/fetchShoppingList/index.js b/Frontend/shared/src/functions/fetchShoppingList/index.ts similarity index 100% rename from Frontend/shared/src/functions/fetchShoppingList/index.js rename to Frontend/shared/src/functions/fetchShoppingList/index.ts diff --git a/Frontend/shared/src/functions/index.js b/Frontend/shared/src/functions/index.ts similarity index 100% rename from Frontend/shared/src/functions/index.js rename to Frontend/shared/src/functions/index.ts diff --git a/Frontend/shared/src/functions/updateGroceryItem/index.js b/Frontend/shared/src/functions/updateGroceryItem/index.ts similarity index 100% rename from Frontend/shared/src/functions/updateGroceryItem/index.js rename to Frontend/shared/src/functions/updateGroceryItem/index.ts diff --git a/Frontend/shared/src/functions/updateGroceryItem/updateGroceryItem.js b/Frontend/shared/src/functions/updateGroceryItem/updateGroceryItem.ts similarity index 61% rename from Frontend/shared/src/functions/updateGroceryItem/updateGroceryItem.js rename to Frontend/shared/src/functions/updateGroceryItem/updateGroceryItem.ts index c937866..66337ff 100644 --- a/Frontend/shared/src/functions/updateGroceryItem/updateGroceryItem.js +++ b/Frontend/shared/src/functions/updateGroceryItem/updateGroceryItem.ts @@ -1,6 +1,7 @@ -import { BASE_URL } from '@constants/config'; +import { BASE_URL } from '@constants'; +import { GroceryItem } from '@types'; -export const updateGroceryItem = async (item) => { +export const updateGroceryItem = async (item: GroceryItem) => { return fetch(`${BASE_URL}/grocery-items/${item.item_id}`, { method: 'PUT', headers: { diff --git a/Frontend/shared/src/functions/updateShoppingListTItle/index.js b/Frontend/shared/src/functions/updateShoppingListTItle/index.ts similarity index 100% rename from Frontend/shared/src/functions/updateShoppingListTItle/index.js rename to Frontend/shared/src/functions/updateShoppingListTItle/index.ts diff --git a/Frontend/shared/src/functions/updateShoppingListTItle/updateShoppingListTitle.js b/Frontend/shared/src/functions/updateShoppingListTItle/updateShoppingListTitle.ts similarity index 65% rename from Frontend/shared/src/functions/updateShoppingListTItle/updateShoppingListTitle.js rename to Frontend/shared/src/functions/updateShoppingListTItle/updateShoppingListTitle.ts index f9f2a2c..701d737 100644 --- a/Frontend/shared/src/functions/updateShoppingListTItle/updateShoppingListTitle.js +++ b/Frontend/shared/src/functions/updateShoppingListTItle/updateShoppingListTitle.ts @@ -1,6 +1,6 @@ -import { BASE_URL } from '@constants/config'; +import { BASE_URL } from '@constants'; -export const updateShoppingListTitle = async (shoppingListName, shoppingListId) => { +export const updateShoppingListTitle = async (shoppingListName: string, shoppingListId: string) => { return fetch(`${BASE_URL}/shopping-lists/${shoppingListId}`, { method: 'PUT', headers: { diff --git a/Frontend/shared/src/hooks/AuthContext/AuthContext.js b/Frontend/shared/src/hooks/AuthContext/AuthContext.tsx similarity index 72% rename from Frontend/shared/src/hooks/AuthContext/AuthContext.js rename to Frontend/shared/src/hooks/AuthContext/AuthContext.tsx index bc9922e..82cc5c6 100644 --- a/Frontend/shared/src/hooks/AuthContext/AuthContext.js +++ b/Frontend/shared/src/hooks/AuthContext/AuthContext.tsx @@ -1,34 +1,29 @@ import React, { createContext, useContext, useState, useEffect } from "react"; import { jwtDecode } from "jwt-decode"; import { googleLogout } from "@react-oauth/google"; -import { BASE_URL } from '@constants/config'; -// Create the context -const AuthContext = createContext(); - -// Helper function to get the CSRF token from the cookies -const getCookie = (name) => { - const value = `; ${document.cookie}`; - const parts = value.split(`; ${name}=`); - if (parts.length === 2) return parts.pop().split(";").shift(); -}; +import { BASE_URL } from '@constants'; +import { AuthContextType } from "./AuthContextType"; +import { GoogleToken } from "@types"; +// Initialize the context with a default value of `null` +const AuthContext = createContext(null); // Create a provider component -export const AuthProvider = ({ children }) => { - const [isAuthenticated, setIsAuthenticated] = useState(true); - const [userPicture, setUserPicture] = useState(null); +export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { + const [isAuthenticated, setIsAuthenticated] = useState(false); + const [userPictureLink, setUserPictureLink] = useState(null); useEffect(() => { const token = localStorage.getItem("speedcart_auth_exists"); - if (token) { + if (token === "true") { setIsAuthenticated(true); - setUserPicture(localStorage.getItem("userImageUrl")); + setUserPictureLink(localStorage.getItem("userImageUrl")); } else { setIsAuthenticated(false); } }, []); - const login = (token) => { - const userInfo = jwtDecode(JSON.parse(token).credential); + const login = (token: string) => { + const userInfo: GoogleToken = jwtDecode(JSON.parse(token).credential); // Initialize CSRF protection for the application fetch(`${BASE_URL}/sanctum/csrf-cookie`, { @@ -56,7 +51,7 @@ export const AuthProvider = ({ children }) => { if (response.status === 200) { setIsAuthenticated(true); localStorage.setItem("speedcart_auth_bearer_token", token); - localStorage.setItem("speedcart_auth_exists", true); + localStorage.setItem("speedcart_auth_exists", 'true'); localStorage.setItem("userImageUrl", userInfo.picture); } return response.json(); @@ -71,7 +66,7 @@ export const AuthProvider = ({ children }) => { console.error("Error:", error); }); setIsAuthenticated(true); - setUserPicture(userInfo.picture); + setUserPictureLink(userInfo.picture); } ); @@ -94,15 +89,21 @@ export const AuthProvider = ({ children }) => { localStorage.removeItem("speedcart_auth_exists"); localStorage.removeItem("userImageUrl"); setIsAuthenticated(false); - setUserPicture(null); + setUserPictureLink(null); }) .catch((error) => { console.error("Error:", error); }); }; - return {children}; + return {children}; }; // Create a custom hook to use the AuthContext -export const useAuth = () => useContext(AuthContext); \ No newline at end of file +export const useAuth = (): AuthContextType => { + const context: AuthContextType = useContext(AuthContext); + if (!context) { + throw new Error("useAuth must be used within an AuthProvider"); + } + return context; +}; \ No newline at end of file diff --git a/Frontend/shared/src/hooks/AuthContext/AuthContextType.ts b/Frontend/shared/src/hooks/AuthContext/AuthContextType.ts new file mode 100644 index 0000000..25474a4 --- /dev/null +++ b/Frontend/shared/src/hooks/AuthContext/AuthContextType.ts @@ -0,0 +1,7 @@ +// Create an interface for AuthContext +export interface AuthContextType { + isAuthenticated: boolean; + userPictureLink: string | null; + login: (token: string) => void; + logout: () => void; +} \ No newline at end of file diff --git a/Frontend/shared/src/hooks/AuthContext/index.d.ts b/Frontend/shared/src/hooks/AuthContext/index.d.ts new file mode 100644 index 0000000..d4ec837 --- /dev/null +++ b/Frontend/shared/src/hooks/AuthContext/index.d.ts @@ -0,0 +1,6 @@ +import React from 'react'; +import { AuthContextType } from './AuthContextType'; +declare module 'AuthContext' { + export const AuthProvider: React.FC<{ children: React.ReactNode }>; + export const useAuth: AuthContextType; +} \ No newline at end of file diff --git a/Frontend/shared/src/hooks/AuthContext/index.js b/Frontend/shared/src/hooks/AuthContext/index.js deleted file mode 100644 index 016830a..0000000 --- a/Frontend/shared/src/hooks/AuthContext/index.js +++ /dev/null @@ -1 +0,0 @@ -export { AuthProvider, useAuth } from "./AuthContext.js"; diff --git a/Frontend/shared/src/hooks/AuthContext/index.ts b/Frontend/shared/src/hooks/AuthContext/index.ts new file mode 100644 index 0000000..d461e21 --- /dev/null +++ b/Frontend/shared/src/hooks/AuthContext/index.ts @@ -0,0 +1,2 @@ +export { AuthProvider, useAuth } from "./AuthContext"; +export { AuthContextType } from './AuthContextType'; \ No newline at end of file diff --git a/Frontend/shared/src/hooks/index.js b/Frontend/shared/src/hooks/index.ts similarity index 100% rename from Frontend/shared/src/hooks/index.js rename to Frontend/shared/src/hooks/index.ts diff --git a/Frontend/shared/src/index.js b/Frontend/shared/src/index.js deleted file mode 100644 index 61b6100..0000000 --- a/Frontend/shared/src/index.js +++ /dev/null @@ -1,6 +0,0 @@ -// shared/index.js -//export * from "./components"; -export * from "./hooks"; -export * from './constants'; -// Function exports (purely functional code; no UI content) -export * from "./functions"; \ No newline at end of file diff --git a/Frontend/shared/src/index.ts b/Frontend/shared/src/index.ts new file mode 100644 index 0000000..c7d0dd1 --- /dev/null +++ b/Frontend/shared/src/index.ts @@ -0,0 +1,8 @@ +// shared/index.js +//export * from "./components"; +export * from "./hooks"; +export * from './constants/BaseUrl'; +// Function exports (purely functional code; no UI content) +export * from "./functions"; +//export {default as GroceryItem} from './types/GroceryItem'; +export { GroceryItem, GoogleToken } from './types'; \ No newline at end of file diff --git a/Frontend/shared/src/types/GoogleToken.ts b/Frontend/shared/src/types/GoogleToken.ts new file mode 100644 index 0000000..1822257 --- /dev/null +++ b/Frontend/shared/src/types/GoogleToken.ts @@ -0,0 +1,3 @@ +export interface GoogleToken { + picture: string; +}; \ No newline at end of file diff --git a/Frontend/shared/src/types/GroceryItem.ts b/Frontend/shared/src/types/GroceryItem.ts new file mode 100644 index 0000000..57b1d86 --- /dev/null +++ b/Frontend/shared/src/types/GroceryItem.ts @@ -0,0 +1,7 @@ +export interface GroceryItem { + item_id: number; + name: string; + is_food: boolean; + quantity: number; + list_id: any; // This is technically a uuid value +} \ No newline at end of file diff --git a/Frontend/shared/src/types/index.d.ts b/Frontend/shared/src/types/index.d.ts new file mode 100644 index 0000000..2df16aa --- /dev/null +++ b/Frontend/shared/src/types/index.d.ts @@ -0,0 +1,3 @@ +// src/types/index.d.ts +export * from "./GroceryItem"; +export * from "./GoogleToken"; \ No newline at end of file diff --git a/Frontend/shared/tsconfig.json b/Frontend/shared/tsconfig.json new file mode 100644 index 0000000..b1d6781 --- /dev/null +++ b/Frontend/shared/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es5", + "baseUrl": "./", // Base directory for resolving non-relative module names + "paths": { + "@constants": ["src/constants"], + "@types": ["src/types"] + }, + "module": "commonjs", + "lib": ["es6", "dom"], + "jsx": "react", + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "declaration": true, + "strictNullChecks": false, + "moduleResolution": "node", + "esModuleInterop": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true + }, + "include": ["src"], + "exclude": ["node_modules", "dist"] +} \ No newline at end of file diff --git a/Frontend/speedcart-react/jsconfig.json b/Frontend/speedcart-react/jsconfig.json deleted file mode 100644 index 950880b..0000000 --- a/Frontend/speedcart-react/jsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "baseUrl": ".", - "paths": { - "shared/*": ["../shared/src/*"] - } - }, - "include": ["src/**/*"] -} \ No newline at end of file diff --git a/Frontend/speedcart-react/src/App.js b/Frontend/speedcart-react/src/App.tsx similarity index 94% rename from Frontend/speedcart-react/src/App.js rename to Frontend/speedcart-react/src/App.tsx index bc5ef45..8f12f5d 100644 --- a/Frontend/speedcart-react/src/App.js +++ b/Frontend/speedcart-react/src/App.tsx @@ -6,7 +6,7 @@ import Footer from '@components/Footer'; import Modal from '@components/Modal'; import SitePolicies from '@components/SitePolicies'; -import { AppRoute } from '@constants/routes.ts'; +import { AppRoute } from '@constants/routes'; import Home from '@pages/Home'; import ShoppingListShare from '@pages/ShoppingListShare'; @@ -28,7 +28,7 @@ function App() { }, []); const handleSitePoliciesAccept = () => { - localStorage.setItem('acceptedSitePolicies', true); + localStorage.setItem('acceptedSitePolicies', 'true'); setShowSitePolicies(false); }; diff --git a/Frontend/speedcart-react/src/components/AddShoppingListItemButton/AddShoppingListItemButton.js b/Frontend/speedcart-react/src/components/AddShoppingListItemButton/AddShoppingListItemButton.tsx similarity index 100% rename from Frontend/speedcart-react/src/components/AddShoppingListItemButton/AddShoppingListItemButton.js rename to Frontend/speedcart-react/src/components/AddShoppingListItemButton/AddShoppingListItemButton.tsx diff --git a/Frontend/speedcart-react/src/components/AddShoppingListItemButton/index.js b/Frontend/speedcart-react/src/components/AddShoppingListItemButton/index.ts similarity index 100% rename from Frontend/speedcart-react/src/components/AddShoppingListItemButton/index.js rename to Frontend/speedcart-react/src/components/AddShoppingListItemButton/index.ts diff --git a/Frontend/speedcart-react/src/components/CustomCheckbox/CustomCheckbox.js b/Frontend/speedcart-react/src/components/CustomCheckbox/CustomCheckbox.tsx similarity index 63% rename from Frontend/speedcart-react/src/components/CustomCheckbox/CustomCheckbox.js rename to Frontend/speedcart-react/src/components/CustomCheckbox/CustomCheckbox.tsx index 8428331..146225f 100644 --- a/Frontend/speedcart-react/src/components/CustomCheckbox/CustomCheckbox.js +++ b/Frontend/speedcart-react/src/components/CustomCheckbox/CustomCheckbox.tsx @@ -1,15 +1,16 @@ import React from 'react'; import styles from './CustomCheckbox.module.css'; -const CustomCheckbox = ({ checked = false, onChange, children, disabled = false }) => { +const CustomCheckbox = ({ name = '', className = '', checked = false, onChange = null, disabled = false, children}) => { return ( -